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

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

%struct.yajl_callbacks = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.context_s = type { ptr, ptr, ptr, i64 }
%struct.yajl_handle_t = type { ptr, ptr, ptr, ptr, i64, ptr, %struct.yajl_bytestack_t, %struct.yajl_alloc_funcs, i32 }
%struct.yajl_bytestack_t = type { ptr, i64, i64, ptr }
%struct.yajl_alloc_funcs = type { ptr, ptr, ptr, ptr }

@yajl_tree_parse.callbacks = external hidden constant %struct.yajl_callbacks, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1

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

19:                                               ; preds = %3
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = load i64, ptr %7, align 8, !tbaa !9
  call void @llvm.memset.p0.i64(ptr align 1 %20, i8 0, i64 %21, i1 false)
  br label %22

22:                                               ; preds = %19, %3
  %23 = call ptr @yajl_alloc(ptr noundef @yajl_tree_parse.callbacks, ptr noundef null, ptr noundef %11)
  store ptr %23, ptr %8, align 8, !tbaa !5
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = call i32 (ptr, i32, ...) @yajl_config(ptr noundef %24, i32 noundef 1, i32 noundef 1)
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = call i64 @strlen(ptr noundef %28) #7
  %30 = call i32 @yajl_parse(ptr noundef %26, ptr noundef %27, i64 noundef %29)
  store i32 %30, ptr %9, align 4, !tbaa !14
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = call i32 @yajl_complete_parse(ptr noundef %31)
  store i32 %32, ptr %9, align 4, !tbaa !14
  %33 = load i32, ptr %9, align 4, !tbaa !14
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %62

35:                                               ; preds = %22
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = icmp ne ptr %36, null
  br i1 %37, label %38, label %60

38:                                               ; preds = %35
  %39 = load i64, ptr %7, align 8, !tbaa !9
  %40 = icmp ugt i64 %39, 0
  br i1 %40, label %41, label %60

41:                                               ; preds = %38
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = call i64 @strlen(ptr noundef %44) #7
  %46 = call ptr @yajl_get_error(ptr noundef %42, i32 noundef 1, ptr noundef %43, i64 noundef %45)
  store ptr %46, ptr %10, align 8, !tbaa !5
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = load i64, ptr %7, align 8, !tbaa !9
  %49 = load ptr, ptr %10, align 8, !tbaa !5
  %50 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %47, i64 noundef %48, ptr noundef @.str, ptr noundef %49) #6
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.yajl_handle_t, ptr %51, i32 0, i32 7
  %53 = getelementptr inbounds %struct.yajl_alloc_funcs, ptr %52, i32 0, i32 2
  %54 = load ptr, ptr %53, align 8, !tbaa !16
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.yajl_handle_t, ptr %55, i32 0, i32 7
  %57 = getelementptr inbounds %struct.yajl_alloc_funcs, ptr %56, i32 0, i32 3
  %58 = load ptr, ptr %57, align 8, !tbaa !20
  %59 = load ptr, ptr %10, align 8, !tbaa !5
  call void %54(ptr noundef %58, ptr noundef %59)
  br label %60

60:                                               ; preds = %41, %38, %35
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  call void @yajl_free(ptr noundef %61)
  store ptr null, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %66

62:                                               ; preds = %22
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  call void @yajl_free(ptr noundef %63)
  %64 = getelementptr inbounds %struct.context_s, ptr %11, i32 0, i32 1
  %65 = load ptr, ptr %64, align 8, !tbaa !21
  store ptr %65, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %66

66:                                               ; preds = %62, %60
  call void @llvm.lifetime.end.p0(i64 32, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  %67 = load ptr, ptr %4, align 8
  ret ptr %67
}

; 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: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

declare ptr @yajl_alloc(ptr noundef, ptr noundef, ptr noundef) #3

declare i32 @yajl_config(ptr noundef, i32 noundef, ...) #3

declare i32 @yajl_parse(ptr noundef, ptr noundef, i64 noundef) #3

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

declare i32 @yajl_complete_parse(ptr noundef) #3

declare ptr @yajl_get_error(ptr noundef, i32 noundef, ptr noundef, i64 noundef) #3

; Function Attrs: nounwind
declare i32 @snprintf(ptr noundef, i64 noundef, ptr noundef, ...) #5

declare void @yajl_free(ptr 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: write) }
attributes #3 = { "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 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 #5 = { nounwind "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 #6 = { nounwind }
attributes #7 = { 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, !6, i64 16}
!12 = !{!"context_s", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24}
!13 = !{!12, !10, i64 24}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!17, !6, i64 96}
!17 = !{!"yajl_handle_t", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !6, i64 40, !18, i64 48, !19, i64 80, !15, i64 112}
!18 = !{!"yajl_bytestack_t", !6, i64 0, !10, i64 8, !10, i64 16, !6, i64 24}
!19 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!20 = !{!17, !6, i64 104}
!21 = !{!12, !6, i64 8}


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

%struct.yajl_callbacks = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.context_s = type { ptr, ptr, ptr, i64 }

@yajl_tree_parse.callbacks = external hidden constant %struct.yajl_callbacks, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @yajl_tree_parse(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = alloca %struct.context_s, align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #6
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %4, i8 0, i64 16, i1 false)
  %5 = getelementptr inbounds i8, ptr %4, i64 16
  store ptr %1, ptr %5, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %4, i64 24
  store i64 %2, ptr %6, align 8, !tbaa !11
  %7 = icmp ne ptr %1, null
  br i1 %7, label %8, label %9

8:                                                ; preds = %3
  tail call void @llvm.memset.p0.i64(ptr nonnull align 1 %1, i8 0, i64 %2, i1 false)
  br label %9

9:                                                ; preds = %8, %3
  %10 = call ptr @yajl_alloc(ptr noundef nonnull @yajl_tree_parse.callbacks, ptr noundef null, ptr noundef nonnull %4) #6
  %11 = call i32 (ptr, i32, ...) @yajl_config(ptr noundef %10, i32 noundef 1, i32 noundef 1) #6
  %12 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #7
  %13 = call i32 @yajl_parse(ptr noundef %10, ptr noundef %0, i64 noundef %12) #6
  %14 = call i32 @yajl_complete_parse(ptr noundef %10) #6
  %.not = icmp eq i32 %14, 0
  br i1 %.not, label %26, label %15

15:                                               ; preds = %9
  %16 = icmp ne i64 %2, 0
  %or.cond = and i1 %7, %16
  br i1 %or.cond, label %17, label %25

17:                                               ; preds = %15
  %18 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #7
  %19 = call ptr @yajl_get_error(ptr noundef %10, i32 noundef 1, ptr noundef %0, i64 noundef %18) #6
  %20 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull %1, i64 noundef %2, ptr noundef nonnull @.str, ptr noundef %19) #6
  %21 = getelementptr inbounds i8, ptr %10, i64 96
  %22 = load ptr, ptr %21, align 8, !tbaa !12
  %23 = getelementptr inbounds i8, ptr %10, i64 104
  %24 = load ptr, ptr %23, align 8, !tbaa !17
  call void %22(ptr noundef %24, ptr noundef %19) #6
  br label %25

25:                                               ; preds = %17, %15
  call void @yajl_free(ptr noundef %10) #6
  br label %29

26:                                               ; preds = %9
  call void @yajl_free(ptr noundef %10) #6
  %27 = getelementptr inbounds i8, ptr %4, i64 8
  %28 = load ptr, ptr %27, align 8, !tbaa !18
  br label %29

29:                                               ; preds = %26, %25
  %.0 = phi ptr [ null, %25 ], [ %28, %26 ]
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #6
  ret ptr %.0
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

declare ptr @yajl_alloc(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

declare i32 @yajl_config(ptr noundef, i32 noundef, ...) local_unnamed_addr #3

declare i32 @yajl_parse(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #3

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

declare i32 @yajl_complete_parse(ptr noundef) local_unnamed_addr #3

declare ptr @yajl_get_error(ptr noundef, i32 noundef, ptr noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @snprintf(ptr noalias nocapture noundef writeonly, i64 noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #5

declare void @yajl_free(ptr noundef) local_unnamed_addr #3

; 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 nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { "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 = { 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 #5 = { nofree nounwind "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 #6 = { nounwind }
attributes #7 = { 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, !7, i64 16}
!6 = !{!"context_s", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 24}
!12 = !{!13, !7, i64 96}
!13 = !{!"yajl_handle_t", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !7, i64 40, !14, i64 48, !15, i64 80, !16, i64 112}
!14 = !{!"yajl_bytestack_t", !7, i64 0, !10, i64 8, !10, i64 16, !7, i64 24}
!15 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!16 = !{!"int", !8, i64 0}
!17 = !{!13, !7, i64 104}
!18 = !{!6, !7, i64 8}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass