#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;
typedef int /*<<< orphan*/ uint64_t;
typedef int /*<<< orphan*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ memcpy(int *, int *, int);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int write_ps_header(int *, int /*<<< orphan*/, int /*<<< orphan*/, int,
                    int /*<<< orphan*/, int /*<<< orphan*/, int, int, int, int);
int write_nav_pack(int pack_size, int apidn, int ac3n, uint64_t SCR,
                   uint32_t muxr, uint8_t *buf) {
  int pos = 0;
  uint8_t headr[5] = {0x00, 0x00, 0x01, 0xBF, 0x03};
  pos = write_ps_header(buf, SCR, muxr, apidn + ac3n, 0, 0, 1, 1, 1, 1);
  memcpy(buf + pos, headr, 5);
  buf[pos + 5] = 0xD4;
  pos += 6;
  memset(buf + pos, 0, 0x03d4);
  pos += 0x03d4;
  memcpy(buf + pos, headr, 5);
  buf[pos + 5] = 0xFA;
  pos += 6;
  memset(buf + pos, 0, 0x03fA);
  pos += 0x03fA;
  return pos;
}


x86 assembly (clang, -O0):
<write_nav_pack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8d,-0x14(%rbp)
mov    %r9,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    0xea6(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xea3(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xea1(%rip),%eax
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%ecx
add    -0xc(%rbp),%ecx
xor    %r9d,%r9d
mov    %r9d,%r8d
movl   $0x1,(%rsp)
movl   $0x1,0x8(%rsp)
movl   $0x1,0x10(%rsp)
movl   $0x1,0x18(%rsp)
call   1050 <write_ps_header@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
lea    -0x40(%rbp),%rsi
mov    $0x5,%edx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x5,%ecx
movslq %ecx,%rcx
movl   $0xd4,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x6,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
xor    %esi,%esi
mov    $0x3d4,%edx
call   1030 <memset@plt>
mov    -0x24(%rbp),%eax
add    $0x3d4,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
lea    -0x40(%rbp),%rsi
mov    $0x5,%edx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x5,%ecx
movslq %ecx,%rcx
movl   $0xfa,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x6,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
xor    %esi,%esi
mov    $0x3fa,%edx
call   1030 <memset@plt>
mov    -0x24(%rbp),%eax
add    $0x3fa,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_nav_pack>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %r9,%r14
mov    0xece(%rip),%eax
mov    %eax,0x10(%rsp)
movaps 0xeb3(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    (%rsi,%rdx,1),%eax
mov    %r9,%rdi
mov    %ecx,%esi
mov    %r8d,%edx
mov    %eax,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
push   $0x1
push   $0x1
push   $0x1
push   $0x1
call   1050 <write_ps_header@plt>
add    $0x20,%rsp
movslq %eax,%rbx
lea    (%r14,%rbx,4),%rdi
mov    %rsp,%r15
mov    %r15,%rsi
mov    $0x5,%edx
call   1040 <memcpy@plt>
movl   $0xd4,0x14(%r14,%rbx,4)
lea    (%r14,%rbx,4),%rdi
add    $0x18,%rdi
xor    %esi,%esi
mov    $0x3d4,%edx
call   1030 <memset@plt>
lea    (%r14,%rbx,4),%rdi
add    $0xf68,%rdi
mov    %r15,%rsi
mov    $0x5,%edx
call   1040 <memcpy@plt>
movl   $0xfa,0xf7c(%r14,%rbx,4)
lea    (%r14,%rbx,4),%rdi
add    $0xf80,%rdi
xor    %esi,%esi
mov    $0x3fa,%edx
call   1030 <memset@plt>
add    $0x7da,%ebx
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.write_nav_pack.headr = [5 x i32] [i32 0, i32 0, i32 1, i32 191, i32 3]
define i32 @write_nav_pack(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32
%14 = alloca [5 x i32]
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32* %5, i32** %12
store i32 0, i32* %13
%15 = bitcast [5 x i32]* %14 to i8*
%16 = load i32*, i32** %12
%17 = load i32, i32* %10
%18 = load i32, i32* %11
%19 = load i32, i32* %8
%20 = load i32, i32* %9
%21 = add nsw i32 %19, %20
%22 = call i32 @write_ps_header(i32* %16, i32 %17, i32 %18, i32 %21, i32 0, i32 0, i32 1, i32 1, i32 1, i32 1)
store i32 %22, i32* %13
%23 = load i32*, i32** %12
%24 = load i32, i32* %13
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = getelementptr inbounds [5 x i32], [5 x i32]* %14, i64 0, i64 0
%28 = call i32 @memcpy(i32* %26, i32* %27, i32 5)
%29 = load i32*, i32** %12
%30 = load i32, i32* %13
%31 = add nsw i32 %30, 5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %29, i64 %32
store i32 212, i32* %33
%34 = load i32, i32* %13
%35 = add nsw i32 %34, 6
store i32 %35, i32* %13
%36 = load i32*, i32** %12
%37 = load i32, i32* %13
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %36, i64 %38
%40 = call i32 @memset(i32* %39, i32 0, i32 980)
%41 = load i32, i32* %13
%42 = add nsw i32 %41, 980
store i32 %42, i32* %13
%43 = load i32*, i32** %12
%44 = load i32, i32* %13
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %43, i64 %45
%47 = getelementptr inbounds [5 x i32], [5 x i32]* %14, i64 0, i64 0
%48 = call i32 @memcpy(i32* %46, i32* %47, i32 5)
%49 = load i32*, i32** %12
%50 = load i32, i32* %13
%51 = add nsw i32 %50, 5
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i32, i32* %49, i64 %52
store i32 250, i32* %53
%54 = load i32, i32* %13
%55 = add nsw i32 %54, 6
store i32 %55, i32* %13
%56 = load i32*, i32** %12
%57 = load i32, i32* %13
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i32, i32* %56, i64 %58
%60 = call i32 @memset(i32* %59, i32 0, i32 1018)
%61 = load i32, i32* %13
%62 = add nsw i32 %61, 1018
store i32 %62, i32* %13
%63 = load i32, i32* %13
ret i32 %63
}

LLVM IR (-O2):
@__const.write_nav_pack.headr = [5 x i32] [i32 0, i32 0, i32 1, i32 191, i32 3]
define i32 @write_nav_pack(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32* %5) {
%7 = alloca [5 x i32]
%8 = bitcast [5 x i32]* %7 to i8*
%9 = add nsw i32 %2, %1
%10 = tail call i32 @write_ps_header(i32* %5, i32 %3, i32 %4, i32 %9, i32 0, i32 0, i32 1, i32 1, i32 1, i32 1)
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i32, i32* %5, i64 %11
%13 = getelementptr inbounds [5 x i32], [5 x i32]* %7, i64 0, i64 0
%14 = call i32 @memcpy(i32* %12, i32* %13, i32 5)
%15 = add nsw i32 %10, 5
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i32, i32* %5, i64 %16
store i32 212, i32* %17
%18 = add nsw i32 %10, 6
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %5, i64 %19
%21 = call i32 @memset(i32* %20, i32 0, i32 980)
%22 = add nsw i32 %10, 986
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %5, i64 %23
%25 = call i32 @memcpy(i32* %24, i32* %13, i32 5)
%26 = add nsw i32 %10, 991
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %5, i64 %27
store i32 250, i32* %28
%29 = add nsw i32 %10, 992
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %5, i64 %30
%32 = call i32 @memset(i32* %31, i32 0, i32 1018)
%33 = add nsw i32 %10, 2010
ret i32 %33
}