; LLVM IR from lzyrapx/Competitive-Programming :: HDUOJ (1727)

; 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"

@__const.main.s = external hidden unnamed_addr constant [10 x [10 x i8]], align 16
@__const.main.p = external hidden unnamed_addr constant [10 x [10 x i8]], align 16
@__const.main.q = external hidden unnamed_addr constant [20 x [10 x i8]], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [2 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 [10 x [10 x i8]], align 16
  %5 = alloca [10 x [10 x i8]], align 16
  %6 = alloca [20 x [10 x i8]], 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 100, ptr %4) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %4, ptr align 16 @__const.main.s, i64 100, i1 false)
  call void @llvm.lifetime.start.p0(i64 100, ptr %5) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %5, ptr align 16 @__const.main.p, i64 100, i1 false)
  call void @llvm.lifetime.start.p0(i64 200, ptr %6) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %6, ptr align 16 @__const.main.q, i64 200, i1 false)
  br label %7

7:                                                ; preds = %95, %14, %0
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  %9 = xor i32 %8, -1
  %10 = icmp ne i32 %9, 0
  br i1 %10, label %11, label %97

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

14:                                               ; preds = %11
  %15 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  br label %7, !llvm.loop !9

16:                                               ; preds = %11
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = sdiv i32 %17, 1000
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %38

20:                                               ; preds = %16
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = sdiv i32 %21, 1000
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [10 x [10 x i8]], ptr %4, i64 0, i64 %23
  %25 = getelementptr inbounds [10 x i8], ptr %24, i64 0, i64 0
  %26 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, ptr noundef %25)
  %27 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %27, ptr %3, align 4, !tbaa !5
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = sdiv i32 %29, 1000
  %31 = mul nsw i32 %30, 1000
  %32 = sub nsw i32 %28, %31
  store i32 %32, ptr %2, align 4, !tbaa !5
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %37

35:                                               ; preds = %20
  %36 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  br label %37

37:                                               ; preds = %35, %20
  br label %38

38:                                               ; preds = %37, %16
  %39 = load i32, ptr %2, align 4, !tbaa !5
  %40 = sdiv i32 %39, 100
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %60

42:                                               ; preds = %38
  %43 = load i32, ptr %2, align 4, !tbaa !5
  %44 = sdiv i32 %43, 100
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [10 x [10 x i8]], ptr %4, i64 0, i64 %45
  %47 = getelementptr inbounds [10 x i8], ptr %46, i64 0, i64 0
  %48 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, ptr noundef %47)
  %49 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %49, ptr %3, align 4, !tbaa !5
  %50 = load i32, ptr %2, align 4, !tbaa !5
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = sdiv i32 %51, 100
  %53 = mul nsw i32 %52, 100
  %54 = sub nsw i32 %50, %53
  store i32 %54, ptr %2, align 4, !tbaa !5
  %55 = load i32, ptr %2, align 4, !tbaa !5
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %59

57:                                               ; preds = %42
  %58 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  br label %59

59:                                               ; preds = %57, %42
  br label %60

60:                                               ; preds = %59, %38
  %61 = load i32, ptr %2, align 4, !tbaa !5
  %62 = icmp slt i32 %61, 20
  br i1 %62, label %63, label %69

63:                                               ; preds = %60
  %64 = load i32, ptr %2, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [20 x [10 x i8]], ptr %6, i64 0, i64 %65
  %67 = getelementptr inbounds [10 x i8], ptr %66, i64 0, i64 0
  %68 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, ptr noundef %67)
  br label %95

69:                                               ; preds = %60
  %70 = load i32, ptr %2, align 4, !tbaa !5
  %71 = icmp sge i32 %70, 20
  br i1 %71, label %72, label %85

72:                                               ; preds = %69
  %73 = load i32, ptr %2, align 4, !tbaa !5
  %74 = sdiv i32 %73, 10
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [10 x [10 x i8]], ptr %5, i64 0, i64 %75
  %77 = getelementptr inbounds [10 x i8], ptr %76, i64 0, i64 0
  %78 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, ptr noundef %77)
  %79 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %79, ptr %3, align 4, !tbaa !5
  %80 = load i32, ptr %2, align 4, !tbaa !5
  %81 = load i32, ptr %3, align 4, !tbaa !5
  %82 = sdiv i32 %81, 10
  %83 = mul nsw i32 %82, 10
  %84 = sub nsw i32 %80, %83
  store i32 %84, ptr %2, align 4, !tbaa !5
  br label %85

85:                                               ; preds = %72, %69
  %86 = load i32, ptr %2, align 4, !tbaa !5
  %87 = icmp ne i32 %86, 0
  br i1 %87, label %88, label %94

88:                                               ; preds = %85
  %89 = load i32, ptr %2, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [10 x [10 x i8]], ptr %4, i64 0, i64 %90
  %92 = getelementptr inbounds [10 x i8], ptr %91, i64 0, i64 0
  %93 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, ptr noundef %92)
  br label %94

94:                                               ; preds = %88, %85
  br label %95

95:                                               ; preds = %94, %63
  %96 = call i32 (ptr, ...) @printf(ptr noundef @.str.7)
  br label %7, !llvm.loop !9

97:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 200, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 100, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 100, 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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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) #1

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 = { nocallback nofree 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 = !{!"int", !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"

@__const.main.s = external hidden unnamed_addr constant [10 x [10 x i8]], align 16
@__const.main.p = external hidden unnamed_addr constant [10 x [10 x i8]], align 16
@__const.main.q = external hidden unnamed_addr constant [20 x [10 x i8]], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [2 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 [10 x [10 x i8]], align 16
  %3 = alloca [10 x [10 x i8]], align 16
  %4 = alloca [20 x [10 x i8]], align 16
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 100, ptr nonnull %2) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(100) %2, ptr noundef nonnull align 16 dereferenceable(100) @__const.main.s, i64 100, i1 false)
  call void @llvm.lifetime.start.p0(i64 100, ptr nonnull %3) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(100) %3, ptr noundef nonnull align 16 dereferenceable(100) @__const.main.p, i64 100, i1 false)
  call void @llvm.lifetime.start.p0(i64 200, ptr nonnull %4) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(200) %4, ptr noundef nonnull align 16 dereferenceable(200) @__const.main.q, i64 200, i1 false)
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %.not15 = icmp eq i32 %5, -1
  br i1 %.not15, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %.backedge
  %6 = load i32, ptr %1, align 4, !tbaa !5
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %.backedge, label %10

.backedge:                                        ; preds = %.lr.ph, %.thread, %45, %38
  %.str.1.sink = phi ptr [ @.str.7, %38 ], [ @.str.7, %45 ], [ @.str.7, %.thread ], [ @.str.1, %.lr.ph ]
  %8 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.1.sink)
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %.not = icmp eq i32 %9, -1
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

10:                                               ; preds = %.lr.ph
  %.off = add i32 %6, 999
  %.not7 = icmp ult i32 %.off, 1999
  br i1 %.not7, label %20, label %11

11:                                               ; preds = %10
  %12 = sdiv i32 %6, 1000
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [10 x [10 x i8]], ptr %2, i64 0, i64 %13
  %15 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef nonnull %14)
  %16 = load i32, ptr %1, align 4, !tbaa !5
  %.fr = freeze i32 %16
  %17 = srem i32 %.fr, 1000
  store i32 %17, ptr %1, align 4, !tbaa !5
  %.not8 = icmp eq i32 %17, 0
  br i1 %.not8, label %.thread, label %18

18:                                               ; preds = %11
  %19 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  %.pre = load i32, ptr %1, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %18, %10
  %21 = phi i32 [ %.pre, %18 ], [ %6, %10 ]
  %.off10 = add i32 %21, 99
  %.not9 = icmp ult i32 %.off10, 199
  br i1 %.not9, label %31, label %22

22:                                               ; preds = %20
  %23 = sdiv i32 %21, 100
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [10 x [10 x i8]], ptr %2, i64 0, i64 %24
  %26 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, ptr noundef nonnull %25)
  %27 = load i32, ptr %1, align 4, !tbaa !5
  %.fr11 = freeze i32 %27
  %28 = srem i32 %.fr11, 100
  store i32 %28, ptr %1, align 4, !tbaa !5
  %.not12 = icmp eq i32 %28, 0
  br i1 %.not12, label %.thread, label %29

29:                                               ; preds = %22
  %30 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  %.pr = load i32, ptr %1, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %29, %20
  %32 = phi i32 [ %.pr, %29 ], [ %21, %20 ]
  %33 = icmp slt i32 %32, 20
  br i1 %33, label %.thread, label %38

.thread:                                          ; preds = %11, %22, %31
  %34 = phi i32 [ %32, %31 ], [ 0, %22 ], [ 0, %11 ]
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [20 x [10 x i8]], ptr %4, i64 0, i64 %35
  %37 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, ptr noundef nonnull %36)
  br label %.backedge

38:                                               ; preds = %31
  %39 = udiv i32 %32, 10
  %40 = zext nneg i32 %39 to i64
  %41 = getelementptr inbounds [10 x [10 x i8]], ptr %3, i64 0, i64 %40
  %42 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, ptr noundef nonnull %41)
  %43 = load i32, ptr %1, align 4, !tbaa !5
  %.fr13 = freeze i32 %43
  %44 = srem i32 %.fr13, 10
  store i32 %44, ptr %1, align 4, !tbaa !5
  %.not14 = icmp eq i32 %44, 0
  br i1 %.not14, label %.backedge, label %45

45:                                               ; preds = %38
  %46 = sext i32 %44 to i64
  %47 = getelementptr inbounds [10 x [10 x i8]], ptr %2, i64 0, i64 %46
  %48 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, ptr noundef nonnull %47)
  br label %.backedge

._crit_edge:                                      ; preds = %.backedge, %0
  call void @llvm.lifetime.end.p0(i64 200, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 100, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 100, 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: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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) #1

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


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