; 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.1 = external hidden unnamed_addr constant [50 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [49 x i8], align 1

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

11:                                               ; preds = %2
  %12 = call ptr (ptr, i32, ptr, ...) @liquid_error_config_fl(ptr noundef @.str, i32 noundef 43, ptr noundef @.str.1)
  store ptr %12, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %117

13:                                               ; preds = %2
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %28, %13
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = load i32, ptr %5, align 4, !tbaa !9
  %17 = icmp ult i32 %15, %16
  br i1 %17, label %18, label %31

18:                                               ; preds = %14
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = zext i32 %20 to i64
  %22 = getelementptr inbounds i32, ptr %19, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !9
  %24 = icmp ugt i32 %23, 32
  br i1 %24, label %25, label %27

25:                                               ; preds = %18
  %26 = call ptr (ptr, i32, ptr, ...) @liquid_error_config_fl(ptr noundef @.str, i32 noundef 46, ptr noundef @.str.2, i32 noundef 32)
  store ptr %26, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %117

27:                                               ; preds = %18
  br label %28

28:                                               ; preds = %27
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = add i32 %29, 1
  store i32 %30, ptr %6, align 4, !tbaa !9
  br label %14, !llvm.loop !11

31:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %32 = call noalias ptr @malloc(i64 noundef 40) #5
  store ptr %32, ptr %8, align 8, !tbaa !5
  %33 = load i32, ptr %5, align 4, !tbaa !9
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.chromosome_s, ptr %34, i32 0, i32 0
  store i32 %33, ptr %35, align 8, !tbaa !13
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.chromosome_s, ptr %36, i32 0, i32 0
  %38 = load i32, ptr %37, align 8, !tbaa !13
  %39 = zext i32 %38 to i64
  %40 = mul i64 %39, 4
  %41 = call noalias ptr @malloc(i64 noundef %40) #5
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.chromosome_s, ptr %42, i32 0, i32 1
  store ptr %41, ptr %43, align 8, !tbaa !15
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.chromosome_s, ptr %44, i32 0, i32 0
  %46 = load i32, ptr %45, align 8, !tbaa !13
  %47 = zext i32 %46 to i64
  %48 = mul i64 %47, 8
  %49 = call noalias ptr @malloc(i64 noundef %48) #5
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.chromosome_s, ptr %50, i32 0, i32 2
  store ptr %49, ptr %51, align 8, !tbaa !16
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.chromosome_s, ptr %52, i32 0, i32 0
  %54 = load i32, ptr %53, align 8, !tbaa !13
  %55 = zext i32 %54 to i64
  %56 = mul i64 %55, 8
  %57 = call noalias ptr @malloc(i64 noundef %56) #5
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.chromosome_s, ptr %58, i32 0, i32 3
  store ptr %57, ptr %59, align 8, !tbaa !17
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.chromosome_s, ptr %60, i32 0, i32 4
  store i32 0, ptr %61, align 8, !tbaa !18
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %62

62:                                               ; preds = %112, %31
  %63 = load i32, ptr %6, align 4, !tbaa !9
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.chromosome_s, ptr %64, i32 0, i32 0
  %66 = load i32, ptr %65, align 8, !tbaa !13
  %67 = icmp ult i32 %63, %66
  br i1 %67, label %68, label %115

68:                                               ; preds = %62
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = load i32, ptr %6, align 4, !tbaa !9
  %71 = zext i32 %70 to i64
  %72 = getelementptr inbounds i32, ptr %69, i64 %71
  %73 = load i32, ptr %72, align 4, !tbaa !9
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.chromosome_s, ptr %74, i32 0, i32 1
  %76 = load ptr, ptr %75, align 8, !tbaa !15
  %77 = load i32, ptr %6, align 4, !tbaa !9
  %78 = zext i32 %77 to i64
  %79 = getelementptr inbounds i32, ptr %76, i64 %78
  store i32 %73, ptr %79, align 4, !tbaa !9
  %80 = load ptr, ptr %8, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.chromosome_s, ptr %80, i32 0, i32 1
  %82 = load ptr, ptr %81, align 8, !tbaa !15
  %83 = load i32, ptr %6, align 4, !tbaa !9
  %84 = zext i32 %83 to i64
  %85 = getelementptr inbounds i32, ptr %82, i64 %84
  %86 = load i32, ptr %85, align 4, !tbaa !9
  %87 = zext i32 %86 to i64
  %88 = shl i64 1, %87
  %89 = load ptr, ptr %8, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.chromosome_s, ptr %89, i32 0, i32 2
  %91 = load ptr, ptr %90, align 8, !tbaa !16
  %92 = load i32, ptr %6, align 4, !tbaa !9
  %93 = zext i32 %92 to i64
  %94 = getelementptr inbounds i64, ptr %91, i64 %93
  store i64 %88, ptr %94, align 8, !tbaa !19
  %95 = load ptr, ptr %8, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.chromosome_s, ptr %95, i32 0, i32 3
  %97 = load ptr, ptr %96, align 8, !tbaa !17
  %98 = load i32, ptr %6, align 4, !tbaa !9
  %99 = zext i32 %98 to i64
  %100 = getelementptr inbounds i64, ptr %97, i64 %99
  store i64 0, ptr %100, align 8, !tbaa !19
  %101 = load ptr, ptr %8, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.chromosome_s, ptr %101, i32 0, i32 1
  %103 = load ptr, ptr %102, align 8, !tbaa !15
  %104 = load i32, ptr %6, align 4, !tbaa !9
  %105 = zext i32 %104 to i64
  %106 = getelementptr inbounds i32, ptr %103, i64 %105
  %107 = load i32, ptr %106, align 4, !tbaa !9
  %108 = load ptr, ptr %8, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.chromosome_s, ptr %108, i32 0, i32 4
  %110 = load i32, ptr %109, align 8, !tbaa !18
  %111 = add i32 %110, %107
  store i32 %111, ptr %109, align 8, !tbaa !18
  br label %112

112:                                              ; preds = %68
  %113 = load i32, ptr %6, align 4, !tbaa !9
  %114 = add i32 %113, 1
  store i32 %114, ptr %6, align 4, !tbaa !9
  br label %62, !llvm.loop !21

115:                                              ; preds = %62
  %116 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %116, ptr %3, align 8
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %117

117:                                              ; preds = %115, %25, %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %118 = load ptr, ptr %3, align 8
  ret ptr %118
}

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

