; LLVM IR from openappsec/openappsec :: external/yajl/src (yajl_encode)

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

@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [3 x i8], align 1

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

20:                                               ; preds = %82, %5
  %21 = load i64, ptr %12, align 8, !tbaa !9
  %22 = load i64, ptr %9, align 8, !tbaa !9
  %23 = icmp ult i64 %21, %22
  br i1 %23, label %24, label %83

24:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  store ptr null, ptr %14, align 8, !tbaa !5
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = load i64, ptr %12, align 8, !tbaa !9
  %27 = getelementptr inbounds i8, ptr %25, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !13
  %29 = zext i8 %28 to i32
  switch i32 %29, label %42 [
    i32 13, label %30
    i32 10, label %31
    i32 92, label %32
    i32 47, label %33
    i32 34, label %38
    i32 12, label %39
    i32 8, label %40
    i32 9, label %41
  ]

30:                                               ; preds = %24
  store ptr @.str, ptr %14, align 8, !tbaa !5
  br label %58

31:                                               ; preds = %24
  store ptr @.str.1, ptr %14, align 8, !tbaa !5
  br label %58

32:                                               ; preds = %24
  store ptr @.str.2, ptr %14, align 8, !tbaa !5
  br label %58

33:                                               ; preds = %24
  %34 = load i32, ptr %10, align 4, !tbaa !11
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %37

36:                                               ; preds = %33
  store ptr @.str.3, ptr %14, align 8, !tbaa !5
  br label %37

37:                                               ; preds = %36, %33
  br label %58

38:                                               ; preds = %24
  store ptr @.str.4, ptr %14, align 8, !tbaa !5
  br label %58

39:                                               ; preds = %24
  store ptr @.str.5, ptr %14, align 8, !tbaa !5
  br label %58

40:                                               ; preds = %24
  store ptr @.str.6, ptr %14, align 8, !tbaa !5
  br label %58

41:                                               ; preds = %24
  store ptr @.str.7, ptr %14, align 8, !tbaa !5
  br label %58

42:                                               ; preds = %24
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = load i64, ptr %12, align 8, !tbaa !9
  %45 = getelementptr inbounds i8, ptr %43, i64 %44
  %46 = load i8, ptr %45, align 1, !tbaa !13
  %47 = zext i8 %46 to i32
  %48 = icmp slt i32 %47, 32
  br i1 %48, label %49, label %57

49:                                               ; preds = %42
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = load i64, ptr %12, align 8, !tbaa !9
  %52 = getelementptr inbounds i8, ptr %50, i64 %51
  %53 = load i8, ptr %52, align 1, !tbaa !13
  %54 = getelementptr inbounds [7 x i8], ptr %13, i64 0, i64 0
  %55 = getelementptr inbounds i8, ptr %54, i64 4
  call void @CharToHex(i8 noundef zeroext %53, ptr noundef %55)
  %56 = getelementptr inbounds [7 x i8], ptr %13, i64 0, i64 0
  store ptr %56, ptr %14, align 8, !tbaa !5
  br label %57

57:                                               ; preds = %49, %42
  br label %58

58:                                               ; preds = %57, %41, %40, %39, %38, %37, %32, %31, %30
  %59 = load ptr, ptr %14, align 8, !tbaa !5
  %60 = icmp ne ptr %59, null
  br i1 %60, label %61, label %79

61:                                               ; preds = %58
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = load i64, ptr %11, align 8, !tbaa !9
  %66 = getelementptr inbounds i8, ptr %64, i64 %65
  %67 = load i64, ptr %12, align 8, !tbaa !9
  %68 = load i64, ptr %11, align 8, !tbaa !9
  %69 = sub i64 %67, %68
  call void %62(ptr noundef %63, ptr noundef %66, i64 noundef %69)
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  %72 = load ptr, ptr %14, align 8, !tbaa !5
  %73 = load ptr, ptr %14, align 8, !tbaa !5
  %74 = call i64 @strlen(ptr noundef %73) #4
  %75 = trunc i64 %74 to i32
  %76 = zext i32 %75 to i64
  call void %70(ptr noundef %71, ptr noundef %72, i64 noundef %76)
  %77 = load i64, ptr %12, align 8, !tbaa !9
  %78 = add i64 %77, 1
  store i64 %78, ptr %12, align 8, !tbaa !9
  store i64 %78, ptr %11, align 8, !tbaa !9
  br label %82

79:                                               ; preds = %58
  %80 = load i64, ptr %12, align 8, !tbaa !9
  %81 = add i64 %80, 1
  store i64 %81, ptr %12, align 8, !tbaa !9
  br label %82

82:                                               ; preds = %79, %61
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  br label %20, !llvm.loop !14

83:                                               ; preds = %20
  %84 = load ptr, ptr %6, align 8, !tbaa !5
  %85 = load ptr, ptr %7, align 8, !tbaa !5
  %86 = load ptr, ptr %8, align 8, !tbaa !5
  %87 = load i64, ptr %11, align 8, !tbaa !9
  %88 = getelementptr inbounds i8, ptr %86, i64 %87
  %89 = load i64, ptr %12, align 8, !tbaa !9
  %90 = load i64, ptr %11, align 8, !tbaa !9
  %91 = sub i64 %89, %90
  call void %84(ptr noundef %85, ptr noundef %88, i64 noundef %91)
  call void @llvm.lifetime.end.p0(i64 7, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  ret void
}

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

; Function Attrs: nounwind uwtable
declare hidden void @CharToHex(i8 noundef zeroext, ptr noundef) #0

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

; 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 = { nounwind willreturn memory(read) "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 }
attributes #4 = { nounwind willreturn memory(read) }

!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 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @yajl_string_encode(ptr nocapture noundef readonly %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = alloca [7 x i8], align 4
  call void @llvm.lifetime.start.p0(i64 7, ptr nonnull %6) #3
  store <4 x i8> <i8 92, i8 117, i8 48, i8 48>, ptr %6, align 4, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 6
  store i8 0, ptr %7, align 2, !tbaa !5
  %.not38 = icmp eq i64 %3, 0
  br i1 %.not38, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5
  %.not = icmp eq i32 %4, 0
  %8 = getelementptr inbounds i8, ptr %6, i64 4
  br i1 %.not, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph, %27
  %.02735.us = phi i64 [ %.1.us, %27 ], [ 0, %.lr.ph ]
  %.02834.us = phi i64 [ %.129.us, %27 ], [ 0, %.lr.ph ]
  %9 = getelementptr inbounds i8, ptr %2, i64 %.02735.us
  %10 = load i8, ptr %9, align 1, !tbaa !5
  switch i8 %10, label %17 [
    i8 13, label %21
    i8 10, label %16
    i8 92, label %15
    i8 47, label %select.unfold.us
    i8 34, label %14
    i8 12, label %13
    i8 8, label %12
    i8 9, label %11
  ]

11:                                               ; preds = %.lr.ph.split.us
  br label %21

12:                                               ; preds = %.lr.ph.split.us
  br label %21

13:                                               ; preds = %.lr.ph.split.us
  br label %21

14:                                               ; preds = %.lr.ph.split.us
  br label %21

15:                                               ; preds = %.lr.ph.split.us
  br label %21

16:                                               ; preds = %.lr.ph.split.us
  br label %21

17:                                               ; preds = %.lr.ph.split.us
  %18 = icmp ult i8 %10, 32
  br i1 %18, label %20, label %select.unfold.us

select.unfold.us:                                 ; preds = %.lr.ph.split.us, %17
  %19 = add nuw i64 %.02735.us, 1
  br label %27

20:                                               ; preds = %17
  call void @CharToHex(i8 noundef zeroext %10, ptr noundef nonnull %8)
  br label %21

21:                                               ; preds = %20, %16, %15, %14, %13, %12, %11, %.lr.ph.split.us
  %.0.ph.us = phi ptr [ @.str, %.lr.ph.split.us ], [ @.str.1, %16 ], [ @.str.2, %15 ], [ @.str.4, %14 ], [ @.str.5, %13 ], [ @.str.6, %12 ], [ @.str.7, %11 ], [ %6, %20 ]
  %22 = getelementptr inbounds i8, ptr %2, i64 %.02834.us
  %23 = sub i64 %.02735.us, %.02834.us
  call void %0(ptr noundef %1, ptr noundef %22, i64 noundef %23) #3
  %24 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %.0.ph.us) #4
  %25 = and i64 %24, 4294967295
  call void %0(ptr noundef %1, ptr noundef nonnull %.0.ph.us, i64 noundef %25) #3
  %26 = add nuw i64 %.02735.us, 1
  br label %27

27:                                               ; preds = %21, %select.unfold.us
  %.129.us = phi i64 [ %26, %21 ], [ %.02834.us, %select.unfold.us ]
  %.1.us = phi i64 [ %26, %21 ], [ %19, %select.unfold.us ]
  %28 = icmp ult i64 %.1.us, %3
  br i1 %28, label %.lr.ph.split.us, label %._crit_edge, !llvm.loop !8

.lr.ph.split:                                     ; preds = %.lr.ph, %48
  %.02735 = phi i64 [ %.1, %48 ], [ 0, %.lr.ph ]
  %.02834 = phi i64 [ %.129, %48 ], [ 0, %.lr.ph ]
  %29 = getelementptr inbounds i8, ptr %2, i64 %.02735
  %30 = load i8, ptr %29, align 1, !tbaa !5
  switch i8 %30, label %38 [
    i8 13, label %41
    i8 10, label %31
    i8 92, label %32
    i8 47, label %33
    i8 34, label %34
    i8 12, label %35
    i8 8, label %36
    i8 9, label %37
  ]

31:                                               ; preds = %.lr.ph.split
  br label %41

32:                                               ; preds = %.lr.ph.split
  br label %41

33:                                               ; preds = %.lr.ph.split
  br label %41

34:                                               ; preds = %.lr.ph.split
  br label %41

35:                                               ; preds = %.lr.ph.split
  br label %41

36:                                               ; preds = %.lr.ph.split
  br label %41

37:                                               ; preds = %.lr.ph.split
  br label %41

38:                                               ; preds = %.lr.ph.split
  %39 = icmp ult i8 %30, 32
  br i1 %39, label %40, label %select.unfold

40:                                               ; preds = %38
  call void @CharToHex(i8 noundef zeroext %30, ptr noundef nonnull %8)
  br label %41

41:                                               ; preds = %33, %40, %37, %36, %35, %34, %32, %31, %.lr.ph.split
  %.0.ph = phi ptr [ @.str.3, %33 ], [ @.str, %.lr.ph.split ], [ @.str.1, %31 ], [ @.str.2, %32 ], [ @.str.4, %34 ], [ @.str.5, %35 ], [ @.str.6, %36 ], [ @.str.7, %37 ], [ %6, %40 ]
  %42 = getelementptr inbounds i8, ptr %2, i64 %.02834
  %43 = sub i64 %.02735, %.02834
  call void %0(ptr noundef %1, ptr noundef %42, i64 noundef %43) #3
  %44 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %.0.ph) #4
  %45 = and i64 %44, 4294967295
  call void %0(ptr noundef %1, ptr noundef nonnull %.0.ph, i64 noundef %45) #3
  %46 = add nuw i64 %.02735, 1
  br label %48

select.unfold:                                    ; preds = %38
  %47 = add nuw i64 %.02735, 1
  br label %48

48:                                               ; preds = %select.unfold, %41
  %.129 = phi i64 [ %46, %41 ], [ %.02834, %select.unfold ]
  %.1 = phi i64 [ %46, %41 ], [ %47, %select.unfold ]
  %49 = icmp ult i64 %.1, %3
  br i1 %49, label %.lr.ph.split, label %._crit_edge, !llvm.loop !8

._crit_edge:                                      ; preds = %48, %27, %5
  %.028.lcssa = phi i64 [ 0, %5 ], [ %.129.us, %27 ], [ %.129, %48 ]
  %.027.lcssa = phi i64 [ 0, %5 ], [ %.1.us, %27 ], [ %.1, %48 ]
  %50 = getelementptr inbounds i8, ptr %2, i64 %.028.lcssa
  %51 = sub i64 %.027.lcssa, %.028.lcssa
  call void %0(ptr noundef %1, ptr noundef %50, i64 noundef %51) #3
  call void @llvm.lifetime.end.p0(i64 7, ptr nonnull %6) #3
  ret void
}

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

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 }
attributes #4 = { nounwind willreturn memory(read) }

!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,GVNPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass