; LLVM IR from CactiLab/Sherloc-Cortex-M-CFVD :: Sherloc_runtime/evaluation/src/frac (libfrac)

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

@nums = external dso_local global [10 x double], align 16

; Function Attrs: nounwind uwtable
declare dso_local double @frac(double noundef, ptr noundef, ptr 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: nounwind uwtable
define dso_local i32 @benchmark_frac() #0 {
  %1 = alloca double, align 8
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #2
  store double 1.000000e-10, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %2, align 4, !tbaa !9
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %5

5:                                                ; preds = %15, %0
  %6 = load i32, ptr %4, align 4, !tbaa !9
  %7 = icmp slt i32 %6, 10
  br i1 %7, label %8, label %18

8:                                                ; preds = %5
  %9 = load i32, ptr %4, align 4, !tbaa !9
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [10 x double], ptr @nums, i64 0, i64 %10
  %12 = load double, ptr %11, align 8, !tbaa !5
  %13 = load double, ptr %1, align 8, !tbaa !5
  %14 = call double @frac(double noundef %12, ptr noundef %2, ptr noundef %3, double noundef %13)
  br label %15

15:                                               ; preds = %8
  %16 = load i32, ptr %4, align 4, !tbaa !9
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr %4, align 4, !tbaa !9
  br label %5, !llvm.loop !11

18:                                               ; preds = %5
  %19 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #2
  ret i32 %19
}

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 }

!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 = 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"

@nums = external dso_local local_unnamed_addr global [10 x double], align 16

; Function Attrs: nounwind uwtable
declare dso_local double @frac(double noundef, ptr noundef, ptr 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: nounwind uwtable
define dso_local i32 @benchmark_frac() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #2
  store i32 0, ptr %1, align 4, !tbaa !5
  %3 = load double, ptr @nums, align 16, !tbaa !9
  %4 = call double @frac(double noundef %3, ptr noundef nonnull %1, ptr noundef nonnull %2, double noundef 1.000000e-10)
  %5 = load double, ptr getelementptr inbounds (i8, ptr @nums, i64 8), align 8, !tbaa !9
  %6 = call double @frac(double noundef %5, ptr noundef nonnull %1, ptr noundef nonnull %2, double noundef 1.000000e-10)
  %7 = load double, ptr getelementptr inbounds (i8, ptr @nums, i64 16), align 16, !tbaa !9
  %8 = call double @frac(double noundef %7, ptr noundef nonnull %1, ptr noundef nonnull %2, double noundef 1.000000e-10)
  %9 = load double, ptr getelementptr inbounds (i8, ptr @nums, i64 24), align 8, !tbaa !9
  %10 = call double @frac(double noundef %9, ptr noundef nonnull %1, ptr noundef nonnull %2, double noundef 1.000000e-10)
  %11 = load double, ptr getelementptr inbounds (i8, ptr @nums, i64 32), align 16, !tbaa !9
  %12 = call double @frac(double noundef %11, ptr noundef nonnull %1, ptr noundef nonnull %2, double noundef 1.000000e-10)
  %13 = load double, ptr getelementptr inbounds (i8, ptr @nums, i64 40), align 8, !tbaa !9
  %14 = call double @frac(double noundef %13, ptr noundef nonnull %1, ptr noundef nonnull %2, double noundef 1.000000e-10)
  %15 = load double, ptr getelementptr inbounds (i8, ptr @nums, i64 48), align 16, !tbaa !9
  %16 = call double @frac(double noundef %15, ptr noundef nonnull %1, ptr noundef nonnull %2, double noundef 1.000000e-10)
  %17 = load double, ptr getelementptr inbounds (i8, ptr @nums, i64 56), align 8, !tbaa !9
  %18 = call double @frac(double noundef %17, ptr noundef nonnull %1, ptr noundef nonnull %2, double noundef 1.000000e-10)
  %19 = load double, ptr getelementptr inbounds (i8, ptr @nums, i64 64), align 16, !tbaa !9
  %20 = call double @frac(double noundef %19, ptr noundef nonnull %1, ptr noundef nonnull %2, double noundef 1.000000e-10)
  %21 = load double, ptr getelementptr inbounds (i8, ptr @nums, i64 72), align 8, !tbaa !9
  %22 = call double @frac(double noundef %21, ptr noundef nonnull %1, ptr noundef nonnull %2, double noundef 1.000000e-10)
  %23 = load i32, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #2
  ret i32 %23
}

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 willreturn memory(argmem: readwrite) }
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}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,SROAPass,SimplifyCFGPass