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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef 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 [1000009 x i8], align 16
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  br label %14

14:                                               ; preds = %111, %0
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = add nsw i32 %15, -1
  store i32 %16, ptr %2, align 4, !tbaa !5
  %17 = icmp ne i32 %15, 0
  br i1 %17, label %18, label %112

18:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %19 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %3, ptr noundef %4)
  call void @llvm.lifetime.start.p0(i64 1000009, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %20 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %20, ptr %10, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %102, %18
  %22 = load i32, ptr %10, align 4, !tbaa !5
  %23 = icmp sle i32 %22, 9
  br i1 %23, label %25, label %24

24:                                               ; preds = %21
  store i32 4, ptr %11, align 4
  br label %105

25:                                               ; preds = %21
  %26 = load i32, ptr %10, align 4, !tbaa !5
  %27 = add nsw i32 %26, 48
  %28 = trunc i32 %27 to i8
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = sub nsw i32 %29, 1
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [1000009 x i8], ptr %5, i64 0, i64 %31
  store i8 %28, ptr %32, align 1, !tbaa !9
  store i32 0, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = sub nsw i32 %33, 2
  store i32 %34, ptr %12, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %69, %25
  %36 = load i32, ptr %12, align 4, !tbaa !5
  %37 = icmp sge i32 %36, 0
  br i1 %37, label %39, label %38

38:                                               ; preds = %35
  store i32 7, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %72

39:                                               ; preds = %35
  %40 = load i32, ptr %12, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [1000009 x i8], ptr %5, i64 0, i64 %42
  %44 = load i8, ptr %43, align 1, !tbaa !9
  %45 = sext i8 %44 to i32
  %46 = sub nsw i32 %45, 48
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = mul nsw i32 %46, %47
  %49 = load i32, ptr %7, align 4, !tbaa !5
  %50 = add nsw i32 %48, %49
  %51 = srem i32 %50, 10
  %52 = add nsw i32 %51, 48
  %53 = trunc i32 %52 to i8
  %54 = load i32, ptr %12, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [1000009 x i8], ptr %5, i64 0, i64 %55
  store i8 %53, ptr %56, align 1, !tbaa !9
  %57 = load i32, ptr %12, align 4, !tbaa !5
  %58 = add nsw i32 %57, 1
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [1000009 x i8], ptr %5, i64 0, i64 %59
  %61 = load i8, ptr %60, align 1, !tbaa !9
  %62 = sext i8 %61 to i32
  %63 = sub nsw i32 %62, 48
  %64 = load i32, ptr %4, align 4, !tbaa !5
  %65 = mul nsw i32 %63, %64
  %66 = load i32, ptr %7, align 4, !tbaa !5
  %67 = add nsw i32 %65, %66
  %68 = sdiv i32 %67, 10
  store i32 %68, ptr %7, align 4, !tbaa !5
  br label %69

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

72:                                               ; preds = %38
  %73 = load i32, ptr %3, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [1000009 x i8], ptr %5, i64 0, i64 %74
  store i8 0, ptr %75, align 1, !tbaa !9
  %76 = getelementptr inbounds [1000009 x i8], ptr %5, i64 0, i64 0
  %77 = load i8, ptr %76, align 16, !tbaa !9
  %78 = sext i8 %77 to i32
  %79 = sub nsw i32 %78, 48
  store i32 %79, ptr %6, align 4, !tbaa !5
  %80 = load i32, ptr %6, align 4, !tbaa !5
  %81 = load i32, ptr %4, align 4, !tbaa !5
  %82 = mul nsw i32 %80, %81
  %83 = load i32, ptr %7, align 4, !tbaa !5
  %84 = add nsw i32 %82, %83
  %85 = srem i32 %84, 10
  store i32 %85, ptr %8, align 4, !tbaa !5
  %86 = load i32, ptr %6, align 4, !tbaa !5
  %87 = load i32, ptr %4, align 4, !tbaa !5
  %88 = mul nsw i32 %86, %87
  %89 = load i32, ptr %7, align 4, !tbaa !5
  %90 = add nsw i32 %88, %89
  %91 = sdiv i32 %90, 10
  store i32 %91, ptr %7, align 4, !tbaa !5
  %92 = load i32, ptr %8, align 4, !tbaa !5
  %93 = load i32, ptr %10, align 4, !tbaa !5
  %94 = icmp eq i32 %92, %93
  br i1 %94, label %95, label %101

95:                                               ; preds = %72
  %96 = load i32, ptr %7, align 4, !tbaa !5
  %97 = icmp eq i32 %96, 0
  br i1 %97, label %98, label %101

98:                                               ; preds = %95
  %99 = getelementptr inbounds [1000009 x i8], ptr %5, i64 0, i64 0
  %100 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, ptr noundef %99)
  store i32 1, ptr %9, align 4, !tbaa !5
  store i32 4, ptr %11, align 4
  br label %105

101:                                              ; preds = %95, %72
  br label %102

102:                                              ; preds = %101
  %103 = load i32, ptr %10, align 4, !tbaa !5
  %104 = add nsw i32 %103, 1
  store i32 %104, ptr %10, align 4, !tbaa !5
  br label %21, !llvm.loop !12

105:                                              ; preds = %98, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %106

106:                                              ; preds = %105
  %107 = load i32, ptr %9, align 4, !tbaa !5
  %108 = icmp ne i32 %107, 0
  br i1 %108, label %111, label %109

109:                                              ; preds = %106
  %110 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  br label %111

111:                                              ; preds = %109, %106
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 1000009, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %14, !llvm.loop !13

112:                                              ; preds = %14
  store i32 0, ptr %1, align 4
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  %113 = load i32, ptr %1, align 4
  ret i32 %113
}

; 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !11}


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

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

.lr.ph.preheader:                                 ; preds = %0
  %scevgep = getelementptr inbounds i8, ptr %4, i64 1
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %56
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %2, ptr noundef nonnull %3)
  call void @llvm.lifetime.start.p0(i64 1000009, ptr nonnull %4) #3
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = icmp sgt i32 %9, 9
  br i1 %10, label %.critedge, label %.lr.ph28

.lr.ph28:                                         ; preds = %.lr.ph
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = add nsw i32 %11, -1
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [1000009 x i8], ptr %4, i64 0, i64 %13
  %15 = icmp sgt i32 %11, 1
  %16 = sext i32 %11 to i64
  %17 = getelementptr inbounds [1000009 x i8], ptr %4, i64 0, i64 %16
  br i1 %15, label %.lr.ph.us.preheader, label %.lr.ph28.split

.lr.ph.us.preheader:                              ; preds = %.lr.ph28
  %18 = add nsw i32 %11, -2
  %19 = zext i32 %18 to i64
  %scevgep38 = getelementptr i8, ptr %scevgep, i64 %19
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %22
  %.02026.us = phi i32 [ %23, %22 ], [ %9, %.lr.ph.us.preheader ]
  %20 = trunc i32 %.02026.us to i8
  %21 = add i8 %20, 48
  store i8 %21, ptr %14, align 1, !tbaa !9
  %load_initial = load i8, ptr %scevgep38, align 1
  br label %24

22:                                               ; preds = %._crit_edge.us
  %23 = add nsw i32 %.02026.us, 1
  %exitcond33 = icmp eq i32 %23, 10
  br i1 %exitcond33, label %.critedge, label %.lr.ph.us, !llvm.loop !10

24:                                               ; preds = %.lr.ph.us, %24
  %store_forwarded = phi i8 [ %load_initial, %.lr.ph.us ], [ %31, %24 ]
  %indvars.iv = phi i64 [ %19, %.lr.ph.us ], [ %indvars.iv.next, %24 ]
  %.02224.us = phi i32 [ 0, %.lr.ph.us ], [ %33, %24 ]
  %25 = sext i8 %store_forwarded to i32
  %26 = add nsw i32 %25, -48
  %27 = mul nsw i32 %26, %9
  %28 = add nsw i32 %27, %.02224.us
  %29 = srem i32 %28, 10
  %30 = trunc nsw i32 %29 to i8
  %31 = add nsw i8 %30, 48
  %32 = getelementptr inbounds [1000009 x i8], ptr %4, i64 0, i64 %indvars.iv
  store i8 %31, ptr %32, align 1, !tbaa !9
  %33 = sdiv i32 %28, 10
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %34 = icmp sgt i64 %indvars.iv, 0
  br i1 %34, label %24, label %._crit_edge.us, !llvm.loop !12

._crit_edge.us:                                   ; preds = %24
  store i8 0, ptr %17, align 1, !tbaa !9
  %35 = load i8, ptr %4, align 16, !tbaa !9
  %36 = sext i8 %35 to i32
  %37 = add nsw i32 %36, -48
  %38 = mul nsw i32 %37, %9
  %39 = add nsw i32 %38, %33
  %40 = srem i32 %39, 10
  %41 = icmp eq i32 %40, %.02026.us
  %.off.us = add i32 %39, 9
  %42 = icmp ult i32 %.off.us, 19
  %or.cond.us = and i1 %41, %42
  br i1 %or.cond.us, label %.split.us, label %22

43:                                               ; preds = %.lr.ph28.split
  %44 = add i32 %.02026, 1
  %exitcond = icmp eq i32 %44, 10
  br i1 %exitcond, label %.critedge, label %.lr.ph28.split, !llvm.loop !10

.lr.ph28.split:                                   ; preds = %.lr.ph28, %43
  %.02026 = phi i32 [ %44, %43 ], [ %9, %.lr.ph28 ]
  %45 = trunc i32 %.02026 to i8
  %46 = add i8 %45, 48
  store i8 %46, ptr %14, align 1, !tbaa !9
  store i8 0, ptr %17, align 1, !tbaa !9
  %47 = load i8, ptr %4, align 16, !tbaa !9
  %48 = sext i8 %47 to i32
  %49 = add nsw i32 %48, -48
  %50 = mul nsw i32 %49, %9
  %51 = srem i32 %50, 10
  %52 = icmp eq i32 %51, %.02026
  %.off = add i32 %50, 9
  %53 = icmp ult i32 %.off, 19
  %or.cond = and i1 %52, %53
  br i1 %or.cond, label %.split.us, label %43

.split.us:                                        ; preds = %.lr.ph28.split, %._crit_edge.us
  %54 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef nonnull %4)
  br label %56

.critedge:                                        ; preds = %43, %22, %.lr.ph
  %55 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %56

56:                                               ; preds = %.split.us, %.critedge
  call void @llvm.lifetime.end.p0(i64 1000009, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  %57 = load i32, ptr %1, align 4, !tbaa !5
  %58 = add nsw i32 %57, -1
  store i32 %58, ptr %1, align 4, !tbaa !5
  %.not = icmp eq i32 %57, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %56, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
  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

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 = { 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++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !11}


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