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

; 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_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 }

; 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
define dso_local i32 @yajl_parse(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 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 4, ptr %7) #3
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.yajl_handle_t, ptr %8, i32 0, i32 2
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %29

12:                                               ; preds = %3
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.yajl_handle_t, ptr %13, i32 0, i32 7
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.yajl_handle_t, ptr %15, i32 0, i32 8
  %17 = load i32, ptr %16, align 8, !tbaa !16
  %18 = and i32 %17, 1
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.yajl_handle_t, ptr %19, i32 0, i32 8
  %21 = load i32, ptr %20, align 8, !tbaa !16
  %22 = and i32 %21, 2
  %23 = icmp ne i32 %22, 0
  %24 = xor i1 %23, true
  %25 = zext i1 %24 to i32
  %26 = call ptr @yajl_lex_alloc(ptr noundef %14, i32 noundef %18, i32 noundef %25)
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.yajl_handle_t, ptr %27, i32 0, i32 2
  store ptr %26, ptr %28, align 8, !tbaa !11
  br label %29

29:                                               ; preds = %12, %3
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load i64, ptr %6, align 8, !tbaa !9
  %33 = call i32 @yajl_do_parse(ptr noundef %30, ptr noundef %31, i64 noundef %32)
  store i32 %33, ptr %7, align 4, !tbaa !17
  %34 = load i32, ptr %7, align 4, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret i32 %34
}

declare ptr @yajl_lex_alloc(ptr noundef, i32 noundef, i32 noundef) #2

declare i32 @yajl_do_parse(ptr noundef, ptr noundef, i64 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 = { "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 = !{!12, !6, i64 16}
!12 = !{!"yajl_handle_t", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !6, i64 40, !13, i64 48, !14, i64 80, !15, i64 112}
!13 = !{!"yajl_bytestack_t", !6, i64 0, !10, i64 8, !10, i64 16, !6, i64 24}
!14 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!15 = !{!"int", !7, i64 0}
!16 = !{!12, !15, i64 112}
!17 = !{!15, !15, 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 i32 @yajl_parse(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %7, label %15

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 80
  %9 = getelementptr inbounds i8, ptr %0, i64 112
  %10 = load i32, ptr %9, align 8, !tbaa !14
  %11 = and i32 %10, 1
  %12 = lshr i32 %10, 1
  %.lobit = and i32 %12, 1
  %13 = xor i32 %.lobit, 1
  %14 = tail call ptr @yajl_lex_alloc(ptr noundef nonnull %8, i32 noundef %11, i32 noundef %13) #2
  store ptr %14, ptr %4, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %7, %3
  %16 = tail call i32 @yajl_do_parse(ptr noundef nonnull %0, ptr noundef %1, i64 noundef %2) #2
  ret i32 %16
}

declare ptr @yajl_lex_alloc(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

declare i32 @yajl_do_parse(ptr noundef, ptr noundef, i64 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 = { "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 16}
!6 = !{!"yajl_handle_t", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !7, i64 40, !11, i64 48, !12, i64 80, !13, i64 112}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"yajl_bytestack_t", !7, i64 0, !10, i64 8, !10, i64 16, !7, i64 24}
!12 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!13 = !{!"int", !8, i64 0}
!14 = !{!6, !13, i64 112}


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