; LLVM IR from harharkh/sb_desc :: src (utility)

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

@randn_state = external hidden thread_local global i32, align 4
@sb_randn.z = external hidden thread_local global double, align 8
@sb_randn.stored = external hidden thread_local global i8, align 1

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

; Function Attrs: nounwind uwtable
define dso_local double @sb_randn() #1 {
  %1 = alloca double, align 8
  %2 = alloca double, align 8
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = call align 1 ptr @llvm.threadlocal.address.p0(ptr align 1 @sb_randn.stored)
  %6 = load i8, ptr %5, align 1, !tbaa !5, !range !9, !noundef !10
  %7 = trunc i8 %6 to i1
  br i1 %7, label %8, label %12

8:                                                ; preds = %0
  %9 = call align 1 ptr @llvm.threadlocal.address.p0(ptr align 1 @sb_randn.stored)
  store i8 0, ptr %9, align 1, !tbaa !5
  %10 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @sb_randn.z)
  %11 = load double, ptr %10, align 8, !tbaa !11
  store double %11, ptr %1, align 8
  br label %75

12:                                               ; preds = %0
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  %13 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @randn_state)
  %14 = load i32, ptr %13, align 4, !tbaa !13
  %15 = shl i32 %14, 13
  %16 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @randn_state)
  %17 = load i32, ptr %16, align 4, !tbaa !13
  %18 = xor i32 %17, %15
  store i32 %18, ptr %16, align 4, !tbaa !13
  %19 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @randn_state)
  %20 = load i32, ptr %19, align 4, !tbaa !13
  %21 = lshr i32 %20, 17
  %22 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @randn_state)
  %23 = load i32, ptr %22, align 4, !tbaa !13
  %24 = xor i32 %23, %21
  store i32 %24, ptr %22, align 4, !tbaa !13
  %25 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @randn_state)
  %26 = load i32, ptr %25, align 4, !tbaa !13
  %27 = shl i32 %26, 5
  %28 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @randn_state)
  %29 = load i32, ptr %28, align 4, !tbaa !13
  %30 = xor i32 %29, %27
  store i32 %30, ptr %28, align 4, !tbaa !13
  %31 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @randn_state)
  %32 = load i32, ptr %31, align 4, !tbaa !13
  %33 = uitofp i32 %32 to double
  %34 = fadd double %33, 5.000000e-01
  %35 = fdiv double %34, 0x41F0000000000000
  store double %35, ptr %2, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %36 = load double, ptr %2, align 8, !tbaa !11
  %37 = call double @log(double noundef %36) #4
  %38 = fmul double -2.000000e+00, %37
  %39 = call double @sqrt(double noundef %38) #4
  store double %39, ptr %3, align 8, !tbaa !11
  %40 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @randn_state)
  %41 = load i32, ptr %40, align 4, !tbaa !13
  %42 = shl i32 %41, 13
  %43 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @randn_state)
  %44 = load i32, ptr %43, align 4, !tbaa !13
  %45 = xor i32 %44, %42
  store i32 %45, ptr %43, align 4, !tbaa !13
  %46 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @randn_state)
  %47 = load i32, ptr %46, align 4, !tbaa !13
  %48 = lshr i32 %47, 17
  %49 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @randn_state)
  %50 = load i32, ptr %49, align 4, !tbaa !13
  %51 = xor i32 %50, %48
  store i32 %51, ptr %49, align 4, !tbaa !13
  %52 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @randn_state)
  %53 = load i32, ptr %52, align 4, !tbaa !13
  %54 = shl i32 %53, 5
  %55 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @randn_state)
  %56 = load i32, ptr %55, align 4, !tbaa !13
  %57 = xor i32 %56, %54
  store i32 %57, ptr %55, align 4, !tbaa !13
  %58 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @randn_state)
  %59 = load i32, ptr %58, align 4, !tbaa !13
  %60 = uitofp i32 %59 to double
  %61 = fadd double %60, 5.000000e-01
  %62 = fdiv double %61, 0x41F0000000000000
  store double %62, ptr %2, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %63 = load double, ptr %2, align 8, !tbaa !11
  %64 = fmul double 0x401921FB54442D18, %63
  store double %64, ptr %4, align 8, !tbaa !11
  %65 = load double, ptr %3, align 8, !tbaa !11
  %66 = load double, ptr %4, align 8, !tbaa !11
  %67 = call double @sin(double noundef %66) #4
  %68 = fmul double %65, %67
  %69 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @sb_randn.z)
  store double %68, ptr %69, align 8, !tbaa !11
  %70 = call align 1 ptr @llvm.threadlocal.address.p0(ptr align 1 @sb_randn.stored)
  store i8 1, ptr %70, align 1, !tbaa !5
  %71 = load double, ptr %3, align 8, !tbaa !11
  %72 = load double, ptr %4, align 8, !tbaa !11
  %73 = call double @cos(double noundef %72) #4
  %74 = fmul double %71, %73
  store double %74, ptr %1, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  br label %75

75:                                               ; preds = %12, %8
  %76 = load double, ptr %1, align 8
  ret double %76
}

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

; Function Attrs: nounwind
declare double @sqrt(double noundef) #3

; Function Attrs: nounwind
declare double @log(double noundef) #3

; Function Attrs: nounwind
declare double @sin(double noundef) #3

; Function Attrs: nounwind
declare double @cos(double noundef) #3

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

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 "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 = !{!"_Bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"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"

@randn_state = external hidden thread_local local_unnamed_addr global i32, align 4
@sb_randn.z = external hidden thread_local local_unnamed_addr global double, align 8
@sb_randn.stored = external hidden thread_local local_unnamed_addr global i8, align 1

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(readwrite, argmem: write, inaccessiblemem: write) uwtable
define dso_local double @sb_randn() local_unnamed_addr #1 {
  %1 = tail call align 1 ptr @llvm.threadlocal.address.p0(ptr align 1 @sb_randn.stored)
  %2 = load i8, ptr %1, align 1, !tbaa !5, !range !9, !noundef !10
  %3 = trunc nuw i8 %2 to i1
  br i1 %3, label %4, label %7

4:                                                ; preds = %0
  store i8 0, ptr %1, align 1, !tbaa !5
  %5 = tail call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @sb_randn.z)
  %6 = load double, ptr %5, align 8, !tbaa !11
  br label %38

7:                                                ; preds = %0
  %8 = tail call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @randn_state)
  %9 = load i32, ptr %8, align 4, !tbaa !13
  %10 = shl i32 %9, 13
  %11 = xor i32 %10, %9
  %12 = lshr i32 %11, 17
  %13 = xor i32 %12, %11
  %14 = shl i32 %13, 5
  %15 = xor i32 %14, %13
  store i32 %15, ptr %8, align 4, !tbaa !13
  %16 = uitofp i32 %15 to double
  %17 = fadd double %16, 5.000000e-01
  %18 = fmul double %17, 0x3DF0000000000000
  %19 = tail call double @log(double noundef %18) #3
  %20 = fmul double %19, -2.000000e+00
  %21 = tail call double @sqrt(double noundef %20) #3
  %22 = load i32, ptr %8, align 4, !tbaa !13
  %23 = shl i32 %22, 13
  %24 = xor i32 %23, %22
  %25 = lshr i32 %24, 17
  %26 = xor i32 %25, %24
  %27 = shl i32 %26, 5
  %28 = xor i32 %27, %26
  store i32 %28, ptr %8, align 4, !tbaa !13
  %29 = uitofp i32 %28 to double
  %30 = fadd double %29, 5.000000e-01
  %31 = fmul double %30, 0x3DF0000000000000
  %32 = fmul double %31, 0x401921FB54442D18
  %33 = tail call double @sin(double noundef %32) #3
  %34 = fmul double %21, %33
  %35 = tail call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @sb_randn.z)
  store double %34, ptr %35, align 8, !tbaa !11
  store i8 1, ptr %1, align 1, !tbaa !5
  %36 = tail call double @cos(double noundef %32) #3
  %37 = fmul double %21, %36
  br label %38

38:                                               ; preds = %7, %4
  %.0 = phi double [ %6, %4 ], [ %37, %7 ]
  ret double %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @log(double noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sin(double noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @cos(double noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree nounwind willreturn memory(readwrite, argmem: write, inaccessiblemem: write) 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 nofree nounwind willreturn memory(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 #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 = !{!"_Bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}


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