; 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

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

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

; 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) #3

; Function Attrs: nounwind uwtable
define dso_local i64 @jbl_clone_into_pool(ptr noundef %0, ptr noundef %1, ptr noundef %2) #4 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr null, ptr %10, align 8, !tbaa !5
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.jbl, ptr %11, i32 0, i32 0
  %13 = getelementptr inbounds %struct.binn_struct, ptr %12, i32 0, i32 2
  %14 = load i32, ptr %13, align 8, !tbaa !9
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %29

16:                                               ; preds = %3
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.jbl, ptr %17, i32 0, i32 0
  %19 = getelementptr inbounds %struct.binn_struct, ptr %18, i32 0, i32 3
  %20 = load i32, ptr %19, align 4, !tbaa !13
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %29

22:                                               ; preds = %16
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.jbl, ptr %23, i32 0, i32 0
  %25 = call i32 @binn_save_header(ptr noundef %24)
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %28, label %27

27:                                               ; preds = %22
  store i64 76003, ptr %4, align 8
  br label %75

28:                                               ; preds = %22
  br label %29

29:                                               ; preds = %28, %16, %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.jbl, ptr %30, i32 0, i32 0
  %32 = getelementptr inbounds %struct.binn_struct, ptr %31, i32 0, i32 10
  %33 = load i32, ptr %32, align 8, !tbaa !14
  %34 = sext i32 %33 to i64
  %35 = add i64 96, %34
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = call ptr @iwpool_alloc(i64 noundef %35, ptr noundef %36)
  store ptr %37, ptr %8, align 8, !tbaa !5
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = icmp ne ptr %38, null
  br i1 %39, label %44, label %40

40:                                               ; preds = %29
  %41 = call ptr @__errno_location() #6
  %42 = load i32, ptr %41, align 4, !tbaa !15
  %43 = call i64 @iwrc_set_errno(i64 noundef 70013, i32 noundef %42)
  store i64 %43, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %74

44:                                               ; preds = %29
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.jbl, ptr %45, i32 0, i32 1
  store ptr null, ptr %46, align 8, !tbaa !16
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.jbl, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.jbl, ptr %49, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %48, ptr align 8 %50, i64 88, i1 false)
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = getelementptr inbounds i8, ptr %51, i64 96
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.jbl, ptr %53, i32 0, i32 0
  %55 = getelementptr inbounds %struct.binn_struct, ptr %54, i32 0, i32 9
  store ptr %52, ptr %55, align 8, !tbaa !17
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.jbl, ptr %56, i32 0, i32 0
  %58 = getelementptr inbounds %struct.binn_struct, ptr %57, i32 0, i32 9
  %59 = load ptr, ptr %58, align 8, !tbaa !17
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.jbl, ptr %60, i32 0, i32 0
  %62 = getelementptr inbounds %struct.binn_struct, ptr %61, i32 0, i32 9
  %63 = load ptr, ptr %62, align 8, !tbaa !17
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.jbl, ptr %64, i32 0, i32 0
  %66 = getelementptr inbounds %struct.binn_struct, ptr %65, i32 0, i32 10
  %67 = load i32, ptr %66, align 8, !tbaa !14
  %68 = sext i32 %67 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %59, ptr align 1 %63, i64 %68, i1 false)
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.jbl, ptr %69, i32 0, i32 0
  %71 = getelementptr inbounds %struct.binn_struct, ptr %70, i32 0, i32 12
  store ptr null, ptr %71, align 8, !tbaa !18
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %72, ptr %73, align 8, !tbaa !5
  store i64 0, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %74

74:                                               ; preds = %44, %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %75

75:                                               ; preds = %74, %27
  %76 = load i64, ptr %4, align 8
  ret i64 %76
}

declare i32 @binn_save_header(ptr noundef) #1

declare ptr @iwpool_alloc(i64 noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { nounwind }
attributes #6 = { 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, !12, i64 8}
!10 = !{!"jbl", !11, i64 0, !6, i64 88}
!11 = !{!"binn_struct", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !6, i64 16, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !6, i64 40, !12, i64 48, !12, i64 52, !6, i64 56, !6, i64 64, !6, i64 72, !7, i64 80}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !12, i64 12}
!14 = !{!10, !12, i64 48}
!15 = !{!12, !12, i64 0}
!16 = !{!10, !6, i64 88}
!17 = !{!10, !6, i64 40}
!18 = !{!10, !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"

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

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

; 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) #2

; Function Attrs: nounwind uwtable
define dso_local i64 @jbl_clone_into_pool(ptr noundef %0, ptr nocapture noundef writeonly %1, ptr noundef %2) local_unnamed_addr #3 {
  store ptr null, ptr %1, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !9
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %11, label %6

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 12
  %8 = load i32, ptr %7, align 4, !tbaa !13
  %.not19 = icmp eq i32 %8, 0
  br i1 %.not19, label %11, label %9

9:                                                ; preds = %6
  %10 = tail call i32 @binn_save_header(ptr noundef nonnull %0) #4
  %.not20 = icmp eq i32 %10, 0
  br i1 %.not20, label %30, label %11

11:                                               ; preds = %9, %6, %3
  %12 = getelementptr inbounds i8, ptr %0, i64 48
  %13 = load i32, ptr %12, align 8, !tbaa !14
  %14 = sext i32 %13 to i64
  %15 = add nsw i64 %14, 96
  %16 = tail call ptr @iwpool_alloc(i64 noundef %15, ptr noundef %2) #4
  %.not21 = icmp eq ptr %16, null
  br i1 %.not21, label %17, label %21

17:                                               ; preds = %11
  %18 = tail call ptr @__errno_location() #5
  %19 = load i32, ptr %18, align 4, !tbaa !15
  %20 = tail call i64 @iwrc_set_errno(i64 noundef 70013, i32 noundef %19) #4
  br label %30

21:                                               ; preds = %11
  %22 = getelementptr inbounds i8, ptr %16, i64 88
  store ptr null, ptr %22, align 8, !tbaa !16
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(88) %16, ptr noundef nonnull align 8 dereferenceable(88) %0, i64 88, i1 false)
  %23 = getelementptr inbounds i8, ptr %16, i64 96
  %24 = getelementptr inbounds i8, ptr %16, i64 40
  store ptr %23, ptr %24, align 8, !tbaa !17
  %25 = getelementptr inbounds i8, ptr %0, i64 40
  %26 = load ptr, ptr %25, align 8, !tbaa !17
  %27 = load i32, ptr %12, align 8, !tbaa !14
  %28 = sext i32 %27 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %23, ptr align 1 %26, i64 %28, i1 false)
  %29 = getelementptr inbounds i8, ptr %16, i64 56
  store ptr null, ptr %29, align 8, !tbaa !18
  store ptr %16, ptr %1, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %17, %21, %9
  %.1 = phi i64 [ 76003, %9 ], [ 0, %21 ], [ %20, %17 ]
  ret i64 %.1
}

declare i32 @binn_save_header(ptr noundef) local_unnamed_addr #0

declare ptr @iwpool_alloc(i64 noundef, ptr noundef) local_unnamed_addr #0

attributes #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 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 #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { nounwind }
attributes #5 = { 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, !12, i64 8}
!10 = !{!"jbl", !11, i64 0, !6, i64 88}
!11 = !{!"binn_struct", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !6, i64 16, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !6, i64 40, !12, i64 48, !12, i64 52, !6, i64 56, !6, i64 64, !6, i64 72, !7, i64 80}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !12, i64 12}
!14 = !{!10, !12, i64 48}
!15 = !{!12, !12, i64 0}
!16 = !{!10, !6, i64 88}
!17 = !{!10, !6, i64 40}
!18 = !{!10, !6, i64 56}


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