; LLVM IR from tangjz/acm-icpc :: self_training/2014-12-07 (B)

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

@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@a = external dso_local global [23333 x i32], 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 [4 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
  store i32 0, ptr %1, align 4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %5

5:                                                ; preds = %63, %0
  %6 = load i32, ptr @t, align 4, !tbaa !5
  %7 = add nsw i32 %6, -1
  store i32 %7, ptr @t, align 4, !tbaa !5
  %8 = icmp ne i32 %6, 0
  br i1 %8, label %9, label %69

9:                                                ; preds = %5
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  store i32 0, ptr @a, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %34, %9
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = mul nsw i32 %12, %13
  %15 = load i32, ptr @n, align 4, !tbaa !5
  %16 = icmp sle i32 %14, %15
  br i1 %16, label %18, label %17

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

18:                                               ; preds = %11
  br label %19

19:                                               ; preds = %24, %18
  %20 = load i32, ptr @n, align 4, !tbaa !5
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = srem i32 %20, %21
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %24, label %33

24:                                               ; preds = %19
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = load i32, ptr @a, align 16, !tbaa !5
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr @a, align 16, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [23333 x i32], ptr @a, i64 0, i64 %28
  store i32 %25, ptr %29, align 4, !tbaa !5
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = load i32, ptr @n, align 4, !tbaa !5
  %32 = sdiv i32 %31, %30
  store i32 %32, ptr @n, align 4, !tbaa !5
  br label %19, !llvm.loop !9

33:                                               ; preds = %19
  br label %34

34:                                               ; preds = %33
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %2, align 4, !tbaa !5
  br label %11, !llvm.loop !11

37:                                               ; preds = %17
  %38 = load i32, ptr @n, align 4, !tbaa !5
  %39 = icmp sgt i32 %38, 1
  br i1 %39, label %40, label %46

40:                                               ; preds = %37
  %41 = load i32, ptr @n, align 4, !tbaa !5
  %42 = load i32, ptr @a, align 16, !tbaa !5
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr @a, align 16, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [23333 x i32], ptr @a, i64 0, i64 %44
  store i32 %41, ptr %45, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %40, %37
  %47 = load i32, ptr @a, align 16, !tbaa !5
  %48 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %47)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %60, %46
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = load i32, ptr @a, align 16, !tbaa !5
  %52 = icmp slt i32 %50, %51
  br i1 %52, label %54, label %53

53:                                               ; preds = %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %63

54:                                               ; preds = %49
  %55 = load i32, ptr %3, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [23333 x i32], ptr @a, i64 0, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %58)
  br label %60

60:                                               ; preds = %54
  %61 = load i32, ptr %3, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %3, align 4, !tbaa !5
  br label %49, !llvm.loop !12

63:                                               ; preds = %53
  %64 = load i32, ptr @a, align 16, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [23333 x i32], ptr @a, i64 0, i64 %65
  %67 = load i32, ptr %66, align 4, !tbaa !5
  %68 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %67)
  br label %5, !llvm.loop !13

69:                                               ; preds = %5
  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 = distinct !{!11, !10}
!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"

@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@a = external dso_local local_unnamed_addr global [23333 x i32], 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 [4 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 @t)
  %2 = load i32, ptr @t, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @t, align 4, !tbaa !5
  %.not29 = icmp eq i32 %2, 0
  br i1 %.not29, label %._crit_edge32, label %.lr.ph31

.lr.ph31:                                         ; preds = %0, %._crit_edge27
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  store i32 0, ptr @a, align 16, !tbaa !5
  %.pr = load i32, ptr @n, align 4, !tbaa !5
  %.not1219 = icmp slt i32 %.pr, 4
  br i1 %.not1219, label %._crit_edge22, label %.preheader

.preheader:                                       ; preds = %.lr.ph31, %16
  %.0921 = phi i32 [ %17, %16 ], [ 2, %.lr.ph31 ]
  %.lcssa151820 = phi i32 [ %.lcssa1517, %16 ], [ %.pr, %.lr.ph31 ]
  %5 = srem i32 %.lcssa151820, %.0921
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %.lr.ph, label %16

._crit_edge22.loopexit:                           ; preds = %16
  %.pre35.pre = load i32, ptr @a, align 16, !tbaa !5
  br label %._crit_edge22

._crit_edge22:                                    ; preds = %._crit_edge22.loopexit, %.lr.ph31
  %.pre35 = phi i32 [ 0, %.lr.ph31 ], [ %.pre35.pre, %._crit_edge22.loopexit ]
  %.lcssa13 = phi i32 [ %.pr, %.lr.ph31 ], [ %.lcssa1517, %._crit_edge22.loopexit ]
  %7 = icmp sgt i32 %.lcssa13, 1
  br i1 %7, label %19, label %23

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %8 = phi i32 [ %13, %.lr.ph ], [ %.lcssa151820, %.preheader ]
  %9 = load i32, ptr @a, align 16, !tbaa !5
  %10 = add nsw i32 %9, 1
  store i32 %10, ptr @a, align 16, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [23333 x i32], ptr @a, i64 0, i64 %11
  store i32 %.0921, ptr %12, align 4, !tbaa !5
  %13 = sdiv i32 %8, %.0921
  %14 = srem i32 %13, %.0921
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph
  store i32 %13, ptr @n, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %._crit_edge, %.preheader
  %.lcssa1517 = phi i32 [ %13, %._crit_edge ], [ %.lcssa151820, %.preheader ]
  %17 = add nuw nsw i32 %.0921, 1
  %18 = mul nuw nsw i32 %17, %17
  %.not12 = icmp sgt i32 %18, %.lcssa1517
  br i1 %.not12, label %._crit_edge22.loopexit, label %.preheader, !llvm.loop !11

19:                                               ; preds = %._crit_edge22
  %20 = add nsw i32 %.pre35, 1
  store i32 %20, ptr @a, align 16, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [23333 x i32], ptr @a, i64 0, i64 %21
  store i32 %.lcssa13, ptr %22, align 4, !tbaa !5
  %.pre = load i32, ptr @a, align 16, !tbaa !5
  br label %23

23:                                               ; preds = %19, %._crit_edge22
  %24 = phi i32 [ %.pre, %19 ], [ %.pre35, %._crit_edge22 ]
  %25 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %24)
  %26 = load i32, ptr @a, align 16, !tbaa !5
  %27 = icmp sgt i32 %26, 1
  br i1 %27, label %.lr.ph26, label %.._crit_edge27_crit_edge

.._crit_edge27_crit_edge:                         ; preds = %23
  %.pre37 = sext i32 %26 to i64
  br label %._crit_edge27

._crit_edge27:                                    ; preds = %.lr.ph26, %.._crit_edge27_crit_edge
  %.pre-phi = phi i64 [ %.pre37, %.._crit_edge27_crit_edge ], [ %37, %.lr.ph26 ]
  %28 = getelementptr inbounds [23333 x i32], ptr @a, i64 0, i64 %.pre-phi
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %29)
  %31 = load i32, ptr @t, align 4, !tbaa !5
  %32 = add nsw i32 %31, -1
  store i32 %32, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %31, 0
  br i1 %.not, label %._crit_edge32, label %.lr.ph31, !llvm.loop !12

.lr.ph26:                                         ; preds = %23, %.lr.ph26
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph26 ], [ 1, %23 ]
  %33 = getelementptr inbounds [23333 x i32], ptr @a, i64 0, i64 %indvars.iv
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %34)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %36 = load i32, ptr @a, align 16, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = icmp slt i64 %indvars.iv.next, %37
  br i1 %38, label %.lr.ph26, label %._crit_edge27, !llvm.loop !13

._crit_edge32:                                    ; preds = %._crit_edge27, %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 = !{!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 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}


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