declare ptr @liquid_error_config_fl(ptr noundef, i32 noundef, ptr noundef, ...) #2

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { 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 = { nounwind allocsize(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 #4 = { nounwind }
attributes #5 = { nounwind allocsize(0) }

!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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !10, i64 0}
!14 = !{!"chromosome_s", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32}
!15 = !{!14, !6, i64 8}
!16 = !{!14, !6, i64 16}
!17 = !{!14, !6, i64 24}
!18 = !{!14, !10, i64 32}
!19 = !{!20, !20, i64 0}
!20 = !{!"long", !7, i64 0}
!21 = distinct !{!21, !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 [81 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [50 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [49 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @chromosome_create(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq i32 %1, 0
  br i1 %3, label %4, label %.preheader.preheader

.preheader.preheader:                             ; preds = %2
  %wide.trip.count = zext i32 %1 to i64
  br label %.preheader

4:                                                ; preds = %2
  %5 = tail call ptr (ptr, i32, ptr, ...) @liquid_error_config_fl(ptr noundef nonnull @.str, i32 noundef 43, ptr noundef nonnull @.str.1) #6
  br label %41

6:                                                ; preds = %.preheader
  %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 %12, label %.preheader, !llvm.loop !5

.preheader:                                       ; preds = %.preheader.preheader, %6
  %indvars.iv = phi i64 [ 0, %.preheader.preheader ], [ %indvars.iv.next, %6 ]
  %7 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv
  %8 = load i32, ptr %7, align 4, !tbaa !7
  %9 = icmp ugt i32 %8, 32
  br i1 %9, label %10, label %6

10:                                               ; preds = %.preheader
  %11 = tail call ptr (ptr, i32, ptr, ...) @liquid_error_config_fl(ptr noundef nonnull @.str, i32 noundef 46, ptr noundef nonnull @.str.2, i32 noundef 32) #6
  br label %41

12:                                               ; preds = %6
  %13 = tail call noalias dereferenceable_or_null(40) ptr @malloc(i64 noundef 40) #7
  store i32 %1, ptr %13, align 8, !tbaa !11
  %14 = shl nuw nsw i64 %wide.trip.count, 2
  %15 = tail call noalias ptr @malloc(i64 noundef %14) #7
  %16 = getelementptr inbounds i8, ptr %13, i64 8
  store ptr %15, ptr %16, align 8, !tbaa !14
  %17 = shl nuw nsw i64 %wide.trip.count, 3
  %18 = tail call noalias ptr @malloc(i64 noundef %17) #7
  %19 = getelementptr inbounds i8, ptr %13, i64 16
  store ptr %18, ptr %19, align 8, !tbaa !15
  %calloc = tail call ptr @calloc(i64 1, i64 %17)
  %20 = getelementptr inbounds i8, ptr %13, i64 24
  store ptr %calloc, ptr %20, align 8, !tbaa !16
  %21 = getelementptr inbounds i8, ptr %13, i64 32
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 4 %15, ptr nonnull align 4 %0, i64 %14, i1 false), !tbaa !7
  %min.iters.check = icmp ult i32 %1, 4
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %12
  %n.vec = and i64 %wide.trip.count, 4294967292
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <2 x i32> [ zeroinitializer, %vector.ph ], [ %30, %vector.body ]
  %vec.phi42 = phi <2 x i32> [ zeroinitializer, %vector.ph ], [ %31, %vector.body ]
  %22 = getelementptr inbounds i32, ptr %0, i64 %index
  %23 = getelementptr inbounds i8, ptr %22, i64 8
  %wide.load = load <2 x i32>, ptr %22, align 4, !tbaa !7
  %wide.load43 = load <2 x i32>, ptr %23, align 4, !tbaa !7
  %24 = zext nneg <2 x i32> %wide.load to <2 x i64>
  %25 = zext nneg <2 x i32> %wide.load43 to <2 x i64>
  %26 = shl nuw <2 x i64> <i64 1, i64 1>, %24
  %27 = shl nuw <2 x i64> <i64 1, i64 1>, %25
  %28 = getelementptr inbounds i64, ptr %18, i64 %index
  %29 = getelementptr inbounds i8, ptr %28, i64 16
  store <2 x i64> %26, ptr %28, align 8, !tbaa !17
  store <2 x i64> %27, ptr %29, align 8, !tbaa !17
  %30 = add <2 x i32> %vec.phi, %wide.load
  %31 = add <2 x i32> %vec.phi42, %wide.load43
  %index.next = add nuw i64 %index, 4
  %32 = icmp eq i64 %index.next, %n.vec
  br i1 %32, label %middle.block, label %vector.body, !llvm.loop !19

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <2 x i32> %31, %30
  %33 = tail call i32 @llvm.vector.reduce.add.v2i32(<2 x i32> %bin.rdx)
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %.loopexit, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %12
  %indvars.iv37.ph = phi i64 [ 0, %12 ], [ %n.vec, %middle.block ]
  %.ph = phi i32 [ 0, %12 ], [ %33, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv37 = phi i64 [ %indvars.iv.next38, %scalar.ph ], [ %indvars.iv37.ph, %scalar.ph.preheader ]
  %34 = phi i32 [ %40, %scalar.ph ], [ %.ph, %scalar.ph.preheader ]
  %35 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv37
  %36 = load i32, ptr %35, align 4, !tbaa !7
  %37 = zext nneg i32 %36 to i64
  %38 = shl nuw i64 1, %37
  %39 = getelementptr inbounds i64, ptr %18, i64 %indvars.iv37
  store i64 %38, ptr %39, align 8, !tbaa !17
  %40 = add i32 %34, %36
  %indvars.iv.next38 = add nuw nsw i64 %indvars.iv37, 1
  %exitcond41.not = icmp eq i64 %indvars.iv.next38, %wide.trip.count
  br i1 %exitcond41.not, label %.loopexit, label %scalar.ph, !llvm.loop !22

.loopexit:                                        ; preds = %scalar.ph, %middle.block
  %.lcssa = phi i32 [ %33, %middle.block ], [ %40, %scalar.ph ]
  store i32 %.lcssa, ptr %21, align 8, !tbaa !23
  br label %41

41:                                               ; preds = %.loopexit, %10, %4
  %.0 = phi ptr [ %5, %4 ], [ %11, %10 ], [ %13, %.loopexit ]
  ret ptr %.0
}

declare ptr @liquid_error_config_fl(ptr noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

; 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) #3

; Function Attrs: nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #4

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v2i32(<2 x i32>) #5

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 = { "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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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: readwrite) }
attributes #4 = { nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { nounwind }
attributes #7 = { nounwind allocsize(0) }

!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 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!12, !8, i64 0}
!12 = !{!"chromosome_s", !8, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !8, i64 32}
!13 = !{!"any pointer", !9, i64 0}
!14 = !{!12, !13, i64 8}
!15 = !{!12, !13, i64 16}
!16 = !{!12, !13, i64 24}
!17 = !{!18, !18, i64 0}
!18 = !{!"long", !9, i64 0}
!19 = distinct !{!19, !6, !20, !21}
!20 = !{!"llvm.loop.isvectorized", i32 1}
!21 = !{!"llvm.loop.unroll.runtime.disable"}
!22 = distinct !{!22, !6, !21, !20}
!23 = !{!12, !8, i64 32}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass