; LLVM IR from tangjz/acm-icpc :: TDL_training/2016-03-27 (C - Cool Numbers - lzy)

; 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"

@k = external dso_local global i32, align 4
@f = external dso_local global [1000001 x i8], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3revi(i32 noundef) #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %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
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %36, %0
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = mul nsw i32 %7, %8
  %10 = icmp slt i32 %9, 1000001
  br i1 %10, label %12, label %11

11:                                               ; preds = %6
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %39

12:                                               ; preds = %6
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [1000001 x i8], ptr @f, i64 0, i64 %14
  %16 = load i8, ptr %15, align 1, !tbaa !9, !range !11, !noundef !12
  %17 = trunc i8 %16 to i1
  br i1 %17, label %35, label %18

18:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = mul nsw i32 %19, %20
  store i32 %21, ptr %4, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %30, %18
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = icmp slt i32 %23, 1000001
  br i1 %24, label %26, label %25

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

26:                                               ; preds = %22
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [1000001 x i8], ptr @f, i64 0, i64 %28
  store i8 1, ptr %29, align 1, !tbaa !9
  br label %30

30:                                               ; preds = %26
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = add nsw i32 %32, %31
  store i32 %33, ptr %4, align 4, !tbaa !5
  br label %22, !llvm.loop !13

34:                                               ; preds = %25
  br label %35

35:                                               ; preds = %34, %12
  br label %36

36:                                               ; preds = %35
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %2, align 4, !tbaa !5
  br label %6, !llvm.loop !15

39:                                               ; preds = %11
  %40 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @k)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 2, ptr %5, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %75, %39
  %42 = load i32, ptr %5, align 4, !tbaa !5
  %43 = icmp slt i32 %42, 1000001
  br i1 %43, label %45, label %44

44:                                               ; preds = %41
  store i32 8, ptr %3, align 4
  br label %78

45:                                               ; preds = %41
  %46 = load i32, ptr %5, align 4, !tbaa !5
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = call noundef i32 @_Z3revi(i32 noundef %47)
  %49 = icmp ne i32 %46, %48
  br i1 %49, label %50, label %64

50:                                               ; preds = %45
  %51 = load i32, ptr %5, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [1000001 x i8], ptr @f, i64 0, i64 %52
  %54 = load i8, ptr %53, align 1, !tbaa !9, !range !11, !noundef !12
  %55 = trunc i8 %54 to i1
  br i1 %55, label %64, label %56

56:                                               ; preds = %50
  %57 = load i32, ptr %5, align 4, !tbaa !5
  %58 = call noundef i32 @_Z3revi(i32 noundef %57)
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [1000001 x i8], ptr @f, i64 0, i64 %59
  %61 = load i8, ptr %60, align 1, !tbaa !9, !range !11, !noundef !12
  %62 = trunc i8 %61 to i1
  %63 = xor i1 %62, true
  br label %64

64:                                               ; preds = %56, %50, %45
  %65 = phi i1 [ false, %50 ], [ false, %45 ], [ %63, %56 ]
  %66 = zext i1 %65 to i32
  %67 = load i32, ptr @k, align 4, !tbaa !5
  %68 = sub nsw i32 %67, %66
  store i32 %68, ptr @k, align 4, !tbaa !5
  %69 = load i32, ptr @k, align 4, !tbaa !5
  %70 = icmp ne i32 %69, 0
  br i1 %70, label %74, label %71

71:                                               ; preds = %64
  %72 = load i32, ptr %5, align 4, !tbaa !5
  %73 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %72)
  store i32 8, ptr %3, align 4
  br label %78

74:                                               ; preds = %64
  br label %75

75:                                               ; preds = %74
  %76 = load i32, ptr %5, align 4, !tbaa !5
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr %5, align 4, !tbaa !5
  br label %41, !llvm.loop !16

78:                                               ; preds = %71, %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %79

79:                                               ; preds = %78
  %80 = load i32, ptr @k, align 4, !tbaa !5
  %81 = icmp ne i32 %80, 0
  br i1 %81, label %82, label %84

82:                                               ; preds = %79
  %83 = call i32 @puts(ptr noundef @.str.2)
  br label %84

84:                                               ; preds = %82, %79
  ret i32 0
}

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

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

declare i32 @puts(ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 #2 = { 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 #3 = { "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 #4 = { 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 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


; 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"

@k = external dso_local global i32, align 4
@f = external dso_local local_unnamed_addr global [1000001 x i8], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3revi(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  br label %3

1:                                                ; preds = %.loopexit22
  %2 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @k)
  br label %22

3:                                                ; preds = %.loopexit22.1, %0
  %indvars.iv = phi i64 [ 2, %0 ], [ %indvars.iv.next.1, %.loopexit22.1 ]
  %4 = phi i32 [ 4, %0 ], [ %21, %.loopexit22.1 ]
  %5 = getelementptr inbounds [1000001 x i8], ptr @f, i64 0, i64 %indvars.iv
  %6 = load i8, ptr %5, align 2, !tbaa !5, !range !9, !noundef !10
  %7 = trunc nuw i8 %6 to i1
  %8 = icmp ugt i32 %4, 1000000
  %or.cond.not = or i1 %8, %7
  br i1 %or.cond.not, label %.loopexit22, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %9 = zext nneg i32 %4 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv31 = phi i64 [ %9, %.lr.ph.preheader ], [ %indvars.iv.next32, %.lr.ph ]
  %10 = getelementptr inbounds [1000001 x i8], ptr @f, i64 0, i64 %indvars.iv31
  store i8 1, ptr %10, align 1, !tbaa !5
  %indvars.iv.next32 = add nuw nsw i64 %indvars.iv31, %indvars.iv
  %11 = icmp ult i64 %indvars.iv.next32, 1000001
  br i1 %11, label %.lr.ph, label %.loopexit22, !llvm.loop !11

.loopexit22:                                      ; preds = %.lr.ph, %3
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %12 = mul nuw nsw i64 %indvars.iv.next, %indvars.iv.next
  %exitcond.not = icmp eq i64 %indvars.iv, 1000
  br i1 %exitcond.not, label %1, label %13, !llvm.loop !13

13:                                               ; preds = %.loopexit22
  %14 = getelementptr inbounds [1000001 x i8], ptr @f, i64 0, i64 %indvars.iv.next
  %15 = load i8, ptr %14, align 1, !tbaa !5, !range !9, !noundef !10
  %16 = trunc nuw i8 %15 to i1
  %17 = icmp ugt i64 %12, 1000000
  %or.cond.not.1 = or i1 %17, %16
  br i1 %or.cond.not.1, label %.loopexit22.1, label %.lr.ph.1

.lr.ph.1:                                         ; preds = %13, %.lr.ph.1
  %indvars.iv31.1 = phi i64 [ %indvars.iv.next32.1, %.lr.ph.1 ], [ %12, %13 ]
  %18 = getelementptr inbounds [1000001 x i8], ptr @f, i64 0, i64 %indvars.iv31.1
  store i8 1, ptr %18, align 1, !tbaa !5
  %indvars.iv.next32.1 = add nuw nsw i64 %indvars.iv31.1, %indvars.iv.next
  %19 = icmp ult i64 %indvars.iv.next32.1, 1000001
  br i1 %19, label %.lr.ph.1, label %.loopexit22.1, !llvm.loop !11

.loopexit22.1:                                    ; preds = %.lr.ph.1, %13
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %20 = mul nuw nsw i64 %indvars.iv.next.1, %indvars.iv.next.1
  %21 = trunc nuw i64 %20 to i32
  br label %3

22:                                               ; preds = %1, %43
  %indvars.iv35 = phi i64 [ 2, %1 ], [ %indvars.iv.next36, %43 ]
  %23 = trunc nuw nsw i64 %indvars.iv35 to i32
  %24 = tail call noundef i32 @_Z3revi(i32 noundef %23)
  %25 = zext i32 %24 to i64
  %.not = icmp eq i64 %indvars.iv35, %25
  br i1 %.not, label %37, label %26

26:                                               ; preds = %22
  %27 = getelementptr inbounds [1000001 x i8], ptr @f, i64 0, i64 %indvars.iv35
  %28 = load i8, ptr %27, align 1, !tbaa !5, !range !9, !noundef !10
  %29 = trunc nuw i8 %28 to i1
  br i1 %29, label %37, label %30

30:                                               ; preds = %26
  %31 = tail call noundef i32 @_Z3revi(i32 noundef %23)
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [1000001 x i8], ptr @f, i64 0, i64 %32
  %34 = load i8, ptr %33, align 1, !tbaa !5, !range !9, !noundef !10
  %35 = xor i8 %34, 1
  %36 = zext nneg i8 %35 to i32
  br label %37

37:                                               ; preds = %30, %26, %22
  %38 = phi i32 [ 0, %26 ], [ 0, %22 ], [ %36, %30 ]
  %39 = load i32, ptr @k, align 4, !tbaa !14
  %40 = sub nsw i32 %39, %38
  store i32 %40, ptr @k, align 4, !tbaa !14
  %.not20 = icmp eq i32 %39, %38
  br i1 %.not20, label %41, label %43

41:                                               ; preds = %37
  %42 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %23)
  %.pre = load i32, ptr @k, align 4, !tbaa !14
  br label %.loopexit

43:                                               ; preds = %37
  %indvars.iv.next36 = add nuw nsw i64 %indvars.iv35, 1
  %exitcond38.not = icmp eq i64 %indvars.iv.next36, 1000001
  br i1 %exitcond38.not, label %.loopexit, label %22, !llvm.loop !16

.loopexit:                                        ; preds = %43, %41
  %44 = phi i32 [ %.pre, %41 ], [ %40, %43 ]
  %.not21 = icmp eq i32 %44, 0
  br i1 %.not21, label %47, label %45

45:                                               ; preds = %.loopexit
  %46 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %47

47:                                               ; preds = %45, %.loopexit
  ret i32 0
}

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #2

attributes #0 = { mustprogress 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 = { mustprogress 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 #2 = { 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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = distinct !{!16, !12}


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