; LLVM IR from mwarning/KadNode :: src (utils)

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

@base16enc.hexchars = external hidden 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: nounwind uwtable
declare dso_local i64 @base16encsize(i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @base16enc(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i64 %3, ptr %9, align 8, !tbaa !9
  %11 = load i64, ptr %7, align 8, !tbaa !9
  %12 = load i64, ptr %9, align 8, !tbaa !9
  %13 = call i64 @base16encsize(i64 noundef %12)
  %14 = add i64 %13, 1
  %15 = icmp ult i64 %11, %14
  br i1 %15, label %16, label %17

16:                                               ; preds = %4
  store ptr null, ptr %5, align 8
  br label %60

17:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  store i64 0, ptr %10, align 8, !tbaa !9
  br label %18

18:                                               ; preds = %51, %17
  %19 = load i64, ptr %10, align 8, !tbaa !9
  %20 = load i64, ptr %9, align 8, !tbaa !9
  %21 = icmp ult i64 %19, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %54

23:                                               ; preds = %18
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = load i64, ptr %10, align 8, !tbaa !9
  %26 = getelementptr inbounds i8, ptr %24, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !11
  %28 = zext i8 %27 to i32
  %29 = sdiv i32 %28, 16
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [16 x i8], ptr @base16enc.hexchars, i64 0, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !11
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = load i64, ptr %10, align 8, !tbaa !9
  %35 = mul i64 2, %34
  %36 = getelementptr inbounds i8, ptr %33, i64 %35
  store i8 %32, ptr %36, align 1, !tbaa !11
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = load i64, ptr %10, align 8, !tbaa !9
  %39 = getelementptr inbounds i8, ptr %37, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !11
  %41 = zext i8 %40 to i32
  %42 = srem i32 %41, 16
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [16 x i8], ptr @base16enc.hexchars, i64 0, i64 %43
  %45 = load i8, ptr %44, align 1, !tbaa !11
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = load i64, ptr %10, align 8, !tbaa !9
  %48 = mul i64 2, %47
  %49 = add i64 %48, 1
  %50 = getelementptr inbounds i8, ptr %46, i64 %49
  store i8 %45, ptr %50, align 1, !tbaa !11
  br label %51

51:                                               ; preds = %23
  %52 = load i64, ptr %10, align 8, !tbaa !9
  %53 = add i64 %52, 1
  store i64 %53, ptr %10, align 8, !tbaa !9
  br label %18, !llvm.loop !12

54:                                               ; preds = %22
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = load i64, ptr %9, align 8, !tbaa !9
  %57 = mul i64 2, %56
  %58 = getelementptr inbounds i8, ptr %55, i64 %57
  store i8 0, ptr %58, align 1, !tbaa !11
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %59, ptr %5, align 8
  br label %60

60:                                               ; preds = %54, %16
  %61 = load ptr, ptr %5, align 8
  ret ptr %61
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !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"

@base16enc.hexchars = external hidden local_unnamed_addr constant [16 x i8], align 16

; Function Attrs: nounwind uwtable
declare dso_local i64 @base16encsize(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @base16enc(ptr noundef writeonly %0, i64 noundef %1, ptr nocapture noundef readonly %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = tail call i64 @base16encsize(i64 noundef %3)
  %6 = add i64 %5, 1
  %7 = icmp ugt i64 %6, %1
  br i1 %7, label %26, label %.preheader

.preheader:                                       ; preds = %4
  %.not = icmp eq i64 %3, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %8 = shl i64 %3, 1
  %9 = getelementptr inbounds i8, ptr %0, i64 %8
  store i8 0, ptr %9, align 1, !tbaa !5
  br label %26

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.018 = phi i64 [ %25, %.lr.ph ], [ 0, %.preheader ]
  %10 = getelementptr inbounds i8, ptr %2, i64 %.018
  %11 = load i8, ptr %10, align 1, !tbaa !5
  %12 = lshr i8 %11, 4
  %13 = zext nneg i8 %12 to i64
  %14 = getelementptr inbounds [16 x i8], ptr @base16enc.hexchars, i64 0, i64 %13
  %15 = load i8, ptr %14, align 1, !tbaa !5
  %16 = shl i64 %.018, 1
  %17 = getelementptr inbounds i8, ptr %0, i64 %16
  store i8 %15, ptr %17, align 1, !tbaa !5
  %18 = load i8, ptr %10, align 1, !tbaa !5
  %19 = and i8 %18, 15
  %20 = zext nneg i8 %19 to i64
  %21 = getelementptr inbounds [16 x i8], ptr @base16enc.hexchars, i64 0, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !5
  %23 = or disjoint i64 %16, 1
  %24 = getelementptr inbounds i8, ptr %0, i64 %23
  store i8 %22, ptr %24, align 1, !tbaa !5
  %25 = add nuw i64 %.018, 1
  %exitcond.not = icmp eq i64 %25, %3
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !8

26:                                               ; preds = %4, %._crit_edge
  %.016 = phi ptr [ %0, %._crit_edge ], [ null, %4 ]
  ret ptr %.016
}

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

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass