; LLVM IR from DimitrisJim/leetcode_solutions :: C/Algorithms (788)

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

@power = external hidden global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local i32 @rotatedDigits(i32 noundef %0) #0 {
  %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 i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %9 = load i32, ptr @power, align 4, !tbaa !5
  %10 = sitofp i32 %9 to double
  %11 = call double @pow(double noundef 1.000000e+01, double noundef %10) #4
  %12 = fptosi double %11 to i32
  store i32 %12, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %13 = load i32, ptr @power, align 4, !tbaa !5
  store i32 %13, ptr %6, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %68, %1
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %69

17:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = sdiv i32 %18, %19
  store i32 %20, ptr %7, align 4, !tbaa !5
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = srem i32 %22, %21
  store i32 %23, ptr %3, align 4, !tbaa !5
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = sdiv i32 %24, 10
  store i32 %25, ptr %4, align 4, !tbaa !5
  %26 = load i32, ptr %7, align 4, !tbaa !5
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %63

28:                                               ; preds = %17
  %29 = load i32, ptr %7, align 4, !tbaa !5
  %30 = load i32, ptr %6, align 4, !tbaa !5
  %31 = call i32 @add_until_previous(i32 noundef %29, i32 noundef %30)
  %32 = load i32, ptr %5, align 4, !tbaa !5
  %33 = add nsw i32 %32, %31
  store i32 %33, ptr %5, align 4, !tbaa !5
  %34 = load i32, ptr %7, align 4, !tbaa !5
  %35 = icmp eq i32 %34, 3
  br i1 %35, label %42, label %36

36:                                               ; preds = %28
  %37 = load i32, ptr %7, align 4, !tbaa !5
  %38 = icmp eq i32 %37, 4
  br i1 %38, label %42, label %39

39:                                               ; preds = %36
  %40 = load i32, ptr %7, align 4, !tbaa !5
  %41 = icmp eq i32 %40, 7
  br i1 %41, label %42, label %44

42:                                               ; preds = %39, %36, %28
  %43 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %43, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %66

44:                                               ; preds = %39
  %45 = load i32, ptr %7, align 4, !tbaa !5
  %46 = icmp eq i32 %45, 2
  br i1 %46, label %56, label %47

47:                                               ; preds = %44
  %48 = load i32, ptr %7, align 4, !tbaa !5
  %49 = icmp eq i32 %48, 5
  br i1 %49, label %56, label %50

50:                                               ; preds = %47
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = icmp eq i32 %51, 6
  br i1 %52, label %56, label %53

53:                                               ; preds = %50
  %54 = load i32, ptr %7, align 4, !tbaa !5
  %55 = icmp eq i32 %54, 9
  br i1 %55, label %56, label %61

56:                                               ; preds = %53, %50, %47, %44
  %57 = load i32, ptr %3, align 4, !tbaa !5
  %58 = call i32 @include_mirror_rotations(i32 noundef %57)
  %59 = load i32, ptr %5, align 4, !tbaa !5
  %60 = add nsw i32 %59, %58
  store i32 %60, ptr %5, align 4, !tbaa !5
  br label %61

61:                                               ; preds = %56, %53
  br label %62

62:                                               ; preds = %61
  br label %63

63:                                               ; preds = %62, %17
  %64 = load i32, ptr %6, align 4, !tbaa !5
  %65 = add nsw i32 %64, -1
  store i32 %65, ptr %6, align 4, !tbaa !5
  store i32 0, ptr %8, align 4
  br label %66

66:                                               ; preds = %63, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  %67 = load i32, ptr %8, align 4
  switch i32 %67, label %71 [
    i32 0, label %68
  ]

68:                                               ; preds = %66
  br label %14, !llvm.loop !9

69:                                               ; preds = %14
  %70 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %70, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %71

71:                                               ; preds = %69, %66
  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
  %72 = load i32, ptr %2, align 4
  ret i32 %72
}

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

; Function Attrs: nounwind
declare double @pow(double noundef, double noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare i32 @add_until_previous(i32 noundef, i32 noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare i32 @include_mirror_rotations(i32 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 = { 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 = { 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 = { inlinehint 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 #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"}


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

@power = external hidden local_unnamed_addr global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local i32 @rotatedDigits(i32 noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @power, align 4, !tbaa !5
  %3 = sitofp i32 %2 to double
  %4 = tail call double @pow(double noundef 1.000000e+01, double noundef %3) #3
  %.not47 = icmp eq i32 %0, 0
  br i1 %.not47, label %.thread, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %1
  %5 = load i32, ptr @power, align 4, !tbaa !5
  %6 = fptosi double %4 to i32
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %16
  %.03451 = phi i32 [ %17, %16 ], [ %5, %.lr.ph.preheader ]
  %.03650 = phi i32 [ %.137, %16 ], [ 0, %.lr.ph.preheader ]
  %.03949 = phi i32 [ %9, %16 ], [ %6, %.lr.ph.preheader ]
  %.04048 = phi i32 [ %8, %16 ], [ %0, %.lr.ph.preheader ]
  %7 = sdiv i32 %.04048, %.03949
  %8 = srem i32 %.04048, %.03949
  %9 = sdiv i32 %.03949, 10
  %.not42 = icmp eq i32 %7, 0
  br i1 %.not42, label %16, label %10

10:                                               ; preds = %.lr.ph
  %11 = tail call i32 @add_until_previous(i32 noundef %7, i32 noundef %.03451)
  %12 = add nsw i32 %11, %.03650
  switch i32 %7, label %16 [
    i32 7, label %.thread
    i32 4, label %.thread
    i32 3, label %.thread
    i32 9, label %13
    i32 6, label %13
    i32 5, label %13
    i32 2, label %13
  ]

13:                                               ; preds = %10, %10, %10, %10
  %14 = tail call i32 @include_mirror_rotations(i32 noundef %8)
  %15 = add nsw i32 %14, %12
  br label %16

16:                                               ; preds = %.lr.ph, %13, %10
  %.137 = phi i32 [ %15, %13 ], [ %.03650, %.lr.ph ], [ %12, %10 ]
  %17 = add nsw i32 %.03451, -1
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %.thread, label %.lr.ph, !llvm.loop !9

.thread:                                          ; preds = %16, %10, %10, %10, %1
  %.2 = phi i32 [ 0, %1 ], [ %12, %10 ], [ %12, %10 ], [ %12, %10 ], [ %.137, %16 ]
  ret i32 %.2
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @pow(double noundef, double noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare i32 @add_until_previous(i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare i32 @include_mirror_rotations(i32 noundef) local_unnamed_addr #2

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 = { mustprogress nofree nounwind willreturn memory(write) "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 = { inlinehint 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 }

!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"}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass