; LLVM IR from openappsec/openappsec :: external/yajl/example (parse_config)

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

@fileData = external hidden global [65536 x i8], align 16
@stdin = external global ptr, align 8
@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [32 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [2 x i8], align 1
@__const.main.path = external hidden unnamed_addr constant [3 x ptr], align 16
@.str.8 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca [1024 x i8], align 16
  %5 = alloca i32, align 4
  %6 = alloca [3 x ptr], align 16
  %7 = alloca ptr, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  call void @llvm.lifetime.start.p0(i64 1024, ptr %4) #6
  %8 = getelementptr inbounds [1024 x i8], ptr %4, i64 0, i64 0
  store i8 0, ptr %8, align 16, !tbaa !5
  store i8 0, ptr @fileData, align 16, !tbaa !5
  %9 = load ptr, ptr @stdin, align 8, !tbaa !8
  %10 = call i64 @fread(ptr noundef @fileData, i64 noundef 1, i64 noundef 65535, ptr noundef %9)
  store i64 %10, ptr %2, align 8, !tbaa !10
  %11 = load i64, ptr %2, align 8, !tbaa !10
  %12 = icmp eq i64 %11, 0
  br i1 %12, label %13, label %20

13:                                               ; preds = %0
  %14 = load ptr, ptr @stdin, align 8, !tbaa !8
  %15 = call i32 @feof(ptr noundef %14) #6
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %20, label %17

17:                                               ; preds = %13
  %18 = load ptr, ptr @stderr, align 8, !tbaa !8
  %19 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %18, ptr noundef @.str) #6
  store i32 1, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %82

20:                                               ; preds = %13, %0
  %21 = load i64, ptr %2, align 8, !tbaa !10
  %22 = icmp uge i64 %21, 65535
  br i1 %22, label %23, label %26

23:                                               ; preds = %20
  %24 = load ptr, ptr @stderr, align 8, !tbaa !8
  %25 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %24, ptr noundef @.str.1) #6
  store i32 1, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %82

26:                                               ; preds = %20
  br label %27

27:                                               ; preds = %26
  %28 = getelementptr inbounds [1024 x i8], ptr %4, i64 0, i64 0
  %29 = call ptr @yajl_tree_parse(ptr noundef @fileData, ptr noundef %28, i64 noundef 1024)
  store ptr %29, ptr %3, align 8, !tbaa !8
  %30 = load ptr, ptr %3, align 8, !tbaa !8
  %31 = icmp eq ptr %30, null
  br i1 %31, label %32, label %48

32:                                               ; preds = %27
  %33 = load ptr, ptr @stderr, align 8, !tbaa !8
  %34 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %33, ptr noundef @.str.2) #6
  %35 = getelementptr inbounds [1024 x i8], ptr %4, i64 0, i64 0
  %36 = call i64 @strlen(ptr noundef %35) #7
  %37 = icmp ne i64 %36, 0
  br i1 %37, label %38, label %42

38:                                               ; preds = %32
  %39 = load ptr, ptr @stderr, align 8, !tbaa !8
  %40 = getelementptr inbounds [1024 x i8], ptr %4, i64 0, i64 0
  %41 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %39, ptr noundef @.str.3, ptr noundef %40) #6
  br label %45

42:                                               ; preds = %32
  %43 = load ptr, ptr @stderr, align 8, !tbaa !8
  %44 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %43, ptr noundef @.str.4) #6
  br label %45

45:                                               ; preds = %42, %38
  %46 = load ptr, ptr @stderr, align 8, !tbaa !8
  %47 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %46, ptr noundef @.str.5) #6
  store i32 1, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %82

48:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 24, ptr %6) #6
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %6, ptr align 16 @__const.main.path, i64 24, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %49 = load ptr, ptr %3, align 8, !tbaa !8
  %50 = getelementptr inbounds [3 x ptr], ptr %6, i64 0, i64 0
  %51 = call ptr @yajl_tree_get(ptr noundef %49, ptr noundef %50, i32 noundef 1)
  store ptr %51, ptr %7, align 8, !tbaa !8
  %52 = load ptr, ptr %7, align 8, !tbaa !8
  %53 = icmp ne ptr %52, null
  br i1 %53, label %54, label %74

54:                                               ; preds = %48
  %55 = getelementptr inbounds [3 x ptr], ptr %6, i64 0, i64 0
  %56 = load ptr, ptr %55, align 16, !tbaa !8
  %57 = getelementptr inbounds [3 x ptr], ptr %6, i64 0, i64 1
  %58 = load ptr, ptr %57, align 8, !tbaa !8
  %59 = load ptr, ptr %7, align 8, !tbaa !8
  %60 = icmp ne ptr %59, null
  br i1 %60, label %61, label %70

61:                                               ; preds = %54
  %62 = load ptr, ptr %7, align 8, !tbaa !8
  %63 = getelementptr inbounds %struct.yajl_val_s, ptr %62, i32 0, i32 0
  %64 = load i32, ptr %63, align 8, !tbaa !12
  %65 = icmp eq i32 %64, 1
  br i1 %65, label %66, label %70

66:                                               ; preds = %61
  %67 = load ptr, ptr %7, align 8, !tbaa !8
  %68 = getelementptr inbounds %struct.yajl_val_s, ptr %67, i32 0, i32 1
  %69 = load ptr, ptr %68, align 8, !tbaa !5
  br label %71

70:                                               ; preds = %61, %54
  br label %71

71:                                               ; preds = %70, %66
  %72 = phi ptr [ %69, %66 ], [ null, %70 ]
  %73 = call i32 (ptr, ...) @printf(ptr noundef @.str.8, ptr noundef %56, ptr noundef %58, ptr noundef %72)
  br label %80

74:                                               ; preds = %48
  %75 = getelementptr inbounds [3 x ptr], ptr %6, i64 0, i64 0
  %76 = load ptr, ptr %75, align 16, !tbaa !8
  %77 = getelementptr inbounds [3 x ptr], ptr %6, i64 0, i64 1
  %78 = load ptr, ptr %77, align 8, !tbaa !8
  %79 = call i32 (ptr, ...) @printf(ptr noundef @.str.9, ptr noundef %76, ptr noundef %78)
  br label %80

80:                                               ; preds = %74, %71
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 24, ptr %6) #6
  %81 = load ptr, ptr %3, align 8, !tbaa !8
  call void @yajl_tree_free(ptr noundef %81)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %82

82:                                               ; preds = %80, %45, %23, %17
  call void @llvm.lifetime.end.p0(i64 1024, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #6
  %83 = load i32, ptr %1, align 4
  ret i32 %83
}

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

declare i64 @fread(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #2

; Function Attrs: nounwind
declare i32 @feof(ptr noundef) #3

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #3

declare ptr @yajl_tree_parse(ptr noundef, ptr noundef, i64 noundef) #2

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #5

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

declare i32 @printf(ptr noundef, ...) #2

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

declare void @yajl_tree_free(ptr noundef) #2

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 = { "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 "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !6, i64 0}
!12 = !{!13, !14, i64 0}
!13 = !{!"yajl_val_s", !14, i64 0, !6, i64 8}
!14 = !{!"int", !6, 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"

@fileData = external hidden global [65536 x i8], align 16
@stdin = external local_unnamed_addr global ptr, align 8
@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [32 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [2 x i8], align 1
@__const.main.path = external hidden unnamed_addr constant [3 x ptr], align 16
@.str.8 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @main() local_unnamed_addr #0 {
  %1 = alloca [1024 x i8], align 16
  %2 = alloca [3 x ptr], align 16
  call void @llvm.lifetime.start.p0(i64 1024, ptr nonnull %1) #5
  store i8 0, ptr %1, align 16, !tbaa !5
  store i8 0, ptr @fileData, align 16, !tbaa !5
  %3 = load ptr, ptr @stdin, align 8, !tbaa !8
  %4 = tail call i64 @fread(ptr noundef nonnull @fileData, i64 noundef 1, i64 noundef 65535, ptr noundef %3)
  %5 = icmp eq i64 %4, 0
  br i1 %5, label %6, label %12

6:                                                ; preds = %0
  %7 = load ptr, ptr @stdin, align 8, !tbaa !8
  %8 = tail call i32 @feof(ptr noundef %7) #5
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %9, label %.thread

9:                                                ; preds = %6
  %10 = load ptr, ptr @stderr, align 8, !tbaa !8
  %11 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %10, ptr noundef nonnull @.str) #6
  br label %47

12:                                               ; preds = %0
  %13 = icmp ugt i64 %4, 65534
  br i1 %13, label %14, label %.thread

14:                                               ; preds = %12
  %15 = load ptr, ptr @stderr, align 8, !tbaa !8
  %16 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %15, ptr noundef nonnull @.str.1) #6
  br label %47

.thread:                                          ; preds = %6, %12
  %17 = call ptr @yajl_tree_parse(ptr noundef nonnull @fileData, ptr noundef nonnull %1, i64 noundef 1024) #5
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %30

19:                                               ; preds = %.thread
  %20 = load ptr, ptr @stderr, align 8, !tbaa !8
  %21 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %20, ptr noundef nonnull @.str.2) #6
  %char0 = load i8, ptr %1, align 16
  %.not12 = icmp eq i8 %char0, 0
  %22 = load ptr, ptr @stderr, align 8, !tbaa !8
  br i1 %.not12, label %25, label %23

23:                                               ; preds = %19
  %24 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %22, ptr noundef nonnull @.str.3, ptr noundef nonnull %1) #6
  br label %27

25:                                               ; preds = %19
  %26 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %22, ptr noundef nonnull @.str.4) #6
  br label %27

27:                                               ; preds = %25, %23
  %28 = load ptr, ptr @stderr, align 8, !tbaa !8
  %29 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %28, ptr noundef nonnull @.str.5) #6
  br label %47

30:                                               ; preds = %.thread
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %2) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(24) %2, ptr noundef nonnull align 16 dereferenceable(24) @__const.main.path, i64 24, i1 false)
  %31 = call ptr @yajl_tree_get(ptr noundef nonnull %17, ptr noundef nonnull %2, i32 noundef 1) #5
  %.not11 = icmp eq ptr %31, null
  %32 = load ptr, ptr %2, align 16, !tbaa !8
  %33 = getelementptr inbounds i8, ptr %2, i64 8
  %34 = load ptr, ptr %33, align 8, !tbaa !8
  br i1 %.not11, label %44, label %35

35:                                               ; preds = %30
  %36 = load i32, ptr %31, align 8, !tbaa !10
  %37 = icmp eq i32 %36, 1
  br i1 %37, label %38, label %41

38:                                               ; preds = %35
  %39 = getelementptr inbounds i8, ptr %31, i64 8
  %40 = load ptr, ptr %39, align 8, !tbaa !5
  br label %41

41:                                               ; preds = %35, %38
  %42 = phi ptr [ %40, %38 ], [ null, %35 ]
  %43 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8, ptr noundef %32, ptr noundef %34, ptr noundef %42)
  br label %46

44:                                               ; preds = %30
  %45 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.9, ptr noundef %32, ptr noundef %34)
  br label %46

46:                                               ; preds = %44, %41
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %2) #5
  call void @yajl_tree_free(ptr noundef nonnull %17) #5
  br label %47

47:                                               ; preds = %46, %27, %14, %9
  %.0 = phi i32 [ 1, %14 ], [ 1, %27 ], [ 0, %46 ], [ 1, %9 ]
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %1) #5
  ret i32 %.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: nofree nounwind
declare noundef i64 @fread(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @feof(ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

declare ptr @yajl_tree_parse(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

declare ptr @yajl_tree_get(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) 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

declare void @yajl_tree_free(ptr noundef) local_unnamed_addr #3

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 = { 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 #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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nounwind }
attributes #6 = { cold 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !12, i64 0}
!11 = !{!"yajl_val_s", !12, i64 0, !6, i64 8}
!12 = !{!"int", !6, i64 0}


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