; LLVM IR from libtcod/libtcod :: src/libtcod (mersenne_c)

; 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: nounwind uwtable
declare dso_local ptr @TCOD_random_get_instance() #0

; 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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
declare hidden double @get_random_double(ptr noundef) #0

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

; Function Attrs: nounwind uwtable
define dso_local double @TCOD_random_get_gaussian_double(ptr noundef %0, double noundef %1, double noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !9
  store double %2, ptr %6, align 8, !tbaa !9
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %15, label %13

13:                                               ; preds = %3
  %14 = call ptr @TCOD_random_get_instance()
  store ptr %14, ptr %4, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %13, %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  br label %16

16:                                               ; preds = %29, %15
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = call double @get_random_double(ptr noundef %17)
  %19 = call double @llvm.fmuladd.f64(double %18, double 2.000000e+00, double -1.000000e+00)
  store double %19, ptr %7, align 8, !tbaa !9
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = call double @get_random_double(ptr noundef %20)
  %22 = call double @llvm.fmuladd.f64(double %21, double 2.000000e+00, double -1.000000e+00)
  store double %22, ptr %8, align 8, !tbaa !9
  %23 = load double, ptr %7, align 8, !tbaa !9
  %24 = load double, ptr %7, align 8, !tbaa !9
  %25 = load double, ptr %8, align 8, !tbaa !9
  %26 = load double, ptr %8, align 8, !tbaa !9
  %27 = fmul double %25, %26
  %28 = call double @llvm.fmuladd.f64(double %23, double %24, double %27)
  store double %28, ptr %9, align 8, !tbaa !9
  br label %29

29:                                               ; preds = %16
  %30 = load double, ptr %9, align 8, !tbaa !9
  %31 = fcmp oge double %30, 1.000000e+00
  br i1 %31, label %16, label %32, !llvm.loop !11

32:                                               ; preds = %29
  %33 = load double, ptr %9, align 8, !tbaa !9
  %34 = call double @log(double noundef %33) #4
  %35 = fmul double -2.000000e+00, %34
  %36 = load double, ptr %9, align 8, !tbaa !9
  %37 = fdiv double %35, %36
  %38 = call double @sqrt(double noundef %37) #4
  store double %38, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %39 = load double, ptr %7, align 8, !tbaa !9
  %40 = load double, ptr %9, align 8, !tbaa !9
  %41 = fmul double %39, %40
  store double %41, ptr %10, align 8, !tbaa !9
  %42 = load double, ptr %5, align 8, !tbaa !9
  %43 = load double, ptr %10, align 8, !tbaa !9
  %44 = load double, ptr %6, align 8, !tbaa !9
  %45 = call double @llvm.fmuladd.f64(double %43, double %44, double %42)
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret double %45
}

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

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

attributes #0 = { 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 = !{!"any pointer", !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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; 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: nounwind uwtable
declare dso_local ptr @TCOD_random_get_instance() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden double @get_random_double(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local double @TCOD_random_get_gaussian_double(ptr noundef %0, double noundef %1, double noundef %2) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %4, label %6

4:                                                ; preds = %3
  %5 = tail call ptr @TCOD_random_get_instance()
  br label %6

6:                                                ; preds = %4, %3
  %.0 = phi ptr [ %0, %3 ], [ %5, %4 ]
  br label %7

7:                                                ; preds = %7, %6
  %8 = tail call double @get_random_double(ptr noundef %.0)
  %9 = tail call double @llvm.fmuladd.f64(double %8, double 2.000000e+00, double -1.000000e+00)
  %10 = tail call double @get_random_double(ptr noundef %.0)
  %11 = tail call double @llvm.fmuladd.f64(double %10, double 2.000000e+00, double -1.000000e+00)
  %12 = fmul double %11, %11
  %13 = tail call double @llvm.fmuladd.f64(double %9, double %9, double %12)
  %14 = fcmp ult double %13, 1.000000e+00
  br i1 %14, label %15, label %7, !llvm.loop !5

15:                                               ; preds = %7
  %16 = tail call double @log(double noundef %13) #3
  %17 = fmul double %16, -2.000000e+00
  %18 = fdiv double %17, %13
  %19 = tail call double @sqrt(double noundef %18) #3
  %20 = fmul double %9, %19
  %21 = tail call double @llvm.fmuladd.f64(double %20, double %2, double %1)
  ret double %21
}

; 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

attributes #0 = { 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass