; LLVM IR from jgaeddert/liquid-dsp :: src/optim/src (chromosome)

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

%struct.chromosome_s = type { i32, ptr, ptr, ptr, i32 }

@.str = external hidden unnamed_addr constant [81 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [43 x i8], align 1

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

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

declare i32 @liquid_error_fl(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @chromosome_initf(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %9

9:                                                ; preds = %57, %2
  %10 = load i32, ptr %6, align 4, !tbaa !9
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.chromosome_s, ptr %11, i32 0, i32 0
  %13 = load i32, ptr %12, align 8, !tbaa !11
  %14 = icmp ult i32 %10, %13
  br i1 %14, label %15, label %60

15:                                               ; preds = %9
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = zext i32 %17 to i64
  %19 = getelementptr inbounds float, ptr %16, i64 %18
  %20 = load float, ptr %19, align 4, !tbaa !13
  %21 = fcmp olt float %20, 0.000000e+00
  br i1 %21, label %29, label %22

22:                                               ; preds = %15
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = zext i32 %24 to i64
  %26 = getelementptr inbounds float, ptr %23, i64 %25
  %27 = load float, ptr %26, align 4, !tbaa !13
  %28 = fcmp ogt float %27, 1.000000e+00
  br i1 %28, label %29, label %31

29:                                               ; preds = %22, %15
  %30 = call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 5, ptr noundef @.str, i32 noundef 195, ptr noundef @.str.11)
  store i32 %30, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %61

31:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.chromosome_s, ptr %32, i32 0, i32 1
  %34 = load ptr, ptr %33, align 8, !tbaa !15
  %35 = load i32, ptr %6, align 4, !tbaa !9
  %36 = zext i32 %35 to i64
  %37 = getelementptr inbounds i32, ptr %34, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !9
  %39 = zext i32 %38 to i64
  %40 = shl i64 1, %39
  store i64 %40, ptr %8, align 8, !tbaa !16
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load i32, ptr %6, align 4, !tbaa !9
  %43 = zext i32 %42 to i64
  %44 = getelementptr inbounds float, ptr %41, i64 %43
  %45 = load float, ptr %44, align 4, !tbaa !13
  %46 = load i64, ptr %8, align 8, !tbaa !16
  %47 = uitofp i64 %46 to float
  %48 = fmul float %45, %47
  %49 = call float @llvm.floor.f32(float %48)
  %50 = fptoui float %49 to i64
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.chromosome_s, ptr %51, i32 0, i32 3
  %53 = load ptr, ptr %52, align 8, !tbaa !18
  %54 = load i32, ptr %6, align 4, !tbaa !9
  %55 = zext i32 %54 to i64
  %56 = getelementptr inbounds i64, ptr %53, i64 %55
  store i64 %50, ptr %56, align 8, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %57

57:                                               ; preds = %31
  %58 = load i32, ptr %6, align 4, !tbaa !9
  %59 = add i32 %58, 1
  store i32 %59, ptr %6, align 4, !tbaa !9
  br label %9, !llvm.loop !19

60:                                               ; preds = %9
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %61

61:                                               ; preds = %60, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %62 = load i32, ptr %3, align 4
  ret i32 %62
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.floor.f32(float) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"any pointer", !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 = !{!12, !10, i64 0}
!12 = !{!"chromosome_s", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = !{!12, !6, i64 8}
!16 = !{!17, !17, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = !{!12, !6, i64 24}
!19 = distinct !{!19, !20}
!20 = !{!"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"

@.str = external hidden unnamed_addr constant [81 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [43 x i8], align 1

declare i32 @liquid_error_fl(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @chromosome_initf(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 {
  %3 = load i32, ptr %0, align 8, !tbaa !5
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %wide.trip.count = zext i32 %3 to i64
  br label %6

6:                                                ; preds = %.lr.ph, %13
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %13 ]
  %7 = getelementptr inbounds float, ptr %1, i64 %indvars.iv
  %8 = load float, ptr %7, align 4, !tbaa !11
  %9 = fcmp olt float %8, 0.000000e+00
  %10 = fcmp ogt float %8, 1.000000e+00
  %or.cond = or i1 %9, %10
  br i1 %or.cond, label %11, label %13

11:                                               ; preds = %6
  %12 = tail call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 5, ptr noundef nonnull @.str, i32 noundef 195, ptr noundef nonnull @.str.11) #3
  br label %.loopexit

13:                                               ; preds = %6
  %14 = load ptr, ptr %4, align 8, !tbaa !13
  %15 = getelementptr inbounds i32, ptr %14, i64 %indvars.iv
  %16 = load i32, ptr %15, align 4, !tbaa !14
  %17 = zext nneg i32 %16 to i64
  %18 = shl nuw i64 1, %17
  %19 = uitofp i64 %18 to float
  %20 = fmul float %8, %19
  %21 = tail call float @llvm.floor.f32(float %20)
  %22 = fptoui float %21 to i64
  %23 = load ptr, ptr %5, align 8, !tbaa !15
  %24 = getelementptr inbounds i64, ptr %23, i64 %indvars.iv
  store i64 %22, ptr %24, align 8, !tbaa !16
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %6, !llvm.loop !18

.loopexit:                                        ; preds = %13, %2, %11
  %.0 = phi i32 [ %12, %11 ], [ 0, %2 ], [ 0, %13 ]
  ret i32 %.0
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.floor.f32(float) #2

attributes #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 = { 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 #2 = { mustprogress 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, !7, i64 0}
!6 = !{!"chromosome_s", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !7, i64 32}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !8, i64 0}
!13 = !{!6, !10, i64 8}
!14 = !{!7, !7, i64 0}
!15 = !{!6, !10, i64 24}
!16 = !{!17, !17, i64 0}
!17 = !{!"long", !8, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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