; LLVM IR from 0r-gh0/NUMERICAL_ANALYSIS :: CODES (newton)

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

; Function Attrs: nounwind uwtable
declare dso_local double @func(double noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local double @derivFunc(double noundef) #0

; Function Attrs: nounwind uwtable
define dso_local float @newtonRaphson(double noundef %0, i32 noundef %1, i32 noundef %2, double noundef %3, ptr noundef %4) #0 {
  %6 = alloca float, align 4
  %7 = alloca double, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca double, align 8
  %11 = alloca ptr, align 8
  %12 = alloca double, align 8
  %13 = alloca i32, align 4
  store double %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !9
  store double %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %14 = load double, ptr %7, align 8, !tbaa !5
  %15 = call double @func(double noundef %14)
  %16 = load double, ptr %7, align 8, !tbaa !5
  %17 = call double @derivFunc(double noundef %16)
  %18 = fdiv double %15, %17
  store double %18, ptr %12, align 8, !tbaa !5
  %19 = load double, ptr %12, align 8, !tbaa !5
  %20 = call double @llvm.fabs.f64(double %19)
  %21 = load double, ptr %10, align 8, !tbaa !5
  %22 = fcmp oge double %20, %21
  br i1 %22, label %23, label %48

23:                                               ; preds = %5
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %27, label %48

27:                                               ; preds = %23
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %8, align 4, !tbaa !9
  %30 = load ptr, ptr %11, align 8, !tbaa !11
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = load double, ptr %7, align 8, !tbaa !5
  %33 = load double, ptr %7, align 8, !tbaa !5
  %34 = call double @func(double noundef %33)
  %35 = load double, ptr %7, align 8, !tbaa !5
  %36 = call double @derivFunc(double noundef %35)
  %37 = load double, ptr %12, align 8, !tbaa !5
  %38 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %30, ptr noundef @.str, i32 noundef %31, double noundef %32, double noundef %34, double noundef %36, double noundef %37) #5
  %39 = load double, ptr %7, align 8, !tbaa !5
  %40 = load double, ptr %12, align 8, !tbaa !5
  %41 = fsub double %39, %40
  store double %41, ptr %7, align 8, !tbaa !5
  %42 = load double, ptr %7, align 8, !tbaa !5
  %43 = load i32, ptr %8, align 4, !tbaa !9
  %44 = load i32, ptr %9, align 4, !tbaa !9
  %45 = load double, ptr %10, align 8, !tbaa !5
  %46 = load ptr, ptr %11, align 8, !tbaa !11
  %47 = call float @newtonRaphson(double noundef %42, i32 noundef %43, i32 noundef %44, double noundef %45, ptr noundef %46)
  br label %57

48:                                               ; preds = %23, %5
  %49 = load ptr, ptr %11, align 8, !tbaa !11
  %50 = load i32, ptr %8, align 4, !tbaa !9
  %51 = load double, ptr %7, align 8, !tbaa !5
  %52 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %49, ptr noundef @.str.1, i32 noundef %50, double noundef %51) #5
  %53 = load ptr, ptr %11, align 8, !tbaa !11
  %54 = call i32 @fclose(ptr noundef %53)
  %55 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  %56 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  store float 0.000000e+00, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %58

57:                                               ; preds = %27
  store i32 0, ptr %13, align 4
  br label %58

58:                                               ; preds = %57, %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  %59 = load i32, ptr %13, align 4
  switch i32 %59, label %62 [
    i32 0, label %60
    i32 1, label %60
  ]

60:                                               ; preds = %58, %58
  %61 = load float, ptr %6, align 4
  ret float %61

62:                                               ; preds = %58
  unreachable
}

; 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 speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #2

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #3

declare i32 @fclose(ptr noundef) #4

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 = { "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 = !{!"double", !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 = !{!"any pointer", !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"

@.str = external hidden unnamed_addr constant [62 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [54 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [53 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local double @func(double noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local double @derivFunc(double noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef float @newtonRaphson(double noundef %0, i32 noundef %1, i32 noundef %2, double noundef %3, ptr nocapture noundef %4) local_unnamed_addr #0 {
  %6 = tail call double @func(double noundef %0)
  %7 = tail call double @derivFunc(double noundef %0)
  %8 = fdiv double %6, %7
  %9 = tail call double @llvm.fabs.f64(double %8)
  %10 = fcmp oge double %9, %3
  %11 = icmp slt i32 %1, %2
  %or.cond31 = and i1 %11, %10
  br i1 %or.cond31, label %tailrecurse, label %tailrecurse._crit_edge

tailrecurse:                                      ; preds = %5, %tailrecurse
  %12 = phi double [ %20, %tailrecurse ], [ %8, %5 ]
  %.tr2633 = phi i32 [ %13, %tailrecurse ], [ %1, %5 ]
  %.tr32 = phi double [ %17, %tailrecurse ], [ %0, %5 ]
  %13 = add nsw i32 %.tr2633, 1
  %14 = tail call double @func(double noundef %.tr32)
  %15 = tail call double @derivFunc(double noundef %.tr32)
  %16 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %4, ptr noundef nonnull @.str, i32 noundef %13, double noundef %.tr32, double noundef %14, double noundef %15, double noundef %12) #3
  %17 = fsub double %.tr32, %12
  %18 = tail call double @func(double noundef %17)
  %19 = tail call double @derivFunc(double noundef %17)
  %20 = fdiv double %18, %19
  %21 = tail call double @llvm.fabs.f64(double %20)
  %22 = fcmp oge double %21, %3
  %23 = icmp slt i32 %13, %2
  %or.cond = and i1 %23, %22
  br i1 %or.cond, label %tailrecurse, label %tailrecurse._crit_edge

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %5
  %.tr.lcssa = phi double [ %0, %5 ], [ %17, %tailrecurse ]
  %.tr26.lcssa = phi i32 [ %1, %5 ], [ %13, %tailrecurse ]
  %24 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %4, ptr noundef nonnull @.str.1, i32 noundef %.tr26.lcssa, double noundef %.tr.lcssa) #3
  %25 = tail call i32 @fclose(ptr noundef %4)
  %26 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  %27 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  ret float 0.000000e+00
}

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #2

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

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


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