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

; 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

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

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

19:                                               ; preds = %16, %1
  call void @llvm.lifetime.start.p0(i64 16, ptr %4) #5
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = invoke { i64, i32 } @_ZN8simdjson8internal19parse_long_mantissaINS0_13binary_formatIdEEEENS0_17adjusted_mantissaEPKc(ptr noundef %20)
          to label %22 unwind label %48

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

29:                                               ; preds = %22
  %30 = zext i32 %28 to i64
  %31 = shl i64 %27, %30
  %32 = load i64, ptr %6, align 8, !tbaa !18
  %33 = or i64 %32, %31
  store i64 %33, ptr %6, align 8, !tbaa !18
  %34 = load i8, ptr %3, align 1, !tbaa !10, !range !12, !noundef !13
  %35 = trunc i8 %34 to i1
  br i1 %35, label %36, label %43

36:                                               ; preds = %29
  %37 = load i64, ptr %6, align 8, !tbaa !18
  %38 = invoke noundef i32 @_ZN8simdjson8internal13binary_formatIdE10sign_indexEv()
          to label %39 unwind label %48

39:                                               ; preds = %36
  %40 = zext i32 %38 to i64
  %41 = shl i64 1, %40
  %42 = or i64 %37, %41
  br label %45

43:                                               ; preds = %29
  %44 = load i64, ptr %6, align 8, !tbaa !18
  br label %45

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

48:                                               ; preds = %36, %22, %19
  %49 = landingpad { ptr, i32 }
          catch ptr null
  %50 = extractvalue { ptr, i32 } %49, 0
  call void @__clang_call_terminate(ptr %50) #6
  unreachable
}

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

declare i32 @__gxx_personality_v0(...)

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

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

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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"

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

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

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

16:                                               ; preds = %5, %11
  %17 = phi i64 [ %15, %11 ], [ %10, %5 ]
  %18 = bitcast i64 %17 to double
  ret double %18

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

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

declare i32 @__gxx_personality_v0(...)

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

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

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

attributes #0 = { 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 #1 = { 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 #2 = { 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 #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