; LLVM IR from yourtion/LearningMasteringAlgorithms-C :: source (root)

; 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: nounwind uwtable
define dso_local i32 @root(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, double noundef %4) #0 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca double, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store double %4, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 0, ptr %13, align 4, !tbaa !11
  store i32 0, ptr %12, align 4, !tbaa !11
  br label %15

15:                                               ; preds = %69, %5
  %16 = load i32, ptr %12, align 4, !tbaa !11
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %24, label %18

18:                                               ; preds = %15
  %19 = load i32, ptr %13, align 4, !tbaa !11
  %20 = add nsw i32 %19, 1
  %21 = load ptr, ptr %10, align 8, !tbaa !5
  %22 = load i32, ptr %21, align 4, !tbaa !11
  %23 = icmp slt i32 %20, %22
  br label %24

24:                                               ; preds = %18, %15
  %25 = phi i1 [ false, %15 ], [ %23, %18 ]
  br i1 %25, label %26, label %72

26:                                               ; preds = %24
  %27 = load ptr, ptr %9, align 8, !tbaa !5
  %28 = load i32, ptr %13, align 4, !tbaa !11
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds double, ptr %27, i64 %29
  %31 = load double, ptr %30, align 8, !tbaa !9
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = load i32, ptr %13, align 4, !tbaa !11
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds double, ptr %33, i64 %35
  %37 = load double, ptr %36, align 8, !tbaa !9
  %38 = call double %32(double noundef %37)
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = load i32, ptr %13, align 4, !tbaa !11
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds double, ptr %40, i64 %42
  %44 = load double, ptr %43, align 8, !tbaa !9
  %45 = call double %39(double noundef %44)
  %46 = fdiv double %38, %45
  %47 = fsub double %31, %46
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = load i32, ptr %13, align 4, !tbaa !11
  %50 = add nsw i32 %49, 1
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds double, ptr %48, i64 %51
  store double %47, ptr %52, align 8, !tbaa !9
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = load i32, ptr %13, align 4, !tbaa !11
  %55 = add nsw i32 %54, 1
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds double, ptr %53, i64 %56
  %58 = load double, ptr %57, align 8, !tbaa !9
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = load i32, ptr %13, align 4, !tbaa !11
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds double, ptr %59, i64 %61
  %63 = load double, ptr %62, align 8, !tbaa !9
  %64 = fsub double %58, %63
  %65 = call double @llvm.fabs.f64(double %64)
  %66 = load double, ptr %11, align 8, !tbaa !9
  %67 = fcmp olt double %65, %66
  br i1 %67, label %68, label %69

68:                                               ; preds = %26
  store i32 1, ptr %12, align 4, !tbaa !11
  br label %69

69:                                               ; preds = %68, %26
  %70 = load i32, ptr %13, align 4, !tbaa !11
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %13, align 4, !tbaa !11
  br label %15, !llvm.loop !13

72:                                               ; preds = %24
  %73 = load i32, ptr %13, align 4, !tbaa !11
  %74 = icmp eq i32 %73, 0
  br i1 %74, label %75, label %77

75:                                               ; preds = %72
  %76 = load ptr, ptr %10, align 8, !tbaa !5
  store i32 1, ptr %76, align 4, !tbaa !11
  br label %81

77:                                               ; preds = %72
  %78 = load i32, ptr %13, align 4, !tbaa !11
  %79 = add nsw i32 %78, 1
  %80 = load ptr, ptr %10, align 8, !tbaa !5
  store i32 %79, ptr %80, align 4, !tbaa !11
  br label %81

81:                                               ; preds = %77, %75
  %82 = load i32, ptr %12, align 4, !tbaa !11
  %83 = icmp ne i32 %82, 0
  br i1 %83, label %84, label %85

84:                                               ; preds = %81
  store i32 0, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %86

85:                                               ; preds = %81
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %86

86:                                               ; preds = %85, %84
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  %87 = load i32, ptr %6, align 4
  ret i32 %87
}

; 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: 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 }

!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 = !{!"any pointer", !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 = !{!12, !12, i64 0}
!12 = !{!"int", !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"

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @root(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef %2, ptr nocapture noundef %3, double noundef %4) local_unnamed_addr #0 {
  br label %6

6:                                                ; preds = %5, %.backedge
  %indvars.iv = phi i64 [ 0, %5 ], [ %indvars.iv.next, %.backedge ]
  %.028 = phi i32 [ 0, %5 ], [ %10, %.backedge ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = icmp sge i64 %indvars.iv.next, %8
  br i1 %9, label %.critedge.split.loop.exit29, label %.backedge

.backedge:                                        ; preds = %6
  %10 = add nuw nsw i32 %.028, 1
  %11 = getelementptr inbounds double, ptr %2, i64 %indvars.iv
  %12 = load double, ptr %11, align 8, !tbaa !9
  %13 = tail call double %0(double noundef %12) #2
  %14 = load double, ptr %11, align 8, !tbaa !9
  %15 = tail call double %1(double noundef %14) #2
  %16 = fdiv double %13, %15
  %17 = fsub double %12, %16
  %18 = getelementptr inbounds double, ptr %2, i64 %indvars.iv.next
  store double %17, ptr %18, align 8, !tbaa !9
  %19 = load double, ptr %11, align 8, !tbaa !9
  %20 = fsub double %17, %19
  %21 = tail call double @llvm.fabs.f64(double %20)
  %22 = fcmp uge double %21, %4
  br i1 %22, label %6, label %.critedge, !llvm.loop !11

.critedge.split.loop.exit29:                      ; preds = %6
  %23 = trunc nuw nsw i64 %indvars.iv to i32
  br label %.critedge

.critedge:                                        ; preds = %.backedge, %.critedge.split.loop.exit29
  %.0.lcssa = phi i32 [ %23, %.critedge.split.loop.exit29 ], [ %10, %.backedge ]
  %24 = add nuw nsw i32 %.0.lcssa, 1
  store i32 %24, ptr %3, align 4, !tbaa !5
  %.025 = sext i1 %9 to i32
  ret i32 %.025
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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)"}
!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"}


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