; LLVM IR from EntityFX/anybench :: src/benchmarks/generic/scimark2 (kernel)

; 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

declare ptr @new_Stopwatch() #1

declare void @Stopwatch_start(ptr noundef) #1

declare void @Stopwatch_stop(ptr noundef) #1

declare double @Stopwatch_read(ptr noundef) #1

declare void @Stopwatch_delete(ptr noundef) #1

; 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
define dso_local double @kernel_measureMonteCarlo(double noundef %0, ptr noundef %1) #2 {
  %3 = alloca double, align 8
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store double %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store double 0.000000e+00, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %8 = call ptr @new_Stopwatch()
  store ptr %8, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 1, ptr %7, align 4, !tbaa !11
  br label %9

9:                                                ; preds = %20, %2
  br label %10

10:                                               ; preds = %9
  %11 = load ptr, ptr %6, align 8, !tbaa !9
  call void @Stopwatch_start(ptr noundef %11)
  %12 = load i32, ptr %7, align 4, !tbaa !11
  %13 = call double @MonteCarlo_integrate(i32 noundef %12)
  %14 = load ptr, ptr %6, align 8, !tbaa !9
  call void @Stopwatch_stop(ptr noundef %14)
  %15 = load ptr, ptr %6, align 8, !tbaa !9
  %16 = call double @Stopwatch_read(ptr noundef %15)
  %17 = load double, ptr %3, align 8, !tbaa !5
  %18 = fcmp oge double %16, %17
  br i1 %18, label %19, label %20

19:                                               ; preds = %10
  br label %23

20:                                               ; preds = %10
  %21 = load i32, ptr %7, align 4, !tbaa !11
  %22 = mul nsw i32 %21, 2
  store i32 %22, ptr %7, align 4, !tbaa !11
  br label %9

23:                                               ; preds = %19
  %24 = load i32, ptr %7, align 4, !tbaa !11
  %25 = call double @MonteCarlo_num_flops(i32 noundef %24)
  %26 = load ptr, ptr %6, align 8, !tbaa !9
  %27 = call double @Stopwatch_read(ptr noundef %26)
  %28 = fdiv double %25, %27
  %29 = fmul double %28, 0x3EB0C6F7A0B5ED8D
  store double %29, ptr %5, align 8, !tbaa !5
  %30 = load ptr, ptr %6, align 8, !tbaa !9
  call void @Stopwatch_delete(ptr noundef %30)
  %31 = load double, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret double %31
}

declare double @MonteCarlo_integrate(i32 noundef) #1

declare double @MonteCarlo_num_flops(i32 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 #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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"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"

declare ptr @new_Stopwatch() local_unnamed_addr #0

declare void @Stopwatch_start(ptr noundef) local_unnamed_addr #0

declare void @Stopwatch_stop(ptr noundef) local_unnamed_addr #0

declare double @Stopwatch_read(ptr noundef) local_unnamed_addr #0

declare void @Stopwatch_delete(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local double @kernel_measureMonteCarlo(double noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #1 {
  %3 = tail call ptr @new_Stopwatch() #2
  br label %4

4:                                                ; preds = %4, %2
  %.0 = phi i32 [ 1, %2 ], [ %8, %4 ]
  tail call void @Stopwatch_start(ptr noundef %3) #2
  %5 = tail call double @MonteCarlo_integrate(i32 noundef %.0) #2
  tail call void @Stopwatch_stop(ptr noundef %3) #2
  %6 = tail call double @Stopwatch_read(ptr noundef %3) #2
  %7 = fcmp ult double %6, %0
  %8 = shl nsw i32 %.0, 1
  br i1 %7, label %4, label %9

9:                                                ; preds = %4
  %10 = tail call double @MonteCarlo_num_flops(i32 noundef %.0) #2
  %11 = tail call double @Stopwatch_read(ptr noundef %3) #2
  %12 = fdiv double %10, %11
  %13 = fmul double %12, 0x3EB0C6F7A0B5ED8D
  tail call void @Stopwatch_delete(ptr noundef %3) #2
  ret double %13
}

declare double @MonteCarlo_integrate(i32 noundef) local_unnamed_addr #0

declare double @MonteCarlo_num_flops(i32 noundef) local_unnamed_addr #0

attributes #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 = { 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)"}


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