; LLVM IR from tangjz/acm-icpc :: codeforces/1408A.ll (Z5solvev)

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

@_ZZ5solvevE3arr = external hidden global [3 x [100001 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 [1 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5solvev() #0 {
  %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
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %1)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %33, %0
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = icmp slt i32 %11, 3
  br i1 %12, label %14, label %13

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

14:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %29, %14
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = load i32, ptr %1, align 4, !tbaa !5
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %20, label %19

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

20:                                               ; preds = %15
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [3 x [100001 x i32]], ptr @_ZZ5solvevE3arr, i64 0, i64 %22
  %24 = getelementptr inbounds [100001 x i32], ptr %23, i64 0, i64 0
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds i32, ptr %24, i64 %26
  %28 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %27)
  br label %29

29:                                               ; preds = %20
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %4, align 4, !tbaa !5
  br label %15, !llvm.loop !9

32:                                               ; preds = %19
  br label %33

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

36:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %37 = load i32, ptr @_ZZ5solvevE3arr, align 16, !tbaa !5
  store i32 %37, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %38 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %38, ptr %6, align 4, !tbaa !5
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %39)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 1, ptr %7, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %92, %36
  %42 = load i32, ptr %7, align 4, !tbaa !5
  %43 = load i32, ptr %1, align 4, !tbaa !5
  %44 = icmp slt i32 %42, %43
  br i1 %44, label %46, label %45

45:                                               ; preds = %41
  store i32 8, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %95

46:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %87, %46
  %48 = load i32, ptr %8, align 4, !tbaa !5
  %49 = icmp slt i32 %48, 3
  br i1 %49, label %51, label %50

50:                                               ; preds = %47
  store i32 11, ptr %3, align 4
  br label %90

51:                                               ; preds = %47
  %52 = load i32, ptr %8, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [3 x [100001 x i32]], ptr @_ZZ5solvevE3arr, i64 0, i64 %53
  %55 = load i32, ptr %7, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [100001 x i32], ptr %54, i64 0, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = load i32, ptr %6, align 4, !tbaa !5
  %60 = icmp ne i32 %58, %59
  br i1 %60, label %61, label %86

61:                                               ; preds = %51
  %62 = load i32, ptr %7, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  %64 = load i32, ptr %1, align 4, !tbaa !5
  %65 = icmp slt i32 %63, %64
  br i1 %65, label %76, label %66

66:                                               ; preds = %61
  %67 = load i32, ptr %8, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [3 x [100001 x i32]], ptr @_ZZ5solvevE3arr, i64 0, i64 %68
  %70 = load i32, ptr %7, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [100001 x i32], ptr %69, i64 0, i64 %71
  %73 = load i32, ptr %72, align 4, !tbaa !5
  %74 = load i32, ptr %5, align 4, !tbaa !5
  %75 = icmp ne i32 %73, %74
  br i1 %75, label %76, label %86

76:                                               ; preds = %66, %61
  %77 = load i32, ptr %8, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [3 x [100001 x i32]], ptr @_ZZ5solvevE3arr, i64 0, i64 %78
  %80 = load i32, ptr %7, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [100001 x i32], ptr %79, i64 0, i64 %81
  %83 = load i32, ptr %82, align 4, !tbaa !5
  store i32 %83, ptr %6, align 4, !tbaa !5
  %84 = load i32, ptr %6, align 4, !tbaa !5
  %85 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %84)
  store i32 11, ptr %3, align 4
  br label %90

86:                                               ; preds = %66, %51
  br label %87

87:                                               ; preds = %86
  %88 = load i32, ptr %8, align 4, !tbaa !5
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr %8, align 4, !tbaa !5
  br label %47, !llvm.loop !12

90:                                               ; preds = %76, %50
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %91

91:                                               ; preds = %90
  br label %92

92:                                               ; preds = %91
  %93 = load i32, ptr %7, align 4, !tbaa !5
  %94 = add nsw i32 %93, 1
  store i32 %94, ptr %7, align 4, !tbaa !5
  br label %41, !llvm.loop !13

95:                                               ; preds = %45
  %96 = call i32 @puts(ptr noundef @.str.2)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  ret void
}

; 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

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

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

declare i32 @puts(ptr noundef) #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 = { 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 = { 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"

@_ZZ5solvevE3arr = external hidden global [3 x [100001 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 [1 x i8], align 1

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local void @_Z5solvev() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %3 = load i32, ptr %1, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph, label %.split32.us

.split32.us:                                      ; preds = %.lr.ph.2, %._crit_edge, %._crit_edge.1, %0
  %5 = load i32, ptr @_ZZ5solvevE3arr, align 16, !tbaa !5
  %6 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %5)
  %7 = load i32, ptr %1, align 4, !tbaa !5
  %8 = icmp sgt i32 %7, 1
  br i1 %8, label %.preheader, label %._crit_edge40

._crit_edge:                                      ; preds = %.lr.ph
  %9 = icmp sgt i32 %23, 0
  br i1 %9, label %.lr.ph.1, label %.split32.us

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

._crit_edge.1:                                    ; preds = %.lr.ph.1
  %15 = icmp sgt i32 %12, 0
  br i1 %15, label %.lr.ph.2, label %.split32.us

.lr.ph.2:                                         ; preds = %._crit_edge.1, %.lr.ph.2
  %indvars.iv.2 = phi i64 [ %indvars.iv.next.2, %.lr.ph.2 ], [ 0, %._crit_edge.1 ]
  %16 = getelementptr inbounds i32, ptr getelementptr inbounds (i8, ptr @_ZZ5solvevE3arr, i64 800008), i64 %indvars.iv.2
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %16)
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv.2, 1
  %18 = load i32, ptr %1, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = icmp slt i64 %indvars.iv.next.2, %19
  br i1 %20, label %.lr.ph.2, label %.split32.us, !llvm.loop !9

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %21 = getelementptr inbounds i32, ptr @_ZZ5solvevE3arr, i64 %indvars.iv
  %22 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %21)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %23 = load i32, ptr %1, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = icmp slt i64 %indvars.iv.next, %24
  br i1 %25, label %.lr.ph, label %._crit_edge, !llvm.loop !9

