; LLVM IR from jrl-umi3218/mc_rtc :: 3rd-party/qhull/src/libqhull_r (random_r)

; 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 i32 @qh_rand(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @qh_randommatrix(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca double, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %14, ptr %12, align 8, !tbaa !5
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %15, ptr %11, align 8, !tbaa !5
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %42, %4
  %17 = load i32, ptr %9, align 4, !tbaa !9
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %20, label %45

20:                                               ; preds = %16
  %21 = load ptr, ptr %12, align 8, !tbaa !5
  %22 = load ptr, ptr %11, align 8, !tbaa !5
  %23 = getelementptr inbounds ptr, ptr %22, i32 1
  store ptr %23, ptr %11, align 8, !tbaa !5
  store ptr %21, ptr %22, align 8, !tbaa !5
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %38, %20
  %25 = load i32, ptr %10, align 4, !tbaa !9
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %28, label %41

28:                                               ; preds = %24
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = call i32 @qh_rand(ptr noundef %29)
  %31 = sitofp i32 %30 to double
  store double %31, ptr %13, align 8, !tbaa !11
  %32 = load double, ptr %13, align 8, !tbaa !11
  %33 = fmul double 2.000000e+00, %32
  %34 = fdiv double %33, 0x41DFFFFFFFC00000
  %35 = fsub double %34, 1.000000e+00
  %36 = load ptr, ptr %12, align 8, !tbaa !5
  %37 = getelementptr inbounds double, ptr %36, i32 1
  store ptr %37, ptr %12, align 8, !tbaa !5
  store double %35, ptr %36, align 8, !tbaa !11
  br label %38

38:                                               ; preds = %28
  %39 = load i32, ptr %10, align 4, !tbaa !9
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %10, align 4, !tbaa !9
  br label %24, !llvm.loop !13

41:                                               ; preds = %24
  br label %42

42:                                               ; preds = %41
  %43 = load i32, ptr %9, align 4, !tbaa !9
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %9, align 4, !tbaa !9
  br label %16, !llvm.loop !15

45:                                               ; preds = %16
  %46 = load ptr, ptr %12, align 8, !tbaa !5
  %47 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %46, ptr %47, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  ret void
}

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}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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 i32 @qh_rand(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @qh_randommatrix(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #0 {
  %5 = icmp sgt i32 %2, 0
  br i1 %5, label %.lr.ph.us, label %._crit_edge25

.lr.ph.us:                                        ; preds = %4, %._crit_edge.us
  %.022.us = phi i32 [ %15, %._crit_edge.us ], [ 0, %4 ]
  %.01421.us = phi ptr [ %12, %._crit_edge.us ], [ %1, %4 ]
  %.01520.us = phi ptr [ %14, %._crit_edge.us ], [ %3, %4 ]
  store ptr %.01421.us, ptr %.01520.us, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %.lr.ph.us, %6
  %.119.us = phi ptr [ %.01421.us, %.lr.ph.us ], [ %12, %6 ]
  %.01618.us = phi i32 [ 0, %.lr.ph.us ], [ %13, %6 ]
  %7 = tail call i32 @qh_rand(ptr noundef %0)
  %8 = sitofp i32 %7 to double
  %9 = fmul double %8, 2.000000e+00
  %10 = fdiv double %9, 0x41DFFFFFFFC00000
  %11 = fadd double %10, -1.000000e+00
  %12 = getelementptr inbounds i8, ptr %.119.us, i64 8
  store double %11, ptr %.119.us, align 8, !tbaa !9
  %13 = add nuw nsw i32 %.01618.us, 1
  %exitcond.not = icmp eq i32 %13, %2
  br i1 %exitcond.not, label %._crit_edge.us, label %6, !llvm.loop !11

._crit_edge.us:                                   ; preds = %6
  %14 = getelementptr inbounds i8, ptr %.01520.us, i64 8
  %15 = add nuw nsw i32 %.022.us, 1
  %exitcond30.not = icmp eq i32 %15, %2
  br i1 %exitcond30.not, label %._crit_edge25, label %.lr.ph.us, !llvm.loop !13

._crit_edge25:                                    ; preds = %._crit_edge.us, %4
  %.015.lcssa = phi ptr [ %3, %4 ], [ %14, %._crit_edge.us ]
  %.014.lcssa = phi ptr [ %1, %4 ], [ %12, %._crit_edge.us ]
  store ptr %.014.lcssa, ptr %.015.lcssa, align 8, !tbaa !5
  ret void
}

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)"}
!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"}
!13 = distinct !{!13, !12}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass