; LLVM IR from MinhasKamal/AlgorithmImplementations :: numericalMethods/calculus (IntegrationSimpsonRule)

; 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 [22 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 100, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  store double 0.000000e+00, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  store double 0x400921FB54442D18, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %8 = load double, ptr %4, align 8, !tbaa !9
  %9 = load double, ptr %3, align 8, !tbaa !9
  %10 = fsub double %8, %9
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = sitofp i32 %11 to double
  %13 = fdiv double %10, %12
  store double %13, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  store double 0.000000e+00, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %14 = load double, ptr %6, align 8, !tbaa !9
  %15 = load double, ptr %3, align 8, !tbaa !9
  %16 = call double @sin(double noundef %15) #5
  %17 = fadd double %14, %16
  store double %17, ptr %6, align 8, !tbaa !9
  store i32 1, ptr %7, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %46, %0
  %19 = load i32, ptr %7, align 4, !tbaa !5
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = sub nsw i32 %20, 1
  %22 = icmp slt i32 %19, %21
  br i1 %22, label %23, label %49

23:                                               ; preds = %18
  %24 = load i32, ptr %7, align 4, !tbaa !5
  %25 = srem i32 %24, 2
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %36

27:                                               ; preds = %23
  %28 = load double, ptr %6, align 8, !tbaa !9
  %29 = load double, ptr %3, align 8, !tbaa !9
  %30 = load i32, ptr %7, align 4, !tbaa !5
  %31 = sitofp i32 %30 to double
  %32 = load double, ptr %5, align 8, !tbaa !9
  %33 = call double @llvm.fmuladd.f64(double %31, double %32, double %29)
  %34 = call double @sin(double noundef %33) #5
  %35 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %34, double %28)
  store double %35, ptr %6, align 8, !tbaa !9
  br label %45

36:                                               ; preds = %23
  %37 = load double, ptr %6, align 8, !tbaa !9
  %38 = load double, ptr %3, align 8, !tbaa !9
  %39 = load i32, ptr %7, align 4, !tbaa !5
  %40 = sitofp i32 %39 to double
  %41 = load double, ptr %5, align 8, !tbaa !9
  %42 = call double @llvm.fmuladd.f64(double %40, double %41, double %38)
  %43 = call double @sin(double noundef %42) #5
  %44 = call double @llvm.fmuladd.f64(double 4.000000e+00, double %43, double %37)
  store double %44, ptr %6, align 8, !tbaa !9
  br label %45

45:                                               ; preds = %36, %27
  br label %46

46:                                               ; preds = %45
  %47 = load i32, ptr %7, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %7, align 4, !tbaa !5
  br label %18, !llvm.loop !11

49:                                               ; preds = %18
  %50 = load double, ptr %6, align 8, !tbaa !9
  %51 = load double, ptr %4, align 8, !tbaa !9
  %52 = call double @sin(double noundef %51) #5
  %53 = fadd double %50, %52
  store double %53, ptr %6, align 8, !tbaa !9
  %54 = load double, ptr %6, align 8, !tbaa !9
  %55 = load double, ptr %5, align 8, !tbaa !9
  %56 = fmul double %54, %55
  %57 = fdiv double %56, 3.000000e+00
  store double %57, ptr %6, align 8, !tbaa !9
  %58 = load double, ptr %6, align 8, !tbaa !9
  %59 = call i32 (ptr, ...) @printf(ptr noundef @.str, double noundef %58)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  ret i32 0
}

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

; Function Attrs: nounwind
declare double @sin(double noundef) #2

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

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

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

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 = { 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { "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 #5 = { 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/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"

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

; Function Attrs: nofree nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  br label %1

1:                                                ; preds = %0, %1
  %.023 = phi i32 [ 1, %0 ], [ %9, %1 ]
  %.02122 = phi double [ 0.000000e+00, %0 ], [ %.1, %1 ]
  %2 = and i32 %.023, 1
  %3 = icmp eq i32 %2, 0
  %4 = uitofp nneg i32 %.023 to double
  %5 = tail call double @llvm.fmuladd.f64(double %4, double 0x3FA015BF9217271A, double 0.000000e+00)
  %6 = tail call double @sin(double noundef %5) #4
  %7 = tail call double @llvm.fmuladd.f64(double %6, double 2.000000e+00, double %.02122)
  %8 = tail call double @llvm.fmuladd.f64(double %6, double 4.000000e+00, double %.02122)
  %.1 = select i1 %3, double %7, double %8
  %9 = add nuw nsw i32 %.023, 1
  %exitcond.not = icmp eq i32 %9, 99
  br i1 %exitcond.not, label %10, label %1, !llvm.loop !5

10:                                               ; preds = %1
  %11 = fadd double %.1, 0x3CA1A62633145C07
  %12 = fmul double %11, 0x3FA015BF9217271A
  %13 = fdiv double %12, 3.000000e+00
  %14 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, double noundef %13)
  ret i32 0
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sin(double noundef) local_unnamed_addr #1

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

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

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


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