; LLVM IR from jgaeddert/liquid-dsp :: sandbox (math_lngamma_test)

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

@z = external dso_local global [41 x float], align 16
@lngamma_test = external dso_local global [41 x float], align 16
@__const.main.v = external hidden unnamed_addr constant [2 x float], align 4
@.str = external hidden unnamed_addr constant [34 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local float @sandbox_lngammaf(float noundef, ptr 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
declare dso_local float @gserror(ptr noundef, ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca [2 x float], align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca float, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 1000, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %3, ptr align 4 @__const.main.v, i64 8, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %7 = getelementptr inbounds [2 x float], ptr %3, i64 0, i64 0
  %8 = call ptr @gradsearch_create(ptr noundef null, ptr noundef %7, i32 noundef 2, ptr noundef @gserror, i32 noundef 0)
  store ptr %8, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %25, %0
  %10 = load i32, ptr %5, align 4, !tbaa !5
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = icmp ult i32 %10, %11
  br i1 %12, label %13, label %28

13:                                               ; preds = %9
  %14 = getelementptr inbounds [2 x float], ptr %3, i64 0, i64 0
  %15 = call float @gserror(ptr noundef null, ptr noundef %14, i32 noundef 2)
  store float %15, ptr %6, align 4, !tbaa !11
  %16 = load ptr, ptr %4, align 8, !tbaa !9
  %17 = call float @gradsearch_step(ptr noundef %16)
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = add i32 %18, 1
  %20 = urem i32 %19, 100
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %24

22:                                               ; preds = %13
  %23 = load ptr, ptr %4, align 8, !tbaa !9
  call void @gradsearch_print(ptr noundef %23)
  br label %24

24:                                               ; preds = %22, %13
  br label %25

25:                                               ; preds = %24
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = add i32 %26, 1
  store i32 %27, ptr %5, align 4, !tbaa !5
  br label %9, !llvm.loop !13

28:                                               ; preds = %9
  %29 = load ptr, ptr %4, align 8, !tbaa !9
  call void @gradsearch_destroy(ptr noundef %29)
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %52, %28
  %31 = load i32, ptr %5, align 4, !tbaa !5
  %32 = icmp ult i32 %31, 41
  br i1 %32, label %33, label %55

33:                                               ; preds = %30
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds [41 x float], ptr @z, i64 0, i64 %35
  %37 = load float, ptr %36, align 4, !tbaa !11
  %38 = fpext float %37 to double
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = zext i32 %39 to i64
  %41 = getelementptr inbounds [41 x float], ptr @lngamma_test, i64 0, i64 %40
  %42 = load float, ptr %41, align 4, !tbaa !11
  %43 = fpext float %42 to double
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = zext i32 %44 to i64
  %46 = getelementptr inbounds [41 x float], ptr @z, i64 0, i64 %45
  %47 = load float, ptr %46, align 4, !tbaa !11
  %48 = getelementptr inbounds [2 x float], ptr %3, i64 0, i64 0
  %49 = call float @sandbox_lngammaf(float noundef %47, ptr noundef %48)
  %50 = fpext float %49 to double
  %51 = call i32 (ptr, ...) @printf(ptr noundef @.str, double noundef %38, double noundef %43, double noundef %50)
  br label %52

52:                                               ; preds = %33
  %53 = load i32, ptr %5, align 4, !tbaa !5
  %54 = add i32 %53, 1
  store i32 %54, ptr %5, align 4, !tbaa !5
  br label %30, !llvm.loop !15

55:                                               ; preds = %30
  %56 = load float, ptr %6, align 4, !tbaa !11
  %57 = fpext float %56 to double
  %58 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, double noundef %57)
  %59 = getelementptr inbounds [2 x float], ptr %3, i64 0, i64 0
  %60 = load float, ptr %59, align 4, !tbaa !11
  %61 = fpext float %60 to double
  %62 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, double noundef %61)
  %63 = getelementptr inbounds [2 x float], ptr %3, i64 0, i64 1
  %64 = load float, ptr %63, align 4, !tbaa !11
  %65 = fpext float %64 to double
  %66 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, double noundef %65)
  %67 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  ret i32 0
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

declare ptr @gradsearch_create(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef) #3

declare float @gradsearch_step(ptr noundef) #3

declare void @gradsearch_print(ptr noundef) #3

declare void @gradsearch_destroy(ptr noundef) #3

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

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

!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 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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

@z = external dso_local local_unnamed_addr global [41 x float], align 16
@lngamma_test = external dso_local local_unnamed_addr global [41 x float], align 16
@__const.main.v = external hidden unnamed_addr constant [2 x float], align 4
@.str = external hidden unnamed_addr constant [34 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local float @sandbox_lngammaf(float noundef, ptr 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
declare dso_local float @gserror(ptr noundef, ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca [2 x float], align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  %2 = load i64, ptr @__const.main.v, align 4
  store i64 %2, ptr %1, align 8
  %3 = call ptr @gradsearch_create(ptr noundef null, ptr noundef nonnull %1, i32 noundef 2, ptr noundef nonnull @gserror, i32 noundef 0) #4
  br label %4

4:                                                ; preds = %0, %11
  %.01213 = phi i32 [ 0, %0 ], [ %7, %11 ]
  %5 = call float @gserror(ptr noundef null, ptr noundef nonnull %1, i32 noundef 2)
  %6 = call float @gradsearch_step(ptr noundef %3) #4
  %7 = add nuw nsw i32 %.01213, 1
  %.lhs.trunc = trunc nuw i32 %7 to i16
  %8 = urem i16 %.lhs.trunc, 100
  %9 = icmp eq i16 %8, 0
  br i1 %9, label %10, label %11

10:                                               ; preds = %4
  call void @gradsearch_print(ptr noundef %3) #4
  br label %11

11:                                               ; preds = %4, %10
  %exitcond.not = icmp eq i32 %7, 1000
  br i1 %exitcond.not, label %12, label %4, !llvm.loop !5

12:                                               ; preds = %11
  call void @gradsearch_destroy(ptr noundef %3) #4
  br label %13

13:                                               ; preds = %12, %13
  %indvars.iv = phi i64 [ 0, %12 ], [ %indvars.iv.next, %13 ]
  %14 = getelementptr inbounds [41 x float], ptr @z, i64 0, i64 %indvars.iv
  %15 = load float, ptr %14, align 4, !tbaa !7
  %16 = fpext float %15 to double
  %17 = getelementptr inbounds [41 x float], ptr @lngamma_test, i64 0, i64 %indvars.iv
  %18 = load float, ptr %17, align 4, !tbaa !7
  %19 = fpext float %18 to double
  %20 = call float @sandbox_lngammaf(float noundef %15, ptr noundef nonnull %1)
  %21 = fpext float %20 to double
  %22 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, double noundef %16, double noundef %19, double noundef %21)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond16.not = icmp eq i64 %indvars.iv.next, 41
  br i1 %exitcond16.not, label %23, label %13, !llvm.loop !11

23:                                               ; preds = %13
  %24 = fpext float %5 to double
  %25 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, double noundef %24)
  %26 = load float, ptr %1, align 8, !tbaa !7
  %27 = fpext float %26 to double
  %28 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, double noundef %27)
  %29 = getelementptr inbounds i8, ptr %1, i64 4
  %30 = load float, ptr %29, align 4, !tbaa !7
  %31 = fpext float %30 to double
  %32 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, double noundef %31)
  %33 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #4
  ret i32 0
}

declare ptr @gradsearch_create(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

declare float @gradsearch_step(ptr noundef) local_unnamed_addr #2

declare void @gradsearch_print(ptr noundef) local_unnamed_addr #2

declare void @gradsearch_destroy(ptr noundef) local_unnamed_addr #2

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

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass