; LLVM IR from tangjz/acm-icpc :: self_training/2015-04-30 (A)

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

@a = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@c = external dso_local global i32, align 4
@tot = external dso_local global i32, align 4
@ans = external dso_local global [100 x i32], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = 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 i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  br label %9

9:                                                ; preds = %101, %0
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @a, ptr noundef @b, ptr noundef @c)
  %11 = icmp eq i32 %10, 3
  br i1 %11, label %12, label %102

12:                                               ; preds = %9
  store i32 0, ptr @tot, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %73, %12
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = icmp slt i32 %14, 100
  br i1 %15, label %17, label %16

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

17:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %18 = load i32, ptr @b, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  store i64 %19, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %30, %17
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = load i32, ptr @a, align 4, !tbaa !5
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  store i32 7, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %33

25:                                               ; preds = %20
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = load i64, ptr %5, align 8, !tbaa !9
  %29 = mul nsw i64 %28, %27
  store i64 %29, ptr %5, align 8, !tbaa !9
  br label %30

30:                                               ; preds = %25
  %31 = load i32, ptr %6, align 4, !tbaa !5
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %6, align 4, !tbaa !5
  br label %20, !llvm.loop !11

33:                                               ; preds = %24
  %34 = load i32, ptr @c, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = load i64, ptr %5, align 8, !tbaa !9
  %37 = add nsw i64 %36, %35
  store i64 %37, ptr %5, align 8, !tbaa !9
  %38 = load i64, ptr %5, align 8, !tbaa !9
  %39 = icmp sle i64 %38, 0
  br i1 %39, label %43, label %40

40:                                               ; preds = %33
  %41 = load i64, ptr %5, align 8, !tbaa !9
  %42 = icmp sge i64 %41, 1000000000
  br i1 %42, label %43, label %44

43:                                               ; preds = %40, %33
  store i32 6, ptr %3, align 4
  br label %70

44:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %45 = load i64, ptr %5, align 8, !tbaa !9
  store i64 %45, ptr %7, align 8, !tbaa !9
  br label %46

46:                                               ; preds = %49, %44
  %47 = load i64, ptr %5, align 8, !tbaa !9
  %48 = icmp sgt i64 %47, 0
  br i1 %48, label %49, label %58

49:                                               ; preds = %46
  %50 = load i64, ptr %5, align 8, !tbaa !9
  %51 = srem i64 %50, 10
  %52 = load i32, ptr %4, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = add nsw i64 %53, %51
  %55 = trunc i64 %54 to i32
  store i32 %55, ptr %4, align 4, !tbaa !5
  %56 = load i64, ptr %5, align 8, !tbaa !9
  %57 = sdiv i64 %56, 10
  store i64 %57, ptr %5, align 8, !tbaa !9
  br label %46, !llvm.loop !13

58:                                               ; preds = %46
  %59 = load i32, ptr %2, align 4, !tbaa !5
  %60 = load i32, ptr %4, align 4, !tbaa !5
  %61 = icmp eq i32 %59, %60
  br i1 %61, label %62, label %69

62:                                               ; preds = %58
  %63 = load i64, ptr %7, align 8, !tbaa !9
  %64 = trunc i64 %63 to i32
  %65 = load i32, ptr @tot, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr @tot, align 4, !tbaa !5
  %67 = sext i32 %65 to i64
  %68 = getelementptr inbounds [100 x i32], ptr @ans, i64 0, i64 %67
  store i32 %64, ptr %68, align 4, !tbaa !5
  br label %69

69:                                               ; preds = %62, %58
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  store i32 0, ptr %3, align 4
  br label %70

70:                                               ; preds = %69, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %71 = load i32, ptr %3, align 4
  switch i32 %71, label %103 [
    i32 0, label %72
    i32 6, label %73
  ]

72:                                               ; preds = %70
  br label %73

73:                                               ; preds = %72, %70
  %74 = load i32, ptr %2, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %2, align 4, !tbaa !5
  br label %13, !llvm.loop !14

76:                                               ; preds = %16
  %77 = load i32, ptr @tot, align 4, !tbaa !5
  %78 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %77)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %79

79:                                               ; preds = %98, %76
  %80 = load i32, ptr %8, align 4, !tbaa !5
  %81 = load i32, ptr @tot, align 4, !tbaa !5
  %82 = icmp slt i32 %80, %81
  br i1 %82, label %84, label %83

