; LLVM IR from JessonYue/LeetCodeLearning :: Array/wuchao/other/8-3 10进制整数转换为16进制 (IntegerToHex)

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

11:                                               ; preds = %35, %1
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = icmp slt i32 %12, 8
  br i1 %13, label %14, label %38

14:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = and i32 %15, 15
  store i32 %16, ptr %6, align 4, !tbaa !5
  %17 = load i32, ptr %6, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [16 x i8], ptr %3, i64 0, i64 %18
  %20 = load i8, ptr %19, align 1, !tbaa !11
  %21 = load ptr, ptr %4, align 8, !tbaa !9
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = sub nsw i32 7, %22
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds i8, ptr %21, i64 %24
  store i8 %20, ptr %25, align 1, !tbaa !11
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = ashr i32 %26, 4
  store i32 %27, ptr %2, align 4, !tbaa !5
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %14
  store i32 2, ptr %7, align 4
  br label %32

31:                                               ; preds = %14
  store i32 0, ptr %7, align 4
  br label %32

32:                                               ; preds = %31, %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %33 = load i32, ptr %7, align 4
  switch i32 %33, label %48 [
    i32 0, label %34
    i32 2, label %38
  ]

34:                                               ; preds = %32
  br label %35

35:                                               ; preds = %34
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %5, align 4, !tbaa !5
  br label %11, !llvm.loop !12

38:                                               ; preds = %32, %11
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = icmp eq i32 %39, 8
  br i1 %40, label %41, label %42

41:                                               ; preds = %38
  store i32 7, ptr %5, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %41, %38
  %43 = load ptr, ptr %4, align 8, !tbaa !9
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = sub nsw i32 7, %44
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds i8, ptr %43, i64 %46
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #4
  ret ptr %47

48:                                               ; preds = %32
  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)
declare noalias ptr @malloc(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) "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) }

!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 @malloc(i64 noundef 9) #2
  %3 = getelementptr inbounds i8, ptr %2, i64 8
  store i8 0, ptr %3, align 1, !tbaa !5
  %4 = and i32 %0, 15
  %5 = zext nneg i32 %4 to i64
  %6 = getelementptr inbounds [16 x i8], ptr @__const.toHex.chars, i64 0, i64 %5
  %7 = load i8, ptr %6, align 1, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %2, i64 7
  store i8 %7, ptr %8, align 1, !tbaa !5
  %9 = icmp ult i32 %0, 16
  br i1 %9, label %63, label %10

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

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

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

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

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

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

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

63:                                               ; preds = %58, %50, %42, %34, %26, %18, %10, %1
  %64 = phi i64 [ 7, %1 ], [ 6, %10 ], [ 5, %18 ], [ 4, %26 ], [ 3, %34 ], [ 2, %42 ], [ 1, %50 ], [ 0, %58 ]
  %65 = getelementptr inbounds i8, ptr %2, i64 %64
  ret ptr %65
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(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,uninitialized") allocsize(0) 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) }

!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: ADCEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass