; LLVM IR from tangjz/acm-icpc :: self_training/2015-04-17 (C)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@gray = external dso_local global [1048576 x i32], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %19, %0
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = icmp slt i32 %8, 1048576
  br i1 %9, label %11, label %10

10:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %22

11:                                               ; preds = %7
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = ashr i32 %13, 1
  %15 = xor i32 %12, %14
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [1048576 x i32], ptr @gray, i64 0, i64 %17
  store i32 %15, ptr %18, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %11
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %2, align 4, !tbaa !5
  br label %7, !llvm.loop !9

22:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %62, %22
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = load i32, ptr @n, align 4, !tbaa !5
  %26 = shl i32 1, %25
  %27 = icmp slt i32 %24, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %23
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %65

29:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %58, %29
  %31 = load i32, ptr %5, align 4, !tbaa !5
  %32 = load i32, ptr @m, align 4, !tbaa !5
  %33 = shl i32 1, %32
  %34 = icmp slt i32 %31, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %30
  store i32 8, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %61

36:                                               ; preds = %30
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [1048576 x i32], ptr @gray, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = load i32, ptr @m, align 4, !tbaa !5
  %42 = shl i32 %40, %41
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [1048576 x i32], ptr @gray, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = add nsw i32 %42, %46
  %48 = load i32, ptr %5, align 4, !tbaa !5
  %49 = load i32, ptr @m, align 4, !tbaa !5
  %50 = shl i32 1, %49
  %51 = sub nsw i32 %50, 1
  %52 = icmp eq i32 %48, %51
  %53 = zext i1 %52 to i64
  %54 = getelementptr inbounds [3 x i8], ptr @.str.2, i64 0, i64 %53
  %55 = load i8, ptr %54, align 1, !tbaa !11
  %56 = sext i8 %55 to i32
  %57 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %47, i32 noundef %56)
  br label %58

58:                                               ; preds = %36
  %59 = load i32, ptr %5, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %5, align 4, !tbaa !5
  br label %30, !llvm.loop !12

61:                                               ; preds = %35
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %3, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %3, align 4, !tbaa !5
  br label %23, !llvm.loop !13

65:                                               ; preds = %28
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

declare i32 @printf(ptr noundef, ...) #1

attributes #0 = { mustprogress norecurse uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nounwind }

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

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@gray = external dso_local local_unnamed_addr global [1048576 x i32], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
vector.ph:
  %0 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next.1, %vector.body ]
  %vec.ind = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %vector.ph ], [ %vec.ind.next.1, %vector.body ]
  %step.add = add <4 x i32> %vec.ind, <i32 4, i32 4, i32 4, i32 4>
  %1 = lshr <4 x i32> %vec.ind, <i32 1, i32 1, i32 1, i32 1>
  %2 = lshr <4 x i32> %step.add, <i32 1, i32 1, i32 1, i32 1>
  %3 = xor <4 x i32> %1, %vec.ind
  %4 = xor <4 x i32> %2, %step.add
  %5 = getelementptr inbounds [1048576 x i32], ptr @gray, i64 0, i64 %index
  %6 = getelementptr inbounds i8, ptr %5, i64 16
  store <4 x i32> %3, ptr %5, align 16, !tbaa !5
  store <4 x i32> %4, ptr %6, align 16, !tbaa !5
  %index.next = or disjoint i64 %index, 8
  %vec.ind.next = add <4 x i32> %vec.ind, <i32 8, i32 8, i32 8, i32 8>
  %step.add.1 = add <4 x i32> %vec.ind, <i32 12, i32 12, i32 12, i32 12>
  %7 = lshr <4 x i32> %vec.ind.next, <i32 1, i32 1, i32 1, i32 1>
  %8 = lshr <4 x i32> %step.add.1, <i32 1, i32 1, i32 1, i32 1>
  %9 = xor <4 x i32> %7, %vec.ind.next
  %10 = xor <4 x i32> %8, %step.add.1
  %11 = getelementptr inbounds [1048576 x i32], ptr @gray, i64 0, i64 %index.next
  %12 = getelementptr inbounds i8, ptr %11, i64 16
  store <4 x i32> %9, ptr %11, align 16, !tbaa !5
  store <4 x i32> %10, ptr %12, align 16, !tbaa !5
  %index.next.1 = add nuw nsw i64 %index, 16
  %vec.ind.next.1 = add <4 x i32> %vec.ind, <i32 16, i32 16, i32 16, i32 16>
  %13 = icmp eq i64 %index.next.1, 1048576
  br i1 %13, label %.preheader15, label %vector.body, !llvm.loop !9

.preheader15:                                     ; preds = %vector.body
  %14 = load i32, ptr @n, align 4, !tbaa !5
  %.not = icmp eq i32 %14, 31
  br i1 %.not, label %._crit_edge19, label %.preheader.preheader

.preheader.preheader:                             ; preds = %.preheader15
  %.pre = load i32, ptr @m, align 4, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %._crit_edge
  %15 = phi i32 [ %14, %.preheader.preheader ], [ %19, %._crit_edge ]
  %16 = phi i32 [ %.pre, %.preheader.preheader ], [ %20, %._crit_edge ]
  %indvars.iv25 = phi i64 [ 0, %.preheader.preheader ], [ %indvars.iv.next26, %._crit_edge ]
  %.not20 = icmp eq i32 %16, 31
  br i1 %.not20, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %17 = shl nuw nsw i32 1, %16
  %18 = getelementptr inbounds [1048576 x i32], ptr @gray, i64 0, i64 %indvars.iv25
  br label %24

._crit_edge19:                                    ; preds = %._crit_edge, %.preheader15
  ret i32 0

._crit_edge.loopexit:                             ; preds = %24
  %.pre28 = load i32, ptr @n, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %19 = phi i32 [ %.pre28, %._crit_edge.loopexit ], [ %15, %.preheader ]
  %20 = phi i32 [ %40, %._crit_edge.loopexit ], [ 31, %.preheader ]
  %indvars.iv.next26 = add nuw nsw i64 %indvars.iv25, 1
  %21 = shl nuw i32 1, %19
  %22 = sext i32 %21 to i64
  %23 = icmp slt i64 %indvars.iv.next26, %22
  br i1 %23, label %.preheader, label %._crit_edge19, !llvm.loop !13

24:                                               ; preds = %.lr.ph, %24
  %indvars.iv22 = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next23, %24 ]
  %25 = phi i32 [ %17, %.lr.ph ], [ %41, %24 ]
  %26 = phi i32 [ %16, %.lr.ph ], [ %40, %24 ]
  %27 = load i32, ptr %18, align 4, !tbaa !5
  %28 = shl i32 %27, %26
  %29 = getelementptr inbounds [1048576 x i32], ptr @gray, i64 0, i64 %indvars.iv22
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = add nsw i32 %28, %30
  %32 = add nsw i32 %25, -1
  %33 = zext i32 %32 to i64
  %34 = icmp eq i64 %indvars.iv22, %33
  %35 = zext i1 %34 to i64
  %36 = getelementptr inbounds [3 x i8], ptr @.str.2, i64 0, i64 %35
  %37 = load i8, ptr %36, align 1, !tbaa !14
  %38 = sext i8 %37 to i32
  %39 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %31, i32 noundef %38)
  %indvars.iv.next23 = add nuw nsw i64 %indvars.iv22, 1
  %40 = load i32, ptr @m, align 4, !tbaa !5
  %41 = shl nuw i32 1, %40
  %42 = sext i32 %41 to i64
  %43 = icmp slt i64 %indvars.iv.next23, %42
  br i1 %43, label %24, label %._crit_edge.loopexit, !llvm.loop !15
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

attributes #0 = { mustprogress nofree norecurse nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nofree nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

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

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !10}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass