; LLVM IR from ahampriyanshu/algo-ds-101 :: Maths/Calculus/Riemann_Sum (Riemann_Sum)

; 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 [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_Z2F1dd(double noundef, double noundef) #0

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

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

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

16:                                               ; preds = %88, %0
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %92

19:                                               ; preds = %16
  store i32 2, ptr %9, align 4, !tbaa !9
  %20 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %7)
  %21 = load double, ptr %7, align 8, !tbaa !5
  %22 = fneg double %21
  %23 = call double @pow(double noundef 1.000000e+01, double noundef %22) #6
  store double %23, ptr %10, align 8, !tbaa !5
  %24 = load double, ptr %4, align 8, !tbaa !5
  %25 = load double, ptr %3, align 8, !tbaa !5
  %26 = fsub double %24, %25
  %27 = load i32, ptr %9, align 4, !tbaa !9
  %28 = sitofp i32 %27 to double
  %29 = fdiv double %26, %28
  store double %29, ptr %5, align 8, !tbaa !5
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = icmp eq i32 %30, 1
  br i1 %31, label %32, label %88

32:                                               ; preds = %19
  store double 1.000000e+00, ptr %14, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %83, %32
  %34 = load double, ptr %14, align 8, !tbaa !5
  %35 = load double, ptr %10, align 8, !tbaa !5
  %36 = fcmp oge double %34, %35
  br i1 %36, label %37, label %87

37:                                               ; preds = %33
  %38 = load double, ptr %4, align 8, !tbaa !5
  %39 = load double, ptr %3, align 8, !tbaa !5
  %40 = fsub double %38, %39
  %41 = load i32, ptr %9, align 4, !tbaa !9
  %42 = sitofp i32 %41 to double
  %43 = fdiv double %40, %42
  store double %43, ptr %5, align 8, !tbaa !5
  store double 0.000000e+00, ptr %12, align 8, !tbaa !5
  %44 = load double, ptr %3, align 8, !tbaa !5
  %45 = load double, ptr %5, align 8, !tbaa !5
  %46 = fadd double %44, %45
  store double %46, ptr %6, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %59, %37
  %48 = load double, ptr %6, align 8, !tbaa !5
  %49 = load double, ptr %4, align 8, !tbaa !5
  %50 = load double, ptr %5, align 8, !tbaa !5
  %51 = fsub double %49, %50
  %52 = fcmp ole double %48, %51
  br i1 %52, label %53, label %62

53:                                               ; preds = %47
  %54 = load double, ptr %6, align 8, !tbaa !5
  %55 = load double, ptr %2, align 8, !tbaa !5
  %56 = call noundef double @_Z2F1dd(double noundef %54, double noundef %55)
  %57 = load double, ptr %12, align 8, !tbaa !5
  %58 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %56, double %57)
  store double %58, ptr %12, align 8, !tbaa !5
  br label %59

59:                                               ; preds = %53
  %60 = load double, ptr %6, align 8, !tbaa !5
  %61 = fadd double %60, 1.000000e+00
  store double %61, ptr %6, align 8, !tbaa !5
  br label %47, !llvm.loop !11

62:                                               ; preds = %47
  %63 = load double, ptr %5, align 8, !tbaa !5
  %64 = fdiv double %63, 2.000000e+00
  %65 = load double, ptr %3, align 8, !tbaa !5
  %66 = load double, ptr %2, align 8, !tbaa !5
  %67 = call noundef double @_Z2F1dd(double noundef %65, double noundef %66)
  %68 = load double, ptr %4, align 8, !tbaa !5
  %69 = load double, ptr %2, align 8, !tbaa !5
  %70 = call noundef double @_Z2F1dd(double noundef %68, double noundef %69)
  %71 = fadd double %67, %70
  %72 = load double, ptr %12, align 8, !tbaa !5
  %73 = fadd double %71, %72
  %74 = fmul double %64, %73
  store double %74, ptr %11, align 8, !tbaa !5
  %75 = load double, ptr %14, align 8, !tbaa !5
  %76 = fcmp oeq double %75, 1.000000e+00
  br i1 %76, label %77, label %79

77:                                               ; preds = %62
  %78 = load double, ptr %11, align 8, !tbaa !5
  store double %78, ptr %14, align 8, !tbaa !5
  br label %83

79:                                               ; preds = %62
  %80 = load double, ptr %13, align 8, !tbaa !5
  %81 = load double, ptr %11, align 8, !tbaa !5
  %82 = fsub double %80, %81
  store double %82, ptr %14, align 8, !tbaa !5
  br label %83

83:                                               ; preds = %79, %77
  %84 = load double, ptr %11, align 8, !tbaa !5
  store double %84, ptr %13, align 8, !tbaa !5
  %85 = load i32, ptr %9, align 4, !tbaa !9
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %9, align 4, !tbaa !9
  br label %33, !llvm.loop !13

87:                                               ; preds = %33
  br label %88

88:                                               ; preds = %87, %19
  %89 = load double, ptr %11, align 8, !tbaa !5
  %90 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, double noundef %89)
  %91 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %8)
  br label %16, !llvm.loop !14

92:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #6
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #3

; Function Attrs: nounwind
declare double @pow(double noundef, double noundef) #4

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

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

attributes #0 = { mustprogress 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 = { 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 #3 = { "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 "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


; 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 [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_Z2F1dd(double noundef, double noundef) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = alloca double, align 8
  %2 = alloca double, align 8
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #6
  store double 0.000000e+00, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #6
  store double 0.000000e+00, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #6
  store double 0.000000e+00, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #6
  store double 0.000000e+00, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #6
  store i32 3, ptr %5, align 4, !tbaa !9
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %5)
  %7 = load i32, ptr %5, align 4, !tbaa !9
  %.not34 = icmp eq i32 %7, 0
  br i1 %.not34, label %._crit_edge39, label %.lr.ph38

.lr.ph38:                                         ; preds = %0, %.loopexit
  %.01836 = phi double [ %.2, %.loopexit ], [ 0.000000e+00, %0 ]
  %.02135 = phi double [ %.223, %.loopexit ], [ 0.000000e+00, %0 ]
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1, ptr noundef nonnull %2, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %9 = load double, ptr %4, align 8, !tbaa !5
  %10 = fneg double %9
  %11 = call double @pow(double noundef 1.000000e+01, double noundef %10) #6
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = icmp ne i32 %12, 1
  %14 = fcmp ugt double %11, 1.000000e+00
  %or.cond = select i1 %13, i1 true, i1 %14
  br i1 %or.cond, label %.loopexit, label %.lr.ph31

.lr.ph31:                                         ; preds = %.lr.ph38, %._crit_edge
  %.030 = phi double [ %.1, %._crit_edge ], [ 1.000000e+00, %.lr.ph38 ]
  %.11929 = phi double [ %39, %._crit_edge ], [ %.01836, %.lr.ph38 ]
  %.02428 = phi i32 [ %42, %._crit_edge ], [ 2, %.lr.ph38 ]
  %15 = load double, ptr %3, align 8, !tbaa !5
  %16 = load double, ptr %2, align 8, !tbaa !5
  %17 = fsub double %15, %16
  %18 = uitofp nneg i32 %.02428 to double
  %19 = fdiv double %17, %18
  %20 = fadd double %16, %19
  %21 = fsub double %15, %19
  %22 = fcmp ugt double %20, %21
  br i1 %22, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph31, %.lr.ph
  %.02027 = phi double [ %25, %.lr.ph ], [ 0.000000e+00, %.lr.ph31 ]
  %.02526 = phi double [ %26, %.lr.ph ], [ %20, %.lr.ph31 ]
  %23 = load double, ptr %1, align 8, !tbaa !5
  %24 = call noundef double @_Z2F1dd(double noundef %.02526, double noundef %23)
  %25 = call double @llvm.fmuladd.f64(double %24, double 2.000000e+00, double %.02027)
  %26 = fadd double %.02526, 1.000000e+00
  %27 = load double, ptr %3, align 8, !tbaa !5
  %28 = fsub double %27, %19
  %29 = fcmp ugt double %26, %28
  br i1 %29, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !11

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load double, ptr %2, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.lr.ph31
  %30 = phi double [ %16, %.lr.ph31 ], [ %.pre, %._crit_edge.loopexit ]
  %.020.lcssa = phi double [ 0.000000e+00, %.lr.ph31 ], [ %25, %._crit_edge.loopexit ]
  %31 = fmul double %19, 5.000000e-01
  %32 = load double, ptr %1, align 8, !tbaa !5
  %33 = call noundef double @_Z2F1dd(double noundef %30, double noundef %32)
  %34 = load double, ptr %3, align 8, !tbaa !5
  %35 = load double, ptr %1, align 8, !tbaa !5
  %36 = call noundef double @_Z2F1dd(double noundef %34, double noundef %35)
  %37 = fadd double %33, %36
  %38 = fadd double %.020.lcssa, %37
  %39 = fmul double %31, %38
  %40 = fcmp oeq double %.030, 1.000000e+00
  %41 = fsub double %.11929, %39
  %.1 = select i1 %40, double %39, double %41
  %42 = add nuw nsw i32 %.02428, 1
  %43 = fcmp ult double %.1, %11
  br i1 %43, label %.loopexit, label %.lr.ph31, !llvm.loop !13

.loopexit:                                        ; preds = %._crit_edge, %.lr.ph38
  %.223 = phi double [ %.02135, %.lr.ph38 ], [ %39, %._crit_edge ]
  %.2 = phi double [ %.01836, %.lr.ph38 ], [ %39, %._crit_edge ]
  %44 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, double noundef %.223)
  %45 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %5)
  %46 = load i32, ptr %5, align 4, !tbaa !9
  %.not = icmp eq i32 %46, 0
  br i1 %.not, label %._crit_edge39, label %.lr.ph38, !llvm.loop !14

._crit_edge39:                                    ; preds = %.loopexit, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #6
  ret i32 0
}

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @pow(double noundef, double noundef) local_unnamed_addr #4

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

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

attributes #0 = { mustprogress 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = { 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 #5 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass