; LLVM IR from DionysiosB/CodeForces :: 1400-1499 (1447B-NumbersBox)

; 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 [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 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 i32, align 4
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  br label %13

13:                                               ; preds = %59, %0
  %14 = load i64, ptr %2, align 8, !tbaa !5
  %15 = add nsw i64 %14, -1
  store i64 %15, ptr %2, align 8, !tbaa !5
  %16 = icmp ne i64 %14, 0
  br i1 %16, label %17, label %69

17:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %18 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %3, ptr noundef %4)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store i64 107, 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 0, 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
  br label %19

19:                                               ; preds = %56, %17
  %20 = load i64, ptr %8, align 8, !tbaa !5
  %21 = load i64, ptr %3, align 8, !tbaa !5
  %22 = icmp slt i64 %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  store i32 4, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %59

24:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 0, ptr %10, align 8, !tbaa !5
  br label %25

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

29:                                               ; preds = %25
  store i32 7, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %55

30:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %31 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %11)
  %32 = load i64, ptr %11, align 8, !tbaa !5
  %33 = icmp slt i64 %32, 0
  br i1 %33, label %34, label %39

34:                                               ; preds = %30
  %35 = load i64, ptr %11, align 8, !tbaa !5
  %36 = sub nsw i64 0, %35
  store i64 %36, ptr %11, align 8, !tbaa !5
  %37 = load i64, ptr %6, align 8, !tbaa !5
  %38 = add nsw i64 %37, 1
  store i64 %38, ptr %6, align 8, !tbaa !5
  br label %39

39:                                               ; preds = %34, %30
  %40 = load i64, ptr %5, align 8, !tbaa !5
  %41 = load i64, ptr %11, align 8, !tbaa !5
  %42 = icmp slt i64 %40, %41
  br i1 %42, label %43, label %45

43:                                               ; preds = %39
  %44 = load i64, ptr %5, align 8, !tbaa !5
  br label %47

45:                                               ; preds = %39
  %46 = load i64, ptr %11, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %45, %43
  %48 = phi i64 [ %44, %43 ], [ %46, %45 ]
  store i64 %48, ptr %5, align 8, !tbaa !5
  %49 = load i64, ptr %11, align 8, !tbaa !5
  %50 = load i64, ptr %7, align 8, !tbaa !5
  %51 = add nsw i64 %50, %49
  store i64 %51, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  br label %52

52:                                               ; preds = %47
  %53 = load i64, ptr %10, align 8, !tbaa !5
  %54 = add nsw i64 %53, 1
  store i64 %54, ptr %10, align 8, !tbaa !5
  br label %25, !llvm.loop !9

55:                                               ; preds = %29
  br label %56

56:                                               ; preds = %55
  %57 = load i64, ptr %8, align 8, !tbaa !5
  %58 = add nsw i64 %57, 1
  store i64 %58, ptr %8, align 8, !tbaa !5
  br label %19, !llvm.loop !11

59:                                               ; preds = %23
  %60 = load i64, ptr %6, align 8, !tbaa !5
  %61 = srem i64 %60, 2
  %62 = mul nsw i64 2, %61
  %63 = load i64, ptr %5, align 8, !tbaa !5
  %64 = mul nsw i64 %62, %63
  %65 = load i64, ptr %7, align 8, !tbaa !5
  %66 = sub nsw i64 %65, %64
  store i64 %66, ptr %7, align 8, !tbaa !5
  %67 = load i64, ptr %7, align 8, !tbaa !5
  %68 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %67)
  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
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  br label %13, !llvm.loop !12

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

; 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

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", !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}


; 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 [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 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
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %6 = load i64, ptr %1, align 8, !tbaa !5
  %7 = add nsw i64 %6, -1
  store i64 %7, ptr %1, align 8, !tbaa !5
  %.not36 = icmp eq i64 %6, 0
  br i1 %.not36, label %._crit_edge39, label %.lr.ph38

.lr.ph38:                                         ; preds = %0, %._crit_edge30
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %2, ptr noundef nonnull %3)
  %9 = load i64, ptr %2, align 8, !tbaa !5
  %10 = icmp sgt i64 %9, 0
  %11 = load i64, ptr %3, align 8
  %12 = icmp sgt i64 %11, 0
  %or.cond = select i1 %10, i1 %12, i1 false
  br i1 %or.cond, label %.preheader, label %._crit_edge30

.preheader:                                       ; preds = %.lr.ph38, %._crit_edge
  %13 = phi i64 [ %23, %._crit_edge ], [ %9, %.lr.ph38 ]
  %14 = phi i64 [ %24, %._crit_edge ], [ %11, %.lr.ph38 ]
  %.01329 = phi i64 [ %25, %._crit_edge ], [ 0, %.lr.ph38 ]
  %.01428 = phi i64 [ %.1.lcssa, %._crit_edge ], [ 0, %.lr.ph38 ]
  %.01527 = phi i64 [ %.116.lcssa, %._crit_edge ], [ 0, %.lr.ph38 ]
  %.01726 = phi i64 [ %.118.lcssa, %._crit_edge ], [ 107, %.lr.ph38 ]
  %15 = icmp sgt i64 %14, 0
  br i1 %15, label %.lr.ph, label %._crit_edge

._crit_edge30:                                    ; preds = %._crit_edge, %.lr.ph38
  %.017.lcssa = phi i64 [ 107, %.lr.ph38 ], [ %.118.lcssa, %._crit_edge ]
  %.015.lcssa = phi i64 [ 0, %.lr.ph38 ], [ %.116.lcssa, %._crit_edge ]
  %.014.lcssa = phi i64 [ 0, %.lr.ph38 ], [ %.1.lcssa, %._crit_edge ]
  %16 = srem i64 %.015.lcssa, 2
  %17 = shl i64 %.017.lcssa, 1
  %18 = mul i64 %17, %16
  %19 = sub nsw i64 %.014.lcssa, %18
  %20 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %19)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  %21 = load i64, ptr %1, align 8, !tbaa !5
  %22 = add nsw i64 %21, -1
  store i64 %22, ptr %1, align 8, !tbaa !5
  %.not = icmp eq i64 %21, 0
  br i1 %.not, label %._crit_edge39, label %.lr.ph38, !llvm.loop !9

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i64, ptr %2, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %23 = phi i64 [ %13, %.preheader ], [ %.pre, %._crit_edge.loopexit ]
  %24 = phi i64 [ %14, %.preheader ], [ %34, %._crit_edge.loopexit ]
  %.118.lcssa = phi i64 [ %.01726, %.preheader ], [ %31, %._crit_edge.loopexit ]
  %.116.lcssa = phi i64 [ %.01527, %.preheader ], [ %.2, %._crit_edge.loopexit ]
  %.1.lcssa = phi i64 [ %.01428, %.preheader ], [ %32, %._crit_edge.loopexit ]
  %25 = add nuw nsw i64 %.01329, 1
  %26 = icmp slt i64 %25, %23
  br i1 %26, label %.preheader, label %._crit_edge30, !llvm.loop !11

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.023 = phi i64 [ %33, %.lr.ph ], [ 0, %.preheader ]
  %.122 = phi i64 [ %32, %.lr.ph ], [ %.01428, %.preheader ]
  %.11621 = phi i64 [ %.2, %.lr.ph ], [ %.01527, %.preheader ]
  %.11820 = phi i64 [ %31, %.lr.ph ], [ %.01726, %.preheader ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  %27 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %4)
  %28 = load i64, ptr %4, align 8
  %29 = call i64 @llvm.abs.i64(i64 %28, i1 true)
  %30 = lshr i64 %28, 63
  %.2 = add i64 %.11621, %30
  %31 = call i64 @llvm.smin.i64(i64 %.11820, i64 %29)
  %32 = add nsw i64 %29, %.122
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  %33 = add nuw nsw i64 %.023, 1
  %34 = load i64, ptr %3, align 8, !tbaa !5
  %35 = icmp slt i64 %33, %34
  br i1 %35, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !13

._crit_edge39:                                    ; preds = %._crit_edge30, %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: 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: 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.abs.i64(i64, i1 immarg) #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", !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}
!12 = !{!"llvm.loop.unswitch.partial.disable"}
!13 = distinct !{!13, !10}


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