; LLVM IR from tangjz/acm-icpc :: codeforces/gym/104023E.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"

@_ZZ5solvevE1a = external hidden global [100021 x i32], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [71 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [76 x i8], align 1
@__PRETTY_FUNCTION__._Z5solvev = external hidden unnamed_addr constant [13 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [54 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [37 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
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %1, ptr noundef %2)
  %6 = icmp eq i32 %5, 2
  br i1 %6, label %7, label %19

7:                                                ; preds = %0
  %8 = load i32, ptr %1, align 4, !tbaa !5
  %9 = icmp sle i32 2, %8
  br i1 %9, label %10, label %19

10:                                               ; preds = %7
  %11 = load i32, ptr %1, align 4, !tbaa !5
  %12 = icmp sle i32 %11, 10
  br i1 %12, label %13, label %19

13:                                               ; preds = %10
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = icmp sle i32 1, %14
  br i1 %15, label %16, label %19

16:                                               ; preds = %13
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = icmp sle i32 %17, 1000
  br label %19

19:                                               ; preds = %16, %13, %10, %7, %0
  %20 = phi i1 [ false, %13 ], [ false, %10 ], [ false, %7 ], [ false, %0 ], [ %18, %16 ]
  br i1 %20, label %21, label %22

21:                                               ; preds = %19
  br label %24

22:                                               ; preds = %19
  call void @__assert_fail(ptr noundef @.str.1, ptr noundef @.str.2, i32 noundef 13, ptr noundef @__PRETTY_FUNCTION__._Z5solvev) #5
  unreachable

23:                                               ; No predecessors!
  br label %24

24:                                               ; preds = %23, %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %55, %24
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = load i32, ptr %1, align 4, !tbaa !5
  %28 = icmp sle i32 %26, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %58

30:                                               ; preds = %25
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds i32, ptr @_ZZ5solvevE1a, i64 %32
  %34 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.3, ptr noundef %33)
  %35 = icmp eq i32 %34, 1
  br i1 %35, label %36, label %49

36:                                               ; preds = %30
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [100021 x i32], ptr @_ZZ5solvevE1a, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = icmp slt i32 %37, %41
  br i1 %42, label %43, label %49

43:                                               ; preds = %36
  %44 = load i32, ptr %3, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [100021 x i32], ptr @_ZZ5solvevE1a, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = icmp sle i32 %47, 100000
  br label %49

49:                                               ; preds = %43, %36, %30
  %50 = phi i1 [ false, %36 ], [ false, %30 ], [ %48, %43 ]
  br i1 %50, label %51, label %52

51:                                               ; preds = %49
  br label %54

52:                                               ; preds = %49
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.2, i32 noundef 18, ptr noundef @__PRETTY_FUNCTION__._Z5solvev) #5
  unreachable

53:                                               ; No predecessors!
  br label %54

54:                                               ; preds = %53, %51
  br label %55

55:                                               ; preds = %54
  %56 = load i32, ptr %3, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %3, align 4, !tbaa !5
  br label %25, !llvm.loop !9

58:                                               ; preds = %29
  %59 = load i32, ptr %1, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [100021 x i32], ptr @_ZZ5solvevE1a, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !5
  %63 = load i32, ptr %1, align 4, !tbaa !5
  %64 = sub nsw i32 %63, 1
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [100021 x i32], ptr @_ZZ5solvevE1a, i64 0, i64 %65
  %67 = load i32, ptr %66, align 4, !tbaa !5
  %68 = icmp sge i32 %62, %67
  br i1 %68, label %69, label %71

69:                                               ; preds = %58
  %70 = call i32 @puts(ptr noundef @.str.5)
  store i32 1, ptr %4, align 4
  br label %105

71:                                               ; preds = %58
  br label %72

72:                                               ; preds = %99, %71
  %73 = load i32, ptr %1, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [100021 x i32], ptr @_ZZ5solvevE1a, i64 0, i64 %74
  %76 = load i32, ptr %75, align 4, !tbaa !5
  %77 = load i32, ptr %2, align 4, !tbaa !5
  %78 = icmp sge i32 %76, %77
  br i1 %78, label %79, label %102

79:                                               ; preds = %72
  %80 = load i32, ptr %1, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [100021 x i32], ptr @_ZZ5solvevE1a, i64 0, i64 %81
  %83 = load i32, ptr %82, align 4, !tbaa !5
  %84 = load i32, ptr %1, align 4, !tbaa !5
  %85 = sub nsw i32 %84, 1
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [100021 x i32], ptr @_ZZ5solvevE1a, i64 0, i64 %86
  %88 = load i32, ptr %87, align 4, !tbaa !5
  %89 = sub nsw i32 %83, %88
  %90 = load i32, ptr %1, align 4, !tbaa !5
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds [100021 x i32], ptr @_ZZ5solvevE1a, i64 0, i64 %91
  %93 = load i32, ptr %92, align 4, !tbaa !5
  %94 = add nsw i32 %89, %93
  %95 = load i32, ptr %1, align 4, !tbaa !5
  %96 = add nsw i32 %95, 1
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds [100021 x i32], ptr @_ZZ5solvevE1a, i64 0, i64 %97
  store i32 %94, ptr %98, align 4, !tbaa !5
  br label %99

99:                                               ; preds = %79
  %100 = load i32, ptr %1, align 4, !tbaa !5
  %101 = add nsw i32 %100, 1
  store i32 %101, ptr %1, align 4, !tbaa !5
  br label %72, !llvm.loop !11

102:                                              ; preds = %72
  %103 = load i32, ptr %1, align 4, !tbaa !5
  %104 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, i32 noundef %103)
  store i32 0, ptr %4, align 4
  br label %105

105:                                              ; preds = %102, %69
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #4
  %106 = load i32, ptr %4, align 4
  switch i32 %106, label %108 [
    i32 0, label %107
    i32 1, label %107
  ]

107:                                              ; preds = %105, %105
  ret void

108:                                              ; preds = %105
  unreachable
}

; 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #3

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

declare i32 @puts(ptr noundef) #2

declare i32 @printf(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 = { noreturn 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 #4 = { nounwind }
attributes #5 = { noreturn 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}


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

@_ZZ5solvevE1a = external hidden global [100021 x i32], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [71 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [76 x i8], align 1
@__PRETTY_FUNCTION__._Z5solvev = external hidden unnamed_addr constant [13 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [54 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [37 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5solvev() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %4 = icmp eq i32 %3, 2
  %5 = load i32, ptr %1, align 4
  %6 = add i32 %5, -2
  %7 = icmp ult i32 %6, 9
  %or.cond3 = select i1 %4, i1 %7, i1 false
  %8 = load i32, ptr %2, align 4
  %9 = add i32 %8, -1
  %10 = icmp ult i32 %9, 1000
  %or.cond9 = select i1 %or.cond3, i1 %10, i1 false
  br i1 %or.cond9, label %.lr.ph, label %.critedge

.critedge:                                        ; preds = %0
  call void @__assert_fail(ptr noundef nonnull @.str.1, ptr noundef nonnull @.str.2, i32 noundef 13, ptr noundef nonnull @__PRETTY_FUNCTION__._Z5solvev) #5
  unreachable

11:                                               ; preds = %23
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %12 = load i32, ptr %1, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %.not.not = icmp slt i64 %indvars.iv, %13
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %11
  %14 = getelementptr inbounds [100021 x i32], ptr @_ZZ5solvevE1a, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = add nsw i32 %12, -1
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [100021 x i32], ptr @_ZZ5solvevE1a, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %.not17 = icmp slt i32 %15, %19
  br i1 %.not17, label %.preheader, label %28

.preheader:                                       ; preds = %._crit_edge
  %.not1824 = icmp slt i32 %15, %24
  br i1 %.not1824, label %37, label %.lr.ph25

.lr.ph:                                           ; preds = %0, %11
  %indvars.iv = phi i64 [ %indvars.iv.next, %11 ], [ 1, %0 ]
  %20 = getelementptr inbounds i32, ptr @_ZZ5solvevE1a, i64 %indvars.iv
  %21 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.3, ptr noundef nonnull %20)
  %22 = icmp eq i32 %21, 1
  br i1 %22, label %23, label %.critedge7

23:                                               ; preds = %.lr.ph
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = load i32, ptr %20, align 4, !tbaa !5
  %26 = icmp slt i32 %24, %25
  %27 = icmp slt i32 %25, 100001
  %or.cond = and i1 %26, %27
  br i1 %or.cond, label %11, label %.critedge7

.critedge7:                                       ; preds = %23, %.lr.ph
  call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.2, i32 noundef 18, ptr noundef nonnull @__PRETTY_FUNCTION__._Z5solvev) #5
  unreachable

28:                                               ; preds = %._crit_edge
  %29 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.5)
  br label %39

.lr.ph25:                                         ; preds = %.preheader, %.lr.ph25
  %indvars.iv32 = phi i64 [ %indvars.iv.next33, %.lr.ph25 ], [ %13, %.preheader ]
  %30 = phi i32 [ %34, %.lr.ph25 ], [ %15, %.preheader ]
  %31 = add nsw i64 %indvars.iv32, -1
  %32 = getelementptr inbounds [100021 x i32], ptr @_ZZ5solvevE1a, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %factor = shl i32 %30, 1
  %34 = sub i32 %factor, %33
  %indvars.iv.next33 = add nsw i64 %indvars.iv32, 1
  %35 = getelementptr inbounds [100021 x i32], ptr @_ZZ5solvevE1a, i64 0, i64 %indvars.iv.next33
  store i32 %34, ptr %35, align 4, !tbaa !5
  %.not18 = icmp slt i32 %34, %24
  br i1 %.not18, label %._crit_edge26, label %.lr.ph25, !llvm.loop !11

._crit_edge26:                                    ; preds = %.lr.ph25
  %36 = trunc nsw i64 %indvars.iv.next33 to i32
  store i32 %36, ptr %1, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %._crit_edge26, %.preheader
  %.lcssa = phi i32 [ %36, %._crit_edge26 ], [ %12, %.preheader ]
  %38 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, i32 noundef %.lcssa)
  br label %39

39:                                               ; preds = %37, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret void
}

; 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #3

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

attributes #0 = { mustprogress 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 = { noreturn 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 #4 = { nounwind }
attributes #5 = { noreturn 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,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass