; LLVM IR from openssl/openssl :: ssl/quic (json_enc)

; 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: 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 hidden void @json_write_char(ptr noundef, i8 noundef signext) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @json_pre_item(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden void @json_post_item(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @ossl_json_str_hex(ptr noundef %0, ptr noundef %1, i64 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i8, align 1
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %11, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %12 = load ptr, ptr %7, align 8, !tbaa !5
  %13 = load i64, ptr %6, align 8, !tbaa !9
  %14 = getelementptr inbounds i8, ptr %12, i64 %13
  store ptr %14, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #3
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = call i32 @json_pre_item(ptr noundef %15)
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %19, label %18

18:                                               ; preds = %3
  store i32 1, ptr %10, align 4
  br label %46

19:                                               ; preds = %3
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  call void @json_write_char(ptr noundef %20, i8 noundef signext 34)
  br label %21

21:                                               ; preds = %40, %19
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = icmp ult ptr %22, %23
  br i1 %24, label %25, label %43

25:                                               ; preds = %21
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = load i8, ptr %26, align 1, !tbaa !11
  store i8 %27, ptr %9, align 1, !tbaa !11
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load i8, ptr %9, align 1, !tbaa !11
  %30 = zext i8 %29 to i32
  %31 = ashr i32 %30, 4
  %32 = call i32 @hex_digit(i32 noundef %31)
  %33 = trunc i32 %32 to i8
  call void @json_write_char(ptr noundef %28, i8 noundef signext %33)
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = load i8, ptr %9, align 1, !tbaa !11
  %36 = zext i8 %35 to i32
  %37 = and i32 %36, 15
  %38 = call i32 @hex_digit(i32 noundef %37)
  %39 = trunc i32 %38 to i8
  call void @json_write_char(ptr noundef %34, i8 noundef signext %39)
  br label %40

40:                                               ; preds = %25
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %41, i32 1
  store ptr %42, ptr %7, align 8, !tbaa !5
  br label %21, !llvm.loop !12

43:                                               ; preds = %21
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  call void @json_write_char(ptr noundef %44, i8 noundef signext 34)
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  call void @json_post_item(ptr noundef %45)
  store i32 0, ptr %10, align 4
  br label %46

46:                                               ; preds = %43, %18
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  %47 = load i32, ptr %10, align 4
  switch i32 %47, label %49 [
    i32 0, label %48
    i32 1, label %48
  ]

48:                                               ; preds = %46, %46
  ret void

49:                                               ; preds = %46
  unreachable
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @hex_digit(i32 noundef) #2

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 = { inlinehint 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 #3 = { 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"

; Function Attrs: nounwind uwtable
declare hidden void @json_write_char(ptr noundef, i8 noundef signext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @json_pre_item(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @json_post_item(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @ossl_json_str_hex(ptr noundef %0, ptr noundef readonly %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %1, i64 %2
  %5 = tail call i32 @json_pre_item(ptr noundef %0)
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %18, label %6

6:                                                ; preds = %3
  tail call void @json_write_char(ptr noundef %0, i8 noundef signext 34)
  %7 = icmp sgt i64 %2, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %6, %.lr.ph
  %.014 = phi ptr [ %16, %.lr.ph ], [ %1, %6 ]
  %8 = load i8, ptr %.014, align 1, !tbaa !5
  %9 = zext i8 %8 to i32
  %10 = lshr i32 %9, 4
  %11 = tail call i32 @hex_digit(i32 noundef %10)
  %12 = trunc i32 %11 to i8
  tail call void @json_write_char(ptr noundef %0, i8 noundef signext %12)
  %13 = and i32 %9, 15
  %14 = tail call i32 @hex_digit(i32 noundef %13)
  %15 = trunc i32 %14 to i8
  tail call void @json_write_char(ptr noundef %0, i8 noundef signext %15)
  %16 = getelementptr inbounds i8, ptr %.014, i64 1
  %17 = icmp ult ptr %16, %4
  br i1 %17, label %.lr.ph, label %._crit_edge, !llvm.loop !8

._crit_edge:                                      ; preds = %.lr.ph, %6
  tail call void @json_write_char(ptr noundef %0, i8 noundef signext 34)
  tail call void @json_post_item(ptr noundef %0)
  br label %18

18:                                               ; preds = %3, %._crit_edge
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @hex_digit(i32 noundef) local_unnamed_addr #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 = { inlinehint 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: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass