; LLVM IR from tangjz/acm-icpc :: buaa/oj3rd (1157)

; 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
@num = external dso_local global [105 x i32], align 16
@tmp = external dso_local global i32, align 4
@ans = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3dfsi(i32 noundef) #0

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

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

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

3:                                                ; preds = %64, %0
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %5 = icmp eq i32 %4, 1
  br i1 %5, label %6, label %67

6:                                                ; preds = %3
  store i32 1, ptr @tmp, align 4, !tbaa !5
  store i32 0, ptr @ans, align 4, !tbaa !5
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %7

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

11:                                               ; preds = %7
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds i32, ptr @num, i64 %13
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %14)
  br label %16

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

19:                                               ; preds = %7
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %54, %19
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = load i32, ptr @n, align 4, !tbaa !5
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %24, label %57

24:                                               ; preds = %20
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [105 x i32], ptr @num, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = load i32, ptr @tmp, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr @tmp, align 4, !tbaa !5
  %31 = sext i32 %29 to i64
  %32 = getelementptr inbounds [105 x i32], ptr @num, i64 0, i64 %31
  store i32 %28, ptr %32, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %50, %24
  %34 = load i32, ptr @tmp, align 4, !tbaa !5
  %35 = icmp sge i32 %34, 3
  br i1 %35, label %36, label %48

36:                                               ; preds = %33
  %37 = load i32, ptr @tmp, align 4, !tbaa !5
  %38 = sub nsw i32 %37, 3
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [105 x i32], ptr @num, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = load i32, ptr @tmp, align 4, !tbaa !5
  %43 = sub nsw i32 %42, 1
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [105 x i32], ptr @num, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = icmp sle i32 %41, %46
  br label %48

48:                                               ; preds = %36, %33
  %49 = phi i1 [ false, %33 ], [ %47, %36 ]
  br i1 %49, label %50, label %53

50:                                               ; preds = %48
  %51 = load i32, ptr @tmp, align 4, !tbaa !5
  %52 = sub nsw i32 %51, 2
  call void @_Z3dfsi(i32 noundef %52)
  br label %33, !llvm.loop !11

53:                                               ; preds = %48
  br label %54

54:                                               ; preds = %53
  %55 = load i32, ptr %2, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %2, align 4, !tbaa !5
  br label %20, !llvm.loop !12

57:                                               ; preds = %20
  br label %58

58:                                               ; preds = %61, %57
  %59 = load i32, ptr @tmp, align 4, !tbaa !5
  %60 = icmp sgt i32 %59, 1
  br i1 %60, label %61, label %64

61:                                               ; preds = %58
  %62 = load i32, ptr @tmp, align 4, !tbaa !5
  %63 = sub nsw i32 %62, 1
  call void @_Z3dfsi(i32 noundef %63)
  br label %58, !llvm.loop !13

64:                                               ; preds = %58
  %65 = load i32, ptr @ans, align 4, !tbaa !5
  %66 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %65)
  br label %3, !llvm.loop !14

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

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

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

attributes #0 = { mustprogress 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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !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
@num = external dso_local global [105 x i32], align 16
@tmp = external dso_local local_unnamed_addr global i32, align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %2 = icmp eq i32 %1, 1
  br i1 %2, label %.lr.ph16, label %._crit_edge17

.lr.ph16:                                         ; preds = %0, %._crit_edge
  store i32 1, ptr @tmp, align 4, !tbaa !5
  store i32 0, ptr @ans, align 4, !tbaa !5
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph, label %._crit_edge

.preheader8:                                      ; preds = %.lr.ph
  %.pre23.pre = load i32, ptr @tmp, align 4, !tbaa !5
  %5 = icmp sgt i32 %8, 1
  br i1 %5, label %.lr.ph13, label %.preheader

.lr.ph:                                           ; preds = %.lr.ph16, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.lr.ph16 ]
  %6 = getelementptr inbounds i32, ptr @num, i64 %indvars.iv
  %7 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %6)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = icmp slt i64 %indvars.iv.next, %9
  br i1 %10, label %.lr.ph, label %.preheader8, !llvm.loop !9

.preheader:                                       ; preds = %.critedge, %.preheader8
  %11 = phi i32 [ %.pre23.pre, %.preheader8 ], [ %35, %.critedge ]
  %12 = icmp sgt i32 %11, 1
  br i1 %12, label %.lr.ph14, label %._crit_edge

.lr.ph13:                                         ; preds = %.preheader8, %.critedge
  %13 = phi i32 [ %34, %.critedge ], [ %8, %.preheader8 ]
  %14 = phi i32 [ %35, %.critedge ], [ %.pre23.pre, %.preheader8 ]
  %indvars.iv19 = phi i64 [ %indvars.iv.next20, %.critedge ], [ 1, %.preheader8 ]
  %15 = getelementptr inbounds [105 x i32], ptr @num, i64 0, i64 %indvars.iv19
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = add nsw i32 %14, 1
  store i32 %17, ptr @tmp, align 4, !tbaa !5
  %18 = sext i32 %14 to i64
  %19 = getelementptr inbounds [105 x i32], ptr @num, i64 0, i64 %18
  store i32 %16, ptr %19, align 4, !tbaa !5
  %20 = icmp sgt i32 %14, 1
  br i1 %20, label %.lr.ph10, label %.critedge

.lr.ph10:                                         ; preds = %.lr.ph13, %30
  %21 = phi i32 [ %.pr, %30 ], [ %17, %.lr.ph13 ]
  %22 = add nsw i32 %21, -3
  %23 = zext nneg i32 %22 to i64
  %24 = getelementptr inbounds [105 x i32], ptr @num, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = add nsw i32 %21, -1
  %27 = zext nneg i32 %26 to i64
  %28 = getelementptr inbounds [105 x i32], ptr @num, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %.not = icmp sgt i32 %25, %29
  br i1 %.not, label %.critedge.loopexit, label %30

30:                                               ; preds = %.lr.ph10
  %31 = add nsw i32 %21, -2
  tail call void @_Z3dfsi(i32 noundef %31)
  %.pr = load i32, ptr @tmp, align 4, !tbaa !5
  %32 = icmp sgt i32 %.pr, 2
  br i1 %32, label %.lr.ph10, label %.critedge.loopexit, !llvm.loop !11

.critedge.loopexit:                               ; preds = %.lr.ph10, %30
  %33 = phi i32 [ %21, %.lr.ph10 ], [ %.pr, %30 ]
  %.pre22 = load i32, ptr @n, align 4, !tbaa !5
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %.lr.ph13
  %34 = phi i32 [ %.pre22, %.critedge.loopexit ], [ %13, %.lr.ph13 ]
  %35 = phi i32 [ %33, %.critedge.loopexit ], [ %17, %.lr.ph13 ]
  %indvars.iv.next20 = add nuw nsw i64 %indvars.iv19, 1
  %36 = sext i32 %34 to i64
  %37 = icmp slt i64 %indvars.iv.next20, %36
  br i1 %37, label %.lr.ph13, label %.preheader, !llvm.loop !12

.lr.ph14:                                         ; preds = %.preheader, %.lr.ph14
  %38 = phi i32 [ %40, %.lr.ph14 ], [ %11, %.preheader ]
  %39 = add nsw i32 %38, -1
  tail call void @_Z3dfsi(i32 noundef %39)
  %40 = load i32, ptr @tmp, align 4, !tbaa !5
  %41 = icmp sgt i32 %40, 1
  br i1 %41, label %.lr.ph14, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph14, %.lr.ph16, %.preheader
  %42 = load i32, ptr @ans, align 4, !tbaa !5
  %43 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %42)
  %44 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %45 = icmp eq i32 %44, 1
  br i1 %45, label %.lr.ph16, label %._crit_edge17, !llvm.loop !14

._crit_edge17:                                    ; preds = %._crit_edge, %0
  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

attributes #0 = { mustprogress 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 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 = !{!"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}
!14 = distinct !{!14, !10}


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