; LLVM IR from jgaeddert/liquid-dsp :: src/fec/src (interleaver)

; 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.interleaver_s = type { i32, i32, i32, i32 }

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

; Function Attrs: nounwind uwtable
define dso_local i32 @interleaver_encode_soft(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = load ptr, ptr %5, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.interleaver_s, ptr %9, i32 0, i32 0
  %11 = load i32, ptr %10, align 4, !tbaa !9
  %12 = mul i32 8, %11
  %13 = zext i32 %12 to i64
  call void @llvm.memmove.p0.p0.i64(ptr align 1 %7, ptr align 1 %8, i64 %13, i1 false)
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.interleaver_s, ptr %14, i32 0, i32 3
  %16 = load i32, ptr %15, align 4, !tbaa !12
  %17 = icmp ugt i32 %16, 0
  br i1 %17, label %18, label %30

18:                                               ; preds = %3
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.interleaver_s, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.interleaver_s, ptr %23, i32 0, i32 1
  %25 = load i32, ptr %24, align 4, !tbaa !13
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.interleaver_s, ptr %26, i32 0, i32 2
  %28 = load i32, ptr %27, align 4, !tbaa !14
  %29 = call i32 @interleaver_permute_soft(ptr noundef %19, i32 noundef %22, i32 noundef %25, i32 noundef %28)
  br label %30

30:                                               ; preds = %18, %3
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.interleaver_s, ptr %31, i32 0, i32 3
  %33 = load i32, ptr %32, align 4, !tbaa !12
  %34 = icmp ugt i32 %33, 1
  br i1 %34, label %35, label %48

35:                                               ; preds = %30
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.interleaver_s, ptr %37, i32 0, i32 0
  %39 = load i32, ptr %38, align 4, !tbaa !9
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.interleaver_s, ptr %40, i32 0, i32 1
  %42 = load i32, ptr %41, align 4, !tbaa !13
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.interleaver_s, ptr %43, i32 0, i32 2
  %45 = load i32, ptr %44, align 4, !tbaa !14
  %46 = add i32 %45, 2
  %47 = call i32 @interleaver_permute_mask_soft(ptr noundef %36, i32 noundef %39, i32 noundef %42, i32 noundef %46, i8 noundef zeroext 15)
  br label %48

48:                                               ; preds = %35, %30
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.interleaver_s, ptr %49, i32 0, i32 3
  %51 = load i32, ptr %50, align 4, !tbaa !12
  %52 = icmp ugt i32 %51, 2
  br i1 %52, label %53, label %66

53:                                               ; preds = %48
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.interleaver_s, ptr %55, i32 0, i32 0
  %57 = load i32, ptr %56, align 4, !tbaa !9
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.interleaver_s, ptr %58, i32 0, i32 1
  %60 = load i32, ptr %59, align 4, !tbaa !13
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.interleaver_s, ptr %61, i32 0, i32 2
  %63 = load i32, ptr %62, align 4, !tbaa !14
  %64 = add i32 %63, 4
  %65 = call i32 @interleaver_permute_mask_soft(ptr noundef %54, i32 noundef %57, i32 noundef %60, i32 noundef %64, i8 noundef zeroext 85)
  br label %66

66:                                               ; preds = %53, %48
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.interleaver_s, ptr %67, i32 0, i32 3
  %69 = load i32, ptr %68, align 4, !tbaa !12
  %70 = icmp ugt i32 %69, 3
  br i1 %70, label %71, label %84

71:                                               ; preds = %66
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.interleaver_s, ptr %73, i32 0, i32 0
  %75 = load i32, ptr %74, align 4, !tbaa !9
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.interleaver_s, ptr %76, i32 0, i32 1
  %78 = load i32, ptr %77, align 4, !tbaa !13
  %79 = load ptr, ptr %4, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.interleaver_s, ptr %79, i32 0, i32 2
  %81 = load i32, ptr %80, align 4, !tbaa !14
  %82 = add i32 %81, 8
  %83 = call i32 @interleaver_permute_mask_soft(ptr noundef %72, i32 noundef %75, i32 noundef %78, i32 noundef %82, i8 noundef zeroext 51)
  br label %84

84:                                               ; preds = %71, %66
  ret i32 0
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @interleaver_permute_soft(ptr noundef, i32 noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @interleaver_permute_mask_soft(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i8 noundef zeroext) #1

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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" }

!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, !11, i64 0}
!10 = !{!"interleaver_s", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 12}
!13 = !{!10, !11, i64 4}
!14 = !{!10, !11, i64 8}


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

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @interleaver_encode_soft(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = load i32, ptr %0, align 4, !tbaa !5
  %5 = shl i32 %4, 3
  %6 = zext i32 %5 to i64
  tail call void @llvm.memmove.p0.p0.i64(ptr align 1 %2, ptr align 1 %1, i64 %6, i1 false)
  %7 = getelementptr inbounds i8, ptr %0, i64 12
  %8 = load i32, ptr %7, align 4, !tbaa !10
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %.thread26, label %9

9:                                                ; preds = %3
  %10 = load i32, ptr %0, align 4, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %0, i64 4
  %12 = load i32, ptr %11, align 4, !tbaa !11
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  %14 = load i32, ptr %13, align 4, !tbaa !12
  %15 = tail call i32 @interleaver_permute_soft(ptr noundef %2, i32 noundef %10, i32 noundef %12, i32 noundef %14)
  %.pr = load i32, ptr %7, align 4, !tbaa !10
  %16 = icmp ugt i32 %.pr, 1
  br i1 %16, label %17, label %.thread26

17:                                               ; preds = %9
  %18 = load i32, ptr %0, align 4, !tbaa !5
  %19 = load i32, ptr %11, align 4, !tbaa !11
  %20 = load i32, ptr %13, align 4, !tbaa !12
  %21 = add i32 %20, 2
  %22 = tail call i32 @interleaver_permute_mask_soft(ptr noundef %2, i32 noundef %18, i32 noundef %19, i32 noundef %21, i8 noundef zeroext 15)
  %.pr23 = load i32, ptr %7, align 4, !tbaa !10
  %23 = icmp ugt i32 %.pr23, 2
  br i1 %23, label %.thread24, label %.thread26

.thread24:                                        ; preds = %17
  %24 = load i32, ptr %0, align 4, !tbaa !5
  %25 = load i32, ptr %11, align 4, !tbaa !11
  %26 = load i32, ptr %13, align 4, !tbaa !12
  %27 = add i32 %26, 4
  %28 = tail call i32 @interleaver_permute_mask_soft(ptr noundef %2, i32 noundef %24, i32 noundef %25, i32 noundef %27, i8 noundef zeroext 85)
  %.pr25.pr = load i32, ptr %7, align 4, !tbaa !10
  %29 = icmp ugt i32 %.pr25.pr, 3
  br i1 %29, label %30, label %.thread26

30:                                               ; preds = %.thread24
  %31 = load i32, ptr %0, align 4, !tbaa !5
  %32 = load i32, ptr %11, align 4, !tbaa !11
  %33 = load i32, ptr %13, align 4, !tbaa !12
  %34 = add i32 %33, 8
  %35 = tail call i32 @interleaver_permute_mask_soft(ptr noundef %2, i32 noundef %31, i32 noundef %32, i32 noundef %34, i8 noundef zeroext 51)
  br label %.thread26

.thread26:                                        ; preds = %9, %3, %17, %30, %.thread24
  ret i32 0
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @interleaver_permute_soft(ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @interleaver_permute_mask_soft(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i8 noundef zeroext) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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" }

!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 = !{!"interleaver_s", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 12}
!11 = !{!6, !7, i64 4}
!12 = !{!6, !7, i64 8}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass