; LLVM IR from DionysiosB/CodeForces :: 1600-1699 (1621B-IntegersShop)

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

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  store i64 10000000000, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %3)
  br label %18

18:                                               ; preds = %125, %0
  %19 = load i64, ptr %3, align 8, !tbaa !5
  %20 = add nsw i64 %19, -1
  store i64 %20, ptr %3, align 8, !tbaa !5
  %21 = icmp ne i64 %19, 0
  br i1 %21, label %22, label %126

22:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %23 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %4)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store i64 1000000007, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 0, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 -1000000007, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i64 0, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store i64 0, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 0, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  store i64 0, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  store i64 0, ptr %12, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %122, %22
  %25 = load i64, ptr %12, align 8, !tbaa !5
  %26 = load i64, ptr %4, align 8, !tbaa !5
  %27 = icmp slt i64 %25, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  br label %125

29:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  store i64 0, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  store i64 0, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  store i64 0, ptr %15, align 8, !tbaa !5
  %30 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %13, ptr noundef %14, ptr noundef %15)
  %31 = load i64, ptr %13, align 8, !tbaa !5
  %32 = load i64, ptr %5, align 8, !tbaa !5
  %33 = icmp slt i64 %31, %32
  br i1 %33, label %34, label %36

34:                                               ; preds = %29
  %35 = load i64, ptr %13, align 8, !tbaa !5
  store i64 %35, ptr %5, align 8, !tbaa !5
  store i64 10000000000, ptr %6, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %34, %29
  %37 = load i64, ptr %13, align 8, !tbaa !5
  %38 = load i64, ptr %5, align 8, !tbaa !5
  %39 = icmp eq i64 %37, %38
  br i1 %39, label %40, label %50

40:                                               ; preds = %36
  %41 = load i64, ptr %6, align 8, !tbaa !5
  %42 = load i64, ptr %15, align 8, !tbaa !5
  %43 = icmp slt i64 %41, %42
  br i1 %43, label %44, label %46

44:                                               ; preds = %40
  %45 = load i64, ptr %6, align 8, !tbaa !5
  br label %48

46:                                               ; preds = %40
  %47 = load i64, ptr %15, align 8, !tbaa !5
  br label %48

48:                                               ; preds = %46, %44
  %49 = phi i64 [ %45, %44 ], [ %47, %46 ]
  store i64 %49, ptr %6, align 8, !tbaa !5
  br label %50

50:                                               ; preds = %48, %36
  %51 = load i64, ptr %7, align 8, !tbaa !5
  %52 = load i64, ptr %14, align 8, !tbaa !5
  %53 = icmp slt i64 %51, %52
  br i1 %53, label %54, label %56

54:                                               ; preds = %50
  %55 = load i64, ptr %14, align 8, !tbaa !5
  store i64 %55, ptr %7, align 8, !tbaa !5
  store i64 10000000000, ptr %8, align 8, !tbaa !5
  br label %56

56:                                               ; preds = %54, %50
  %57 = load i64, ptr %7, align 8, !tbaa !5
  %58 = load i64, ptr %14, align 8, !tbaa !5
  %59 = icmp eq i64 %57, %58
  br i1 %59, label %60, label %70

60:                                               ; preds = %56
  %61 = load i64, ptr %8, align 8, !tbaa !5
  %62 = load i64, ptr %15, align 8, !tbaa !5
  %63 = icmp slt i64 %61, %62
  br i1 %63, label %64, label %66

64:                                               ; preds = %60
  %65 = load i64, ptr %8, align 8, !tbaa !5
  br label %68

66:                                               ; preds = %60
  %67 = load i64, ptr %15, align 8, !tbaa !5
  br label %68

68:                                               ; preds = %66, %64
  %69 = phi i64 [ %65, %64 ], [ %67, %66 ]
  store i64 %69, ptr %8, align 8, !tbaa !5
  br label %70

70:                                               ; preds = %68, %56
  %71 = load i64, ptr %9, align 8, !tbaa !5
  %72 = load i64, ptr %14, align 8, !tbaa !5
  %73 = load i64, ptr %13, align 8, !tbaa !5
  %74 = sub nsw i64 %72, %73
  %75 = add nsw i64 %74, 1
  %76 = icmp slt i64 %71, %75
  br i1 %76, label %77, label %82

77:                                               ; preds = %70
  %78 = load i64, ptr %14, align 8, !tbaa !5
  %79 = load i64, ptr %13, align 8, !tbaa !5
  %80 = sub nsw i64 %78, %79
  %81 = add nsw i64 %80, 1
  store i64 %81, ptr %9, align 8, !tbaa !5
  store i64 10000000000, ptr %10, align 8, !tbaa !5
  br label %82

82:                                               ; preds = %77, %70
  %83 = load i64, ptr %9, align 8, !tbaa !5
  %84 = load i64, ptr %14, align 8, !tbaa !5
  %85 = load i64, ptr %13, align 8, !tbaa !5
  %86 = sub nsw i64 %84, %85
  %87 = add nsw i64 %86, 1
  %88 = icmp eq i64 %83, %87
  br i1 %88, label %89, label %99

89:                                               ; preds = %82
  %90 = load i64, ptr %10, align 8, !tbaa !5
  %91 = load i64, ptr %15, align 8, !tbaa !5
  %92 = icmp slt i64 %90, %91
  br i1 %92, label %93, label %95

93:                                               ; preds = %89
  %94 = load i64, ptr %10, align 8, !tbaa !5
  br label %97

95:                                               ; preds = %89
  %96 = load i64, ptr %15, align 8, !tbaa !5
  br label %97

97:                                               ; preds = %95, %93
  %98 = phi i64 [ %94, %93 ], [ %96, %95 ]
  store i64 %98, ptr %10, align 8, !tbaa !5
  br label %99

99:                                               ; preds = %97, %82
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %100 = load i64, ptr %6, align 8, !tbaa !5
  %101 = load i64, ptr %8, align 8, !tbaa !5
  %102 = add nsw i64 %100, %101
  store i64 %102, ptr %16, align 8, !tbaa !5
  %103 = load i64, ptr %9, align 8, !tbaa !5
  %104 = load i64, ptr %7, align 8, !tbaa !5
  %105 = load i64, ptr %5, align 8, !tbaa !5
  %106 = sub nsw i64 %104, %105
  %107 = add nsw i64 %106, 1
  %108 = icmp eq i64 %103, %107
  br i1 %108, label %109, label %119

109:                                              ; preds = %99
  %110 = load i64, ptr %16, align 8, !tbaa !5
  %111 = load i64, ptr %10, align 8, !tbaa !5
  %112 = icmp slt i64 %110, %111
  br i1 %112, label %113, label %115

113:                                              ; preds = %109
  %114 = load i64, ptr %16, align 8, !tbaa !5
  br label %117

115:                                              ; preds = %109
  %116 = load i64, ptr %10, align 8, !tbaa !5
  br label %117

117:                                              ; preds = %115, %113
  %118 = phi i64 [ %114, %113 ], [ %116, %115 ]
  store i64 %118, ptr %16, align 8, !tbaa !5
  br label %119

119:                                              ; preds = %117, %99
  %120 = load i64, ptr %16, align 8, !tbaa !5
  %121 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %120)
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  br label %122

122:                                              ; preds = %119
  %123 = load i64, ptr %12, align 8, !tbaa !5
  %124 = add nsw i64 %123, 1
  store i64 %124, ptr %12, align 8, !tbaa !5
  br label %24, !llvm.loop !9

125:                                              ; preds = %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %18, !llvm.loop !11

126:                                              ; preds = %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  %127 = load i32, ptr %1, align 4
  ret i32 %127
}

; 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 @printf(ptr noundef, ...) #2

; 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 = { 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 = !{!"long long", !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"

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %7 = load i64, ptr %1, align 8, !tbaa !5
  %8 = add nsw i64 %7, -1
  store i64 %8, ptr %1, align 8, !tbaa !5
  %.not53 = icmp eq i64 %7, 0
  br i1 %.not53, label %._crit_edge56, label %.lr.ph55

.lr.ph55:                                         ; preds = %0, %._crit_edge
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %2)
  %10 = load i64, ptr %2, align 8, !tbaa !5
  %11 = icmp sgt i64 %10, 0
  br i1 %11, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph55
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  %12 = load i64, ptr %1, align 8, !tbaa !5
  %13 = add nsw i64 %12, -1
  store i64 %13, ptr %1, align 8, !tbaa !5
  %.not = icmp eq i64 %12, 0
  br i1 %.not, label %._crit_edge56, label %.lr.ph55, !llvm.loop !9

.lr.ph:                                           ; preds = %.lr.ph55, %.lr.ph
  %.02552 = phi i64 [ %31, %.lr.ph ], [ 0, %.lr.ph55 ]
  %.02651 = phi i64 [ %spec.select43, %.lr.ph ], [ 1000000007, %.lr.ph55 ]
  %.02750 = phi i64 [ %.2, %.lr.ph ], [ 0, %.lr.ph55 ]
  %.02949 = phi i64 [ %.130, %.lr.ph ], [ 0, %.lr.ph55 ]
  %.03148 = phi i64 [ %.233, %.lr.ph ], [ 0, %.lr.ph55 ]
  %.03447 = phi i64 [ %.135, %.lr.ph ], [ -1000000007, %.lr.ph55 ]
  %.03646 = phi i64 [ %.238, %.lr.ph ], [ 0, %.lr.ph55 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  store i64 0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  store i64 0, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  store i64 0, ptr %5, align 8, !tbaa !5
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %3, ptr noundef nonnull %4, ptr noundef nonnull %5)
  %15 = load i64, ptr %3, align 8, !tbaa !5
  %16 = icmp slt i64 %15, %.02651
  %spec.select = select i1 %16, i64 10000000000, i64 %.03646
  %spec.select43 = call i64 @llvm.smin.i64(i64 %15, i64 %.02651)
  %.not44 = icmp sgt i64 %15, %.02651
  %17 = load i64, ptr %5, align 8
  %18 = call i64 @llvm.smin.i64(i64 %spec.select, i64 %17)
  %.238 = select i1 %.not44, i64 %.03646, i64 %18
  %19 = load i64, ptr %4, align 8, !tbaa !5
  %20 = icmp slt i64 %.03447, %19
  %.135 = call i64 @llvm.smax.i64(i64 %.03447, i64 %19)
  %.132 = select i1 %20, i64 10000000000, i64 %.03148
  %.not45 = icmp slt i64 %19, %.03447
  %21 = call i64 @llvm.smin.i64(i64 %.132, i64 %17)
  %.233 = select i1 %.not45, i64 %.03148, i64 %21
  %22 = sub nsw i64 %19, %15
  %.not42 = icmp sgt i64 %.02949, %22
  %23 = add nsw i64 %22, 1
  %.130 = select i1 %.not42, i64 %.02949, i64 %23
  %.128 = select i1 %.not42, i64 %.02750, i64 10000000000
  %24 = icmp eq i64 %.130, %23
  %25 = call i64 @llvm.smin.i64(i64 %.128, i64 %17)
  %.2 = select i1 %24, i64 %25, i64 %.128
  %26 = add nsw i64 %.233, %.238
  %reass.sub = sub i64 %.135, %spec.select43
  %27 = add i64 %reass.sub, 1
  %28 = icmp eq i64 %.130, %27
  %29 = call i64 @llvm.smin.i64(i64 %26, i64 %.2)
  %.0 = select i1 %28, i64 %29, i64 %26
  %30 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %.0)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  %31 = add nuw nsw i64 %.02552, 1
  %32 = load i64, ptr %2, align 8, !tbaa !5
  %33 = icmp slt i64 %31, %32
  br i1 %33, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge56:                                    ; preds = %._crit_edge, %0
  call void @llvm.lifetime.end.p0(i64 8, 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 @printf(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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smin.i64(i64, i64) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smax.i64(i64, i64) #3

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 = { 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 = !{!"long long", !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,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass