; LLVM IR from Softmotions/iowow :: src/json (iwjson)

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

; 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 allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #1

declare i64 @iwrc_set_errno(i64 noundef, i32 noundef) #2

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #3

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

; Function Attrs: nounwind uwtable
define dso_local i64 @jbl_from_buf_keep(ptr noundef %0, ptr noundef %1, i64 noundef %2, i1 noundef zeroext %3) #5 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i8, align 1
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !9
  %15 = zext i1 %3 to i8
  store i8 %15, ptr %9, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  store i32 0, ptr %11, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  store i32 0, ptr %12, align 4, !tbaa !13
  %16 = load i64, ptr %8, align 8, !tbaa !9
  %17 = icmp ult i64 %16, 3
  br i1 %17, label %22, label %18

18:                                               ; preds = %4
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = call i32 @binn_is_valid_header(ptr noundef %19, ptr noundef %10, ptr noundef %12, ptr noundef %11, ptr noundef null)
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %23, label %22

22:                                               ; preds = %18, %4
  store i64 76001, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %68

23:                                               ; preds = %18
  %24 = load i32, ptr %11, align 4, !tbaa !13
  %25 = sext i32 %24 to i64
  %26 = load i64, ptr %8, align 8, !tbaa !9
  %27 = icmp ugt i64 %25, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %23
  store i64 76001, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %68

29:                                               ; preds = %23
  %30 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 96) #7
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %30, ptr %31, align 8, !tbaa !5
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = load ptr, ptr %32, align 8, !tbaa !5
  %34 = icmp ne ptr %33, null
  br i1 %34, label %39, label %35

35:                                               ; preds = %29
  %36 = call ptr @__errno_location() #8
  %37 = load i32, ptr %36, align 4, !tbaa !13
  %38 = call i64 @iwrc_set_errno(i64 noundef 70013, i32 noundef %37)
  store i64 %38, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %68

39:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #6
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = load ptr, ptr %40, align 8, !tbaa !5
  store ptr %41, ptr %14, align 8, !tbaa !5
  %42 = load ptr, ptr %14, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.jbl, ptr %42, i32 0, i32 0
  %44 = getelementptr inbounds %struct.binn_struct, ptr %43, i32 0, i32 0
  store i32 522367263, ptr %44, align 8, !tbaa !15
  %45 = load i32, ptr %10, align 4, !tbaa !13
  %46 = load ptr, ptr %14, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.jbl, ptr %46, i32 0, i32 0
  %48 = getelementptr inbounds %struct.binn_struct, ptr %47, i32 0, i32 8
  store i32 %45, ptr %48, align 4, !tbaa !18
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = load ptr, ptr %14, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.jbl, ptr %50, i32 0, i32 0
  %52 = getelementptr inbounds %struct.binn_struct, ptr %51, i32 0, i32 9
  store ptr %49, ptr %52, align 8, !tbaa !19
  %53 = load i32, ptr %11, align 4, !tbaa !13
  %54 = load ptr, ptr %14, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.jbl, ptr %54, i32 0, i32 0
  %56 = getelementptr inbounds %struct.binn_struct, ptr %55, i32 0, i32 10
  store i32 %53, ptr %56, align 8, !tbaa !20
  %57 = load i32, ptr %12, align 4, !tbaa !13
  %58 = load ptr, ptr %14, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.jbl, ptr %58, i32 0, i32 0
  %60 = getelementptr inbounds %struct.binn_struct, ptr %59, i32 0, i32 11
  store i32 %57, ptr %60, align 4, !tbaa !21
  %61 = load i8, ptr %9, align 1, !tbaa !11, !range !22, !noundef !23
  %62 = trunc i8 %61 to i1
  %63 = zext i1 %62 to i64
  %64 = select i1 %62, ptr null, ptr @free
  %65 = load ptr, ptr %14, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.jbl, ptr %65, i32 0, i32 0
  %67 = getelementptr inbounds %struct.binn_struct, ptr %66, i32 0, i32 12
  store ptr %64, ptr %67, align 8, !tbaa !24
  store i64 0, ptr %5, align 8
  store i32 1, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #6
  br label %68

