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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @TCOD_random_get_gaussian_int_inv(ptr noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca double, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = sitofp i32 %10 to double
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = sitofp i32 %12 to double
  %14 = call double @TCOD_random_get_gaussian_double(ptr noundef %9, double noundef %11, double noundef %13)
  store double %14, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %15 = load double, ptr %7, align 8, !tbaa !11
  %16 = fcmp oge double %15, 0.000000e+00
  br i1 %16, label %17, label %21

17:                                               ; preds = %3
  %18 = load double, ptr %7, align 8, !tbaa !11
  %19 = fadd double %18, 5.000000e-01
  %20 = fptosi double %19 to i32
  br label %25

21:                                               ; preds = %3
  %22 = load double, ptr %7, align 8, !tbaa !11
  %23 = fsub double %22, 5.000000e-01
  %24 = fptosi double %23 to i32
  br label %25

25:                                               ; preds = %21, %17
  %26 = phi i32 [ %20, %17 ], [ %24, %21 ]
  store i32 %26, ptr %8, align 4, !tbaa !9
  %27 = load double, ptr %7, align 8, !tbaa !11
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = sitofp i32 %28 to double
  %30 = fcmp oge double %27, %29
  br i1 %30, label %31, label %36

31:                                               ; preds = %25
  %32 = load i32, ptr %8, align 4, !tbaa !9
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = mul nsw i32 3, %33
  %35 = sub nsw i32 %32, %34
  br label %41

36:                                               ; preds = %25
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = load i32, ptr %6, align 4, !tbaa !9
  %39 = mul nsw i32 3, %38
  %40 = add nsw i32 %37, %39
  br label %41

41:                                               ; preds = %36, %31
  %42 = phi i32 [ %35, %31 ], [ %40, %36 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret i32 %42
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !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: nounwind uwtable
declare dso_local double @TCOD_random_get_gaussian_double(ptr noundef, double noundef, double noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @TCOD_random_get_gaussian_int_inv(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = sitofp i32 %1 to double
  %5 = sitofp i32 %2 to double
  %6 = tail call double @TCOD_random_get_gaussian_double(ptr noundef %0, double noundef %4, double noundef %5)
  %7 = fcmp ult double %6, 0.000000e+00
  %.in.v = select i1 %7, double -5.000000e-01, double 5.000000e-01
  %.in = fadd double %6, %.in.v
  %8 = fcmp ult double %6, %4
  %.neg.pn.v = select i1 %8, i32 3, i32 -3
  %.neg.pn = mul i32 %.neg.pn.v, %2
  %9 = fptosi double %.in to i32
  %10 = add i32 %.neg.pn, %9
  ret i32 %10
}

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

!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)"}


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