; LLVM IR from JessonYue/LeetCodeLearning :: Array/cuijilin/Day20200714.ll (Z6toHex2i)

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

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

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

; 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) #1

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_Z6toHex2i(i32 noundef %0) #3 {
  %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
  %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._Z6toHex2i.table, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %9 = call noalias ptr @calloc(i64 noundef 9, i64 noundef 1) #5
  store ptr %9, ptr %4, align 8, !tbaa !9
  %10 = load ptr, ptr %4, align 8, !tbaa !9
  %11 = getelementptr inbounds i8, ptr %10, i64 0
  store i8 48, ptr %11, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 28, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 -268435456, ptr %7, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %39, %1
  %13 = load i32, ptr %7, align 4, !tbaa !5
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %44

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

23:                                               ; preds = %15
  %24 = load ptr, ptr %4, align 8, !tbaa !9
  %25 = getelementptr inbounds i8, ptr %24, i64 0
  %26 = load i8, ptr %25, align 1, !tbaa !11
  %27 = sext i8 %26 to i32
  %28 = icmp ne i32 %27, 48
  br i1 %28, label %29, label %39

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

39:                                               ; preds = %29, %23
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = sub nsw i32 %40, 4
  store i32 %41, ptr %5, align 4, !tbaa !5
  %42 = load i32, ptr %7, align 4, !tbaa !5
  %43 = lshr i32 %42, 4
  store i32 %43, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %12, !llvm.loop !12

44:                                               ; preds = %12
  %45 = load ptr, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  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 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #4
  ret ptr %45
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #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++ 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._Z6toHex2i.table = external hidden unnamed_addr constant [16 x i8], align 16

; 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 #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(readwrite, argmem: none) uwtable
define dso_local noalias noundef ptr @_Z6toHex2i(i32 noundef %0) local_unnamed_addr #1 {
  %2 = tail call noalias dereferenceable_or_null(9) ptr @calloc(i64 noundef 9, i64 noundef 1) #2
  store i8 48, ptr %2, align 1, !tbaa !5
  %.not14 = icmp ult i32 %0, 268435456
  br i1 %.not14, label %.thread, label %3

3:                                                ; preds = %1
  %4 = lshr i32 %0, 28
  %5 = zext nneg i32 %4 to i64
  %6 = getelementptr inbounds [16 x i8], ptr @__const._Z6toHex2i.table, i64 0, i64 %5
  %7 = load i8, ptr %6, align 1, !tbaa !5
  store i8 %7, ptr %2, align 1, !tbaa !5
  %8 = icmp ne i8 %7, 48
  %9 = lshr i32 %0, 24
  %10 = and i32 %9, 15
  %.not14.1 = icmp ne i32 %10, 0
  %brmerge = select i1 %.not14.1, i1 true, i1 %8
  br i1 %brmerge, label %12, label %.thread25

.thread:                                          ; preds = %1
  %11 = lshr i32 %0, 24
  %.not14.121 = icmp ult i32 %0, 16777216
  br i1 %.not14.121, label %.thread25, label %12

12:                                               ; preds = %3, %.thread
  %13 = phi i32 [ %11, %.thread ], [ %10, %3 ]
  %.123 = phi i32 [ 0, %.thread ], [ 1, %3 ]
  %14 = zext nneg i32 %13 to i64
  %15 = getelementptr inbounds [16 x i8], ptr @__const._Z6toHex2i.table, i64 0, i64 %14
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %17 = add nuw nsw i32 %.123, 1
  %18 = zext nneg i32 %.123 to i64
  %19 = getelementptr inbounds i8, ptr %2, i64 %18
  store i8 %16, ptr %19, align 1, !tbaa !5
  br label %.thread25

.thread25:                                        ; preds = %3, %.thread, %12
  %.1.1 = phi i32 [ %17, %12 ], [ 0, %.thread ], [ 1, %3 ]
  %20 = lshr i32 %0, 20
  %21 = and i32 %20, 15
  %.not14.2 = icmp eq i32 %21, 0
  br i1 %.not14.2, label %22, label %24

22:                                               ; preds = %.thread25
  %23 = load i8, ptr %2, align 1, !tbaa !5
  %.not15.2 = icmp eq i8 %23, 48
  br i1 %.not15.2, label %31, label %24

24:                                               ; preds = %22, %.thread25
  %25 = zext nneg i32 %21 to i64
  %26 = getelementptr inbounds [16 x i8], ptr @__const._Z6toHex2i.table, i64 0, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !5
  %28 = add nuw nsw i32 %.1.1, 1
  %29 = zext nneg i32 %.1.1 to i64
  %30 = getelementptr inbounds i8, ptr %2, i64 %29
  store i8 %27, ptr %30, align 1, !tbaa !5
  br label %31

31:                                               ; preds = %24, %22
  %.1.2 = phi i32 [ %28, %24 ], [ %.1.1, %22 ]
  %32 = lshr i32 %0, 16
  %33 = and i32 %32, 15
  %.not14.3 = icmp eq i32 %33, 0
  br i1 %.not14.3, label %34, label %36

34:                                               ; preds = %31
  %35 = load i8, ptr %2, align 1, !tbaa !5
  %.not15.3 = icmp eq i8 %35, 48
  br i1 %.not15.3, label %43, label %36

36:                                               ; preds = %34, %31
  %37 = zext nneg i32 %33 to i64
  %38 = getelementptr inbounds [16 x i8], ptr @__const._Z6toHex2i.table, i64 0, i64 %37
  %39 = load i8, ptr %38, align 1, !tbaa !5
  %40 = add nuw nsw i32 %.1.2, 1
  %41 = zext nneg i32 %.1.2 to i64
  %42 = getelementptr inbounds i8, ptr %2, i64 %41
  store i8 %39, ptr %42, align 1, !tbaa !5
  br label %43

43:                                               ; preds = %36, %34
  %.1.3 = phi i32 [ %40, %36 ], [ %.1.2, %34 ]
  %44 = lshr i32 %0, 12
  %45 = and i32 %44, 15
  %.not14.4 = icmp eq i32 %45, 0
  br i1 %.not14.4, label %46, label %48

46:                                               ; preds = %43
  %47 = load i8, ptr %2, align 1, !tbaa !5
  %.not15.4 = icmp eq i8 %47, 48
  br i1 %.not15.4, label %55, label %48

48:                                               ; preds = %46, %43
  %49 = zext nneg i32 %45 to i64
  %50 = getelementptr inbounds [16 x i8], ptr @__const._Z6toHex2i.table, i64 0, i64 %49
  %51 = load i8, ptr %50, align 1, !tbaa !5
  %52 = add nuw nsw i32 %.1.3, 1
  %53 = zext nneg i32 %.1.3 to i64
  %54 = getelementptr inbounds i8, ptr %2, i64 %53
  store i8 %51, ptr %54, align 1, !tbaa !5
  br label %55

55:                                               ; preds = %48, %46
  %.1.4 = phi i32 [ %52, %48 ], [ %.1.3, %46 ]
  %56 = lshr i32 %0, 8
  %57 = and i32 %56, 15
  %.not14.5 = icmp eq i32 %57, 0
  br i1 %.not14.5, label %58, label %60

58:                                               ; preds = %55
  %59 = load i8, ptr %2, align 1, !tbaa !5
  %.not15.5 = icmp eq i8 %59, 48
  br i1 %.not15.5, label %67, label %60

60:                                               ; preds = %58, %55
  %61 = zext nneg i32 %57 to i64
  %62 = getelementptr inbounds [16 x i8], ptr @__const._Z6toHex2i.table, i64 0, i64 %61
  %63 = load i8, ptr %62, align 1, !tbaa !5
  %64 = add nuw nsw i32 %.1.4, 1
  %65 = zext nneg i32 %.1.4 to i64
  %66 = getelementptr inbounds i8, ptr %2, i64 %65
  store i8 %63, ptr %66, align 1, !tbaa !5
  br label %67

67:                                               ; preds = %60, %58
  %.1.5 = phi i32 [ %64, %60 ], [ %.1.4, %58 ]
  %68 = lshr i32 %0, 4
  %69 = and i32 %68, 15
  %.not14.6 = icmp eq i32 %69, 0
  br i1 %.not14.6, label %70, label %72

70:                                               ; preds = %67
  %71 = load i8, ptr %2, align 1, !tbaa !5
  %.not15.6 = icmp eq i8 %71, 48
  br i1 %.not15.6, label %79, label %72

72:                                               ; preds = %70, %67
  %73 = zext nneg i32 %69 to i64
  %74 = getelementptr inbounds [16 x i8], ptr @__const._Z6toHex2i.table, i64 0, i64 %73
  %75 = load i8, ptr %74, align 1, !tbaa !5
  %76 = add nuw nsw i32 %.1.5, 1
  %77 = zext nneg i32 %.1.5 to i64
  %78 = getelementptr inbounds i8, ptr %2, i64 %77
  store i8 %75, ptr %78, align 1, !tbaa !5
  br label %79

79:                                               ; preds = %72, %70
  %.1.6 = phi i32 [ %76, %72 ], [ %.1.5, %70 ]
  %80 = and i32 %0, 15
  %.not14.7 = icmp eq i32 %80, 0
  br i1 %.not14.7, label %81, label %83

81:                                               ; preds = %79
  %82 = load i8, ptr %2, align 1, !tbaa !5
  %.not15.7 = icmp eq i8 %82, 48
  br i1 %.not15.7, label %89, label %83

83:                                               ; preds = %81, %79
  %84 = zext nneg i32 %80 to i64
  %85 = getelementptr inbounds [16 x i8], ptr @__const._Z6toHex2i.table, i64 0, i64 %84
  %86 = load i8, ptr %85, align 1, !tbaa !5
  %87 = zext nneg i32 %.1.6 to i64
  %88 = getelementptr inbounds i8, ptr %2, i64 %87
  store i8 %86, ptr %88, align 1, !tbaa !5
  br label %89

89:                                               ; preds = %83, %81
  ret ptr %2
}

attributes #0 = { 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 #1 = { mustprogress nofree nounwind willreturn memory(readwrite, argmem: 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 #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++ TBAA"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass