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

; 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
declare dso_local i64 @atoi64(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @type_family(i32 noundef) #1

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

; Function Attrs: nounwind uwtable
declare hidden i32 @is_integer(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @is_float(ptr noundef) #1

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare double @atof(ptr noundef nonnull) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @binn_get_double(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %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
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %13, label %10

10:                                               ; preds = %2
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %10, %2
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %85

14:                                               ; preds = %10
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.binn_struct, ptr %15, i32 0, i32 8
  %17 = load i32, ptr %16, align 4, !tbaa !9
  %18 = call i32 @type_family(i32 noundef %17)
  %19 = icmp eq i32 %18, 242
  br i1 %19, label %20, label %34

20:                                               ; preds = %14
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.binn_struct, ptr %21, i32 0, i32 9
  %23 = load ptr, ptr %22, align 8, !tbaa !12
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.binn_struct, ptr %24, i32 0, i32 8
  %26 = load i32, ptr %25, align 4, !tbaa !9
  %27 = call i32 @copy_int_value(ptr noundef %23, ptr noundef %6, i32 noundef %26, i32 noundef 129)
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %30

29:                                               ; preds = %20
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %85

30:                                               ; preds = %20
  %31 = load i64, ptr %6, align 8, !tbaa !13
  %32 = sitofp i64 %31 to double
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  store double %32, ptr %33, align 8, !tbaa !15
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %85

34:                                               ; preds = %14
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.binn_struct, ptr %35, i32 0, i32 8
  %37 = load i32, ptr %36, align 4, !tbaa !9
  switch i32 %37, label %83 [
    i32 98, label %38
    i32 130, label %44
    i32 160, label %49
    i32 524385, label %77
  ]

38:                                               ; preds = %34
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.binn_struct, ptr %39, i32 0, i32 15
  %41 = load float, ptr %40, align 8, !tbaa !17
  %42 = fpext float %41 to double
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  store double %42, ptr %43, align 8, !tbaa !15
  br label %84

44:                                               ; preds = %34
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.binn_struct, ptr %45, i32 0, i32 15
  %47 = load double, ptr %46, align 8, !tbaa !17
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  store double %47, ptr %48, align 8, !tbaa !15
  br label %84

49:                                               ; preds = %34
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.binn_struct, ptr %50, i32 0, i32 9
  %52 = load ptr, ptr %51, align 8, !tbaa !12
  %53 = call i32 @is_integer(ptr noundef %52)
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %55, label %62

55:                                               ; preds = %49
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.binn_struct, ptr %56, i32 0, i32 9
  %58 = load ptr, ptr %57, align 8, !tbaa !12
  %59 = call i64 @atoi64(ptr noundef %58)
  %60 = sitofp i64 %59 to double
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  store double %60, ptr %61, align 8, !tbaa !15
  br label %76

62:                                               ; preds = %49
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.binn_struct, ptr %63, i32 0, i32 9
  %65 = load ptr, ptr %64, align 8, !tbaa !12
  %66 = call i32 @is_float(ptr noundef %65)
  %67 = icmp ne i32 %66, 0
  br i1 %67, label %68, label %74

68:                                               ; preds = %62
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.binn_struct, ptr %69, i32 0, i32 9
  %71 = load ptr, ptr %70, align 8, !tbaa !12
  %72 = call double @atof(ptr noundef %71) #4
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  store double %72, ptr %73, align 8, !tbaa !15
  br label %75

74:                                               ; preds = %62
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %85

75:                                               ; preds = %68
  br label %76

76:                                               ; preds = %75, %55
  br label %84

77:                                               ; preds = %34
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.binn_struct, ptr %78, i32 0, i32 15
  %80 = load i32, ptr %79, align 8, !tbaa !17
  %81 = sitofp i32 %80 to double
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  store double %81, ptr %82, align 8, !tbaa !15
  br label %84

83:                                               ; preds = %34
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %85

84:                                               ; preds = %77, %76, %44, %38
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %85

85:                                               ; preds = %84, %83, %74, %30, %29, %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %86 = load i32, ptr %3, align 4
  ret i32 %86
}

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 = { inlinehint nounwind willreturn memory(read) 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 36}
!10 = !{!"binn_struct", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !6, i64 16, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !6, i64 40, !11, i64 48, !11, i64 52, !6, i64 56, !6, i64 64, !6, i64 72, !7, i64 80}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 40}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !7, i64 0}
!17 = !{!7, !7, 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: 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: nounwind uwtable
declare dso_local i64 @atoi64(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @type_family(i32 noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare hidden i32 @is_integer(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @is_float(ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare double @atof(ptr nocapture noundef nonnull) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @binn_get_double(ptr noundef readonly %0, ptr noundef writeonly %1) local_unnamed_addr #1 {
  %3 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  %4 = icmp eq ptr %0, null
  %5 = icmp eq ptr %1, null
  %or.cond = or i1 %4, %5
  br i1 %or.cond, label %46, label %6

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 36
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = tail call i32 @type_family(i32 noundef %8)
  %10 = icmp eq i32 %9, 242
  br i1 %10, label %11, label %20

11:                                               ; preds = %6
  %12 = getelementptr inbounds i8, ptr %0, i64 40
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = load i32, ptr %7, align 4, !tbaa !5
  %15 = call i32 @copy_int_value(ptr noundef %13, ptr noundef nonnull %3, i32 noundef %14, i32 noundef 129)
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %46, label %17

17:                                               ; preds = %11
  %18 = load i64, ptr %3, align 8, !tbaa !12
  %19 = sitofp i64 %18 to double
  br label %.sink.split

20:                                               ; preds = %6
  %21 = load i32, ptr %7, align 4, !tbaa !5
  switch i32 %21, label %46 [
    i32 98, label %22
    i32 130, label %26
    i32 160, label %29
    i32 524385, label %42
  ]

22:                                               ; preds = %20
  %23 = getelementptr inbounds i8, ptr %0, i64 80
  %24 = load float, ptr %23, align 8, !tbaa !14
  %25 = fpext float %24 to double
  br label %.sink.split

26:                                               ; preds = %20
  %27 = getelementptr inbounds i8, ptr %0, i64 80
  %28 = load double, ptr %27, align 8, !tbaa !14
  br label %.sink.split

29:                                               ; preds = %20
  %30 = getelementptr inbounds i8, ptr %0, i64 40
  %31 = load ptr, ptr %30, align 8, !tbaa !11
  %32 = tail call i32 @is_integer(ptr noundef %31)
  %.not = icmp eq i32 %32, 0
  %33 = load ptr, ptr %30, align 8, !tbaa !11
  br i1 %.not, label %37, label %34

34:                                               ; preds = %29
  %35 = tail call i64 @atoi64(ptr noundef %33)
  %36 = sitofp i64 %35 to double
  br label %.sink.split

37:                                               ; preds = %29
  %38 = tail call i32 @is_float(ptr noundef %33)
  %.not22 = icmp eq i32 %38, 0
  br i1 %.not22, label %46, label %39

39:                                               ; preds = %37
  %40 = load ptr, ptr %30, align 8, !tbaa !11
  %41 = tail call double @atof(ptr noundef %40) #4
  br label %.sink.split

42:                                               ; preds = %20
  %43 = getelementptr inbounds i8, ptr %0, i64 80
  %44 = load i32, ptr %43, align 8, !tbaa !14
  %45 = sitofp i32 %44 to double
  br label %.sink.split

.sink.split:                                      ; preds = %17, %34, %39, %42, %26, %22
  %.sink = phi double [ %25, %22 ], [ %28, %26 ], [ %45, %42 ], [ %41, %39 ], [ %36, %34 ], [ %19, %17 ]
  store double %.sink, ptr %1, align 8, !tbaa !15
  br label %46

46:                                               ; preds = %.sink.split, %20, %37, %11, %2
  %.0 = phi i32 [ 0, %2 ], [ 0, %11 ], [ 0, %37 ], [ 0, %20 ], [ 1, %.sink.split ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  ret i32 %.0
}

attributes #0 = { mustprogress 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 = { inlinehint mustprogress nofree nounwind willreturn memory(read) 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 #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, !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 = !{!6, !10, i64 40}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !8, i64 0}
!14 = !{!8, !8, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !8, i64 0}


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