; LLVM IR from UtkarshPathrabe/Competitive-Coding :: SPOJ Solutions (FCTRL2)

; 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 [2 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 i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca [1000 x i32], align 16
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  br label %10

10:                                               ; preds = %86, %0
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = add nsw i32 %11, -1
  store i32 %12, ptr %2, align 4, !tbaa !5
  %13 = icmp ne i32 %11, 0
  br i1 %13, label %14, label %88

14:                                               ; preds = %10
  store i32 0, ptr %5, align 4, !tbaa !5
  store i32 0, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4000, ptr %8) #4
  call void @llvm.memset.p0.i64(ptr align 16 %8, i8 0, i64 4000, i1 false)
  %15 = getelementptr inbounds <{ i32, [999 x i32] }>, ptr %8, i32 0, i32 0
  store i32 1, ptr %15, align 16
  %16 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %3)
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %69, %14
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = icmp sle i32 %18, %19
  br i1 %20, label %21, label %72

21:                                               ; preds = %17
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %51, %21
  %23 = load i32, ptr %6, align 4, !tbaa !5
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = icmp sle i32 %23, %24
  br i1 %25, label %26, label %54

26:                                               ; preds = %22
  %27 = load i32, ptr %6, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [1000 x i32], ptr %8, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = mul nsw i32 %30, %31
  %33 = load i32, ptr %7, align 4, !tbaa !5
  %34 = add nsw i32 %32, %33
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [1000 x i32], ptr %8, i64 0, i64 %36
  store i32 %34, ptr %37, align 4, !tbaa !5
  %38 = load i32, ptr %6, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [1000 x i32], ptr %8, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = sdiv i32 %41, 10
  store i32 %42, ptr %7, align 4, !tbaa !5
  %43 = load i32, ptr %6, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [1000 x i32], ptr %8, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = srem i32 %46, 10
  %48 = load i32, ptr %6, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [1000 x i32], ptr %8, i64 0, i64 %49
  store i32 %47, ptr %50, align 4, !tbaa !5
  br label %51

51:                                               ; preds = %26
  %52 = load i32, ptr %6, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %6, align 4, !tbaa !5
  br label %22, !llvm.loop !9

54:                                               ; preds = %22
  br label %55

55:                                               ; preds = %58, %54
  %56 = load i32, ptr %7, align 4, !tbaa !5
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %58, label %68

58:                                               ; preds = %55
  %59 = load i32, ptr %5, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %5, align 4, !tbaa !5
  %61 = load i32, ptr %7, align 4, !tbaa !5
  %62 = srem i32 %61, 10
  %63 = load i32, ptr %5, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [1000 x i32], ptr %8, i64 0, i64 %64
  store i32 %62, ptr %65, align 4, !tbaa !5
  %66 = load i32, ptr %7, align 4, !tbaa !5
  %67 = sdiv i32 %66, 10
  store i32 %67, ptr %7, align 4, !tbaa !5
  br label %55, !llvm.loop !11

68:                                               ; preds = %55
  br label %69

69:                                               ; preds = %68
  %70 = load i32, ptr %4, align 4, !tbaa !5
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %4, align 4, !tbaa !5
  br label %17, !llvm.loop !12

72:                                               ; preds = %17
  %73 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %73, ptr %4, align 4, !tbaa !5
  br label %74

74:                                               ; preds = %83, %72
  %75 = load i32, ptr %4, align 4, !tbaa !5
  %76 = icmp sge i32 %75, 0
  br i1 %76, label %77, label %86

77:                                               ; preds = %74
  %78 = load i32, ptr %4, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [1000 x i32], ptr %8, i64 0, i64 %79
  %81 = load i32, ptr %80, align 4, !tbaa !5
  %82 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %81)
  br label %83

83:                                               ; preds = %77
  %84 = load i32, ptr %4, align 4, !tbaa !5
  %85 = add nsw i32 %84, -1
  store i32 %85, ptr %4, align 4, !tbaa !5
  br label %74, !llvm.loop !13

86:                                               ; preds = %74
  %87 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  call void @llvm.lifetime.end.p0(i64 4000, ptr %8) #4
  br label %10, !llvm.loop !14

88:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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 = { 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 nounwind willreturn memory(argmem: write) }
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}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !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 [2 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
  %3 = alloca [1000 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = add nsw i32 %5, -1
  store i32 %6, ptr %1, align 4, !tbaa !5
  %.not46 = icmp eq i32 %5, 0
  br i1 %.not46, label %._crit_edge49, label %.lr.ph48

.lr.ph48:                                         ; preds = %0, %._crit_edge45
  call void @llvm.lifetime.start.p0(i64 4000, ptr nonnull %3) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(4000) %3, i8 0, i64 4000, i1 false)
  store i32 1, ptr %3, align 16
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %2)
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %.not2639 = icmp slt i32 %8, 1
  br i1 %.not2639, label %.lr.ph44.preheader, label %.preheader29

.preheader30:                                     ; preds = %._crit_edge
  %9 = icmp sgt i32 %.123.lcssa, -1
  br i1 %9, label %.lr.ph44.preheader, label %._crit_edge45

.lr.ph44.preheader:                               ; preds = %.lr.ph48, %.preheader30
  %.022.lcssa60 = phi i32 [ %.123.lcssa, %.preheader30 ], [ 0, %.lr.ph48 ]
  %10 = zext nneg i32 %.022.lcssa60 to i64
  br label %.lr.ph44

.preheader29:                                     ; preds = %.lr.ph48, %._crit_edge
  %.02241 = phi i32 [ %.123.lcssa, %._crit_edge ], [ 0, %.lr.ph48 ]
  %.02440 = phi i32 [ %23, %._crit_edge ], [ 1, %.lr.ph48 ]
  %.not2731 = icmp slt i32 %.02241, 0
  br i1 %.not2731, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader29
  %11 = add nuw i32 %.02241, 1
  %wide.trip.count = zext i32 %11 to i64
  br label %.lr.ph

.preheader:                                       ; preds = %.lr.ph
  %.off = add i32 %16, 9
  %.not2834 = icmp ult i32 %.off, 19
  br i1 %.not2834, label %._crit_edge, label %.lr.ph37.preheader

.lr.ph37.preheader:                               ; preds = %.preheader
  %12 = zext nneg i32 %.02241 to i64
  br label %.lr.ph37

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %.133 = phi i32 [ 0, %.lr.ph.preheader ], [ %17, %.lr.ph ]
  %13 = getelementptr inbounds [1000 x i32], ptr %3, i64 0, i64 %indvars.iv
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = mul nsw i32 %14, %.02440
  %16 = add nsw i32 %15, %.133
  %17 = sdiv i32 %16, 10
  %18 = srem i32 %16, 10
  store i32 %18, ptr %13, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.preheader, label %.lr.ph, !llvm.loop !9

.lr.ph37:                                         ; preds = %.lr.ph37.preheader, %.lr.ph37
  %indvars.iv52 = phi i64 [ %12, %.lr.ph37.preheader ], [ %indvars.iv.next53, %.lr.ph37 ]
  %.236 = phi i32 [ %17, %.lr.ph37.preheader ], [ %21, %.lr.ph37 ]
  %indvars.iv.next53 = add nuw nsw i64 %indvars.iv52, 1
  %19 = srem i32 %.236, 10
  %20 = getelementptr inbounds [1000 x i32], ptr %3, i64 0, i64 %indvars.iv.next53
  store i32 %19, ptr %20, align 4, !tbaa !5
  %21 = sdiv i32 %.236, 10
  %.236.off = add nsw i32 %.236, 9
  %.not28 = icmp ult i32 %.236.off, 19
  br i1 %.not28, label %._crit_edge.loopexit, label %.lr.ph37, !llvm.loop !11

._crit_edge.loopexit:                             ; preds = %.lr.ph37
  %22 = trunc nsw i64 %indvars.iv.next53 to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %.preheader29, %._crit_edge.loopexit, %.preheader
  %.123.lcssa = phi i32 [ %.02241, %.preheader ], [ %22, %._crit_edge.loopexit ], [ %.02241, %.preheader29 ]
  %23 = add nuw i32 %.02440, 1
  %exitcond55.not = icmp eq i32 %.02440, %8
  br i1 %exitcond55.not, label %.preheader30, label %.preheader29, !llvm.loop !12

.lr.ph44:                                         ; preds = %.lr.ph44.preheader, %.lr.ph44
  %indvars.iv56 = phi i64 [ %10, %.lr.ph44.preheader ], [ %indvars.iv.next57, %.lr.ph44 ]
  %24 = getelementptr inbounds [1000 x i32], ptr %3, i64 0, i64 %indvars.iv56
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %25)
  %indvars.iv.next57 = add nsw i64 %indvars.iv56, -1
  %.not63 = icmp eq i64 %indvars.iv56, 0
  br i1 %.not63, label %._crit_edge45, label %.lr.ph44, !llvm.loop !13

._crit_edge45:                                    ; preds = %.lr.ph44, %.preheader30
  %27 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  call void @llvm.lifetime.end.p0(i64 4000, ptr nonnull %3) #4
  %28 = load i32, ptr %1, align 4, !tbaa !5
  %29 = add nsw i32 %28, -1
  store i32 %29, ptr %1, align 4, !tbaa !5
  %.not = icmp eq i32 %28, 0
  br i1 %.not, label %._crit_edge49, label %.lr.ph48, !llvm.loop !14

._crit_edge49:                                    ; preds = %._crit_edge45, %0
  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 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; 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

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 nounwind willreturn memory(argmem: write) }
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}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}


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