; 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(ptr noundef, i32 noundef, i32 noundef, i32 noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @interleaver_decode(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 = 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, 3
  br i1 %16, label %17, label %30

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 = add i32 %27, 8
  %29 = call i32 @interleaver_permute_mask(ptr noundef %18, i32 noundef %21, i32 noundef %24, i32 noundef %28, i8 noundef zeroext 51)
  br label %30

30:                                               ; preds = %17, %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, 2
  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, 4
  %47 = call i32 @interleaver_permute_mask(ptr noundef %36, i32 noundef %39, i32 noundef %42, i32 noundef %46, i8 noundef zeroext 85)
  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, 1
  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, 2
  %65 = call i32 @interleaver_permute_mask(ptr noundef %54, i32 noundef %57, i32 noundef %60, i32 noundef %64, i8 noundef zeroext 15)
  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, 0
  br i1 %70, label %71, label %83

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 = call i32 @interleaver_permute(ptr noundef %72, i32 noundef %75, i32 noundef %78, i32 noundef %81)
  br label %83

83:                                               ; preds = %71, %66
  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(ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

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

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

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 = add i32 %14, 8
  %16 = tail call i32 @interleaver_permute_mask(ptr noundef %2, i32 noundef %10, i32 noundef %12, i32 noundef %15, i8 noundef zeroext 51)
  %.pr = load i32, ptr %6, align 4, !tbaa !10
  br label %17

17:                                               ; preds = %9, %3
  %18 = phi i32 [ %.pr, %9 ], [ %7, %3 ]
  %19 = icmp ugt i32 %18, 2
  br i1 %19, label %20, label %28

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

28:                                               ; preds = %20, %17
  %29 = phi i32 [ %.pre, %20 ], [ %18, %17 ]
  %30 = icmp ugt i32 %29, 1
  br i1 %30, label %31, label %39

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

39:                                               ; preds = %31, %28
  %40 = phi i32 [ %.pr23, %31 ], [ %29, %28 ]
  %.not = icmp eq i32 %40, 0
  br i1 %.not, label %48, label %41

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

48:                                               ; preds = %41, %39
  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