; LLVM IR from tangjz/acm-icpc :: 51nod/1606.ll (Z5solveiiii)

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

@_ZZ5solveiiiiE3buf = external hidden global [21 x i8], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z5solveiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = load i32, ptr %7, align 4, !tbaa !5
  %14 = sub nsw i32 %13, 1
  %15 = load i32, ptr %8, align 4, !tbaa !5
  %16 = sub nsw i32 %15, 1
  %17 = call noundef i32 @_Z5div10ii(i32 noundef %14, i32 noundef %16)
  %18 = sext i32 %17 to i64
  %19 = mul nsw i64 %12, %18
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = load i32, ptr %8, align 4, !tbaa !5
  %22 = sub nsw i32 %21, 1
  %23 = call noundef i32 @_Z5div10ii(i32 noundef %20, i32 noundef %22)
  %24 = sext i32 %23 to i64
  %25 = add nsw i64 %19, %24
  store i64 %25, ptr %9, align 8, !tbaa !9
  %26 = load i32, ptr %7, align 4, !tbaa !5
  %27 = sub nsw i32 %26, 1
  %28 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef @_ZZ5solveiiiiE3buf, ptr noundef @.str, i32 noundef %27) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %46, %4
  %30 = load i32, ptr %10, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [21 x i8], ptr @_ZZ5solveiiiiE3buf, i64 0, i64 %31
  %33 = load i8, ptr %32, align 1, !tbaa !11
  %34 = icmp ne i8 %33, 0
  br i1 %34, label %36, label %35

35:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %49

36:                                               ; preds = %29
  %37 = load i32, ptr %10, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [21 x i8], ptr @_ZZ5solveiiiiE3buf, i64 0, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !11
  %41 = sext i8 %40 to i32
  %42 = icmp ne i32 %41, 48
  %43 = zext i1 %42 to i32
  %44 = load i32, ptr %8, align 4, !tbaa !5
  %45 = sub nsw i32 %44, %43
  store i32 %45, ptr %8, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %36
  %47 = load i32, ptr %10, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %10, align 4, !tbaa !5
  br label %29, !llvm.loop !12

49:                                               ; preds = %35
  %50 = load i32, ptr %5, align 4, !tbaa !5
  %51 = load i32, ptr %8, align 4, !tbaa !5
  %52 = sub nsw i32 %51, 1
  %53 = call noundef i32 @_Z5div10ii(i32 noundef %50, i32 noundef %52)
  %54 = sext i32 %53 to i64
  %55 = load i64, ptr %9, align 8, !tbaa !9
  %56 = add nsw i64 %55, %54
  store i64 %56, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  ret i64 %56
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z5div10ii(i32 noundef, i32 noundef) #2

; Function Attrs: nounwind
declare i32 @sprintf(ptr noundef, 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 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 = { inlinehint mustprogress 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 #3 = { 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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

@_ZZ5solveiiiiE3buf = external hidden global [21 x i8], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef range(i64 -4611686020574871552, 4611686022722355199) i64 @_Z5solveiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = add nsw i32 %2, -1
  %6 = add nsw i32 %3, -1
  %7 = tail call noundef i32 @_Z5div10ii(i32 noundef %5, i32 noundef %6)
  %8 = tail call noundef i32 @_Z5div10ii(i32 noundef %1, i32 noundef %6)
  %9 = tail call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) @_ZZ5solveiiiiE3buf, ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %5) #3
  %10 = load i8, ptr @_ZZ5solveiiiiE3buf, align 16, !tbaa !5
  %.not15 = icmp eq i8 %10, 0
  br i1 %.not15, label %._crit_edge, label %.lr.ph

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = add nsw i32 %21, -1
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %4
  %.pre-phi = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %6, %4 ]
  %11 = sext i32 %0 to i64
  %12 = sext i32 %7 to i64
  %13 = mul nsw i64 %12, %11
  %14 = sext i32 %8 to i64
  %15 = add nsw i64 %13, %14
  %16 = tail call noundef i32 @_Z5div10ii(i32 noundef %0, i32 noundef %.pre-phi)
  %17 = sext i32 %16 to i64
  %18 = add nsw i64 %15, %17
  ret i64 %18

.lr.ph:                                           ; preds = %4, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %4 ]
  %19 = phi i8 [ %23, %.lr.ph ], [ %10, %4 ]
  %.01316 = phi i32 [ %21, %.lr.ph ], [ %3, %4 ]
  %20 = icmp ne i8 %19, 48
  %.neg = sext i1 %20 to i32
  %21 = add i32 %.01316, %.neg
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %22 = getelementptr inbounds [21 x i8], ptr @_ZZ5solveiiiiE3buf, i64 0, i64 %indvars.iv.next
  %23 = load i8, ptr %22, align 1, !tbaa !5
  %.not = icmp eq i8 %23, 0
  br i1 %.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !8
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z5div10ii(i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @sprintf(ptr noalias nocapture noundef writeonly, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

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


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass