; 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_val_s = type { i32, %union.anon }
%union.anon = type { %struct.anon }
%struct.anon = type { i64, double, ptr, i32 }

; Function Attrs: nounwind uwtable
define dso_local void @yajl_tree_free(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %5, label %6

5:                                                ; preds = %1
  br label %68

6:                                                ; preds = %1
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %9, label %19

9:                                                ; preds = %6
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.yajl_val_s, ptr %10, i32 0, i32 0
  %12 = load i32, ptr %11, align 8, !tbaa !9
  %13 = icmp eq i32 %12, 1
  br i1 %13, label %14, label %19

14:                                               ; preds = %9
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.yajl_val_s, ptr %15, i32 0, i32 1
  %17 = load ptr, ptr %16, align 8, !tbaa !12
  call void @free(ptr noundef %17) #2
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %18) #2
  br label %68

19:                                               ; preds = %9, %6
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %33

22:                                               ; preds = %19
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.yajl_val_s, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 8, !tbaa !9
  %26 = icmp eq i32 %25, 2
  br i1 %26, label %27, label %33

27:                                               ; preds = %22
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.yajl_val_s, ptr %28, i32 0, i32 1
  %30 = getelementptr inbounds %struct.anon, ptr %29, i32 0, i32 2
  %31 = load ptr, ptr %30, align 8, !tbaa !12
  call void @free(ptr noundef %31) #2
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %32) #2
  br label %67

33:                                               ; preds = %22, %19
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %45

36:                                               ; preds = %33
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.yajl_val_s, ptr %37, i32 0, i32 0
  %39 = load i32, ptr %38, align 8, !tbaa !9
  %40 = icmp eq i32 %39, 3
  br i1 %40, label %41, label %45

41:                                               ; preds = %36
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.yajl_val_s, ptr %42, i32 0, i32 1
  %44 = icmp ne ptr %43, null
  br i1 %44, label %46, label %48

45:                                               ; preds = %36, %33
  br i1 false, label %46, label %48

46:                                               ; preds = %45, %41
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  call void @yajl_object_free(ptr noundef %47)
  br label %66

48:                                               ; preds = %45, %41
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = icmp ne ptr %49, null
  br i1 %50, label %51, label %60

51:                                               ; preds = %48
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.yajl_val_s, ptr %52, i32 0, i32 0
  %54 = load i32, ptr %53, align 8, !tbaa !9
  %55 = icmp eq i32 %54, 4
  br i1 %55, label %56, label %60

56:                                               ; preds = %51
  %57 = load ptr, ptr %2, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.yajl_val_s, ptr %57, i32 0, i32 1
  %59 = icmp ne ptr %58, null
  br i1 %59, label %61, label %63

60:                                               ; preds = %51, %48
  br i1 false, label %61, label %63

61:                                               ; preds = %60, %56
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  call void @yajl_array_free(ptr noundef %62)
  br label %65

63:                                               ; preds = %60, %56
  %64 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %64) #2
  br label %65

65:                                               ; preds = %63, %61
  br label %66

66:                                               ; preds = %65, %46
  br label %67

67:                                               ; preds = %66, %27
  br label %68

68:                                               ; preds = %67, %14, %5
  ret void
}

; Function Attrs: nounwind
declare void @free(ptr noundef) #1

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

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

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 = { 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 #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, !11, i64 0}
!10 = !{!"yajl_val_s", !11, i64 0, !7, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!7, !7, i64 0}


; 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
define dso_local void @yajl_tree_free(ptr noundef %0) local_unnamed_addr #0 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %14, label %3

3:                                                ; preds = %1
  %4 = load i32, ptr %0, align 8, !tbaa !5
  switch i32 %4, label %13 [
    i32 1, label %5
    i32 2, label %8
    i32 3, label %11
    i32 4, label %12
  ]

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !10
  tail call void @free(ptr noundef %7) #2
  tail call void @free(ptr noundef nonnull %0) #2
  br label %14

8:                                                ; preds = %3
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  %10 = load ptr, ptr %9, align 8, !tbaa !10
  tail call void @free(ptr noundef %10) #2
  tail call void @free(ptr noundef nonnull %0) #2
  br label %14

11:                                               ; preds = %3
  tail call void @yajl_object_free(ptr noundef nonnull %0)
  br label %14

12:                                               ; preds = %3
  tail call void @yajl_array_free(ptr noundef nonnull %0)
  br label %14

13:                                               ; preds = %3
  tail call void @free(ptr noundef nonnull %0) #2
  br label %14

14:                                               ; preds = %8, %12, %13, %11, %1, %5
  ret void
}

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

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

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

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 nounwind willreturn allockind("free") memory(argmem: readwrite, 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 #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, !7, i64 0}
!6 = !{!"yajl_val_s", !7, i64 0, !8, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!8, !8, i64 0}


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