; LLVM IR from DANTE2076/SmartLoopAIproject :: src/util/serfloat.ll (Z12DecodeDoublem)

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_Z12DecodeDoublem(i64 noundef %0) #0 {
  %2 = alloca double, align 8
  %3 = alloca i64, align 8
  %4 = alloca double, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store double 1.000000e+00, ptr %4, align 8, !tbaa !9
  %8 = load i64, ptr %3, align 8, !tbaa !5
  %9 = and i64 %8, -9223372036854775808
  %10 = icmp ne i64 %9, 0
  br i1 %10, label %11, label %14

11:                                               ; preds = %1
  store double -1.000000e+00, ptr %4, align 8, !tbaa !9
  %12 = load i64, ptr %3, align 8, !tbaa !5
  %13 = xor i64 %12, -9223372036854775808
  store i64 %13, ptr %3, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %11, %1
  %15 = load i64, ptr %3, align 8, !tbaa !5
  %16 = icmp eq i64 %15, 0
  br i1 %16, label %17, label %20

17:                                               ; preds = %14
  %18 = load double, ptr %4, align 8, !tbaa !9
  %19 = call double @llvm.copysign.f64(double 0.000000e+00, double %18)
  store double %19, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %55

20:                                               ; preds = %14
  %21 = load i64, ptr %3, align 8, !tbaa !5
  %22 = icmp eq i64 %21, 9218868437227405312
  br i1 %22, label %23, label %26

23:                                               ; preds = %20
  %24 = load double, ptr %4, align 8, !tbaa !9
  %25 = call double @llvm.copysign.f64(double 0x7FF0000000000000, double %24)
  store double %25, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %55

26:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %27 = load i64, ptr %3, align 8, !tbaa !5
  %28 = and i64 %27, 9218868437227405312
  %29 = lshr i64 %28, 52
  %30 = trunc i64 %29 to i32
  store i32 %30, ptr %6, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %31 = load i64, ptr %3, align 8, !tbaa !5
  %32 = and i64 %31, 4503599627370495
  store i64 %32, ptr %7, align 8, !tbaa !5
  %33 = load i32, ptr %6, align 4, !tbaa !11
  %34 = icmp eq i32 %33, 2047
  br i1 %34, label %35, label %36

35:                                               ; preds = %26
  store double 0x7FF8000000000000, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %54

36:                                               ; preds = %26
  %37 = load i32, ptr %6, align 4, !tbaa !11
  %38 = icmp eq i32 %37, 0
  br i1 %38, label %39, label %45

39:                                               ; preds = %36
  %40 = load i64, ptr %7, align 8, !tbaa !5
  %41 = uitofp i64 %40 to double
  %42 = call double @ldexp(double noundef %41, i32 noundef -1074) #4
  %43 = load double, ptr %4, align 8, !tbaa !9
  %44 = call double @llvm.copysign.f64(double %42, double %43)
  store double %44, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %54

45:                                               ; preds = %36
  %46 = load i64, ptr %7, align 8, !tbaa !5
  %47 = add i64 %46, 4503599627370496
  %48 = uitofp i64 %47 to double
  %49 = load i32, ptr %6, align 4, !tbaa !11
  %50 = add nsw i32 -1075, %49
  %51 = call double @ldexp(double noundef %48, i32 noundef %50) #4
  %52 = load double, ptr %4, align 8, !tbaa !9
  %53 = call double @llvm.copysign.f64(double %51, double %52)
  store double %53, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %54

54:                                               ; preds = %45, %39, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %55

55:                                               ; preds = %54, %23, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %56 = load double, ptr %2, align 8
  ret double %56
}

; 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 speculatable willreturn memory(none)
declare double @llvm.copysign.f64(double, double) #2

; Function Attrs: nounwind
declare double @ldexp(double noundef, i32 noundef) #3

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

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

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !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 nofree nounwind willreturn uwtable
define dso_local noundef double @_Z12DecodeDoublem(i64 noundef %0) local_unnamed_addr #0 {
  %.not = icmp sgt i64 %0, -1
  %2 = and i64 %0, 9223372036854775807
  %.016 = select i1 %.not, double 1.000000e+00, double -1.000000e+00
  switch i64 %2, label %7 [
    i64 0, label %3
    i64 9218868437227405312, label %5
  ]

3:                                                ; preds = %1
  %4 = tail call double @llvm.copysign.f64(double 0.000000e+00, double %.016)
  br label %24

5:                                                ; preds = %1
  %6 = tail call double @llvm.copysign.f64(double 0x7FF0000000000000, double %.016)
  br label %24

7:                                                ; preds = %1
  %8 = lshr i64 %2, 52
  %9 = trunc nuw nsw i64 %8 to i32
  %10 = and i64 %0, 4503599627370495
  %11 = icmp eq i64 %8, 2047
  br i1 %11, label %24, label %12

12:                                               ; preds = %7
  %13 = icmp ult i64 %2, 4503599627370496
  br i1 %13, label %14, label %18

14:                                               ; preds = %12
  %15 = uitofp nneg i64 %10 to double
  %16 = tail call double @ldexp(double noundef %15, i32 noundef -1074) #3
  %17 = tail call double @llvm.copysign.f64(double %16, double %.016)
  br label %24

18:                                               ; preds = %12
  %19 = or disjoint i64 %10, 4503599627370496
  %20 = uitofp nneg i64 %19 to double
  %21 = add nsw i32 %9, -1075
  %22 = tail call double @ldexp(double noundef %20, i32 noundef %21) #3
  %23 = tail call double @llvm.copysign.f64(double %22, double %.016)
  br label %24

24:                                               ; preds = %14, %18, %7, %5, %3
  %.1 = phi double [ %4, %3 ], [ %6, %5 ], [ %17, %14 ], [ %23, %18 ], [ 0x7FF8000000000000, %7 ]
  ret double %.1
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.copysign.f64(double, double) #1

; Function Attrs: mustprogress nofree nounwind willreturn
declare double @ldexp(double noundef, i32 noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nofree nounwind willreturn 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 speculatable willreturn memory(none) }
attributes #2 = { mustprogress nofree nounwind willreturn "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 }

!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)"}


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