68:                                               ; preds = %39, %35, %28, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  %69 = load i64, ptr %5, align 8
  ret i64 %69
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind allocsize(0,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 = { "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 willreturn memory(none) "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 "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 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 #6 = { nounwind }
attributes #7 = { nounwind allocsize(0,1) }
attributes #8 = { nounwind willreturn memory(none) }

!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 = !{!"_Bool", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !14, i64 0}
!16 = !{!"jbl", !17, i64 0, !6, i64 88}
!17 = !{!"binn_struct", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12, !6, i64 16, !14, i64 24, !14, i64 28, !14, i64 32, !14, i64 36, !6, i64 40, !14, i64 48, !14, i64 52, !6, i64 56, !6, i64 64, !6, i64 72, !7, i64 80}
!18 = !{!16, !14, i64 36}
!19 = !{!16, !6, i64 40}
!20 = !{!16, !14, i64 48}
!21 = !{!16, !14, i64 52}
!22 = !{i8 0, i8 2}
!23 = !{}
!24 = !{!16, !6, i64 56}


; 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #1

declare i64 @iwrc_set_errno(i64 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #3

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

; Function Attrs: nounwind uwtable
define dso_local i64 @jbl_from_buf_keep(ptr nocapture noundef writeonly %0, ptr noundef %1, i64 noundef %2, i1 noundef zeroext %3) local_unnamed_addr #5 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #6
  store i32 0, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #6
  store i32 0, ptr %7, align 4, !tbaa !5
  %8 = icmp ult i64 %2, 3
  br i1 %8, label %29, label %9

9:                                                ; preds = %4
  %10 = call i32 @binn_is_valid_header(ptr noundef %1, ptr noundef nonnull %5, ptr noundef nonnull %7, ptr noundef nonnull %6, ptr noundef null) #6
  %.not = icmp eq i32 %10, 0
  %11 = load i32, ptr %6, align 4
  %12 = sext i32 %11 to i64
  %13 = icmp ugt i64 %12, %2
  %or.cond = select i1 %.not, i1 true, i1 %13
  br i1 %or.cond, label %29, label %14

14:                                               ; preds = %9
  %15 = call noalias dereferenceable_or_null(96) ptr @calloc(i64 noundef 1, i64 noundef 96) #7
  store ptr %15, ptr %0, align 8, !tbaa !9
  %.not16 = icmp eq ptr %15, null
  br i1 %.not16, label %16, label %20

16:                                               ; preds = %14
  %17 = tail call ptr @__errno_location() #8
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = call i64 @iwrc_set_errno(i64 noundef 70013, i32 noundef %18) #6
  br label %29

20:                                               ; preds = %14
  store i32 522367263, ptr %15, align 8, !tbaa !11
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %15, i64 36
  store i32 %21, ptr %22, align 4, !tbaa !14
  %23 = getelementptr inbounds i8, ptr %15, i64 40
  store ptr %1, ptr %23, align 8, !tbaa !15
  %24 = getelementptr inbounds i8, ptr %15, i64 48
  store i32 %11, ptr %24, align 8, !tbaa !16
  %25 = load i32, ptr %7, align 4, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %15, i64 52
  store i32 %25, ptr %26, align 4, !tbaa !17
  %27 = select i1 %3, ptr null, ptr @free
  %28 = getelementptr inbounds i8, ptr %15, i64 56
  store ptr %27, ptr %28, align 8, !tbaa !18
  br label %29

29:                                               ; preds = %4, %9, %20, %16
  %.0 = phi i64 [ 0, %20 ], [ %19, %16 ], [ 76001, %9 ], [ 76001, %4 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #6
  ret i64 %.0
}

declare i32 @binn_is_valid_header(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(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 = { "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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 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 #5 = { 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 #6 = { nounwind }
attributes #7 = { nounwind allocsize(0,1) }
attributes #8 = { nounwind willreturn memory(none) }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"jbl", !13, i64 0, !10, i64 88}
!13 = !{!"binn_struct", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !10, i64 16, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !10, i64 40, !6, i64 48, !6, i64 52, !10, i64 56, !10, i64 64, !10, i64 72, !7, i64 80}
!14 = !{!12, !6, i64 36}
!15 = !{!12, !10, i64 40}
!16 = !{!12, !6, i64 48}
!17 = !{!12, !6, i64 52}
!18 = !{!12, !10, i64 56}


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