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

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

@free_fn = external dso_local global ptr, align 8

; Function Attrs: nounwind uwtable
declare dso_local i32 @binn_get_type_info(i32 noundef, ptr noundef, ptr noundef) #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local noalias ptr @binn_value(i32 noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %13 = call ptr @binn_alloc_item()
  store ptr %13, ptr %11, align 8, !tbaa !9
  %14 = load ptr, ptr %11, align 8, !tbaa !9
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %81

16:                                               ; preds = %4
  %17 = load i32, ptr %6, align 4, !tbaa !5
  %18 = load ptr, ptr %11, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.binn_struct, ptr %18, i32 0, i32 8
  store i32 %17, ptr %19, align 4, !tbaa !11
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = call i32 @binn_get_type_info(i32 noundef %20, ptr noundef %10, ptr noundef null)
  %22 = load i32, ptr %10, align 4, !tbaa !5
  switch i32 %22, label %69 [
    i32 0, label %80
    i32 160, label %23
    i32 192, label %32
    i32 224, label %32
  ]

23:                                               ; preds = %16
  %24 = load i32, ptr %8, align 4, !tbaa !5
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %31

26:                                               ; preds = %23
  %27 = load ptr, ptr %7, align 8, !tbaa !9
  %28 = call i64 @strlen(ptr noundef %27) #4
  %29 = add i64 %28, 1
  %30 = trunc i64 %29 to i32
  store i32 %30, ptr %8, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %26, %23
  br label %32

32:                                               ; preds = %31, %16, %16
  %33 = load ptr, ptr %9, align 8, !tbaa !9
  %34 = icmp eq ptr %33, inttoptr (i64 -1 to ptr)
  br i1 %34, label %35, label %58

35:                                               ; preds = %32
  %36 = load ptr, ptr %7, align 8, !tbaa !9
  %37 = load i32, ptr %8, align 4, !tbaa !5
  %38 = call ptr @binn_memdup(ptr noundef %36, i32 noundef %37)
  %39 = load ptr, ptr %11, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.binn_struct, ptr %39, i32 0, i32 9
  store ptr %38, ptr %40, align 8, !tbaa !13
  %41 = load ptr, ptr %11, align 8, !tbaa !9
  %42 = getelementptr inbounds %struct.binn_struct, ptr %41, i32 0, i32 9
  %43 = load ptr, ptr %42, align 8, !tbaa !13
  %44 = icmp eq ptr %43, null
  br i1 %44, label %45, label %48

45:                                               ; preds = %35
  %46 = load ptr, ptr @free_fn, align 8, !tbaa !9
  %47 = load ptr, ptr %11, align 8, !tbaa !9
  call void %46(ptr noundef %47)
  store ptr null, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %83

48:                                               ; preds = %35
  %49 = load ptr, ptr @free_fn, align 8, !tbaa !9
  %50 = load ptr, ptr %11, align 8, !tbaa !9
  %51 = getelementptr inbounds %struct.binn_struct, ptr %50, i32 0, i32 12
  store ptr %49, ptr %51, align 8, !tbaa !14
  %52 = load i32, ptr %10, align 4, !tbaa !5
  %53 = icmp eq i32 %52, 160
  br i1 %53, label %54, label %57

54:                                               ; preds = %48
  %55 = load i32, ptr %8, align 4, !tbaa !5
  %56 = add nsw i32 %55, -1
  store i32 %56, ptr %8, align 4, !tbaa !5
  br label %57

57:                                               ; preds = %54, %48
  br label %65

58:                                               ; preds = %32
  %59 = load ptr, ptr %7, align 8, !tbaa !9
  %60 = load ptr, ptr %11, align 8, !tbaa !9
  %61 = getelementptr inbounds %struct.binn_struct, ptr %60, i32 0, i32 9
  store ptr %59, ptr %61, align 8, !tbaa !13
  %62 = load ptr, ptr %9, align 8, !tbaa !9
  %63 = load ptr, ptr %11, align 8, !tbaa !9
  %64 = getelementptr inbounds %struct.binn_struct, ptr %63, i32 0, i32 12
  store ptr %62, ptr %64, align 8, !tbaa !14
  br label %65

65:                                               ; preds = %58, %57
  %66 = load i32, ptr %8, align 4, !tbaa !5
  %67 = load ptr, ptr %11, align 8, !tbaa !9
  %68 = getelementptr inbounds %struct.binn_struct, ptr %67, i32 0, i32 10
  store i32 %66, ptr %68, align 8, !tbaa !15
  br label %80

69:                                               ; preds = %16
  %70 = load ptr, ptr %11, align 8, !tbaa !9
  %71 = getelementptr inbounds %struct.binn_struct, ptr %70, i32 0, i32 15
  %72 = load ptr, ptr %11, align 8, !tbaa !9
  %73 = getelementptr inbounds %struct.binn_struct, ptr %72, i32 0, i32 9
  store ptr %71, ptr %73, align 8, !tbaa !13
  %74 = load ptr, ptr %7, align 8, !tbaa !9
  %75 = load ptr, ptr %11, align 8, !tbaa !9
  %76 = getelementptr inbounds %struct.binn_struct, ptr %75, i32 0, i32 9
  %77 = load ptr, ptr %76, align 8, !tbaa !13
  %78 = load i32, ptr %10, align 4, !tbaa !5
  %79 = call i32 @copy_raw_value(ptr noundef %74, ptr noundef %77, i32 noundef %78)
  br label %80

80:                                               ; preds = %69, %65, %16
  br label %81

81:                                               ; preds = %80, %4
  %82 = load ptr, ptr %11, align 8, !tbaa !9
  store ptr %82, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %83

83:                                               ; preds = %81, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %84 = load ptr, ptr %5, align 8
  ret ptr %84
}

; Function Attrs: nounwind uwtable
declare hidden ptr @binn_alloc_item() #0

; Function Attrs: nounwind uwtable
declare hidden ptr @binn_memdup(ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @copy_raw_value(ptr noundef, ptr noundef, i32 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { nounwind }
attributes #4 = { 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 = !{!"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 36}
!12 = !{!"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}
!13 = !{!12, !10, i64 40}
!14 = !{!12, !10, i64 56}
!15 = !{!12, !6, i64 48}


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

@free_fn = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
declare dso_local i32 @binn_get_type_info(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local noalias ptr @binn_value(i32 noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #4
  %6 = tail call ptr @binn_alloc_item()
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %40, label %7

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %6, i64 36
  store i32 %0, ptr %8, align 4, !tbaa !5
  %9 = call i32 @binn_get_type_info(i32 noundef %0, ptr noundef nonnull %5, ptr noundef null)
  %10 = load i32, ptr %5, align 4, !tbaa !11
  %11 = call i32 @llvm.fshl.i32(i32 %10, i32 %10, i32 27)
  switch i32 %11, label %36 [
    i32 0, label %40
    i32 5, label %12
    i32 6, label %18
    i32 7, label %18
  ]

12:                                               ; preds = %7
  %13 = icmp eq i32 %2, 0
  br i1 %13, label %14, label %18

14:                                               ; preds = %12
  %15 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #5
  %16 = trunc i64 %15 to i32
  %17 = add i32 %16, 1
  br label %18

18:                                               ; preds = %12, %14, %7, %7
  %.025 = phi i32 [ %2, %7 ], [ %2, %7 ], [ %17, %14 ], [ %2, %12 ]
  %19 = icmp eq ptr %3, inttoptr (i64 -1 to ptr)
  br i1 %19, label %20, label %31

20:                                               ; preds = %18
  %21 = call ptr @binn_memdup(ptr noundef %1, i32 noundef %.025)
  %22 = getelementptr inbounds i8, ptr %6, i64 40
  store ptr %21, ptr %22, align 8, !tbaa !12
  %23 = icmp eq ptr %21, null
  %24 = load ptr, ptr @free_fn, align 8, !tbaa !13
  br i1 %23, label %25, label %26

25:                                               ; preds = %20
  call void %24(ptr noundef nonnull %6) #4
  br label %40

26:                                               ; preds = %20
  %27 = getelementptr inbounds i8, ptr %6, i64 56
  store ptr %24, ptr %27, align 8, !tbaa !14
  %28 = load i32, ptr %5, align 4, !tbaa !11
  %29 = icmp eq i32 %28, 160
  %30 = sext i1 %29 to i32
  %spec.select = add nsw i32 %.025, %30
  br label %34

31:                                               ; preds = %18
  %32 = getelementptr inbounds i8, ptr %6, i64 40
  store ptr %1, ptr %32, align 8, !tbaa !12
  %33 = getelementptr inbounds i8, ptr %6, i64 56
  store ptr %3, ptr %33, align 8, !tbaa !14
  br label %34

34:                                               ; preds = %26, %31
  %.1 = phi i32 [ %.025, %31 ], [ %spec.select, %26 ]
  %35 = getelementptr inbounds i8, ptr %6, i64 48
  store i32 %.1, ptr %35, align 8, !tbaa !15
  br label %40

36:                                               ; preds = %7
  %37 = getelementptr inbounds i8, ptr %6, i64 80
  %38 = getelementptr inbounds i8, ptr %6, i64 40
  store ptr %37, ptr %38, align 8, !tbaa !12
  %39 = call i32 @copy_raw_value(ptr noundef %1, ptr noundef nonnull %37, i32 noundef %10)
  br label %40

40:                                               ; preds = %4, %36, %34, %7, %25
  %.0 = phi ptr [ null, %25 ], [ %6, %7 ], [ %6, %34 ], [ %6, %36 ], [ null, %4 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #4
  ret ptr %.0
}

; Function Attrs: nounwind uwtable
declare hidden ptr @binn_alloc_item() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden ptr @binn_memdup(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @copy_raw_value(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.fshl.i32(i32, i32, i32) #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 = { mustprogress nofree nounwind willreturn memory(argmem: 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nounwind }
attributes #5 = { 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, !7, i64 36}
!6 = !{!"binn_struct", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !10, i64 16, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !10, i64 40, !7, i64 48, !7, i64 52, !10, i64 56, !10, i64 64, !10, i64 72, !8, i64 80}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!6, !10, i64 40}
!13 = !{!10, !10, i64 0}
!14 = !{!6, !10, i64 56}
!15 = !{!6, !7, i64 48}


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