; LLVM IR from tangjz/acm-icpc :: codechef/OCT13 (LEBAMBOO)

; 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 [51 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 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
  %4 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %6

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

10:                                               ; preds = %6
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  store i32 0, ptr %4, align 4, !tbaa !5
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %21, %10
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = load i32, ptr @n, align 4, !tbaa !5
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %16, label %24

16:                                               ; preds = %12
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [51 x i32], ptr @a, i64 0, i64 %18
  %20 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %19)
  br label %21

21:                                               ; preds = %16
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %2, align 4, !tbaa !5
  br label %12, !llvm.loop !9

24:                                               ; preds = %12
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %46, %24
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = load i32, ptr @n, align 4, !tbaa !5
  %28 = icmp slt i32 %26, %27
  br i1 %28, label %29, label %49

29:                                               ; preds = %25
  %30 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %3)
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [51 x i32], ptr @a, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = sub nsw i32 %31, %35
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [51 x i32], ptr @a, i64 0, i64 %38
  store i32 %36, ptr %39, align 4, !tbaa !5
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [51 x i32], ptr @a, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = add nsw i32 %44, %43
  store i32 %45, ptr %4, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %29
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %2, align 4, !tbaa !5
  br label %25, !llvm.loop !11

49:                                               ; preds = %25
  %50 = load i32, ptr @n, align 4, !tbaa !5
  %51 = icmp eq i32 %50, 1
  br i1 %51, label %52, label %62

52:                                               ; preds = %49
  %53 = load i32, ptr %4, align 4, !tbaa !5
  %54 = icmp sgt i32 %53, 0
  br i1 %54, label %55, label %57

55:                                               ; preds = %52
  %56 = call i32 @puts(ptr noundef @.str.1)
  br label %61

57:                                               ; preds = %52
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = sub nsw i32 0, %58
  %60 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %59)
  br label %61

61:                                               ; preds = %57, %55
  br label %136

62:                                               ; preds = %49
  %63 = load i32, ptr @n, align 4, !tbaa !5
  %64 = icmp eq i32 %63, 2
  br i1 %64, label %65, label %82

65:                                               ; preds = %62
  %66 = load i32, ptr %4, align 4, !tbaa !5
  %67 = icmp ne i32 %66, 0
  br i1 %67, label %68, label %70

68:                                               ; preds = %65
  %69 = call i32 @puts(ptr noundef @.str.1)
  br label %81

70:                                               ; preds = %65
  %71 = load i32, ptr @a, align 16, !tbaa !5
  %72 = icmp sge i32 %71, 0
  br i1 %72, label %73, label %75

73:                                               ; preds = %70
  %74 = load i32, ptr @a, align 16, !tbaa !5
  br label %78

75:                                               ; preds = %70
  %76 = load i32, ptr @a, align 16, !tbaa !5
  %77 = sub nsw i32 0, %76
  br label %78

78:                                               ; preds = %75, %73
  %79 = phi i32 [ %74, %73 ], [ %77, %75 ]
  %80 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %79)
  br label %81

81:                                               ; preds = %78, %68
  br label %135

82:                                               ; preds = %62
  %83 = load i32, ptr %4, align 4, !tbaa !5
  %84 = load i32, ptr @n, align 4, !tbaa !5
  %85 = sub nsw i32 %84, 2
  %86 = srem i32 %83, %85
  %87 = icmp ne i32 %86, 0
  br i1 %87, label %91, label %88

88:                                               ; preds = %82
  %89 = load i32, ptr %4, align 4, !tbaa !5
  %90 = icmp slt i32 %89, 0
  br i1 %90, label %91, label %93

91:                                               ; preds = %88, %82
  %92 = call i32 @puts(ptr noundef @.str.1)
  br label %134

93:                                               ; preds = %88
  %94 = load i32, ptr @n, align 4, !tbaa !5
  %95 = sub nsw i32 %94, 2
  %96 = load i32, ptr %4, align 4, !tbaa !5
  %97 = sdiv i32 %96, %95
  store i32 %97, ptr %4, align 4, !tbaa !5
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %98