.preheader:                                       ; preds = %.split32.us, %.loopexit
  %26 = phi i32 [ %41, %.loopexit ], [ %7, %.split32.us ]
  %indvars.iv57 = phi i64 [ %indvars.iv.next58, %.loopexit ], [ 1, %.split32.us ]
  %.02338 = phi i32 [ %.1, %.loopexit ], [ %5, %.split32.us ]
  %indvars.iv.next58 = add nuw nsw i64 %indvars.iv57, 1
  %27 = sext i32 %26 to i64
  %28 = icmp sge i64 %indvars.iv.next58, %27
  %.fr = freeze i1 %28
  %29 = getelementptr inbounds [3 x [100001 x i32]], ptr @_ZZ5solvevE3arr, i64 0, i64 0, i64 %indvars.iv57
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %.not = icmp eq i32 %30, %.02338
  br i1 %.fr, label %.preheader.split.preheader, label %.preheader.split.us.preheader

.preheader.split.us.preheader:                    ; preds = %.preheader
  br i1 %.not, label %.preheader.split.us.1, label %.split35.us

.preheader.split.preheader:                       ; preds = %.preheader
  %.not27 = icmp eq i32 %30, %5
  %or.cond = or i1 %.not, %.not27
  br i1 %or.cond, label %.preheader.split.1, label %.split35.us

.preheader.split.us.1:                            ; preds = %.preheader.split.us.preheader
  %31 = getelementptr inbounds [3 x [100001 x i32]], ptr @_ZZ5solvevE3arr, i64 0, i64 1, i64 %indvars.iv57
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %.not.us.1 = icmp eq i32 %32, %.02338
  br i1 %.not.us.1, label %.preheader.split.us.2, label %.split35.us

.preheader.split.us.2:                            ; preds = %.preheader.split.us.1
  %33 = getelementptr inbounds [3 x [100001 x i32]], ptr @_ZZ5solvevE3arr, i64 0, i64 2, i64 %indvars.iv57
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %.not.us.2 = icmp eq i32 %34, %.02338
  br i1 %.not.us.2, label %.loopexit, label %.split35.us

._crit_edge40:                                    ; preds = %.loopexit, %.split32.us
  %35 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.2)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
  ret void

.split35.us:                                      ; preds = %.preheader.split.us.preheader, %.preheader.split.us.1, %.preheader.split.us.2, %.preheader.split.preheader, %.preheader.split.1, %.preheader.split.2
  %.us-phi = phi i32 [ %30, %.preheader.split.preheader ], [ %38, %.preheader.split.1 ], [ %40, %.preheader.split.2 ], [ %30, %.preheader.split.us.preheader ], [ %32, %.preheader.split.us.1 ], [ %34, %.preheader.split.us.2 ]
  %36 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.us-phi)
  %.pre = load i32, ptr %1, align 4, !tbaa !5
  br label %.loopexit

.preheader.split.1:                               ; preds = %.preheader.split.preheader
  %37 = getelementptr inbounds [3 x [100001 x i32]], ptr @_ZZ5solvevE3arr, i64 0, i64 1, i64 %indvars.iv57
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %.not.1 = icmp eq i32 %38, %.02338
  %.not27.1 = icmp eq i32 %38, %5
  %or.cond.1 = or i1 %.not.1, %.not27.1
  br i1 %or.cond.1, label %.preheader.split.2, label %.split35.us

.preheader.split.2:                               ; preds = %.preheader.split.1
  %39 = getelementptr inbounds [3 x [100001 x i32]], ptr @_ZZ5solvevE3arr, i64 0, i64 2, i64 %indvars.iv57
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %.not.2 = icmp eq i32 %40, %.02338
  %.not27.2 = icmp eq i32 %40, %5
  %or.cond.2 = or i1 %.not.2, %.not27.2
  br i1 %or.cond.2, label %.loopexit, label %.split35.us

.loopexit:                                        ; preds = %.preheader.split.2, %.preheader.split.us.2, %.split35.us
  %41 = phi i32 [ %.pre, %.split35.us ], [ %26, %.preheader.split.us.2 ], [ %26, %.preheader.split.2 ]
  %.1 = phi i32 [ %.us-phi, %.split35.us ], [ %.02338, %.preheader.split.us.2 ], [ %.02338, %.preheader.split.2 ]
  %42 = sext i32 %41 to i64
  %43 = icmp slt i64 %indvars.iv.next58, %42
  br i1 %43, label %.preheader, label %._crit_edge40, !llvm.loop !11
}

; 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; 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 nofree 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 = { 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}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass