; LLVM IR from Izaron/ACM-ICPC :: Timus Online Judge/Volume 7/1658. Sum of Digits.ll (Z2dpii)

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

@calced = external dso_local global [905 x [8105 x i32]], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z2dpii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %10 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = icmp slt i32 %11, 0
  br i1 %12, label %13, label %14

13:                                               ; preds = %2
  store i32 1073741823, ptr %3, align 4
  br label %77

14:                                               ; preds = %2
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %20

17:                                               ; preds = %14
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = icmp sgt i32 %18, 0
  br i1 %19, label %26, label %20

20:                                               ; preds = %17, %14
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = icmp sgt i32 %21, 0
  br i1 %22, label %23, label %27

23:                                               ; preds = %20
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %27

26:                                               ; preds = %23, %17
  store i32 1073741823, ptr %3, align 4
  br label %77

27:                                               ; preds = %23, %20
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %30, label %34

30:                                               ; preds = %27
  %31 = load i32, ptr %5, align 4, !tbaa !5
  %32 = icmp eq i32 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %30
  store i32 0, ptr %3, align 4
  br label %77

34:                                               ; preds = %30, %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [905 x [8105 x i32]], ptr @calced, i64 0, i64 %36
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [8105 x i32], ptr %37, i64 0, i64 %39
  store ptr %40, ptr %6, align 8, !tbaa !9
  %41 = load ptr, ptr %6, align 8, !tbaa !9
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = icmp ne i32 %42, -1
  br i1 %43, label %44, label %47

44:                                               ; preds = %34
  %45 = load ptr, ptr %6, align 8, !tbaa !9
  %46 = load i32, ptr %45, align 4, !tbaa !5
  store i32 %46, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %76

47:                                               ; preds = %34
  %48 = load ptr, ptr %6, align 8, !tbaa !9
  store i32 1073741823, ptr %48, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 1, ptr %8, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %67, %47
  %50 = load i32, ptr %8, align 4, !tbaa !5
  %51 = icmp slt i32 %50, 10
  br i1 %51, label %53, label %52

52:                                               ; preds = %49
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %70

53:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %54 = load i32, ptr %4, align 4, !tbaa !5
  %55 = load i32, ptr %8, align 4, !tbaa !5
  %56 = sub nsw i32 %54, %55
  %57 = load i32, ptr %5, align 4, !tbaa !5
  %58 = load i32, ptr %8, align 4, !tbaa !5
  %59 = load i32, ptr %8, align 4, !tbaa !5
  %60 = mul nsw i32 %58, %59
  %61 = sub nsw i32 %57, %60
  %62 = call noundef i32 @_Z2dpii(i32 noundef %56, i32 noundef %61)
  store i32 %62, ptr %9, align 4, !tbaa !5
  %63 = load ptr, ptr %6, align 8, !tbaa !9
  %64 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %63, ptr noundef nonnull align 4 dereferenceable(4) %9)
  %65 = load i32, ptr %64, align 4, !tbaa !5
  %66 = load ptr, ptr %6, align 8, !tbaa !9
  store i32 %65, ptr %66, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %67

67:                                               ; preds = %53
  %68 = load i32, ptr %8, align 4, !tbaa !5
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %8, align 4, !tbaa !5
  br label %49, !llvm.loop !11

70:                                               ; preds = %52
  %71 = load ptr, ptr %6, align 8, !tbaa !9
  %72 = load i32, ptr %71, align 4, !tbaa !5
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %71, align 4, !tbaa !5
  %74 = load ptr, ptr %6, align 8, !tbaa !9
  %75 = load i32, ptr %74, align 4, !tbaa !5
  store i32 %75, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %76

76:                                               ; preds = %70, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %77

77:                                               ; preds = %76, %33, %26, %13
  %78 = load i32, ptr %3, align 4
  ret i32 %78
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #1

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

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

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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

@calced = external dso_local global [905 x [8105 x i32]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z2dpii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %6 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = icmp slt i32 %7, 0
  br i1 %8, label %86, label %9

9:                                                ; preds = %2
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = icmp eq i32 %10, 0
  %12 = load i32, ptr %4, align 4
  %13 = icmp sgt i32 %12, 0
  %or.cond = select i1 %11, i1 %13, i1 false
  br i1 %or.cond, label %86, label %14

14:                                               ; preds = %9
  %15 = icmp sgt i32 %10, 0
  %16 = icmp eq i32 %12, 0
  %or.cond3 = select i1 %15, i1 %16, i1 false
  br i1 %or.cond3, label %86, label %17

17:                                               ; preds = %14
  %or.cond5 = select i1 %11, i1 %16, i1 false
  br i1 %or.cond5, label %86, label %18

18:                                               ; preds = %17
  %19 = sext i32 %10 to i64
  %20 = sext i32 %12 to i64
  %21 = getelementptr inbounds [905 x [8105 x i32]], ptr @calced, i64 0, i64 %19, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %.not = icmp eq i32 %22, -1
  br i1 %.not, label %23, label %86

23:                                               ; preds = %18
  store i32 1073741823, ptr %21, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  %24 = add nsw i32 %10, -1
  %25 = add nsw i32 %12, -1
  %26 = call noundef i32 @_Z2dpii(i32 noundef %24, i32 noundef %25)
  store i32 %26, ptr %5, align 4, !tbaa !5
  %27 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %21, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %28 = load i32, ptr %27, align 4, !tbaa !5
  store i32 %28, ptr %21, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = add nsw i32 %29, -2
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = add nsw i32 %31, -4
  %33 = call noundef i32 @_Z2dpii(i32 noundef %30, i32 noundef %32)
  store i32 %33, ptr %5, align 4, !tbaa !5
  %34 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %21, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %35 = load i32, ptr %34, align 4, !tbaa !5
  store i32 %35, ptr %21, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = add nsw i32 %36, -3
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = add nsw i32 %38, -9
  %40 = call noundef i32 @_Z2dpii(i32 noundef %37, i32 noundef %39)
  store i32 %40, ptr %5, align 4, !tbaa !5
  %41 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %21, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %42 = load i32, ptr %41, align 4, !tbaa !5
  store i32 %42, ptr %21, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = add nsw i32 %43, -4
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = add nsw i32 %45, -16
  %47 = call noundef i32 @_Z2dpii(i32 noundef %44, i32 noundef %46)
  store i32 %47, ptr %5, align 4, !tbaa !5
  %48 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %21, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %49 = load i32, ptr %48, align 4, !tbaa !5
  store i32 %49, ptr %21, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = add nsw i32 %50, -5
  %52 = load i32, ptr %4, align 4, !tbaa !5
  %53 = add nsw i32 %52, -25
  %54 = call noundef i32 @_Z2dpii(i32 noundef %51, i32 noundef %53)
  store i32 %54, ptr %5, align 4, !tbaa !5
  %55 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %21, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %56 = load i32, ptr %55, align 4, !tbaa !5
  store i32 %56, ptr %21, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  %57 = load i32, ptr %3, align 4, !tbaa !5
  %58 = add nsw i32 %57, -6
  %59 = load i32, ptr %4, align 4, !tbaa !5
  %60 = add nsw i32 %59, -36
  %61 = call noundef i32 @_Z2dpii(i32 noundef %58, i32 noundef %60)
  store i32 %61, ptr %5, align 4, !tbaa !5
  %62 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %21, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %63 = load i32, ptr %62, align 4, !tbaa !5
  store i32 %63, ptr %21, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  %64 = load i32, ptr %3, align 4, !tbaa !5
  %65 = add nsw i32 %64, -7
  %66 = load i32, ptr %4, align 4, !tbaa !5
  %67 = add nsw i32 %66, -49
  %68 = call noundef i32 @_Z2dpii(i32 noundef %65, i32 noundef %67)
  store i32 %68, ptr %5, align 4, !tbaa !5
  %69 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %21, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %70 = load i32, ptr %69, align 4, !tbaa !5
  store i32 %70, ptr %21, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  %71 = load i32, ptr %3, align 4, !tbaa !5
  %72 = add nsw i32 %71, -8
  %73 = load i32, ptr %4, align 4, !tbaa !5
  %74 = add nsw i32 %73, -64
  %75 = call noundef i32 @_Z2dpii(i32 noundef %72, i32 noundef %74)
  store i32 %75, ptr %5, align 4, !tbaa !5
  %76 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %21, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %77 = load i32, ptr %76, align 4, !tbaa !5
  store i32 %77, ptr %21, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  %78 = load i32, ptr %3, align 4, !tbaa !5
  %79 = add nsw i32 %78, -9
  %80 = load i32, ptr %4, align 4, !tbaa !5
  %81 = add nsw i32 %80, -81
  %82 = call noundef i32 @_Z2dpii(i32 noundef %79, i32 noundef %81)
  store i32 %82, ptr %5, align 4, !tbaa !5
  %83 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %21, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %84 = load i32, ptr %83, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  %85 = add nsw i32 %84, 1
  store i32 %85, ptr %21, align 4, !tbaa !5
  br label %86

86:                                               ; preds = %23, %18, %17, %9, %14, %2
  %.1 = phi i32 [ 1073741823, %2 ], [ 1073741823, %14 ], [ 1073741823, %9 ], [ 0, %17 ], [ %85, %23 ], [ %22, %18 ]
  ret i32 %.1
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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"}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass