; LLVM IR from jgaeddert/liquid-dsp :: src/framing/src (gmskframegen)

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @gmskframegen_encode_header(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %16

8:                                                ; preds = %2
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.gmskframegen_s, ptr %9, i32 0, i32 11
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.gmskframegen_s, ptr %12, i32 0, i32 9
  %14 = load i32, ptr %13, align 8, !tbaa !13
  %15 = zext i32 %14 to i64
  call void @llvm.memset.p0.i64(ptr align 1 %11, i8 0, i64 %15, i1 false)
  br label %25

16:                                               ; preds = %2
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.gmskframegen_s, ptr %17, i32 0, i32 11
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.gmskframegen_s, ptr %21, i32 0, i32 9
  %23 = load i32, ptr %22, align 8, !tbaa !13
  %24 = zext i32 %23 to i64
  call void @llvm.memmove.p0.p0.i64(ptr align 1 %19, ptr align 1 %20, i64 %24, i1 false)
  br label %25

25:                                               ; preds = %16, %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.gmskframegen_s, ptr %26, i32 0, i32 9
  %28 = load i32, ptr %27, align 8, !tbaa !13
  store i32 %28, ptr %5, align 4, !tbaa !14
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.gmskframegen_s, ptr %29, i32 0, i32 11
  %31 = load ptr, ptr %30, align 8, !tbaa !9
  %32 = load i32, ptr %5, align 4, !tbaa !14
  %33 = add i32 %32, 0
  %34 = zext i32 %33 to i64
  %35 = getelementptr inbounds i8, ptr %31, i64 %34
  store i8 4, ptr %35, align 1, !tbaa !15
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.gmskframegen_s, ptr %36, i32 0, i32 18
  %38 = load i32, ptr %37, align 4, !tbaa !16
  %39 = lshr i32 %38, 8
  %40 = and i32 %39, 255
  %41 = trunc i32 %40 to i8
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.gmskframegen_s, ptr %42, i32 0, i32 11
  %44 = load ptr, ptr %43, align 8, !tbaa !9
  %45 = load i32, ptr %5, align 4, !tbaa !14
  %46 = add i32 %45, 1
  %47 = zext i32 %46 to i64
  %48 = getelementptr inbounds i8, ptr %44, i64 %47
  store i8 %41, ptr %48, align 1, !tbaa !15
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.gmskframegen_s, ptr %49, i32 0, i32 18
  %51 = load i32, ptr %50, align 4, !tbaa !16
  %52 = and i32 %51, 255
  %53 = trunc i32 %52 to i8
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.gmskframegen_s, ptr %54, i32 0, i32 11
  %56 = load ptr, ptr %55, align 8, !tbaa !9
  %57 = load i32, ptr %5, align 4, !tbaa !14
  %58 = add i32 %57, 2
  %59 = zext i32 %58 to i64
  %60 = getelementptr inbounds i8, ptr %56, i64 %59
  store i8 %53, ptr %60, align 1, !tbaa !15
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.gmskframegen_s, ptr %61, i32 0, i32 15
  %63 = load i32, ptr %62, align 8, !tbaa !17
  %64 = and i32 %63, 7
  %65 = shl i32 %64, 5
  %66 = trunc i32 %65 to i8
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.gmskframegen_s, ptr %67, i32 0, i32 11
  %69 = load ptr, ptr %68, align 8, !tbaa !9
  %70 = load i32, ptr %5, align 4, !tbaa !14
  %71 = add i32 %70, 3
  %72 = zext i32 %71 to i64
  %73 = getelementptr inbounds i8, ptr %69, i64 %72
  store i8 %66, ptr %73, align 1, !tbaa !15
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.gmskframegen_s, ptr %74, i32 0, i32 16
  %76 = load i32, ptr %75, align 4, !tbaa !18
  %77 = and i32 %76, 31
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.gmskframegen_s, ptr %78, i32 0, i32 11
  %80 = load ptr, ptr %79, align 8, !tbaa !9
  %81 = load i32, ptr %5, align 4, !tbaa !14
  %82 = add i32 %81, 3
  %83 = zext i32 %82 to i64
  %84 = getelementptr inbounds i8, ptr %80, i64 %83
  %85 = load i8, ptr %84, align 1, !tbaa !15
  %86 = zext i8 %85 to i32
  %87 = or i32 %86, %77
  %88 = trunc i32 %87 to i8
  store i8 %88, ptr %84, align 1, !tbaa !15
  %89 = load ptr, ptr %3, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.gmskframegen_s, ptr %89, i32 0, i32 17
  %91 = load i32, ptr %90, align 8, !tbaa !19
  %92 = and i32 %91, 31
  %93 = trunc i32 %92 to i8
  %94 = load ptr, ptr %3, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.gmskframegen_s, ptr %94, i32 0, i32 11
  %96 = load ptr, ptr %95, align 8, !tbaa !9
  %97 = load i32, ptr %5, align 4, !tbaa !14
  %98 = add i32 %97, 4
  %99 = zext i32 %98 to i64
  %100 = getelementptr inbounds i8, ptr %96, i64 %99
  store i8 %93, ptr %100, align 1, !tbaa !15
  %101 = load ptr, ptr %3, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.gmskframegen_s, ptr %101, i32 0, i32 13
  %103 = load ptr, ptr %102, align 8, !tbaa !20
  %104 = load ptr, ptr %3, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.gmskframegen_s, ptr %104, i32 0, i32 11
  %106 = load ptr, ptr %105, align 8, !tbaa !9
  %107 = load ptr, ptr %3, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.gmskframegen_s, ptr %107, i32 0, i32 12
  %109 = load ptr, ptr %108, align 8, !tbaa !21
  %110 = call i32 @packetizer_encode(ptr noundef %103, ptr noundef %106, ptr noundef %109)
  %111 = load ptr, ptr %3, align 8, !tbaa !5
  %112 = getelementptr inbounds %struct.gmskframegen_s, ptr %111, i32 0, i32 12
  %113 = load ptr, ptr %112, align 8, !tbaa !21
  %114 = load ptr, ptr %3, align 8, !tbaa !5
  %115 = getelementptr inbounds %struct.gmskframegen_s, ptr %114, i32 0, i32 10
  %116 = load i32, ptr %115, align 4, !tbaa !22
  call void @scramble_data(ptr noundef %113, i32 noundef %116)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  ret i32 0
}

declare i32 @packetizer_encode(ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

declare void @scramble_data(ptr noundef, i32 noundef) #2

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

!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, !6, i64 56}
!10 = !{!"gmskframegen_s", !6, i64 0, !11, i64 8, !11, i64 12, !12, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !6, i64 40, !11, i64 48, !11, i64 52, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !11, i64 88, !11, i64 92, !11, i64 96, !11, i64 100, !11, i64 104, !6, i64 112, !11, i64 120, !11, i64 124, !11, i64 128, !11, i64 132, !6, i64 136, !11, i64 144}
!11 = !{!"int", !7, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!10, !11, i64 48}
!14 = !{!11, !11, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{!10, !11, i64 100}
!17 = !{!10, !11, i64 88}
!18 = !{!10, !11, i64 92}
!19 = !{!10, !11, i64 96}
!20 = !{!10, !6, i64 72}
!21 = !{!10, !6, i64 64}
!22 = !{!10, !11, i64 52}


; 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 @gmskframegen_encode_header(ptr nocapture noundef readonly %0, ptr noundef readonly %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %1, null
  %4 = getelementptr inbounds i8, ptr %0, i64 56
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 48
  %7 = load i32, ptr %6, align 8, !tbaa !12
  %8 = zext i32 %7 to i64
  br i1 %3, label %9, label %10

9:                                                ; preds = %2
  tail call void @llvm.memset.p0.i64(ptr align 1 %5, i8 0, i64 %8, i1 false)
  br label %11

10:                                               ; preds = %2
  tail call void @llvm.memmove.p0.p0.i64(ptr align 1 %5, ptr nonnull align 1 %1, i64 %8, i1 false)
  br label %11

11:                                               ; preds = %10, %9
  %12 = getelementptr inbounds i8, ptr %0, i64 48
  %13 = load i32, ptr %12, align 8, !tbaa !12
  %14 = getelementptr inbounds i8, ptr %0, i64 56
  %15 = load ptr, ptr %14, align 8, !tbaa !5
  %16 = zext i32 %13 to i64
  %17 = getelementptr inbounds i8, ptr %15, i64 %16
  store i8 4, ptr %17, align 1, !tbaa !13
  %18 = getelementptr inbounds i8, ptr %0, i64 100
  %19 = load i32, ptr %18, align 4, !tbaa !14
  %20 = lshr i32 %19, 8
  %21 = trunc i32 %20 to i8
  %22 = load ptr, ptr %14, align 8, !tbaa !5
  %23 = add i32 %13, 1
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds i8, ptr %22, i64 %24
  store i8 %21, ptr %25, align 1, !tbaa !13
  %26 = load i32, ptr %18, align 4, !tbaa !14
  %27 = trunc i32 %26 to i8
  %28 = load ptr, ptr %14, align 8, !tbaa !5
  %29 = add i32 %13, 2
  %30 = zext i32 %29 to i64
  %31 = getelementptr inbounds i8, ptr %28, i64 %30
  store i8 %27, ptr %31, align 1, !tbaa !13
  %32 = getelementptr inbounds i8, ptr %0, i64 88
  %33 = load i32, ptr %32, align 8, !tbaa !15
  %.tr = trunc i32 %33 to i8
  %34 = shl i8 %.tr, 5
  %35 = load ptr, ptr %14, align 8, !tbaa !5
  %36 = add i32 %13, 3
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds i8, ptr %35, i64 %37
  store i8 %34, ptr %38, align 1, !tbaa !13
  %39 = getelementptr inbounds i8, ptr %0, i64 92
  %40 = load i32, ptr %39, align 4, !tbaa !16
  %41 = load ptr, ptr %14, align 8, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %41, i64 %37
  %43 = load i8, ptr %42, align 1, !tbaa !13
  %44 = trunc i32 %40 to i8
  %45 = and i8 %44, 31
  %46 = or i8 %45, %43
  store i8 %46, ptr %42, align 1, !tbaa !13
  %47 = getelementptr inbounds i8, ptr %0, i64 96
  %48 = load i32, ptr %47, align 8, !tbaa !17
  %49 = trunc i32 %48 to i8
  %50 = and i8 %49, 31
  %51 = load ptr, ptr %14, align 8, !tbaa !5
  %52 = add i32 %13, 4
  %53 = zext i32 %52 to i64
  %54 = getelementptr inbounds i8, ptr %51, i64 %53
  store i8 %50, ptr %54, align 1, !tbaa !13
  %55 = getelementptr inbounds i8, ptr %0, i64 72
  %56 = load ptr, ptr %55, align 8, !tbaa !18
  %57 = load ptr, ptr %14, align 8, !tbaa !5
  %58 = getelementptr inbounds i8, ptr %0, i64 64
  %59 = load ptr, ptr %58, align 8, !tbaa !19
  %60 = tail call i32 @packetizer_encode(ptr noundef %56, ptr noundef %57, ptr noundef %59) #4
  %61 = load ptr, ptr %58, align 8, !tbaa !19
  %62 = getelementptr inbounds i8, ptr %0, i64 52
  %63 = load i32, ptr %62, align 4, !tbaa !20
  tail call void @scramble_data(ptr noundef %61, i32 noundef %63) #4
  ret i32 0
}

declare i32 @packetizer_encode(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

declare void @scramble_data(ptr noundef, i32 noundef) local_unnamed_addr #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 = { "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 nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind }

!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 56}
!6 = !{!"gmskframegen_s", !7, i64 0, !10, i64 8, !10, i64 12, !11, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !7, i64 40, !10, i64 48, !10, i64 52, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !10, i64 88, !10, i64 92, !10, i64 96, !10, i64 100, !10, i64 104, !7, i64 112, !10, i64 120, !10, i64 124, !10, i64 128, !10, i64 132, !7, i64 136, !10, i64 144}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"float", !8, i64 0}
!12 = !{!6, !10, i64 48}
!13 = !{!8, !8, i64 0}
!14 = !{!6, !10, i64 100}
!15 = !{!6, !10, i64 88}
!16 = !{!6, !10, i64 92}
!17 = !{!6, !10, i64 96}
!18 = !{!6, !7, i64 72}
!19 = !{!6, !7, i64 64}
!20 = !{!6, !10, i64 52}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass