; LLVM IR from Shah-Shishir/Codeforces-Solutions :: 552B. Vanya and Books (main)

; 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 [6 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z4minixx(i64 noundef, i64 noundef) #0

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

5:                                                ; preds = %100, %0
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  %7 = icmp ne i32 %6, -1
  br i1 %7, label %8, label %103

8:                                                ; preds = %5
  %9 = load i64, ptr %2, align 8, !tbaa !5
  %10 = call noundef i64 @_Z4minixx(i64 noundef %9, i64 noundef 9)
  store i64 %10, ptr %3, align 8, !tbaa !5
  %11 = load i64, ptr %2, align 8, !tbaa !5
  %12 = icmp sge i64 %11, 10
  br i1 %12, label %13, label %20

13:                                               ; preds = %8
  %14 = load i64, ptr %2, align 8, !tbaa !5
  %15 = call noundef i64 @_Z4minixx(i64 noundef %14, i64 noundef 99)
  %16 = sub nsw i64 %15, 9
  %17 = mul nsw i64 %16, 2
  %18 = load i64, ptr %3, align 8, !tbaa !5
  %19 = add nsw i64 %18, %17
  store i64 %19, ptr %3, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %13, %8
  %21 = load i64, ptr %2, align 8, !tbaa !5
  %22 = icmp sge i64 %21, 100
  br i1 %22, label %23, label %30

23:                                               ; preds = %20
  %24 = load i64, ptr %2, align 8, !tbaa !5
  %25 = call noundef i64 @_Z4minixx(i64 noundef %24, i64 noundef 999)
  %26 = sub nsw i64 %25, 99
  %27 = mul nsw i64 %26, 3
  %28 = load i64, ptr %3, align 8, !tbaa !5
  %29 = add nsw i64 %28, %27
  store i64 %29, ptr %3, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %23, %20
  %31 = load i64, ptr %2, align 8, !tbaa !5
  %32 = icmp sge i64 %31, 1000
  br i1 %32, label %33, label %40

33:                                               ; preds = %30
  %34 = load i64, ptr %2, align 8, !tbaa !5
  %35 = call noundef i64 @_Z4minixx(i64 noundef %34, i64 noundef 9999)
  %36 = sub nsw i64 %35, 999
  %37 = mul nsw i64 %36, 4
  %38 = load i64, ptr %3, align 8, !tbaa !5
  %39 = add nsw i64 %38, %37
  store i64 %39, ptr %3, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %33, %30
  %41 = load i64, ptr %2, align 8, !tbaa !5
  %42 = icmp sge i64 %41, 10000
  br i1 %42, label %43, label %50

43:                                               ; preds = %40
  %44 = load i64, ptr %2, align 8, !tbaa !5
  %45 = call noundef i64 @_Z4minixx(i64 noundef %44, i64 noundef 99999)
  %46 = sub nsw i64 %45, 9999
  %47 = mul nsw i64 %46, 5
  %48 = load i64, ptr %3, align 8, !tbaa !5
  %49 = add nsw i64 %48, %47
  store i64 %49, ptr %3, align 8, !tbaa !5
  br label %50

50:                                               ; preds = %43, %40
  %51 = load i64, ptr %2, align 8, !tbaa !5
  %52 = icmp sge i64 %51, 100000
  br i1 %52, label %53, label %60

53:                                               ; preds = %50
  %54 = load i64, ptr %2, align 8, !tbaa !5
  %55 = call noundef i64 @_Z4minixx(i64 noundef %54, i64 noundef 999999)
  %56 = sub nsw i64 %55, 99999
  %57 = mul nsw i64 %56, 6
  %58 = load i64, ptr %3, align 8, !tbaa !5
  %59 = add nsw i64 %58, %57
  store i64 %59, ptr %3, align 8, !tbaa !5
  br label %60

60:                                               ; preds = %53, %50
  %61 = load i64, ptr %2, align 8, !tbaa !5
  %62 = icmp sge i64 %61, 1000000
  br i1 %62, label %63, label %70

63:                                               ; preds = %60
  %64 = load i64, ptr %2, align 8, !tbaa !5
  %65 = call noundef i64 @_Z4minixx(i64 noundef %64, i64 noundef 9999999)
  %66 = sub nsw i64 %65, 999999
  %67 = mul nsw i64 %66, 7
  %68 = load i64, ptr %3, align 8, !tbaa !5
  %69 = add nsw i64 %68, %67
  store i64 %69, ptr %3, align 8, !tbaa !5
  br label %70

70:                                               ; preds = %63, %60
  %71 = load i64, ptr %2, align 8, !tbaa !5
  %72 = icmp sge i64 %71, 10000000
  br i1 %72, label %73, label %80

73:                                               ; preds = %70
  %74 = load i64, ptr %2, align 8, !tbaa !5
  %75 = call noundef i64 @_Z4minixx(i64 noundef %74, i64 noundef 99999999)
  %76 = sub nsw i64 %75, 9999999
  %77 = mul nsw i64 %76, 8
  %78 = load i64, ptr %3, align 8, !tbaa !5
  %79 = add nsw i64 %78, %77
  store i64 %79, ptr %3, align 8, !tbaa !5
  br label %80

80:                                               ; preds = %73, %70
  %81 = load i64, ptr %2, align 8, !tbaa !5
  %82 = icmp sge i64 %81, 100000000
  br i1 %82, label %83, label %90

83:                                               ; preds = %80
  %84 = load i64, ptr %2, align 8, !tbaa !5
  %85 = call noundef i64 @_Z4minixx(i64 noundef %84, i64 noundef 999999999)
  %86 = sub nsw i64 %85, 99999999
  %87 = mul nsw i64 %86, 9
  %88 = load i64, ptr %3, align 8, !tbaa !5
  %89 = add nsw i64 %88, %87
  store i64 %89, ptr %3, align 8, !tbaa !5
  br label %90

90:                                               ; preds = %83, %80
  %91 = load i64, ptr %2, align 8, !tbaa !5
  %92 = icmp sge i64 %91, 1000000000
  br i1 %92, label %93, label %100

93:                                               ; preds = %90
  %94 = load i64, ptr %2, align 8, !tbaa !5
  %95 = call noundef i64 @_Z4minixx(i64 noundef %94, i64 noundef 9999999999)
  %96 = sub nsw i64 %95, 999999999
  %97 = mul nsw i64 %96, 10
  %98 = load i64, ptr %3, align 8, !tbaa !5
  %99 = add nsw i64 %98, %97
  store i64 %99, ptr %3, align 8, !tbaa !5
  br label %100

100:                                              ; preds = %93, %90
  %101 = load i64, ptr %3, align 8, !tbaa !5
  %102 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %101)
  br label %5, !llvm.loop !9

103:                                              ; preds = %5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, 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) #2

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; 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 [6 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z4minixx(i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %.not62 = icmp eq i32 %2, -1
  br i1 %.not62, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %.thread44
  %3 = load i64, ptr %1, align 8, !tbaa !5
  %4 = call noundef i64 @_Z4minixx(i64 noundef %3, i64 noundef 9)
  %5 = load i64, ptr %1, align 8, !tbaa !5
  %6 = icmp sgt i64 %5, 9
  br i1 %6, label %7, label %.thread44

7:                                                ; preds = %.lr.ph
  %8 = call noundef i64 @_Z4minixx(i64 noundef %5, i64 noundef 99)
  %9 = shl i64 %8, 1
  %10 = add i64 %4, -18
  %11 = add i64 %10, %9
  %.pr = load i64, ptr %1, align 8, !tbaa !5
  %12 = icmp sgt i64 %.pr, 99
  br i1 %12, label %13, label %.thread44

13:                                               ; preds = %7
  %14 = call noundef i64 @_Z4minixx(i64 noundef %.pr, i64 noundef 999)
  %15 = mul i64 %14, 3
  %16 = add i64 %11, -297
  %17 = add i64 %16, %15
  %.pr20 = load i64, ptr %1, align 8, !tbaa !5
  %18 = icmp sgt i64 %.pr20, 999
  br i1 %18, label %.thread21, label %.thread44

.thread21:                                        ; preds = %13
  %19 = call noundef i64 @_Z4minixx(i64 noundef %.pr20, i64 noundef 9999)
  %20 = shl i64 %19, 2
  %21 = add i64 %17, -3996
  %22 = add i64 %21, %20
  %.pr23.pr = load i64, ptr %1, align 8, !tbaa !5
  %23 = icmp sgt i64 %.pr23.pr, 9999
  br i1 %23, label %24, label %.thread44

24:                                               ; preds = %.thread21
  %25 = call noundef i64 @_Z4minixx(i64 noundef %.pr23.pr, i64 noundef 99999)
  %26 = mul i64 %25, 5
  %27 = add i64 %22, -49995
  %28 = add i64 %27, %26
  %.pr26 = load i64, ptr %1, align 8, !tbaa !5
  %29 = icmp sgt i64 %.pr26, 99999
  br i1 %29, label %.thread28, label %.thread44

.thread28:                                        ; preds = %24
  %30 = call noundef i64 @_Z4minixx(i64 noundef %.pr26, i64 noundef 999999)
  %31 = mul i64 %30, 6
  %32 = add i64 %28, -599994
  %33 = add i64 %32, %31
  %.pr31.pr.pr = load i64, ptr %1, align 8, !tbaa !5
  %34 = icmp sgt i64 %.pr31.pr.pr, 999999
  br i1 %34, label %35, label %.thread44

35:                                               ; preds = %.thread28
  %36 = call noundef i64 @_Z4minixx(i64 noundef %.pr31.pr.pr, i64 noundef 9999999)
  %37 = mul i64 %36, 7
  %38 = add i64 %33, -6999993
  %39 = add i64 %38, %37
  %.pr34 = load i64, ptr %1, align 8, !tbaa !5
  %40 = icmp sgt i64 %.pr34, 9999999
  br i1 %40, label %.thread36, label %.thread44

.thread36:                                        ; preds = %35
  %41 = call noundef i64 @_Z4minixx(i64 noundef %.pr34, i64 noundef 99999999)
  %42 = shl i64 %41, 3
  %43 = add i64 %39, -79999992
  %44 = add i64 %43, %42
  %.pr39.pr.pr = load i64, ptr %1, align 8, !tbaa !5
  %45 = icmp sgt i64 %.pr39.pr.pr, 99999999
  br i1 %45, label %46, label %.thread44

46:                                               ; preds = %.thread36
  %47 = call noundef i64 @_Z4minixx(i64 noundef %.pr39.pr.pr, i64 noundef 999999999)
  %48 = mul i64 %47, 9
  %49 = add i64 %44, -899999991
  %50 = add i64 %49, %48
  %.pr42 = load i64, ptr %1, align 8, !tbaa !5
  %51 = icmp sgt i64 %.pr42, 999999999
  br i1 %51, label %52, label %.thread44

52:                                               ; preds = %46
  %53 = call noundef i64 @_Z4minixx(i64 noundef %.pr42, i64 noundef 9999999999)
  %54 = mul i64 %53, 10
  %55 = add i64 %50, -9999999990
  %56 = add i64 %55, %54
  br label %.thread44

.thread44:                                        ; preds = %13, %.thread21, %.lr.ph, %7, %.thread28, %24, %35, %.thread36, %52, %46
  %.8 = phi i64 [ %56, %52 ], [ %50, %46 ], [ %44, %.thread36 ], [ %39, %35 ], [ %28, %24 ], [ %33, %.thread28 ], [ %11, %7 ], [ %4, %.lr.ph ], [ %22, %.thread21 ], [ %17, %13 ]
  %57 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %.8)
  %58 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %.not = icmp eq i32 %58, -1
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.thread44, %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) #2

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) 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) #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 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass