; LLVM IR from hanzohasashi33/Competetive_programming :: CodeChef/Easy (Carvans)

; 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 [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  br label %11

11:                                               ; preds = %59, %0
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %14, label %65

14:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %3)
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = zext i32 %16 to i64
  %18 = call ptr @llvm.stacksave.p0()
  store ptr %18, ptr %4, align 8
  %19 = alloca i32, i64 %17, align 16
  store i64 %17, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 1, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %30, %14
  %21 = load i32, ptr %7, align 4, !tbaa !5
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %33

25:                                               ; preds = %20
  %26 = load i32, ptr %7, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds i32, ptr %19, i64 %27
  %29 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %28)
  br label %30

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

33:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %34 = getelementptr inbounds i32, ptr %19, i64 0
  %35 = load i32, ptr %34, align 16, !tbaa !5
  store i32 %35, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 1, ptr %9, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %56, %33
  %37 = load i32, ptr %9, align 4, !tbaa !5
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %59

41:                                               ; preds = %36
  %42 = load i32, ptr %8, align 4, !tbaa !5
  %43 = load i32, ptr %9, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds i32, ptr %19, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = icmp sgt i32 %42, %46
  br i1 %47, label %48, label %55

48:                                               ; preds = %41
  %49 = load i32, ptr %9, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds i32, ptr %19, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  store i32 %52, ptr %8, align 4, !tbaa !5
  %53 = load i32, ptr %6, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %6, align 4, !tbaa !5
  br label %55

55:                                               ; preds = %48, %41
  br label %56

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

59:                                               ; preds = %40
  %60 = load i32, ptr %6, align 4, !tbaa !5
  %61 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %60)
  %62 = load i32, ptr %2, align 4, !tbaa !5
  %63 = add nsw i32 %62, -1
  store i32 %63, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %64 = load ptr, ptr %4, align 8
  call void @llvm.stackrestore.p0(ptr %64)
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %11, !llvm.loop !12

65:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, 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) #1

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

; 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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

attributes #0 = { 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 = { 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 = { nocallback nofree nosync nounwind willreturn }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/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 [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local noundef i32 @main() 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) #5
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %4 = load i32, ptr %1, align 4, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph25, label %._crit_edge26

.lr.ph25:                                         ; preds = %0, %._crit_edge22
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #5
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %2)
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = zext i32 %7 to i64
  %9 = call ptr @llvm.stacksave.p0()
  %10 = alloca i32, i64 %8, align 16
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.lr.ph, label %._crit_edge22

._crit_edge:                                      ; preds = %.lr.ph
  %13 = icmp sgt i32 %18, 1
  br i1 %13, label %.lr.ph21.preheader, label %._crit_edge22

.lr.ph21.preheader:                               ; preds = %._crit_edge
  %.pre = load i32, ptr %10, align 16, !tbaa !5
  %wide.trip.count = zext nneg i32 %18 to i64
  %14 = add nsw i64 %wide.trip.count, -1
  %xtraiter = and i64 %14, 1
  %15 = icmp eq i32 %18, 2
  br i1 %15, label %._crit_edge22.loopexit.unr-lcssa, label %.lr.ph21.preheader.new

.lr.ph21.preheader.new:                           ; preds = %.lr.ph21.preheader
  %unroll_iter = and i64 %14, -2
  %invariant.gep = getelementptr inbounds i8, ptr %10, i64 4
  br label %.lr.ph21

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

._crit_edge22.loopexit.unr-lcssa:                 ; preds = %.lr.ph21, %.lr.ph21.preheader
  %spec.select.lcssa.ph = phi i32 [ poison, %.lr.ph21.preheader ], [ %spec.select.1, %.lr.ph21 ]
  %indvars.iv29.unr = phi i64 [ 1, %.lr.ph21.preheader ], [ %indvars.iv.next30.1, %.lr.ph21 ]
  %.01018.unr = phi i32 [ %.pre, %.lr.ph21.preheader ], [ %spec.select15.1, %.lr.ph21 ]
  %.01217.unr = phi i32 [ 1, %.lr.ph21.preheader ], [ %spec.select.1, %.lr.ph21 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge22, label %.lr.ph21.epil

.lr.ph21.epil:                                    ; preds = %._crit_edge22.loopexit.unr-lcssa
  %21 = getelementptr inbounds i32, ptr %10, i64 %indvars.iv29.unr
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = icmp sgt i32 %.01018.unr, %22
  %24 = zext i1 %23 to i32
  %spec.select.epil = add nuw nsw i32 %.01217.unr, %24
  br label %._crit_edge22

._crit_edge22:                                    ; preds = %.lr.ph21.epil, %._crit_edge22.loopexit.unr-lcssa, %.lr.ph25, %._crit_edge
  %.012.lcssa = phi i32 [ 1, %._crit_edge ], [ 1, %.lr.ph25 ], [ %spec.select.lcssa.ph, %._crit_edge22.loopexit.unr-lcssa ], [ %spec.select.epil, %.lr.ph21.epil ]
  %25 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.012.lcssa)
  %26 = load i32, ptr %1, align 4, !tbaa !5
  %27 = add nsw i32 %26, -1
  store i32 %27, ptr %1, align 4, !tbaa !5
  call void @llvm.stackrestore.p0(ptr %9)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #5
  %28 = load i32, ptr %1, align 4, !tbaa !5
  %29 = icmp sgt i32 %28, 0
  br i1 %29, label %.lr.ph25, label %._crit_edge26, !llvm.loop !11

.lr.ph21:                                         ; preds = %.lr.ph21, %.lr.ph21.preheader.new
  %indvars.iv29 = phi i64 [ 1, %.lr.ph21.preheader.new ], [ %indvars.iv.next30.1, %.lr.ph21 ]
  %.01018 = phi i32 [ %.pre, %.lr.ph21.preheader.new ], [ %spec.select15.1, %.lr.ph21 ]
  %.01217 = phi i32 [ 1, %.lr.ph21.preheader.new ], [ %spec.select.1, %.lr.ph21 ]
  %niter = phi i64 [ 0, %.lr.ph21.preheader.new ], [ %niter.next.1, %.lr.ph21 ]
  %30 = getelementptr inbounds i32, ptr %10, i64 %indvars.iv29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = icmp sgt i32 %.01018, %31
  %33 = zext i1 %32 to i32
  %spec.select = add nuw nsw i32 %.01217, %33
  %spec.select15 = call i32 @llvm.smin.i32(i32 %.01018, i32 %31)
  %gep = getelementptr inbounds i32, ptr %invariant.gep, i64 %indvars.iv29
  %34 = load i32, ptr %gep, align 4, !tbaa !5
  %35 = icmp sgt i32 %spec.select15, %34
  %36 = zext i1 %35 to i32
  %spec.select.1 = add nuw nsw i32 %spec.select, %36
  %spec.select15.1 = call i32 @llvm.smin.i32(i32 %spec.select15, i32 %34)
  %indvars.iv.next30.1 = add nuw nsw i64 %indvars.iv29, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge22.loopexit.unr-lcssa, label %.lr.ph21, !llvm.loop !12

._crit_edge26:                                    ; preds = %._crit_edge22, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  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
declare ptr @llvm.stacksave.p0() #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 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #4

attributes #0 = { 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 = { mustprogress nocallback nofree nosync nounwind willreturn }
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


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