program XXOR
  implicit none
  integer :: n, m, i, j
  integer(8) :: k, a(100000) = 0_8, x = 0_8, f = 0_8
  read(*,*) n, k
  read(*,*) a(1:n)
  do i = 40, 0, -1
    m = 0
    do j = 1, n
      if (btest(a(j),i)) m = m+1
    end do
    if (m < n-m) x = ibset(x,i)
    if (x > k) x = ibclr(x,i)
  end do
  do i = 1, n
    f = f+xor(x,a(i))
  end do
  write(*,'(i0)') f
end program XXOR
; ModuleID = 'FIRModule'
source_filename = "FIRModule"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

@_QFEa = internal global [100000 x i64] zeroinitializer
@_QFEf = internal unnamed_addr global i64 0
@_QFEx = internal unnamed_addr global i64 0
@_QQcl.93441a741444c4d2c4e9f1a6b46dc1ed = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_5029/source.f\00"
@_QQcl.28693029 = linkonce constant [4 x i8] c"(i0)"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

define void @_QQmain() local_unnamed_addr {
  %1 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %2 = alloca i64, align 8
  %3 = alloca i32, align 4
  %4 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.93441a741444c4d2c4e9f1a6b46dc1ed, i32 5)
  %5 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %3, i32 4)
  %6 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %2, i32 8)
  %7 = call i32 @_FortranAioEndIoStatement(ptr %4)
  %8 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.93441a741444c4d2c4e9f1a6b46dc1ed, i32 6)
  %9 = load i32, ptr %3, align 4, !tbaa !3
  %10 = call i32 @llvm.smax.i32(i32 %9, i32 0)
  %11 = zext i32 %10 to i64
  store ptr @_QFEa, ptr %1, align 8, !tbaa !7
  %.fca.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 1
  store i64 8, ptr %.fca.1.gep, align 8, !tbaa !7
  %.fca.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 2
  store i32 20180515, ptr %.fca.2.gep, align 8, !tbaa !7
  %.fca.3.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 3
  store i8 1, ptr %.fca.3.gep, align 4, !tbaa !7
  %.fca.4.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 4
  store i8 10, ptr %.fca.4.gep, align 1, !tbaa !7
  %.fca.5.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 5
  store i8 0, ptr %.fca.5.gep, align 2, !tbaa !7
  %.fca.6.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 6
  store i8 0, ptr %.fca.6.gep, align 1, !tbaa !7
  %.fca.7.0.0.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 0
  store i64 1, ptr %.fca.7.0.0.gep, align 8, !tbaa !7
  %.fca.7.0.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 1
  store i64 %11, ptr %.fca.7.0.1.gep, align 8, !tbaa !7
  %.fca.7.0.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 2
  store i64 8, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  %12 = call i1 @_FortranAioInputDescriptor(ptr %8, ptr nonnull %1)
  %13 = call i32 @_FortranAioEndIoStatement(ptr %8)
  %14 = load i32, ptr %3, align 4, !tbaa !3
  %15 = sext i32 %14 to i64
  %16 = icmp sgt i32 %14, 0
  %17 = load i64, ptr %2, align 8, !tbaa !3
  %_QFEx.promoted = load i64, ptr @_QFEx, align 8, !tbaa !3
  br i1 %16, label %.lr.ph.us.preheader, label %.split.split

.lr.ph.us.preheader:                              ; preds = %0
  %min.iters.check = icmp ult i32 %14, 4
  %n.vec = and i64 %15, -4
  %ind.end = or i64 %n.vec, 1
  %cmp.n = icmp eq i64 %n.vec, %15
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %34
  %indvars.iv23 = phi i64 [ %indvars.iv.next24, %34 ], [ 40, %.lr.ph.us.preheader ]
  %18 = phi i64 [ %35, %34 ], [ 41, %.lr.ph.us.preheader ]
  %19 = phi i64 [ %46, %34 ], [ %_QFEx.promoted, %.lr.ph.us.preheader ]
  %20 = shl nuw i64 1, %indvars.iv23
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.us
  %broadcast.splatinsert = insertelement <2 x i64> poison, i64 %20, i64 0
  %broadcast.splat = shufflevector <2 x i64> %broadcast.splatinsert, <2 x i64> poison, <2 x i32> zeroinitializer
  %broadcast.splatinsert41 = insertelement <2 x i64> poison, i64 %20, i64 0
  %broadcast.splat42 = shufflevector <2 x i64> %broadcast.splatinsert41, <2 x i64> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <2 x i32> [ zeroinitializer, %vector.ph ], [ %29, %vector.body ]
  %vec.phi39 = phi <2 x i32> [ zeroinitializer, %vector.ph ], [ %30, %vector.body ]
  %21 = getelementptr [100000 x i64], ptr @_QFEa, i64 0, i64 %index
  %wide.load = load <2 x i64>, ptr %21, align 16, !tbaa !3
  %22 = getelementptr i64, ptr %21, i64 2
  %wide.load40 = load <2 x i64>, ptr %22, align 16, !tbaa !3
  %23 = and <2 x i64> %wide.load, %broadcast.splat
  %24 = and <2 x i64> %wide.load40, %broadcast.splat42
  %25 = icmp ne <2 x i64> %23, zeroinitializer
  %26 = icmp ne <2 x i64> %24, zeroinitializer
  %27 = zext <2 x i1> %25 to <2 x i32>
  %28 = zext <2 x i1> %26 to <2 x i32>
  %29 = add <2 x i32> %vec.phi, %27
  %30 = add <2 x i32> %vec.phi39, %28
  %index.next = add nuw i64 %index, 4
  %31 = icmp eq i64 %index.next, %n.vec
  br i1 %31, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <2 x i32> %30, %29
  %32 = call i32 @llvm.vector.reduce.add.v2i32(<2 x i32> %bin.rdx)
  br i1 %cmp.n, label %._crit_edge.us, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %.lr.ph.us, %middle.block
  %indvars.iv20.ph = phi i64 [ 1, %.lr.ph.us ], [ %ind.end, %middle.block ]
  %.014.us.ph = phi i32 [ 0, %.lr.ph.us ], [ %32, %middle.block ]
  br label %scalar.ph

33:                                               ; preds = %._crit_edge.us
  store i64 %46, ptr @_QFEx, align 8, !tbaa !3
  br label %34

34:                                               ; preds = %._crit_edge.us, %33
  %indvars.iv.next24 = add nsw i64 %indvars.iv23, -1
  %35 = add nsw i64 %18, -1
  %.not30 = icmp eq i64 %35, 0
  br i1 %.not30, label %.split16.us, label %.lr.ph.us

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv20 = phi i64 [ %indvars.iv.next21, %scalar.ph ], [ %indvars.iv20.ph, %scalar.ph.preheader ]
  %.014.us = phi i32 [ %spec.select.us, %scalar.ph ], [ %.014.us.ph, %scalar.ph.preheader ]
  %36 = add nsw i64 %indvars.iv20, -1
  %37 = getelementptr [100000 x i64], ptr @_QFEa, i64 0, i64 %36
  %38 = load i64, ptr %37, align 8, !tbaa !3
  %39 = and i64 %38, %20
  %.not.us = icmp ne i64 %39, 0
  %40 = zext i1 %.not.us to i32
  %spec.select.us = add i32 %.014.us, %40
  %indvars.iv.next21 = add nuw nsw i64 %indvars.iv20, 1
  %exitcond.not = icmp eq i64 %indvars.iv20, %15
  br i1 %exitcond.not, label %._crit_edge.us, label %scalar.ph, !llvm.loop !12

._crit_edge.us:                                   ; preds = %scalar.ph, %middle.block
  %spec.select.us.lcssa = phi i32 [ %32, %middle.block ], [ %spec.select.us, %scalar.ph ]
  %41 = sub i32 %14, %spec.select.us.lcssa
  %.not34 = icmp slt i32 %spec.select.us.lcssa, %41
  %42 = select i1 %.not34, i64 %20, i64 0
  %43 = or i64 %19, %42
  %.not35 = icmp sgt i64 %43, %17
  %44 = xor i64 %20, -1
  %45 = and i64 %19, %44
  %46 = select i1 %.not35, i64 %45, i64 %43
  %47 = or i1 %.not34, %.not35
  br i1 %47, label %33, label %34

.split.split:                                     ; preds = %0, %62
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %62 ], [ 40, %0 ]
  %48 = phi i64 [ %64, %62 ], [ 41, %0 ]
  %49 = phi i64 [ %63, %62 ], [ %_QFEx.promoted, %0 ]
  %50 = icmp sgt i64 %49, %17
  br i1 %50, label %51, label %55

51:                                               ; preds = %.split.split
  %52 = shl nuw i64 1, %indvars.iv
  %53 = xor i64 %52, -1
  %54 = and i64 %49, %53
  store i64 %54, ptr @_QFEx, align 8, !tbaa !3
  br label %55

55:                                               ; preds = %51, %.split.split
  %56 = phi i64 [ %54, %51 ], [ %49, %.split.split ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %.not = icmp eq i64 %48, 1
  br i1 %.not, label %.split16.us, label %.split.split.1

.split.split.1:                                   ; preds = %55
  %57 = icmp sgt i64 %56, %17
  br i1 %57, label %58, label %62

58:                                               ; preds = %.split.split.1
  %59 = shl nuw i64 1, %indvars.iv.next
  %60 = xor i64 %59, -1
  %61 = and i64 %56, %60
  store i64 %61, ptr @_QFEx, align 8, !tbaa !3
  br label %62

62:                                               ; preds = %58, %.split.split.1
  %63 = phi i64 [ %61, %58 ], [ %56, %.split.split.1 ]
  %indvars.iv.next.1 = add nsw i64 %indvars.iv, -2
  %64 = add nsw i64 %48, -2
  br label %.split.split

.split16.us:                                      ; preds = %55, %34
  %65 = phi i64 [ %46, %34 ], [ %56, %55 ]
  br i1 %16, label %.lr.ph, label %81

.lr.ph:                                           ; preds = %.split16.us
  %_QFEf.promoted = load i64, ptr @_QFEf, align 8, !tbaa !3
  %min.iters.check45 = icmp ult i32 %14, 4
  br i1 %min.iters.check45, label %scalar.ph44.preheader, label %vector.ph46

vector.ph46:                                      ; preds = %.lr.ph
  %n.vec48 = and i64 %15, -4
  %ind.end49 = or i64 %n.vec48, 1
  %66 = insertelement <2 x i64> <i64 poison, i64 0>, i64 %_QFEf.promoted, i64 0
  %broadcast.splatinsert59 = insertelement <2 x i64> poison, i64 %65, i64 0
  %broadcast.splat60 = shufflevector <2 x i64> %broadcast.splatinsert59, <2 x i64> poison, <2 x i32> zeroinitializer
  %broadcast.splatinsert61 = insertelement <2 x i64> poison, i64 %65, i64 0
  %broadcast.splat62 = shufflevector <2 x i64> %broadcast.splatinsert61, <2 x i64> poison, <2 x i32> zeroinitializer
  br label %vector.body52

vector.body52:                                    ; preds = %vector.body52, %vector.ph46
  %index53 = phi i64 [ 0, %vector.ph46 ], [ %index.next63, %vector.body52 ]
  %vec.phi54 = phi <2 x i64> [ %66, %vector.ph46 ], [ %71, %vector.body52 ]
  %vec.phi55 = phi <2 x i64> [ zeroinitializer, %vector.ph46 ], [ %72, %vector.body52 ]
  %67 = getelementptr [100000 x i64], ptr @_QFEa, i64 0, i64 %index53
  %wide.load57 = load <2 x i64>, ptr %67, align 16, !tbaa !3
  %68 = getelementptr i64, ptr %67, i64 2
  %wide.load58 = load <2 x i64>, ptr %68, align 16, !tbaa !3
  %69 = xor <2 x i64> %wide.load57, %broadcast.splat60
  %70 = xor <2 x i64> %wide.load58, %broadcast.splat62
  %71 = add <2 x i64> %69, %vec.phi54
  %72 = add <2 x i64> %70, %vec.phi55
  %index.next63 = add nuw i64 %index53, 4
  %73 = icmp eq i64 %index.next63, %n.vec48
  br i1 %73, label %middle.block43, label %vector.body52, !llvm.loop !13

middle.block43:                                   ; preds = %vector.body52
  %bin.rdx64 = add <2 x i64> %72, %71
  %74 = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %bin.rdx64)
  %cmp.n51 = icmp eq i64 %n.vec48, %15
  br i1 %cmp.n51, label %._crit_edge, label %scalar.ph44.preheader

scalar.ph44.preheader:                            ; preds = %.lr.ph, %middle.block43
  %indvars.iv26.ph = phi i64 [ 1, %.lr.ph ], [ %ind.end49, %middle.block43 ]
  %.ph = phi i64 [ %_QFEf.promoted, %.lr.ph ], [ %74, %middle.block43 ]
  br label %scalar.ph44

scalar.ph44:                                      ; preds = %scalar.ph44.preheader, %scalar.ph44
  %indvars.iv26 = phi i64 [ %indvars.iv.next27, %scalar.ph44 ], [ %indvars.iv26.ph, %scalar.ph44.preheader ]
  %75 = phi i64 [ %80, %scalar.ph44 ], [ %.ph, %scalar.ph44.preheader ]
  %76 = add nsw i64 %indvars.iv26, -1
  %77 = getelementptr [100000 x i64], ptr @_QFEa, i64 0, i64 %76
  %78 = load i64, ptr %77, align 8, !tbaa !3
  %79 = xor i64 %78, %65
  %80 = add i64 %79, %75
  %indvars.iv.next27 = add nuw nsw i64 %indvars.iv26, 1
  %exitcond29.not = icmp eq i64 %indvars.iv26, %15
  br i1 %exitcond29.not, label %._crit_edge, label %scalar.ph44, !llvm.loop !14

._crit_edge:                                      ; preds = %scalar.ph44, %middle.block43
  %.lcssa = phi i64 [ %74, %middle.block43 ], [ %80, %scalar.ph44 ]
  store i64 %.lcssa, ptr @_QFEf, align 8, !tbaa !3
  br label %81

81:                                               ; preds = %._crit_edge, %.split16.us
  %82 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.93441a741444c4d2c4e9f1a6b46dc1ed, i32 18)
  %83 = load i64, ptr @_QFEf, align 8, !tbaa !3
  %84 = call i1 @_FortranAioOutputInteger64(ptr %82, i64 %83)
  %85 = call i32 @_FortranAioEndIoStatement(ptr %82)
  ret void
}

declare ptr @_FortranAioBeginExternalListInput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioInputInteger(ptr, ptr, i32) local_unnamed_addr

declare i32 @_FortranAioEndIoStatement(ptr) local_unnamed_addr

declare i1 @_FortranAioInputDescriptor(ptr, ptr) local_unnamed_addr

declare ptr @_FortranAioBeginExternalFormattedOutput(ptr, i64, ptr, i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger64(ptr, i64) local_unnamed_addr

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v2i32(<2 x i32>) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.vector.reduce.add.v2i64(<2 x i64>) #1

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(none) }

!llvm.module.flags = !{!0, !1, !2}

!0 = !{i32 2, !"Debug Info Version", i32 3}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{!4, !4, i64 0}
!4 = !{!"any data access", !5, i64 0}
!5 = !{!"any access", !6, i64 0}
!6 = !{!"Flang Type TBAA Root"}
!7 = !{!8, !8, i64 0}
!8 = !{!"descriptor member", !5, i64 0}
!9 = distinct !{!9, !10, !11}
!10 = !{!"llvm.loop.isvectorized", i32 1}
!11 = !{!"llvm.loop.unroll.runtime.disable"}
!12 = distinct !{!12, !11, !10}
!13 = distinct !{!13, !10, !11}
!14 = distinct !{!14, !11, !10}