98:                                               ; preds = %121, %93
  %99 = load i32, ptr %2, align 4, !tbaa !5
  %100 = load i32, ptr @n, align 4, !tbaa !5
  %101 = icmp slt i32 %99, %100
  br i1 %101, label %102, label %124

102:                                              ; preds = %98
  %103 = load i32, ptr %2, align 4, !tbaa !5
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds [51 x i32], ptr @a, i64 0, i64 %104
  %106 = load i32, ptr %105, align 4, !tbaa !5
  %107 = call i32 @llvm.abs.i32(i32 %106, i1 true)
  %108 = load i32, ptr %4, align 4, !tbaa !5
  %109 = icmp sgt i32 %107, %108
  br i1 %109, label %119, label %110

110:                                              ; preds = %102
  %111 = load i32, ptr %4, align 4, !tbaa !5
  %112 = load i32, ptr %2, align 4, !tbaa !5
  %113 = sext i32 %112 to i64
  %114 = getelementptr inbounds [51 x i32], ptr @a, i64 0, i64 %113
  %115 = load i32, ptr %114, align 4, !tbaa !5
  %116 = sub nsw i32 %111, %115
  %117 = and i32 %116, 1
  %118 = icmp ne i32 %117, 0
  br i1 %118, label %119, label %120

119:                                              ; preds = %110, %102
  br label %124

120:                                              ; preds = %110
  br label %121

121:                                              ; preds = %120
  %122 = load i32, ptr %2, align 4, !tbaa !5
  %123 = add nsw i32 %122, 1
  store i32 %123, ptr %2, align 4, !tbaa !5
  br label %98, !llvm.loop !12

124:                                              ; preds = %119, %98
  %125 = load i32, ptr %2, align 4, !tbaa !5
  %126 = load i32, ptr @n, align 4, !tbaa !5
  %127 = icmp slt i32 %125, %126
  br i1 %127, label %128, label %130

128:                                              ; preds = %124
  %129 = call i32 @puts(ptr noundef @.str.1)
  br label %133

130:                                              ; preds = %124
  %131 = load i32, ptr %4, align 4, !tbaa !5
  %132 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %131)
  br label %133

133:                                              ; preds = %130, %128
  br label %134

134:                                              ; preds = %133, %91
  br label %135

135:                                              ; preds = %134, %81
  br label %136

136:                                              ; preds = %135, %61
  br label %6, !llvm.loop !13

137:                                              ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  ret i32 0
}

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

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

declare i32 @puts(ptr noundef) #2

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = 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 global [51 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 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 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %2 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %3 = load i32, ptr @t, align 4, !tbaa !5
  %4 = add nsw i32 %3, -1
  store i32 %4, ptr @t, align 4, !tbaa !5
  %.not40 = icmp eq i32 %3, 0
  br i1 %.not40, label %._crit_edge43, label %.lr.ph42

.lr.ph42:                                         ; preds = %0, %57
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

.preheader:                                       ; preds = %.lr.ph
  %8 = icmp sgt i32 %11, 0
  br i1 %8, label %.lr.ph33, label %._crit_edge

.lr.ph:                                           ; preds = %.lr.ph42, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.lr.ph42 ]
  %9 = getelementptr inbounds [51 x i32], ptr @a, i64 0, i64 %indvars.iv
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %9)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %11 = load i32, ptr @n, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = icmp slt i64 %indvars.iv.next, %12
  br i1 %13, label %.lr.ph, label %.preheader, !llvm.loop !9

.lr.ph33:                                         ; preds = %.preheader, %.lr.ph33
  %indvars.iv47 = phi i64 [ %indvars.iv.next48, %.lr.ph33 ], [ 0, %.preheader ]
  %.032 = phi i32 [ %19, %.lr.ph33 ], [ 0, %.preheader ]
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %15 = load i32, ptr %1, align 4, !tbaa !5
  %16 = getelementptr inbounds [51 x i32], ptr @a, i64 0, i64 %indvars.iv47
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = sub nsw i32 %15, %17
  store i32 %18, ptr %16, align 4, !tbaa !5
  %19 = add nsw i32 %18, %.032
  %indvars.iv.next48 = add nuw nsw i64 %indvars.iv47, 1
  %.pr = load i32, ptr @n, align 4, !tbaa !5
  %20 = sext i32 %.pr to i64
  %21 = icmp slt i64 %indvars.iv.next48, %20
  br i1 %21, label %.lr.ph33, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph33, %.lr.ph42, %.preheader
  %.lcssa29 = phi i32 [ %11, %.preheader ], [ %6, %.lr.ph42 ], [ %.pr, %.lr.ph33 ]
  %.0.lcssa = phi i32 [ 0, %.preheader ], [ 0, %.lr.ph42 ], [ %19, %.lr.ph33 ]
  switch i32 %.lcssa29, label %36 [
    i32 1, label %22
    i32 2, label %29
  ]

22:                                               ; preds = %._crit_edge
  %23 = icmp sgt i32 %.0.lcssa, 0
  br i1 %23, label %24, label %26

24:                                               ; preds = %22
  %25 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %57

26:                                               ; preds = %22
  %27 = sub nsw i32 0, %.0.lcssa
  %28 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %27)
  br label %57

29:                                               ; preds = %._crit_edge
  %.not28 = icmp eq i32 %.0.lcssa, 0
  br i1 %.not28, label %32, label %30

30:                                               ; preds = %29
  %31 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %57

32:                                               ; preds = %29
  %33 = load i32, ptr @a, align 16
  %34 = call i32 @llvm.abs.i32(i32 %33, i1 true)
  %35 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %34)
  br label %57

36:                                               ; preds = %._crit_edge
  %37 = add nsw i32 %.lcssa29, -2
  %38 = srem i32 %.0.lcssa, %37
  %39 = sdiv i32 %.0.lcssa, %37
  %40 = icmp ne i32 %38, 0
  %41 = icmp slt i32 %.0.lcssa, 0
  %or.cond = or i1 %41, %40
  br i1 %or.cond, label %42, label %44

42:                                               ; preds = %36
  %43 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %57

44:                                               ; preds = %36
  %45 = icmp sgt i32 %.lcssa29, 0
  br i1 %45, label %.lr.ph38.preheader, label %._crit_edge39

.lr.ph38.preheader:                               ; preds = %44
  %wide.trip.count = zext nneg i32 %.lcssa29 to i64
  br label %.lr.ph38

46:                                               ; preds = %51
  %indvars.iv.next51 = add nuw nsw i64 %indvars.iv50, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next51, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge39, label %.lr.ph38, !llvm.loop !12

.lr.ph38:                                         ; preds = %.lr.ph38.preheader, %46
  %indvars.iv50 = phi i64 [ 0, %.lr.ph38.preheader ], [ %indvars.iv.next51, %46 ]
  %47 = getelementptr inbounds [51 x i32], ptr @a, i64 0, i64 %indvars.iv50
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = call i32 @llvm.abs.i32(i32 %48, i1 true)
  %50 = icmp sgt i32 %49, %39
  br i1 %50, label %54, label %51

51:                                               ; preds = %.lr.ph38
  %52 = sub nsw i32 %39, %48
  %53 = and i32 %52, 1
  %.not27 = icmp eq i32 %53, 0
  br i1 %.not27, label %46, label %54

54:                                               ; preds = %.lr.ph38, %51
  %55 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %57

._crit_edge39:                                    ; preds = %46, %44
  %56 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %39)
  br label %57

57:                                               ; preds = %32, %30, %54, %._crit_edge39, %42, %24, %26
  %58 = load i32, ptr @t, align 4, !tbaa !5
  %59 = add nsw i32 %58, -1
  store i32 %59, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %58, 0
  br i1 %.not, label %._crit_edge43, label %.lr.ph42, !llvm.loop !13

._crit_edge43:                                    ; preds = %57, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret i32 0
}

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @puts(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: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #3 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}


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