; LLVM IR from tsotchke/quantum_geometric_tensor :: src/quantum_geometric/core (quantum_rng)

; 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.qrng_ctx = type { i64, i64, i64, i64, i64, [16 x double], i64, [16 x double], [16 x i64], [16 x i64], [16 x i64], %struct.timeval, i32, %union.anon, i64 }
%struct.timeval = type { i64, i64 }
%union.anon = type { [128 x i64] }

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @splitmix64(i64 noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i64 @get_runtime_entropy(ptr noundef) #1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @qrng_uint64(ptr noundef %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = icmp ne ptr %5, null
  br i1 %6, label %8, label %7

7:                                                ; preds = %1
  store i64 0, ptr %2, align 8
  br label %41

8:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = call i32 @qrng_bytes(ptr noundef %9, ptr noundef %4, i64 noundef 8)
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = call i64 @get_runtime_entropy(ptr noundef %11)
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.qrng_ctx, ptr %13, i32 0, i32 2
  store i64 %12, ptr %14, align 8, !tbaa !9
  %15 = load i64, ptr %4, align 8, !tbaa !14
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.qrng_ctx, ptr %16, i32 0, i32 2
  %18 = load i64, ptr %17, align 8, !tbaa !9
  %19 = xor i64 %15, %18
  %20 = call i64 @splitmix64(i64 noundef %19)
  store i64 %20, ptr %4, align 8, !tbaa !14
  %21 = load i64, ptr %4, align 8, !tbaa !14
  %22 = lshr i64 %21, 27
  %23 = mul i64 5518456751979916092, %22
  %24 = load i64, ptr %4, align 8, !tbaa !14
  %25 = xor i64 %24, %23
  store i64 %25, ptr %4, align 8, !tbaa !14
  %26 = load i64, ptr %4, align 8, !tbaa !14
  %27 = mul i64 %26, -4521708957497675121
  store i64 %27, ptr %4, align 8, !tbaa !14
  %28 = load i64, ptr %4, align 8, !tbaa !14
  %29 = lshr i64 %28, 31
  %30 = mul i64 -3176834084079251592, %29
  %31 = load i64, ptr %4, align 8, !tbaa !14
  %32 = xor i64 %31, %30
  store i64 %32, ptr %4, align 8, !tbaa !14
  %33 = load i64, ptr %4, align 8, !tbaa !14
  %34 = mul i64 %33, -7935046062780286179
  store i64 %34, ptr %4, align 8, !tbaa !14
  %35 = load i64, ptr %4, align 8, !tbaa !14
  %36 = lshr i64 %35, 29
  %37 = mul i64 -8136826123048540746, %36
  %38 = load i64, ptr %4, align 8, !tbaa !14
  %39 = xor i64 %38, %37
  store i64 %39, ptr %4, align 8, !tbaa !14
  %40 = load i64, ptr %4, align 8, !tbaa !14
  store i64 %40, ptr %2, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %41

41:                                               ; preds = %8, %7
  %42 = load i64, ptr %2, align 8
  ret i64 %42
}

attributes #0 = { inlinehint 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 = { 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 willreturn memory(argmem: readwrite) }
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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 16}
!10 = !{!"", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !7, i64 40, !11, i64 168, !7, i64 176, !7, i64 304, !7, i64 432, !7, i64 560, !12, i64 688, !13, i64 704, !7, i64 712, !11, i64 1736}
!11 = !{!"long", !7, i64 0}
!12 = !{!"timeval", !11, i64 0, !11, i64 8}
!13 = !{!"int", !7, i64 0}
!14 = !{!11, !11, 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: inlinehint nounwind uwtable
declare hidden i64 @splitmix64(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i64 @get_runtime_entropy(ptr noundef) local_unnamed_addr #1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @qrng_uint64(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca i64, align 8
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %21, label %3

3:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  %4 = call i32 @qrng_bytes(ptr noundef nonnull %0, ptr noundef nonnull %2, i64 noundef 8)
  %5 = call i64 @get_runtime_entropy(ptr noundef nonnull %0)
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %5, ptr %6, align 8, !tbaa !5
  %7 = load i64, ptr %2, align 8, !tbaa !12
  %8 = xor i64 %7, %5
  %9 = call i64 @splitmix64(i64 noundef %8)
  %10 = lshr i64 %9, 27
  %11 = mul i64 %10, 5518456751979916092
  %12 = xor i64 %11, %9
  %13 = mul i64 %12, -4521708957497675121
  %14 = lshr i64 %13, 31
  %15 = mul i64 %14, -3176834084079251592
  %16 = xor i64 %15, %13
  %17 = mul i64 %16, -7935046062780286179
  %18 = lshr i64 %17, 29
  %19 = mul i64 %18, -8136826123048540746
  %20 = xor i64 %19, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  br label %21

21:                                               ; preds = %1, %3
  %.0 = phi i64 [ %20, %3 ], [ 0, %1 ]
  ret i64 %.0
}

attributes #0 = { inlinehint 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 = { 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 willreturn memory(argmem: readwrite) }
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)"}
!5 = !{!6, !7, i64 16}
!6 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !8, i64 40, !7, i64 168, !8, i64 176, !8, i64 304, !8, i64 432, !8, i64 560, !10, i64 688, !11, i64 704, !8, i64 712, !7, i64 1736}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"timeval", !7, i64 0, !7, i64 8}
!11 = !{!"int", !8, i64 0}
!12 = !{!7, !7, i64 0}


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