; LLVM IR from jgaeddert/liquid-dsp :: examples (qnsearch_example)

; 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 [19 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [38 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [24 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca float, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 8, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 4000, ptr %3, align 4, !tbaa !5
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = zext i32 %10 to i64
  %12 = call ptr @llvm.stacksave.p0()
  store ptr %12, ptr %4, align 8
  %13 = alloca float, i64 %11, align 16
  store i64 %11, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %22, %0
  %15 = load i32, ptr %6, align 4, !tbaa !5
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = icmp ult i32 %15, %16
  br i1 %17, label %18, label %25

18:                                               ; preds = %14
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds float, ptr %13, i64 %20
  store float 0.000000e+00, ptr %21, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %18
  %23 = load i32, ptr %6, align 4, !tbaa !5
  %24 = add i32 %23, 1
  store i32 %24, ptr %6, align 4, !tbaa !5
  br label %14, !llvm.loop !11

25:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %26 = call noalias ptr @fopen(ptr noundef @.str, ptr noundef @.str.1)
  store ptr %26, ptr %8, align 8, !tbaa !13
  %27 = load ptr, ptr %8, align 8, !tbaa !13
  %28 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %27, ptr noundef @.str.2, ptr noundef @.str) #5
  %29 = load ptr, ptr %8, align 8, !tbaa !13
  %30 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %29, ptr noundef @.str.3) #5
  %31 = load ptr, ptr %8, align 8, !tbaa !13
  %32 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %31, ptr noundef @.str.4) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = call ptr @qnsearch_create(ptr noundef null, ptr noundef %13, i32 noundef %33, ptr noundef @liquid_rosenbrock, i32 noundef 0)
  store ptr %34, ptr %9, align 8, !tbaa !13
  %35 = load ptr, ptr %8, align 8, !tbaa !13
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %35, ptr noundef @.str.5, i32 noundef %36) #5
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %61, %25
  %39 = load i32, ptr %6, align 4, !tbaa !5
  %40 = load i32, ptr %3, align 4, !tbaa !5
  %41 = icmp ult i32 %39, %40
  br i1 %41, label %42, label %64

42:                                               ; preds = %38
  %43 = load i32, ptr %2, align 4, !tbaa !5
  %44 = call float @liquid_rosenbrock(ptr noundef null, ptr noundef %13, i32 noundef %43)
  store float %44, ptr %7, align 4, !tbaa !9
  %45 = load ptr, ptr %8, align 8, !tbaa !13
  %46 = load i32, ptr %6, align 4, !tbaa !5
  %47 = add i32 %46, 1
  %48 = load float, ptr %7, align 4, !tbaa !9
  %49 = fpext float %48 to double
  %50 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %45, ptr noundef @.str.6, i32 noundef %47, double noundef %49) #5
  %51 = load ptr, ptr %9, align 8, !tbaa !13
  %52 = call i32 @qnsearch_step(ptr noundef %51)
  %53 = load i32, ptr %6, align 4, !tbaa !5
  %54 = add i32 %53, 1
  %55 = urem i32 %54, 100
  %56 = icmp eq i32 %55, 0
  br i1 %56, label %57, label %60

57:                                               ; preds = %42
  %58 = load ptr, ptr %9, align 8, !tbaa !13
  %59 = call i32 @qnsearch_print(ptr noundef %58)
  br label %60

60:                                               ; preds = %57, %42
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %6, align 4, !tbaa !5
  %63 = add i32 %62, 1
  store i32 %63, ptr %6, align 4, !tbaa !5
  br label %38, !llvm.loop !15

64:                                               ; preds = %38
  %65 = call i32 (ptr, ...) @printf(ptr noundef @.str.7)
  %66 = load ptr, ptr %9, align 8, !tbaa !13
  %67 = call i32 @qnsearch_print(ptr noundef %66)
  %68 = load ptr, ptr %8, align 8, !tbaa !13
  %69 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %68, ptr noundef @.str.8) #5
  %70 = load ptr, ptr %8, align 8, !tbaa !13
  %71 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %70, ptr noundef @.str.9) #5
  %72 = load ptr, ptr %8, align 8, !tbaa !13
  %73 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %72, ptr noundef @.str.10) #5
  %74 = load ptr, ptr %8, align 8, !tbaa !13
  %75 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %74, ptr noundef @.str.11) #5
  %76 = load ptr, ptr %8, align 8, !tbaa !13
  %77 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %76, ptr noundef @.str.12) #5
  %78 = load ptr, ptr %8, align 8, !tbaa !13
  %79 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %78, ptr noundef @.str.13) #5
  %80 = load ptr, ptr %8, align 8, !tbaa !13
  %81 = call i32 @fclose(ptr noundef %80)
  %82 = call i32 (ptr, ...) @printf(ptr noundef @.str.14, ptr noundef @.str)
  %83 = load ptr, ptr %9, align 8, !tbaa !13
  %84 = call i32 @qnsearch_destroy(ptr noundef %83)
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  %85 = load ptr, ptr %4, align 8
  call void @llvm.stackrestore.p0(ptr %85)
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  %86 = load i32, ptr %1, align 4
  ret i32 %86
}

; 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
declare ptr @llvm.stacksave.p0() #2

declare noalias ptr @fopen(ptr noundef, ptr noundef) #3

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

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

declare float @liquid_rosenbrock(ptr noundef, ptr noundef, i32 noundef) #3

declare i32 @qnsearch_step(ptr noundef) #3

declare i32 @qnsearch_print(ptr noundef) #3

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

declare i32 @fclose(ptr noundef) #3

declare i32 @qnsearch_destroy(ptr noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #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 willreturn }
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 "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 = !{!"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 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !7, i64 0}
!15 = distinct !{!15, !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"

@.str = external hidden unnamed_addr constant [19 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [38 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [24 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca [8 x float], align 16
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %1, i8 0, i64 32, i1 false), !tbaa !5
  %2 = tail call noalias ptr @fopen(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1)
  %3 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %2, ptr noundef nonnull @.str.2, ptr noundef nonnull @.str) #4
  %4 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %2, ptr noundef nonnull @.str.3) #4
  %5 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %2, ptr noundef nonnull @.str.4) #4
  %6 = call ptr @qnsearch_create(ptr noundef null, ptr noundef nonnull %1, i32 noundef 8, ptr noundef nonnull @liquid_rosenbrock, i32 noundef 0) #4
  %7 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %2, ptr noundef nonnull @.str.5, i32 noundef 4000) #4
  br label %8

8:                                                ; preds = %0, %18
  %.132 = phi i32 [ 0, %0 ], [ %10, %18 ]
  %9 = call float @liquid_rosenbrock(ptr noundef null, ptr noundef nonnull %1, i32 noundef 8) #4
  %10 = add nuw nsw i32 %.132, 1
  %11 = fpext float %9 to double
  %12 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %2, ptr noundef nonnull @.str.6, i32 noundef %10, double noundef %11) #4
  %13 = call i32 @qnsearch_step(ptr noundef %6) #4
  %.lhs.trunc = trunc nuw i32 %10 to i16
  %14 = urem i16 %.lhs.trunc, 100
  %15 = icmp eq i16 %14, 0
  br i1 %15, label %16, label %18

16:                                               ; preds = %8
  %17 = call i32 @qnsearch_print(ptr noundef %6) #4
  br label %18

18:                                               ; preds = %8, %16
  %exitcond.not = icmp eq i32 %10, 4000
  br i1 %exitcond.not, label %19, label %8, !llvm.loop !9

19:                                               ; preds = %18
  %20 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7)
  %21 = call i32 @qnsearch_print(ptr noundef %6) #4
  %22 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %2, ptr noundef nonnull @.str.8) #4
  %23 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %2, ptr noundef nonnull @.str.9) #4
  %24 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %2, ptr noundef nonnull @.str.10) #4
  %25 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %2, ptr noundef nonnull @.str.11) #4
  %26 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %2, ptr noundef nonnull @.str.12) #4
  %27 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %2, ptr noundef nonnull @.str.13) #4
  %28 = call i32 @fclose(ptr noundef %2)
  %29 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.14, ptr noundef nonnull @.str)
  %30 = call i32 @qnsearch_destroy(ptr noundef %6) #4
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #1

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

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

declare float @liquid_rosenbrock(ptr noundef, ptr noundef, i32 noundef) #2

declare i32 @qnsearch_step(ptr noundef) local_unnamed_addr #2

declare i32 @qnsearch_print(ptr noundef) local_unnamed_addr #2

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

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

declare i32 @qnsearch_destroy(ptr noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"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: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopIdiomRecognizePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass