#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int uint8_t;

/* Variables and functions */
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ swab(int const *, int *, size_t);
int iec958_build_ac3frame(const uint8_t *src, size_t framesize, uint8_t *dst) {
  dst[0] = 0x72;
  dst[1] = 0xf8;
  dst[2] = 0x1f;
  dst[3] = 0x4e;
  dst[4] = 1;
  if (src == NULL) {
    memset(dst + 5, 0, 6144 - 5);
  } else {
    dst[5] = src[5] & 7;
    swab(src, dst + 8, framesize);
    memset(dst + 8 + framesize, 0, 6144 - framesize - 8);
    framesize *= 8;
    dst[6] = framesize;
    dst[7] = framesize >> 8;
  }
  return 6144 / 4;
}


x86 assembly (clang, -O0):
<iec958_build_ac3frame>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x72,(%rax)
mov    -0x18(%rbp),%rax
movl   $0xf8,0x4(%rax)
mov    -0x18(%rbp),%rax
movl   $0x1f,0x8(%rax)
mov    -0x18(%rbp),%rax
movl   $0x4e,0xc(%rax)
mov    -0x18(%rbp),%rax
movl   $0x1,0x10(%rax)
cmpq   $0x0,-0x8(%rbp)
jne    118e <iec958_build_ac3frame+0x6e>
mov    -0x18(%rbp),%rdi
add    $0x14,%rdi
xor    %esi,%esi
mov    $0x17fb,%edx
call   1040 <memset@plt>
jmp    1207 <iec958_build_ac3frame+0xe7>
mov    -0x8(%rbp),%rax
mov    0x14(%rax),%ecx
and    $0x7,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x14(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x20,%rsi
mov    -0x10(%rbp),%rdx
call   1030 <swab@plt>
mov    -0x18(%rbp),%rdi
add    $0x20,%rdi
mov    -0x10(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    $0x1800,%eax
sub    -0x10(%rbp),%rax
sub    $0x8,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x10(%rbp),%rax
shl    $0x3,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x18(%rax)
mov    -0x10(%rbp),%rax
shr    $0x8,%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x1c(%rax)
mov    $0x600,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iec958_build_ac3frame>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
movaps 0xed2(%rip),%xmm0
movups %xmm0,(%rdx)
movl   $0x1,0x10(%rdx)
test   %rdi,%rdi
je     1181 <iec958_build_ac3frame+0x61>
mov    %rsi,%r14
mov    0x14(%rdi),%eax
and    $0x7,%eax
mov    %eax,0x14(%rbx)
lea    0x20(%rbx),%rsi
mov    %r14,%rdx
call   1030 <swab@plt>
lea    (%rbx,%r14,4),%rdi
add    $0x20,%rdi
mov    $0x17f8,%edx
sub    %r14d,%edx
xor    %esi,%esi
call   1040 <memset@plt>
lea    0x0(,%r14,8),%eax
mov    %eax,0x18(%rbx)
shr    $0x5,%r14
mov    %r14d,0x1c(%rbx)
jmp    1194 <iec958_build_ac3frame+0x74>
add    $0x14,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x17fb,%edx
call   1040 <memset@plt>
mov    $0x600,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @iec958_build_ac3frame(i32* %0, i64 %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i32*
store i32* %0, i32** %4
store i64 %1, i64* %5
store i32* %2, i32** %6
%7 = load i32*, i32** %6
%8 = getelementptr inbounds i32, i32* %7, i64 0
store i32 114, i32* %8
%9 = load i32*, i32** %6
%10 = getelementptr inbounds i32, i32* %9, i64 1
store i32 248, i32* %10
%11 = load i32*, i32** %6
%12 = getelementptr inbounds i32, i32* %11, i64 2
store i32 31, i32* %12
%13 = load i32*, i32** %6
%14 = getelementptr inbounds i32, i32* %13, i64 3
store i32 78, i32* %14
%15 = load i32*, i32** %6
%16 = getelementptr inbounds i32, i32* %15, i64 4
store i32 1, i32* %16
%17 = load i32*, i32** %4
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %23
19: ; preds = %3
%20 = load i32*, i32** %6
%21 = getelementptr inbounds i32, i32* %20, i64 5
%22 = call i32 @memset(i32* %21, i32 0, i32 6139)
br label %55
23: ; preds = %3
%24 = load i32*, i32** %4
%25 = getelementptr inbounds i32, i32* %24, i64 5
%26 = load i32, i32* %25
%27 = and i32 %26, 7
%28 = load i32*, i32** %6
%29 = getelementptr inbounds i32, i32* %28, i64 5
store i32 %27, i32* %29
%30 = load i32*, i32** %4
%31 = load i32*, i32** %6
%32 = getelementptr inbounds i32, i32* %31, i64 8
%33 = load i64, i64* %5
%34 = call i32 @swab(i32* %30, i32* %32, i64 %33)
%35 = load i32*, i32** %6
%36 = getelementptr inbounds i32, i32* %35, i64 8
%37 = load i64, i64* %5
%38 = getelementptr inbounds i32, i32* %36, i64 %37
%39 = load i64, i64* %5
%40 = sub i64 6144, %39
%41 = sub i64 %40, 8
%42 = trunc i64 %41 to i32
%43 = call i32 @memset(i32* %38, i32 0, i32 %42)
%44 = load i64, i64* %5
%45 = mul i64 %44, 8
store i64 %45, i64* %5
%46 = load i64, i64* %5
%47 = trunc i64 %46 to i32
%48 = load i32*, i32** %6
%49 = getelementptr inbounds i32, i32* %48, i64 6
store i32 %47, i32* %49
%50 = load i64, i64* %5
%51 = lshr i64 %50, 8
%52 = trunc i64 %51 to i32
%53 = load i32*, i32** %6
%54 = getelementptr inbounds i32, i32* %53, i64 7
store i32 %52, i32* %54
br label %55
55: ; preds = %23, %19
ret i32 1536
}

LLVM IR (-O2):
define i32 @iec958_build_ac3frame(i32* %0, i64 %1, i32* %2) {
%4 = bitcast i32* %2 to <4 x i32>*
store <4 x i32> <i32 114, i32 248, i32 31, i32 78>, <4 x i32>* %4
%5 = getelementptr inbounds i32, i32* %2, i64 4
store i32 1, i32* %5
%6 = icmp eq i32* %0, null
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = getelementptr inbounds i32, i32* %2, i64 5
%9 = tail call i32 @memset(i32* %8, i32 0, i32 6139)
br label %27
10: ; preds = %3
%11 = getelementptr inbounds i32, i32* %0, i64 5
%12 = load i32, i32* %11
%13 = and i32 %12, 7
%14 = getelementptr inbounds i32, i32* %2, i64 5
store i32 %13, i32* %14
%15 = getelementptr inbounds i32, i32* %2, i64 8
%16 = tail call i32 @swab(i32* %0, i32* %15, i64 %1)
%17 = getelementptr inbounds i32, i32* %15, i64 %1
%18 = trunc i64 %1 to i32
%19 = sub i32 6136, %18
%20 = tail call i32 @memset(i32* %17, i32 0, i32 %19)
%21 = shl i64 %1, 3
%22 = trunc i64 %21 to i32
%23 = getelementptr inbounds i32, i32* %2, i64 6
store i32 %22, i32* %23
%24 = lshr i64 %21, 8
%25 = trunc i64 %24 to i32
%26 = getelementptr inbounds i32, i32* %2, i64 7
store i32 %25, i32* %26
br label %27
27: ; preds = %10, %7
ret i32 1536
}