; LLVM IR from csc-training/mpi-introduction :: parallel-pi (pi)

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

@.str = external hidden unnamed_addr constant [41 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [42 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  %10 = alloca double, align 8
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  %11 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef 840)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 1, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 840, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store double 0.000000e+00, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %12 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %12, ptr %9, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %29, %2
  %14 = load i32, ptr %9, align 4, !tbaa !5
  %15 = load i32, ptr %7, align 4, !tbaa !5
  %16 = icmp sle i32 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %32

18:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %19 = load i32, ptr %9, align 4, !tbaa !5
  %20 = sitofp i32 %19 to double
  %21 = fsub double %20, 5.000000e-01
  %22 = fdiv double %21, 8.400000e+02
  store double %22, ptr %10, align 8, !tbaa !11
  %23 = load double, ptr %10, align 8, !tbaa !11
  %24 = load double, ptr %10, align 8, !tbaa !11
  %25 = call double @llvm.fmuladd.f64(double %23, double %24, double 1.000000e+00)
  %26 = fdiv double 1.000000e+00, %25
  %27 = load double, ptr %8, align 8, !tbaa !11
  %28 = fadd double %27, %26
  store double %28, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %29

29:                                               ; preds = %18
  %30 = load i32, ptr %9, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %9, align 4, !tbaa !5
  br label %13, !llvm.loop !13

32:                                               ; preds = %17
  %33 = load double, ptr %8, align 8, !tbaa !11
  %34 = fmul double %33, 0x3F73813813813814
  store double %34, ptr %8, align 8, !tbaa !11
  %35 = load double, ptr %8, align 8, !tbaa !11
  %36 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, double noundef %35, double noundef 0x400921FB54442D18)
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %37 = load i32, ptr %3, align 4
  ret i32 %37
}

declare i32 @printf(ptr noundef, ...) #1

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

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

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

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

@.str = external hidden unnamed_addr constant [41 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [42 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  %3 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef 840)
  br label %7

4:                                                ; preds = %7
  %5 = fmul double %27, 0x3F73813813813814
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, double noundef %5, double noundef 0x400921FB54442D18)
  ret i32 0

7:                                                ; preds = %7, %2
  %.012 = phi double [ 0.000000e+00, %2 ], [ %27, %7 ]
  %.01011 = phi i32 [ 1, %2 ], [ %28, %7 ]
  %8 = uitofp nneg i32 %.01011 to double
  %9 = fadd double %8, -5.000000e-01
  %10 = fdiv double %9, 8.400000e+02
  %11 = tail call double @llvm.fmuladd.f64(double %10, double %10, double 1.000000e+00)
  %12 = fdiv double 1.000000e+00, %11
  %13 = fadd double %.012, %12
  %14 = add nuw nsw i32 %.01011, 1
  %15 = uitofp nneg i32 %14 to double
  %16 = fadd double %15, -5.000000e-01
  %17 = fdiv double %16, 8.400000e+02
  %18 = tail call double @llvm.fmuladd.f64(double %17, double %17, double 1.000000e+00)
  %19 = fdiv double 1.000000e+00, %18
  %20 = fadd double %13, %19
  %21 = add nuw nsw i32 %.01011, 2
  %22 = uitofp nneg i32 %21 to double
  %23 = fadd double %22, -5.000000e-01
  %24 = fdiv double %23, 8.400000e+02
  %25 = tail call double @llvm.fmuladd.f64(double %24, double %24, double 1.000000e+00)
  %26 = fdiv double 1.000000e+00, %25
  %27 = fadd double %20, %26
  %28 = add nuw nsw i32 %.01011, 3
  %exitcond.not.2 = icmp eq i32 %28, 841
  br i1 %exitcond.not.2, label %4, label %7, !llvm.loop !5
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

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

attributes #0 = { mustprogress nofree norecurse 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 = { nofree 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 #2 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass