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

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

; 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 i64 @_Z12EncodeDoubled(double noundef %0) #2 personality ptr @__gxx_personality_v0 {
  %2 = alloca i64, align 8
  %3 = alloca double, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  store double %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  %9 = load double, ptr %3, align 8, !tbaa !5
  %10 = invoke noundef i32 @_ZSt10fpclassifyd(double noundef %9)
          to label %11 unwind label %73

11:                                               ; preds = %1
  store i32 %10, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  store i64 0, ptr %5, align 8, !tbaa !11
  %12 = load double, ptr %3, align 8, !tbaa !5
  %13 = call double @llvm.copysign.f64(double 1.000000e+00, double %12)
  %14 = fcmp oeq double %13, -1.000000e+00
  br i1 %14, label %15, label %18

15:                                               ; preds = %11
  %16 = load double, ptr %3, align 8, !tbaa !5
  %17 = fneg double %16
  store double %17, ptr %3, align 8, !tbaa !5
  store i64 -9223372036854775808, ptr %5, align 8, !tbaa !11
  br label %18

18:                                               ; preds = %15, %11
  %19 = load i32, ptr %4, align 4, !tbaa !9
  %20 = icmp eq i32 %19, 2
  br i1 %20, label %21, label %23

21:                                               ; preds = %18
  %22 = load i64, ptr %5, align 8, !tbaa !11
  store i64 %22, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %71

23:                                               ; preds = %18
  %24 = load i32, ptr %4, align 4, !tbaa !9
  %25 = icmp eq i32 %24, 1
  br i1 %25, label %26, label %29

26:                                               ; preds = %23
  %27 = load i64, ptr %5, align 8, !tbaa !11
  %28 = or i64 %27, 9218868437227405312
  store i64 %28, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %71

29:                                               ; preds = %23
  %30 = load i32, ptr %4, align 4, !tbaa !9
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %29
  store i64 9221120237041090560, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %71

33:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %34 = load double, ptr %3, align 8, !tbaa !5
  %35 = call double @frexp(double noundef %34, ptr noundef %7) #5
  %36 = fmul double %35, 0x4340000000000000
  %37 = call double @llvm.round.f64(double %36)
  %38 = fptoui double %37 to i64
  store i64 %38, ptr %8, align 8, !tbaa !11
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = icmp slt i32 %39, -1021
  br i1 %40, label %41, label %54

41:                                               ; preds = %33
  %42 = load i32, ptr %7, align 4, !tbaa !9
  %43 = icmp slt i32 %42, -1084
  br i1 %43, label %44, label %46

44:                                               ; preds = %41
  %45 = load i64, ptr %5, align 8, !tbaa !11
  store i64 %45, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %70

46:                                               ; preds = %41
  %47 = load i64, ptr %5, align 8, !tbaa !11
  %48 = load i64, ptr %8, align 8, !tbaa !11
  %49 = load i32, ptr %7, align 4, !tbaa !9
  %50 = sub nsw i32 -1021, %49
  %51 = zext i32 %50 to i64
  %52 = lshr i64 %48, %51
  %53 = or i64 %47, %52
  store i64 %53, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %70

54:                                               ; preds = %33
  %55 = load i32, ptr %7, align 4, !tbaa !9
  %56 = icmp sgt i32 %55, 1024
  br i1 %56, label %57, label %60

57:                                               ; preds = %54
  %58 = load i64, ptr %5, align 8, !tbaa !11
  %59 = or i64 %58, 9218868437227405312
  store i64 %59, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %70

60:                                               ; preds = %54
  %61 = load i64, ptr %5, align 8, !tbaa !11
  %62 = load i32, ptr %7, align 4, !tbaa !9
  %63 = add nsw i32 1022, %62
  %64 = sext i32 %63 to i64
  %65 = shl i64 %64, 52
  %66 = or i64 %61, %65
  %67 = load i64, ptr %8, align 8, !tbaa !11
  %68 = and i64 %67, 4503599627370495
  %69 = or i64 %66, %68
  store i64 %69, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %70

70:                                               ; preds = %60, %57, %46, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %71

71:                                               ; preds = %70, %32, %26, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  %72 = load i64, ptr %2, align 8
  ret i64 %72

73:                                               ; preds = %1
  %74 = landingpad { ptr, i32 }
          catch ptr null
  %75 = extractvalue { ptr, i32 } %74, 0
  call void @__clang_call_terminate(ptr %75) #6
  unreachable
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZSt10fpclassifyd(double noundef) #2

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: nounwind
declare double @frexp(double noundef, ptr noundef) #4

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #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 = { 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 #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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !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 speculatable willreturn memory(none)
declare double @llvm.copysign.f64(double, double) #1

; Function Attrs: mustprogress 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 i64 @_Z12EncodeDoubled(double noundef %0) local_unnamed_addr #2 personality ptr @__gxx_personality_v0 {
  %2 = alloca i32, align 4
  %3 = tail call noundef i32 @_ZSt10fpclassifyd(double noundef %0)
  %4 = tail call double @llvm.copysign.f64(double 1.000000e+00, double %0)
  %5 = fcmp oeq double %4, -1.000000e+00
  %.015 = select i1 %5, i64 -9223372036854775808, i64 0
  switch i32 %3, label %9 [
    i32 2, label %36
    i32 1, label %6
    i32 0, label %8
  ]

6:                                                ; preds = %1
  %7 = or disjoint i64 %.015, 9218868437227405312
  br label %36

8:                                                ; preds = %1
  br label %36

9:                                                ; preds = %1
  %10 = fneg double %0
  %.016 = select i1 %5, double %10, double %0
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  %11 = call double @frexp(double noundef %.016, ptr noundef nonnull %2) #4
  %12 = fmul double %11, 0x4340000000000000
  %13 = tail call double @llvm.round.f64(double %12)
  %14 = fptoui double %13 to i64
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = icmp slt i32 %15, -1021
  br i1 %16, label %17, label %24

17:                                               ; preds = %9
  %18 = icmp ult i32 %15, -1084
  br i1 %18, label %35, label %19

19:                                               ; preds = %17
  %20 = sub nuw nsw i32 -1021, %15
  %21 = zext nneg i32 %20 to i64
  %22 = lshr i64 %14, %21
  %23 = or i64 %22, %.015
  br label %35

24:                                               ; preds = %9
  %25 = icmp sgt i32 %15, 1024
  br i1 %25, label %26, label %28

26:                                               ; preds = %24
  %27 = or disjoint i64 %.015, 9218868437227405312
  br label %35

28:                                               ; preds = %24
  %29 = add nsw i32 %15, 1022
  %30 = zext nneg i32 %29 to i64
  %31 = shl nuw nsw i64 %30, 52
  %32 = and i64 %14, 4503599627370495
  %33 = or disjoint i64 %31, %32
  %34 = or disjoint i64 %33, %.015
  br label %35

35:                                               ; preds = %17, %28, %26, %19
  %.0 = phi i64 [ %23, %19 ], [ %27, %26 ], [ %34, %28 ], [ %.015, %17 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  br label %36

36:                                               ; preds = %1, %35, %8, %6
  %.1 = phi i64 [ %7, %6 ], [ 9221120237041090560, %8 ], [ %.0, %35 ], [ %.015, %1 ]
  ret i64 %.1
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZSt10fpclassifyd(double noundef) local_unnamed_addr #2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: write)
declare double @frexp(double noundef, ptr nocapture noundef) local_unnamed_addr #3

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #3 = { mustprogress nofree nounwind willreturn memory(argmem: write) "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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