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

/* Variables and functions */
scalar_t__ write_pes_header(int, int, int /*<<< orphan*/, int /*<<< orphan*/,
                            int /*<<< orphan*/ *, int /*<<< orphan*/,
                            int /*<<< orphan*/);
int write_ps_header(int /*<<< orphan*/ *, int /*<<< orphan*/,
                    int /*<<< orphan*/, int, int /*<<< orphan*/,
                    int /*<<< orphan*/, int, int, int, int /*<<< orphan*/);
void write_padding_pes(int pack_size, int apidn, int ac3n, uint64_t SCR,
                       uint64_t muxr, uint8_t *buf) {
  int pos = 0;
  pos = write_ps_header(buf, SCR, muxr, apidn + ac3n, 0, 0, 1, 1, 1, 0);
  pos += write_pes_header(0xBE, pack_size - pos, 0, 0, buf + pos, 0, 0);
}


x86 assembly (clang, -O0):
<write_padding_pes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%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    -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   $0x0,0x18(%rsp)
call   1040 <write_ps_header@plt>
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%esi
sub    -0x24(%rbp),%esi
mov    -0x20(%rbp),%r8
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
add    %rax,%r8
mov    $0xbe,%edi
xor    %r9d,%r9d
mov    %r9d,%edx
mov    %r9d,%ecx
movl   $0x0,(%rsp)
call   1030 <write_pes_header@plt>
mov    %rax,%rcx
movslq -0x24(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x24(%rbp)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_padding_pes>:
push   %rbp
push   %rbx
push   %rax
mov    %r9,%rbx
mov    %edi,%ebp
lea    (%rsi,%rdx,1),%eax
mov    %r9,%rdi
mov    %ecx,%esi
mov    %r8d,%edx
mov    %eax,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
push   $0x0
push   $0x1
push   $0x1
push   $0x1
call   1040 <write_ps_header@plt>
add    $0x20,%rsp
sub    %eax,%ebp
cltq
lea    (%rbx,%rax,4),%r8
sub    $0x8,%rsp
mov    $0xbe,%edi
mov    %ebp,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r9d,%r9d
push   $0x0
call   1030 <write_pes_header@plt>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @write_padding_pes(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
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
%14 = load i32*, i32** %12
%15 = load i32, i32* %10
%16 = load i32, i32* %11
%17 = load i32, i32* %8
%18 = load i32, i32* %9
%19 = add nsw i32 %17, %18
%20 = call i32 @write_ps_header(i32* %14, i32 %15, i32 %16, i32 %19, i32 0, i32 0, i32 1, i32 1, i32 1, i32 0)
store i32 %20, i32* %13
%21 = load i32, i32* %7
%22 = load i32, i32* %13
%23 = sub nsw i32 %21, %22
%24 = load i32*, i32** %12
%25 = load i32, i32* %13
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
%28 = call i64 @write_pes_header(i32 190, i32 %23, i32 0, i32 0, i32* %27, i32 0, i32 0)
%29 = load i32, i32* %13
%30 = sext i32 %29 to i64
%31 = add nsw i64 %30, %28
%32 = trunc i64 %31 to i32
store i32 %32, i32* %13
ret void
}

LLVM IR (-O2):
define void @write_padding_pes(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32* %5) {
%7 = add nsw i32 %2, %1
%8 = tail call i32 @write_ps_header(i32* %5, i32 %3, i32 %4, i32 %7, i32 0, i32 0, i32 1, i32 1, i32 1, i32 0)
%9 = sub nsw i32 %0, %8
%10 = sext i32 %8 to i64
%11 = getelementptr inbounds i32, i32* %5, i64 %10
%12 = tail call i64 @write_pes_header(i32 190, i32 %9, i32 0, i32 0, i32* %11, i32 0, i32 0)
ret void
}