; LLVM IR from tfhe/spqlios-arithmetic :: spqlios/reim (reim_conversions)

; 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.reim_to_znx64_precomp = type { ptr, i64, double }

@reim_to_znx64_simple.p = external hidden thread_local global %struct.reim_to_znx64_precomp, align 8
@reim_to_znx64_simple.prev_log2bound = external hidden thread_local global i32, align 4

; Function Attrs: noreturn nounwind
declare void @abort() #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @init_reim_to_znx64_precomp(ptr noundef, i32 noundef, double noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @reim_to_znx64_simple(i32 noundef %0, double noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) #1 {
  %6 = alloca i32, align 4
  %7 = alloca double, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  store i32 %0, ptr %6, align 4, !tbaa !5
  store double %1, ptr %7, align 8, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !11
  store ptr %4, ptr %10, align 8, !tbaa !11
  %11 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @reim_to_znx64_simple.p)
  %12 = getelementptr inbounds %struct.reim_to_znx64_precomp, ptr %11, i32 0, i32 0
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %33

15:                                               ; preds = %5
  %16 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @reim_to_znx64_simple.p)
  %17 = getelementptr inbounds %struct.reim_to_znx64_precomp, ptr %16, i32 0, i32 1
  %18 = load i64, ptr %17, align 8, !tbaa !16
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = zext i32 %19 to i64
  %21 = icmp ne i64 %18, %20
  br i1 %21, label %33, label %22

22:                                               ; preds = %15
  %23 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @reim_to_znx64_simple.p)
  %24 = getelementptr inbounds %struct.reim_to_znx64_precomp, ptr %23, i32 0, i32 2
  %25 = load double, ptr %24, align 8, !tbaa !17
  %26 = load double, ptr %7, align 8, !tbaa !9
  %27 = fcmp une double %25, %26
  br i1 %27, label %33, label %28

28:                                               ; preds = %22
  %29 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @reim_to_znx64_simple.prev_log2bound)
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = load i32, ptr %8, align 4, !tbaa !5
  %32 = icmp ne i32 %30, %31
  br i1 %32, label %33, label %44

33:                                               ; preds = %28, %22, %15, %5
  %34 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @reim_to_znx64_simple.p)
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = load double, ptr %7, align 8, !tbaa !9
  %37 = load i32, ptr %8, align 4, !tbaa !5
  %38 = call ptr @init_reim_to_znx64_precomp(ptr noundef %34, i32 noundef %35, double noundef %36, i32 noundef %37)
  %39 = icmp ne ptr %38, null
  br i1 %39, label %41, label %40

40:                                               ; preds = %33
  call void @abort() #3
  unreachable

41:                                               ; preds = %33
  %42 = load i32, ptr %8, align 4, !tbaa !5
  %43 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @reim_to_znx64_simple.prev_log2bound)
  store i32 %42, ptr %43, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %41, %28
  %45 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @reim_to_znx64_simple.p)
  %46 = getelementptr inbounds %struct.reim_to_znx64_precomp, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !13
  %48 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @reim_to_znx64_simple.p)
  %49 = load ptr, ptr %9, align 8, !tbaa !11
  %50 = load ptr, ptr %10, align 8, !tbaa !11
  call void %47(ptr noundef %48, ptr noundef %49, ptr noundef %50)
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #2

attributes #0 = { noreturn 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 #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"reim_to_znx64_precomp", !12, i64 0, !15, i64 8, !10, i64 16}
!15 = !{!"long", !7, i64 0}
!16 = !{!14, !15, i64 8}
!17 = !{!14, !10, i64 16}


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

%struct.reim_to_znx64_precomp = type { ptr, i64, double }

@reim_to_znx64_simple.p = external hidden thread_local global %struct.reim_to_znx64_precomp, align 8
@reim_to_znx64_simple.prev_log2bound = external hidden thread_local local_unnamed_addr global i32, align 4

; Function Attrs: noreturn nounwind
declare void @abort() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @init_reim_to_znx64_precomp(ptr noundef, i32 noundef, double noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @reim_to_znx64_simple(i32 noundef %0, double noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #1 {
  %6 = tail call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @reim_to_znx64_simple.p)
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %.not = icmp ne ptr %7, null
  %8 = getelementptr inbounds i8, ptr %6, i64 8
  %9 = load i64, ptr %8, align 8
  %10 = zext i32 %0 to i64
  %.not8 = icmp eq i64 %9, %10
  %or.cond.not18.not21 = select i1 %.not, i1 %.not8, i1 false
  %11 = getelementptr inbounds i8, ptr %6, i64 16
  %12 = load double, ptr %11, align 8
  %13 = fcmp oeq double %12, %1
  %or.cond15.not20 = select i1 %or.cond.not18.not21, i1 %13, i1 false
  %14 = tail call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @reim_to_znx64_simple.prev_log2bound)
  %15 = load i32, ptr %14, align 4
  %.not9 = icmp eq i32 %15, %2
  %or.cond17 = select i1 %or.cond15.not20, i1 %.not9, i1 false
  br i1 %or.cond17, label %20, label %16

16:                                               ; preds = %5
  %17 = tail call ptr @init_reim_to_znx64_precomp(ptr noundef nonnull %6, i32 noundef %0, double noundef %1, i32 noundef %2)
  %.not10 = icmp eq ptr %17, null
  br i1 %.not10, label %18, label %19

18:                                               ; preds = %16
  tail call void @abort() #3
  unreachable

19:                                               ; preds = %16
  store i32 %2, ptr %14, align 4, !tbaa !12
  %.pre = load ptr, ptr %6, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %5, %19
  %21 = phi ptr [ %7, %5 ], [ %.pre, %19 ]
  tail call void %21(ptr noundef nonnull %6, ptr noundef %3, ptr noundef %4) #4
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #2

attributes #0 = { noreturn 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 #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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { noreturn nounwind }
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, !7, i64 0}
!6 = !{!"reim_to_znx64_precomp", !7, i64 0, !10, i64 8, !11, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"double", !8, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !8, i64 0}


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