; LLVM IR from kenjin/Awesome-LC-C-Cracker :: leetcode-c-sol/0788_rotated-digits (0788_rotated-digits)

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

; 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 i8, align 1
  %8 = alloca i8, align 1
  %9 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %63, %1
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = icmp sle i32 %11, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  store i32 2, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %66

15:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %16 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %16, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #2
  store i8 0, ptr %7, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #2
  store i8 0, ptr %8, align 1, !tbaa !9
  br label %17

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

20:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = srem i32 %21, 10
  store i32 %22, ptr %9, align 4, !tbaa !5
  %23 = load i32, ptr %9, align 4, !tbaa !5
  %24 = icmp eq i32 %23, 2
  br i1 %24, label %34, label %25

25:                                               ; preds = %20
  %26 = load i32, ptr %9, align 4, !tbaa !5
  %27 = icmp eq i32 %26, 5
  br i1 %27, label %34, label %28

28:                                               ; preds = %25
  %29 = load i32, ptr %9, align 4, !tbaa !5
  %30 = icmp eq i32 %29, 6
  br i1 %30, label %34, label %31

31:                                               ; preds = %28
  %32 = load i32, ptr %9, align 4, !tbaa !5
  %33 = icmp eq i32 %32, 9
  br i1 %33, label %34, label %35

34:                                               ; preds = %31, %28, %25, %20
  store i8 1, ptr %8, align 1, !tbaa !9
  br label %46

35:                                               ; preds = %31
  %36 = load i32, ptr %9, align 4, !tbaa !5
  %37 = icmp eq i32 %36, 3
  br i1 %37, label %44, label %38

38:                                               ; preds = %35
  %39 = load i32, ptr %9, align 4, !tbaa !5
  %40 = icmp eq i32 %39, 4
  br i1 %40, label %44, label %41

41:                                               ; preds = %38
  %42 = load i32, ptr %9, align 4, !tbaa !5
  %43 = icmp eq i32 %42, 7
  br i1 %43, label %44, label %45

44:                                               ; preds = %41, %38, %35
  store i8 1, ptr %7, align 1, !tbaa !9
  store i32 6, ptr %5, align 4
  br label %49

45:                                               ; preds = %41
  br label %46

46:                                               ; preds = %45, %34
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = sdiv i32 %47, 10
  store i32 %48, ptr %6, align 4, !tbaa !5
  store i32 0, ptr %5, align 4
  br label %49

49:                                               ; preds = %46, %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  %50 = load i32, ptr %5, align 4
  switch i32 %50, label %68 [
    i32 0, label %51
    i32 6, label %52
  ]

51:                                               ; preds = %49
  br label %17, !llvm.loop !10

52:                                               ; preds = %49, %17
  %53 = load i8, ptr %7, align 1, !tbaa !9
  %54 = icmp ne i8 %53, 0
  br i1 %54, label %62, label %55

55:                                               ; preds = %52
  %56 = load i8, ptr %8, align 1, !tbaa !9
  %57 = sext i8 %56 to i32
  %58 = icmp ne i32 %57, 0
  br i1 %58, label %59, label %62

59:                                               ; preds = %55
  %60 = load i32, ptr %3, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %3, align 4, !tbaa !5
  br label %62

62:                                               ; preds = %59, %55, %52
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %63

63:                                               ; preds = %62
  %64 = load i32, ptr %4, align 4, !tbaa !5
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %4, align 4, !tbaa !5
  br label %10, !llvm.loop !12

66:                                               ; preds = %14
  %67 = load i32, ptr %3, align 4, !tbaa !5
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %67

68:                                               ; preds = %49
  unreachable
}

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

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

; Function Attrs: nofree norecurse nosync nounwind memory(none) uwtable
define dso_local i32 @rotatedDigits(i32 noundef %0) local_unnamed_addr #0 {
  %.not61 = icmp slt i32 %0, 0
  br i1 %.not61, label %._crit_edge, label %.preheader.preheader

.preheader.preheader:                             ; preds = %1
  %2 = add nuw i32 %0, 1
  %smax = tail call i32 @llvm.smax.i32(i32 %2, i32 1)
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %.thread
  %.063 = phi i32 [ %spec.select, %.thread ], [ 0, %.preheader.preheader ]
  %.03962 = phi i32 [ %10, %.thread ], [ 0, %.preheader.preheader ]
  %.not4647 = icmp eq i32 %.03962, 0
  br i1 %.not4647, label %.thread, label %.lr.ph

._crit_edge:                                      ; preds = %.thread, %1
  %.0.lcssa = phi i32 [ 0, %1 ], [ %spec.select, %.thread ]
  ret i32 %.0.lcssa

.lr.ph:                                           ; preds = %.preheader, %7
  %.03149 = phi i8 [ %.132, %7 ], [ 0, %.preheader ]
  %.03648 = phi i32 [ %4, %7 ], [ %.03962, %.preheader ]
  %3 = urem i32 %.03648, 10
  %4 = udiv i32 %.03648, 10
  %5 = and i32 %3, 11
  %6 = icmp eq i32 %5, 2
  br i1 %6, label %7, label %switch.early.test

switch.early.test:                                ; preds = %.lr.ph
  switch i32 %3, label %.fold.split [
    i32 9, label %7
    i32 5, label %7
    i32 7, label %.thread
    i32 4, label %.thread
    i32 3, label %.thread
  ]

.fold.split:                                      ; preds = %switch.early.test
  br label %7

7:                                                ; preds = %switch.early.test, %switch.early.test, %.fold.split, %.lr.ph
  %.132 = phi i8 [ 1, %switch.early.test ], [ 1, %.lr.ph ], [ 1, %switch.early.test ], [ %.03149, %.fold.split ]
  %.not46 = icmp ult i32 %.03648, 10
  br i1 %.not46, label %.thread, label %.lr.ph

.thread:                                          ; preds = %7, %switch.early.test, %switch.early.test, %switch.early.test, %.preheader
  %.031.lcssa = phi i8 [ 0, %.preheader ], [ %.03149, %switch.early.test ], [ %.03149, %switch.early.test ], [ %.03149, %switch.early.test ], [ %.132, %7 ]
  %.not46.lcssa = phi i1 [ true, %.preheader ], [ false, %switch.early.test ], [ false, %switch.early.test ], [ false, %switch.early.test ], [ true, %7 ]
  %8 = icmp ne i8 %.031.lcssa, 0
  %or.cond12 = select i1 %.not46.lcssa, i1 %8, i1 false
  %9 = zext i1 %or.cond12 to i32
  %spec.select = add nuw nsw i32 %.063, %9
  %10 = add nuw nsw i32 %.03962, 1
  %exitcond = icmp eq i32 %10, %smax
  br i1 %exitcond, label %._crit_edge, label %.preheader, !llvm.loop !5
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #1

attributes #0 = { nofree norecurse nosync nounwind memory(none) 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 speculatable willreturn memory(none) }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,DivRemPairsPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass