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

; Function Attrs: nounwind uwtable
define dso_local i32 @interleaver_decode_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, 3
  br i1 %17, label %18, label %31

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 = add i32 %28, 8
  %30 = call i32 @interleaver_permute_mask_soft(ptr noundef %19, i32 noundef %22, i32 noundef %25, i32 noundef %29, i8 noundef zeroext 51)
  br label %31

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

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

49:                                               ; preds = %36, %31
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.interleaver_s, ptr %50, i32 0, i32 3
  %52 = load i32, ptr %51, align 4, !tbaa !12
  %53 = icmp ugt i32 %52, 1
  br i1 %53, label %54, label %67

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

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

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

84:                                               ; preds = %72, %67
  ret i32 0
}

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @interleaver_decode_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
  %9 = icmp ugt i32 %8, 3
  br i1 %9, label %10, label %18

10:                                               ; preds = %3
  %11 = load i32, ptr %0, align 4, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %0, i64 4
  %13 = load i32, ptr %12, align 4, !tbaa !11
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  %15 = load i32, ptr %14, align 4, !tbaa !12
  %16 = add i32 %15, 8
  %17 = tail call i32 @interleaver_permute_mask_soft(ptr noundef %2, i32 noundef %11, i32 noundef %13, i32 noundef %16, i8 noundef zeroext 51)
  %.pr = load i32, ptr %7, align 4, !tbaa !10
  br label %18

18:                                               ; preds = %10, %3
  %19 = phi i32 [ %.pr, %10 ], [ %8, %3 ]
  %20 = icmp ugt i32 %19, 2
  br i1 %20, label %21, label %29

21:                                               ; preds = %18
  %22 = load i32, ptr %0, align 4, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %0, i64 4
  %24 = load i32, ptr %23, align 4, !tbaa !11
  %25 = getelementptr inbounds i8, ptr %0, i64 8
  %26 = load i32, ptr %25, align 4, !tbaa !12
  %27 = add i32 %26, 4
  %28 = tail call i32 @interleaver_permute_mask_soft(ptr noundef %2, i32 noundef %22, i32 noundef %24, i32 noundef %27, i8 noundef zeroext 85)
  %.pre = load i32, ptr %7, align 4, !tbaa !10
  br label %29

29:                                               ; preds = %21, %18
  %30 = phi i32 [ %.pre, %21 ], [ %19, %18 ]
  %31 = icmp ugt i32 %30, 1
  br i1 %31, label %32, label %40

32:                                               ; preds = %29
  %33 = load i32, ptr %0, align 4, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %0, i64 4
  %35 = load i32, ptr %34, align 4, !tbaa !11
  %36 = getelementptr inbounds i8, ptr %0, i64 8
  %37 = load i32, ptr %36, align 4, !tbaa !12
  %38 = add i32 %37, 2
  %39 = tail call i32 @interleaver_permute_mask_soft(ptr noundef %2, i32 noundef %33, i32 noundef %35, i32 noundef %38, i8 noundef zeroext 15)
  %.pr23 = load i32, ptr %7, align 4, !tbaa !10
  br label %40

40:                                               ; preds = %32, %29
  %41 = phi i32 [ %.pr23, %32 ], [ %30, %29 ]
  %.not = icmp eq i32 %41, 0
  br i1 %.not, label %49, label %42

42:                                               ; preds = %40
  %43 = load i32, ptr %0, align 4, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %0, i64 4
  %45 = load i32, ptr %44, align 4, !tbaa !11
  %46 = getelementptr inbounds i8, ptr %0, i64 8
  %47 = load i32, ptr %46, align 4, !tbaa !12
  %48 = tail call i32 @interleaver_permute_soft(ptr noundef %2, i32 noundef %43, i32 noundef %45, i32 noundef %47)
  br label %49

49:                                               ; preds = %42, %40
  ret i32 0
}

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