83:                                               ; preds = %79
  store i32 12, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %101

84:                                               ; preds = %79
  %85 = load i32, ptr %8, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [100 x i32], ptr @ans, i64 0, i64 %86
  %88 = load i32, ptr %87, align 4, !tbaa !5
  %89 = load i32, ptr %8, align 4, !tbaa !5
  %90 = load i32, ptr @tot, align 4, !tbaa !5
  %91 = sub nsw i32 %90, 1
  %92 = icmp eq i32 %89, %91
  %93 = zext i1 %92 to i64
  %94 = getelementptr inbounds [3 x i8], ptr @.str.3, i64 0, i64 %93
  %95 = load i8, ptr %94, align 1, !tbaa !15
  %96 = sext i8 %95 to i32
  %97 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %88, i32 noundef %96)
  br label %98

98:                                               ; preds = %84
  %99 = load i32, ptr %8, align 4, !tbaa !5
  %100 = add nsw i32 %99, 1
  store i32 %100, ptr %8, align 4, !tbaa !5
  br label %79, !llvm.loop !16

101:                                              ; preds = %83
  br label %9, !llvm.loop !17

102:                                              ; preds = %9
  ret i32 0

103:                                              ; preds = %70
  unreachable
}

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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !12}
!17 = distinct !{!17, !12}


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

@a = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@c = external dso_local global i32, align 4
@tot = external dso_local local_unnamed_addr global i32, align 4
@ans = external dso_local local_unnamed_addr global [100 x i32], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = 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 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @a, ptr noundef nonnull @b, ptr noundef nonnull @c)
  %2 = icmp eq i32 %1, 3
  br i1 %2, label %.lr.ph41, label %._crit_edge42

.loopexit:                                        ; preds = %.lr.ph39, %12
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @a, ptr noundef nonnull @b, ptr noundef nonnull @c)
  %4 = icmp eq i32 %3, 3
  br i1 %4, label %.lr.ph41, label %._crit_edge42, !llvm.loop !5

.lr.ph41:                                         ; preds = %0, %.loopexit
  store i32 0, ptr @tot, align 4, !tbaa !7
  %5 = load i32, ptr @b, align 4, !tbaa !7
  %6 = sext i32 %5 to i64
  %7 = load i32, ptr @a, align 4, !tbaa !7
  %8 = icmp sgt i32 %7, 0
  %9 = load i32, ptr @c, align 4, !tbaa !7
  %10 = sext i32 %9 to i64
  %xtraiter = and i32 %7, 7
  %11 = icmp ult i32 %7, 8
  %unroll_iter = and i32 %7, 2147483640
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br label %16

12:                                               ; preds = %32
  %13 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %33)
  %14 = load i32, ptr @tot, align 4, !tbaa !7
  %15 = icmp sgt i32 %14, 0
  br i1 %15, label %.lr.ph39, label %.loopexit

16:                                               ; preds = %.lr.ph41, %32
  %indvars.iv = phi i64 [ 0, %.lr.ph41 ], [ %indvars.iv.next, %32 ]
  %17 = phi i32 [ 0, %.lr.ph41 ], [ %33, %32 ]
  br i1 %8, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %16
  br i1 %11, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %factor.op.mul = mul i64 %indvars.iv, %indvars.iv
  %factor.op.mul60 = mul i64 %factor.op.mul, %indvars.iv
  %factor.op.mul61 = mul i64 %factor.op.mul60, %indvars.iv
  %factor.op.mul62 = mul i64 %factor.op.mul61, %indvars.iv
  %factor.op.mul63 = mul i64 %factor.op.mul62, %indvars.iv
  %factor.op.mul64 = mul i64 %factor.op.mul63, %indvars.iv
  %factor.op.mul65 = mul i64 %factor.op.mul64, %indvars.iv
  br label %.lr.ph

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa.ph = phi i64 [ poison, %.lr.ph.preheader ], [ %.reass.reass.reass.reass.reass.reass.reass, %.lr.ph ]
  %.02428.unr = phi i64 [ %6, %.lr.ph.preheader ], [ %.reass.reass.reass.reass.reass.reass.reass, %.lr.ph ]
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %.02428.epil = phi i64 [ %18, %.lr.ph.epil ], [ %.02428.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i32 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %18 = mul nsw i64 %.02428.epil, %indvars.iv
  %epil.iter.next = add i32 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i32 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.lr.ph.epil, !llvm.loop !11

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil, %16
  %.024.lcssa = phi i64 [ %6, %16 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %18, %.lr.ph.epil ]
  %19 = add nsw i64 %.024.lcssa, %10
  %20 = add i64 %19, -1000000000
  %or.cond = icmp ult i64 %20, -999999999
  br i1 %or.cond, label %32, label %.lr.ph33

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.02428 = phi i64 [ %6, %.lr.ph.preheader.new ], [ %.reass.reass.reass.reass.reass.reass.reass, %.lr.ph ]
  %niter = phi i32 [ 0, %.lr.ph.preheader.new ], [ %niter.next.7, %.lr.ph ]
  %.reass.reass.reass.reass.reass.reass.reass = mul i64 %.02428, %factor.op.mul65
  %niter.next.7 = add i32 %niter, 8
  %niter.ncmp.7 = icmp eq i32 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !13

.lr.ph33:                                         ; preds = %._crit_edge, %.lr.ph33
  %.132 = phi i64 [ %24, %.lr.ph33 ], [ %19, %._crit_edge ]
  %.02531 = phi i32 [ %23, %.lr.ph33 ], [ 0, %._crit_edge ]
  %21 = urem i64 %.132, 10
  %22 = trunc nuw nsw i64 %21 to i32
  %23 = add i32 %.02531, %22
  %24 = udiv i64 %.132, 10
  %.not = icmp ult i64 %.132, 10
  br i1 %.not, label %._crit_edge34, label %.lr.ph33, !llvm.loop !14

._crit_edge34:                                    ; preds = %.lr.ph33
  %25 = zext i32 %23 to i64
  %26 = icmp eq i64 %indvars.iv, %25
  br i1 %26, label %27, label %32

27:                                               ; preds = %._crit_edge34
  %28 = trunc nuw nsw i64 %19 to i32
  %29 = add nsw i32 %17, 1
  store i32 %29, ptr @tot, align 4, !tbaa !7
  %30 = sext i32 %17 to i64
  %31 = getelementptr inbounds [100 x i32], ptr @ans, i64 0, i64 %30
  store i32 %28, ptr %31, align 4, !tbaa !7
  br label %32

32:                                               ; preds = %._crit_edge34, %27, %._crit_edge
  %33 = phi i32 [ %17, %._crit_edge34 ], [ %29, %27 ], [ %17, %._crit_edge ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond45.not = icmp eq i64 %indvars.iv.next, 100
  br i1 %exitcond45.not, label %12, label %16, !llvm.loop !15

.lr.ph39:                                         ; preds = %12, %.lr.ph39
  %indvars.iv46 = phi i64 [ %indvars.iv.next47, %.lr.ph39 ], [ 0, %12 ]
  %34 = phi i32 [ %45, %.lr.ph39 ], [ %14, %12 ]
  %35 = getelementptr inbounds [100 x i32], ptr @ans, i64 0, i64 %indvars.iv46
  %36 = load i32, ptr %35, align 4, !tbaa !7
  %37 = add nsw i32 %34, -1
  %38 = zext i32 %37 to i64
  %39 = icmp eq i64 %indvars.iv46, %38
  %40 = zext i1 %39 to i64
  %41 = getelementptr inbounds [3 x i8], ptr @.str.3, i64 0, i64 %40
  %42 = load i8, ptr %41, align 1, !tbaa !16
  %43 = sext i8 %42 to i32
  %44 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %36, i32 noundef %43)
  %indvars.iv.next47 = add nuw nsw i64 %indvars.iv46, 1
  %45 = load i32, ptr @tot, align 4, !tbaa !7
  %46 = sext i32 %45 to i64
  %47 = icmp slt i64 %indvars.iv.next47, %46
  br i1 %47, label %.lr.ph39, label %.loopexit, !llvm.loop !17

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

; 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.unroll.disable"}
!13 = distinct !{!13, !6}
!14 = distinct !{!14, !6}
!15 = distinct !{!15, !6}
!16 = !{!9, !9, i64 0}
!17 = distinct !{!17, !6}


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