; LLVM IR from JessonYue/LeetCodeLearning :: Array/wuchao/other/7-16 转换为16进制数 (ConvertToHex)

; 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.toHex.chars = external hidden unnamed_addr constant [16 x i8], align 16

; Function Attrs: nounwind uwtable
define dso_local ptr @toHex(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca [16 x i8], align 16
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %3) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %3, ptr align 16 @__const.toHex.chars, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 15, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %9 = call noalias ptr @calloc(i64 noundef 9, i64 noundef 1) #5
  store ptr %9, ptr %5, align 8, !tbaa !9
  %10 = load ptr, ptr %5, align 8, !tbaa !9
  %11 = getelementptr inbounds i8, ptr %10, i64 8
  store i8 0, ptr %11, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %54, %1
  %13 = load i32, ptr %6, align 4, !tbaa !5
  %14 = icmp slt i32 %13, 8
  br i1 %14, label %15, label %55

15:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = and i32 %16, %17
  store i32 %18, ptr %7, align 4, !tbaa !5
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = lshr i32 %19, 4
  store i32 %20, ptr %2, align 4, !tbaa !5
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %23, label %39

23:                                               ; preds = %15
  %24 = load i32, ptr %7, align 4, !tbaa !5
  %25 = icmp sgt i32 %24, 0
  br i1 %25, label %26, label %38

26:                                               ; preds = %23
  %27 = load i32, ptr %7, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [16 x i8], ptr %3, i64 0, i64 %28
  %30 = load i8, ptr %29, align 1, !tbaa !11
  %31 = load ptr, ptr %5, align 8, !tbaa !9
  %32 = load i32, ptr %6, align 4, !tbaa !5
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %6, align 4, !tbaa !5
  %34 = sub nsw i32 8, %32
  %35 = sub nsw i32 %34, 1
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds i8, ptr %31, i64 %36
  store i8 %30, ptr %37, align 1, !tbaa !11
  br label %38

38:                                               ; preds = %26, %23
  store i32 3, ptr %8, align 4
  br label %52

39:                                               ; preds = %15
  %40 = load i32, ptr %7, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [16 x i8], ptr %3, i64 0, i64 %41
  %43 = load i8, ptr %42, align 1, !tbaa !11
  %44 = load ptr, ptr %5, align 8, !tbaa !9
  %45 = load i32, ptr %6, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %6, align 4, !tbaa !5
  %47 = sub nsw i32 8, %45
  %48 = sub nsw i32 %47, 1
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds i8, ptr %44, i64 %49
  store i8 %43, ptr %50, align 1, !tbaa !11
  br label %51

51:                                               ; preds = %39
  store i32 0, ptr %8, align 4
  br label %52

52:                                               ; preds = %51, %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  %53 = load i32, ptr %8, align 4
  switch i32 %53, label %72 [
    i32 0, label %54
    i32 3, label %55
  ]

54:                                               ; preds = %52
  br label %12, !llvm.loop !12

55:                                               ; preds = %52, %12
  %56 = load i32, ptr %6, align 4, !tbaa !5
  %57 = icmp eq i32 %56, 0
  br i1 %57, label %58, label %66

58:                                               ; preds = %55
  %59 = load ptr, ptr %5, align 8, !tbaa !9
  %60 = load i32, ptr %6, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %6, align 4, !tbaa !5
  %62 = sub nsw i32 8, %60
  %63 = sub nsw i32 %62, 1
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds i8, ptr %59, i64 %64
  store i8 48, ptr %65, align 1, !tbaa !11
  br label %66

66:                                               ; preds = %58, %55
  %67 = load ptr, ptr %5, align 8, !tbaa !9
  %68 = load i32, ptr %6, align 4, !tbaa !5
  %69 = sub nsw i32 8, %68
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds i8, ptr %67, i64 %70
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #4
  ret ptr %71

72:                                               ; preds = %52
  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 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: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nounwind allocsize(0,1) "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 }
attributes #5 = { nounwind allocsize(0,1) }

!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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !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"

@__const.toHex.chars = external hidden unnamed_addr constant [16 x i8], align 16

; Function Attrs: mustprogress nofree nounwind willreturn memory(write, argmem: none, inaccessiblemem: readwrite) uwtable
define dso_local noalias ptr @toHex(i32 noundef %0) local_unnamed_addr #0 {
  %2 = tail call noalias dereferenceable_or_null(9) ptr @calloc(i64 noundef 9, i64 noundef 1) #2
  %3 = and i32 %0, 15
  %4 = icmp ult i32 %0, 16
  br i1 %4, label %.thread40, label %12

5:                                                ; preds = %52, %44, %36, %28, %20, %12
  %.01929.lcssa.wide = phi i32 [ 1, %12 ], [ 2, %20 ], [ 3, %28 ], [ 4, %36 ], [ 5, %44 ], [ 6, %52 ]
  %.lcssa = phi i32 [ %18, %12 ], [ %26, %20 ], [ %34, %28 ], [ %42, %36 ], [ %50, %44 ], [ %58, %52 ]
  %.not = icmp eq i32 %.lcssa, 0
  br i1 %.not, label %65, label %.thread26

.thread40:                                        ; preds = %1
  %.not43 = icmp eq i32 %3, 0
  br i1 %.not43, label %.thread24.sink.split, label %.thread26

.thread26:                                        ; preds = %.thread40, %.thread, %5
  %.lcssa39 = phi i32 [ %60, %.thread ], [ %.lcssa, %5 ], [ %3, %.thread40 ]
  %.01929.lcssa.wide38 = phi i32 [ 7, %.thread ], [ %.01929.lcssa.wide, %5 ], [ 0, %.thread40 ]
  %6 = zext nneg i32 %.lcssa39 to i64
  %7 = getelementptr inbounds [16 x i8], ptr @__const.toHex.chars, i64 0, i64 %6
  %8 = load i8, ptr %7, align 1, !tbaa !5
  %9 = add nuw nsw i32 %.01929.lcssa.wide38, 1
  %10 = xor i32 %.01929.lcssa.wide38, 7
  %11 = zext nneg i32 %10 to i64
  br label %.thread24.sink.split

12:                                               ; preds = %1
  %13 = lshr i32 %0, 4
  %14 = zext nneg i32 %3 to i64
  %15 = getelementptr inbounds [16 x i8], ptr @__const.toHex.chars, i64 0, i64 %14
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %2, i64 7
  store i8 %16, ptr %17, align 1, !tbaa !5
  %18 = and i32 %13, 15
  %19 = icmp ult i32 %0, 256
  br i1 %19, label %5, label %20

20:                                               ; preds = %12
  %21 = lshr i32 %0, 8
  %22 = zext nneg i32 %18 to i64
  %23 = getelementptr inbounds [16 x i8], ptr @__const.toHex.chars, i64 0, i64 %22
  %24 = load i8, ptr %23, align 1, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %2, i64 6
  store i8 %24, ptr %25, align 1, !tbaa !5
  %26 = and i32 %21, 15
  %27 = icmp ult i32 %0, 4096
  br i1 %27, label %5, label %28

28:                                               ; preds = %20
  %29 = lshr i32 %0, 12
  %30 = zext nneg i32 %26 to i64
  %31 = getelementptr inbounds [16 x i8], ptr @__const.toHex.chars, i64 0, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %2, i64 5
  store i8 %32, ptr %33, align 1, !tbaa !5
  %34 = and i32 %29, 15
  %35 = icmp ult i32 %0, 65536
  br i1 %35, label %5, label %36

36:                                               ; preds = %28
  %37 = lshr i32 %0, 16
  %38 = zext nneg i32 %34 to i64
  %39 = getelementptr inbounds [16 x i8], ptr @__const.toHex.chars, i64 0, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %2, i64 4
  store i8 %40, ptr %41, align 1, !tbaa !5
  %42 = and i32 %37, 15
  %43 = icmp ult i32 %0, 1048576
  br i1 %43, label %5, label %44

44:                                               ; preds = %36
  %45 = lshr i32 %0, 20
  %46 = zext nneg i32 %42 to i64
  %47 = getelementptr inbounds [16 x i8], ptr @__const.toHex.chars, i64 0, i64 %46
  %48 = load i8, ptr %47, align 1, !tbaa !5
  %49 = getelementptr inbounds i8, ptr %2, i64 3
  store i8 %48, ptr %49, align 1, !tbaa !5
  %50 = and i32 %45, 15
  %51 = icmp ult i32 %0, 16777216
  br i1 %51, label %5, label %52

52:                                               ; preds = %44
  %53 = lshr i32 %0, 24
  %54 = zext nneg i32 %50 to i64
  %55 = getelementptr inbounds [16 x i8], ptr @__const.toHex.chars, i64 0, i64 %54
  %56 = load i8, ptr %55, align 1, !tbaa !5
  %57 = getelementptr inbounds i8, ptr %2, i64 2
  store i8 %56, ptr %57, align 1, !tbaa !5
  %58 = and i32 %53, 15
  %59 = icmp ult i32 %0, 268435456
  br i1 %59, label %5, label %.thread

.thread:                                          ; preds = %52
  %60 = lshr i32 %0, 28
  %61 = zext nneg i32 %58 to i64
  %62 = getelementptr inbounds [16 x i8], ptr @__const.toHex.chars, i64 0, i64 %61
  %63 = load i8, ptr %62, align 1, !tbaa !5
  %64 = getelementptr inbounds i8, ptr %2, i64 1
  store i8 %63, ptr %64, align 1, !tbaa !5
  br label %.thread26

65:                                               ; preds = %5
  br i1 %4, label %.thread24.sink.split, label %.thread24

.thread24.sink.split:                             ; preds = %65, %.thread40, %.thread26
  %.sink48 = phi i64 [ %11, %.thread26 ], [ 7, %.thread40 ], [ 7, %65 ]
  %.sink = phi i8 [ %8, %.thread26 ], [ 48, %.thread40 ], [ 48, %65 ]
  %.4.ph = phi i32 [ %9, %.thread26 ], [ 1, %.thread40 ], [ 1, %65 ]
  %66 = getelementptr inbounds i8, ptr %2, i64 %.sink48
  store i8 %.sink, ptr %66, align 1, !tbaa !5
  br label %.thread24

.thread24:                                        ; preds = %.thread24.sink.split, %65
  %.4 = phi i32 [ %.01929.lcssa.wide, %65 ], [ %.4.ph, %.thread24.sink.split ]
  %67 = sub nuw nsw i32 8, %.4
  %68 = zext nneg i32 %67 to i64
  %69 = getelementptr inbounds i8, ptr %2, i64 %68
  ret ptr %69
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nofree nounwind willreturn memory(write, argmem: none, inaccessiblemem: readwrite) 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 allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { nounwind allocsize(0,1) }

!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/C++ TBAA"}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass