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

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

@expected = external hidden constant [10 x [10 x float]], align 16

; Function Attrs: nounwind uwtable
declare dso_local float @stb_perlin_noise3(float noundef, float noundef, float noundef, i32 noundef, i32 noundef, i32 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_stb_perlin() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca float, align 4
  %4 = alloca float, align 4
  %5 = alloca float, align 4
  %6 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %7

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

10:                                               ; preds = %7
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %39, %10
  %12 = load i32, ptr %1, align 4, !tbaa !5
  %13 = icmp slt i32 %12, 10
  br i1 %13, label %14, label %42

14:                                               ; preds = %11
  %15 = load i32, ptr %1, align 4, !tbaa !5
  %16 = sitofp i32 %15 to float
  %17 = fpext float %16 to double
  %18 = call double @llvm.fmuladd.f64(double %17, double 1.000000e-01, double 5.000000e+00)
  %19 = fptrunc double %18 to float
  store float %19, ptr %3, align 4, !tbaa !9
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = sitofp i32 %20 to float
  %22 = fpext float %21 to double
  %23 = call double @llvm.fmuladd.f64(double %22, double 1.000000e-01, double 5.000000e+00)
  %24 = fptrunc double %23 to float
  store float %24, ptr %4, align 4, !tbaa !9
  %25 = load float, ptr %3, align 4, !tbaa !9
  %26 = load float, ptr %4, align 4, !tbaa !9
  %27 = call float @stb_perlin_noise3(float noundef %25, float noundef %26, float noundef 1.000000e+00, i32 noundef 0, i32 noundef 0, i32 noundef 0)
  store float %27, ptr %5, align 4, !tbaa !9
  %28 = load float, ptr %5, align 4, !tbaa !9
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [10 x [10 x float]], ptr @expected, i64 0, i64 %30
  %32 = load i32, ptr %1, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [10 x float], ptr %31, i64 0, i64 %33
  %35 = load float, ptr %34, align 4, !tbaa !9
  %36 = fcmp une float %28, %35
  br i1 %36, label %37, label %38

37:                                               ; preds = %14
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %37, %14
  br label %39

39:                                               ; preds = %38
  %40 = load i32, ptr %1, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %1, align 4, !tbaa !5
  br label %11, !llvm.loop !11

42:                                               ; preds = %11
  br label %43

43:                                               ; preds = %42
  %44 = load i32, ptr %2, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %2, align 4, !tbaa !5
  br label %7, !llvm.loop !13

46:                                               ; preds = %7
  %47 = load i32, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  ret i32 %47
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !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"

@expected = external hidden local_unnamed_addr constant [10 x [10 x float]], align 16

; Function Attrs: nounwind uwtable
declare dso_local float @stb_perlin_noise3(float noundef, float noundef, float noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @benchmark_stb_perlin() local_unnamed_addr #0 {
  br label %.preheader

.preheader:                                       ; preds = %0, %.preheader
  %indvars.iv = phi i64 [ 0, %0 ], [ %indvars.iv.next, %.preheader ]
  %.016 = phi i32 [ 0, %0 ], [ %.2.9, %.preheader ]
  %1 = trunc nuw nsw i64 %indvars.iv to i32
  %2 = uitofp nneg i32 %1 to double
  %3 = tail call double @llvm.fmuladd.f64(double %2, double 1.000000e-01, double 5.000000e+00)
  %4 = fptrunc double %3 to float
  %5 = tail call float @stb_perlin_noise3(float noundef 5.000000e+00, float noundef %4, float noundef 1.000000e+00, i32 noundef 0, i32 noundef 0, i32 noundef 0)
  %6 = getelementptr inbounds [10 x [10 x float]], ptr @expected, i64 0, i64 %indvars.iv, i64 0
  %7 = load float, ptr %6, align 8, !tbaa !5
  %8 = fcmp une float %5, %7
  %9 = tail call float @stb_perlin_noise3(float noundef 0x4014666660000000, float noundef %4, float noundef 1.000000e+00, i32 noundef 0, i32 noundef 0, i32 noundef 0)
  %10 = getelementptr inbounds [10 x [10 x float]], ptr @expected, i64 0, i64 %indvars.iv, i64 1
  %11 = load float, ptr %10, align 4, !tbaa !5
  %12 = fcmp une float %9, %11
  %13 = tail call float @stb_perlin_noise3(float noundef 0x4014CCCCC0000000, float noundef %4, float noundef 1.000000e+00, i32 noundef 0, i32 noundef 0, i32 noundef 0)
  %14 = getelementptr inbounds [10 x [10 x float]], ptr @expected, i64 0, i64 %indvars.iv, i64 2
  %15 = tail call float @stb_perlin_noise3(float noundef 0x4015333340000000, float noundef %4, float noundef 1.000000e+00, i32 noundef 0, i32 noundef 0, i32 noundef 0)
  %16 = tail call float @stb_perlin_noise3(float noundef 0x40159999A0000000, float noundef %4, float noundef 1.000000e+00, i32 noundef 0, i32 noundef 0, i32 noundef 0)
  %17 = tail call float @stb_perlin_noise3(float noundef 5.500000e+00, float noundef %4, float noundef 1.000000e+00, i32 noundef 0, i32 noundef 0, i32 noundef 0)
  %18 = tail call float @stb_perlin_noise3(float noundef 0x4016666660000000, float noundef %4, float noundef 1.000000e+00, i32 noundef 0, i32 noundef 0, i32 noundef 0)
  %19 = tail call float @stb_perlin_noise3(float noundef 0x4016CCCCC0000000, float noundef %4, float noundef 1.000000e+00, i32 noundef 0, i32 noundef 0, i32 noundef 0)
  %20 = tail call float @stb_perlin_noise3(float noundef 0x4017333340000000, float noundef %4, float noundef 1.000000e+00, i32 noundef 0, i32 noundef 0, i32 noundef 0)
  %21 = tail call float @stb_perlin_noise3(float noundef 0x40179999A0000000, float noundef %4, float noundef 1.000000e+00, i32 noundef 0, i32 noundef 0, i32 noundef 0)
  %22 = load <8 x float>, ptr %14, align 8, !tbaa !5
  %23 = insertelement <8 x float> poison, float %13, i64 0
  %24 = insertelement <8 x float> %23, float %15, i64 1
  %25 = insertelement <8 x float> %24, float %16, i64 2
  %26 = insertelement <8 x float> %25, float %17, i64 3
  %27 = insertelement <8 x float> %26, float %18, i64 4
  %28 = insertelement <8 x float> %27, float %19, i64 5
  %29 = insertelement <8 x float> %28, float %20, i64 6
  %30 = insertelement <8 x float> %29, float %21, i64 7
  %31 = fcmp une <8 x float> %30, %22
  %32 = freeze <8 x i1> %31
  %33 = bitcast <8 x i1> %32 to i8
  %34 = icmp ne i8 %33, 0
  %.fr = freeze i1 %12
  %op.rdx = or i1 %34, %.fr
  %op.rdx19 = select i1 %op.rdx, i1 true, i1 %8
  %.2.9 = select i1 %op.rdx19, i32 1, i32 %.016
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 10
  br i1 %exitcond.not, label %35, label %.preheader, !llvm.loop !9

35:                                               ; preds = %.preheader
  ret i32 %.2.9
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, 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) }

!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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalDCEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass