; LLVM IR from Razakhel/RaZ :: extern/simdjson/simdjson.ll (ZN8simdjson8internal10from_charsEPKcS2_)

; 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.simdjson::internal::adjusted_mantissa" = type <{ i64, i32, [4 x i8] }>

; 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 i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) #1

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN8simdjson8internal13binary_formatIdE22mantissa_explicit_bitsEv() #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN8simdjson8internal13binary_formatIdE10sign_indexEv() #3 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_ZN8simdjson8internal10from_charsEPKcS2_(ptr noundef %0, ptr noundef %1) #3 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca %"struct.simdjson::internal::adjusted_mantissa", align 8
  %7 = alloca { i64, i32 }, align 8
  %8 = alloca i64, align 8
  %9 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #5
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %10, i64 0
  %12 = load i8, ptr %11, align 1, !tbaa !9
  %13 = sext i8 %12 to i32
  %14 = icmp eq i32 %13, 45
  %15 = zext i1 %14 to i8
  store i8 %15, ptr %5, align 1, !tbaa !10
  %16 = load i8, ptr %5, align 1, !tbaa !10, !range !12, !noundef !13
  %17 = trunc i8 %16 to i1
  br i1 %17, label %18, label %21

18:                                               ; preds = %2
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i32 1
  store ptr %20, ptr %3, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %18, %2
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #5
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = invoke { i64, i32 } @_ZN8simdjson8internal19parse_long_mantissaINS0_13binary_formatIdEEEENS0_17adjusted_mantissaEPKcS6_(ptr noundef %22, ptr noundef %23)
          to label %25 unwind label %51

25:                                               ; preds = %21
  store { i64, i32 } %24, ptr %7, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %6, ptr align 8 %7, i64 12, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %26 = getelementptr inbounds %"struct.simdjson::internal::adjusted_mantissa", ptr %6, i32 0, i32 0
  %27 = load i64, ptr %26, align 8, !tbaa !14
  store i64 %27, ptr %8, align 8, !tbaa !18
  %28 = getelementptr inbounds %"struct.simdjson::internal::adjusted_mantissa", ptr %6, i32 0, i32 1
  %29 = load i32, ptr %28, align 8, !tbaa !19
  %30 = sext i32 %29 to i64
  %31 = invoke noundef i32 @_ZN8simdjson8internal13binary_formatIdE22mantissa_explicit_bitsEv()
          to label %32 unwind label %51

32:                                               ; preds = %25
  %33 = zext i32 %31 to i64
  %34 = shl i64 %30, %33
  %35 = load i64, ptr %8, align 8, !tbaa !18
  %36 = or i64 %35, %34
  store i64 %36, ptr %8, align 8, !tbaa !18
  %37 = load i8, ptr %5, align 1, !tbaa !10, !range !12, !noundef !13
  %38 = trunc i8 %37 to i1
  br i1 %38, label %39, label %46

39:                                               ; preds = %32
  %40 = load i64, ptr %8, align 8, !tbaa !18
  %41 = invoke noundef i32 @_ZN8simdjson8internal13binary_formatIdE10sign_indexEv()
          to label %42 unwind label %51

42:                                               ; preds = %39
  %43 = zext i32 %41 to i64
  %44 = shl i64 1, %43
  %45 = or i64 %40, %44
  br label %48

46:                                               ; preds = %32
  %47 = load i64, ptr %8, align 8, !tbaa !18
  br label %48

48:                                               ; preds = %46, %42
  %49 = phi i64 [ %45, %42 ], [ %47, %46 ]
  store i64 %49, ptr %8, align 8, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %9, ptr align 8 %8, i64 8, i1 false)
  %50 = load double, ptr %9, align 8, !tbaa !20
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #5
  ret double %50

51:                                               ; preds = %39, %25, %21
  %52 = landingpad { ptr, i32 }
          catch ptr null
  %53 = extractvalue { ptr, i32 } %52, 0
  call void @__clang_call_terminate(ptr %53) #6
  unreachable
}

; Function Attrs: mustprogress uwtable
declare dso_local { i64, i32 } @_ZN8simdjson8internal19parse_long_mantissaINS0_13binary_formatIdEEEENS0_17adjusted_mantissaEPKcS6_(ptr noundef, ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noinline noreturn nounwind uwtable "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress 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 = { mustprogress 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 = { noreturn 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"bool", !7, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{}
!14 = !{!15, !16, i64 0}
!15 = !{!"_ZTSN8simdjson8internal17adjusted_mantissaE", !16, i64 0, !17, i64 8}
!16 = !{!"long", !7, i64 0}
!17 = !{!"int", !7, i64 0}
!18 = !{!16, !16, i64 0}
!19 = !{!15, !17, i64 8}
!20 = !{!21, !21, i64 0}
!21 = !{!"double", !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"

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN8simdjson8internal13binary_formatIdE22mantissa_explicit_bitsEv() local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN8simdjson8internal13binary_formatIdE10sign_indexEv() local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_ZN8simdjson8internal10from_charsEPKcS2_(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 personality ptr @__gxx_personality_v0 {
  %3 = load i8, ptr %0, align 1, !tbaa !5
  %4 = icmp eq i8 %3, 45
  %spec.select.idx = zext i1 %4 to i64
  %spec.select = getelementptr inbounds i8, ptr %0, i64 %spec.select.idx
  %5 = invoke { i64, i32 } @_ZN8simdjson8internal19parse_long_mantissaINS0_13binary_formatIdEEEENS0_17adjusted_mantissaEPKcS6_(ptr noundef nonnull %spec.select, ptr noundef %1)
          to label %6 unwind label %20

6:                                                ; preds = %2
  %.fca.0.extract = extractvalue { i64, i32 } %5, 0
  %.fca.1.extract = extractvalue { i64, i32 } %5, 1
  %7 = sext i32 %.fca.1.extract to i64
  %8 = tail call noundef i32 @_ZN8simdjson8internal13binary_formatIdE22mantissa_explicit_bitsEv()
  %9 = zext nneg i32 %8 to i64
  %10 = shl i64 %7, %9
  %11 = or i64 %10, %.fca.0.extract
  br i1 %4, label %12, label %17

12:                                               ; preds = %6
  %13 = tail call noundef i32 @_ZN8simdjson8internal13binary_formatIdE10sign_indexEv()
  %14 = zext nneg i32 %13 to i64
  %15 = shl nuw i64 1, %14
  %16 = or i64 %15, %11
  br label %17

17:                                               ; preds = %6, %12
  %18 = phi i64 [ %16, %12 ], [ %11, %6 ]
  %19 = bitcast i64 %18 to double
  ret double %19

20:                                               ; preds = %2
  %21 = landingpad { ptr, i32 }
          catch ptr null
  %22 = extractvalue { ptr, i32 } %21, 0
  tail call void @__clang_call_terminate(ptr %22) #3
  unreachable
}

; Function Attrs: mustprogress uwtable
declare dso_local { i64, i32 } @_ZN8simdjson8internal19parse_long_mantissaINS0_13binary_formatIdEEEENS0_17adjusted_mantissaEPKcS6_(ptr noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { noinline noreturn nounwind uwtable "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 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 = { mustprogress 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 = { noreturn 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++ TBAA"}


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