; 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: nounwind uwtable
define dso_local i32 @interleaver_encode(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %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 = zext i32 %11 to i64
  call void @llvm.memmove.p0.p0.i64(ptr align 1 %7, ptr align 1 %8, i64 %12, i1 false)
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.interleaver_s, ptr %13, i32 0, i32 3
  %15 = load i32, ptr %14, align 4, !tbaa !12
  %16 = icmp ugt i32 %15, 0
  br i1 %16, label %17, label %29

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

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

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

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

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

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

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

83:                                               ; preds = %70, %65
  ret i32 0
}

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

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

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

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 nounwind willreturn memory(argmem: readwrite) }

!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: nounwind uwtable
define dso_local noundef i32 @interleaver_encode(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = load i32, ptr %0, align 4, !tbaa !5
  %5 = zext i32 %4 to i64
  tail call void @llvm.memmove.p0.p0.i64(ptr align 1 %2, ptr align 1 %1, i64 %5, i1 false)
  %6 = getelementptr inbounds i8, ptr %0, i64 12
  %7 = load i32, ptr %6, align 4, !tbaa !10
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %.thread26, label %8

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

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

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

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

.thread26:                                        ; preds = %8, %3, %16, %29, %.thread24
  ret i32 0
}

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

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

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

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

!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