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

/* Variables and functions */
scalar_t__ pes_has_dts(int *);
void pes_set_pts(uint8_t *p_pes, uint64_t i_pts) {
  p_pes[7] |= 0x80;
  if (p_pes[8] < 5)
    p_pes[8] = 5;
  uint8_t marker = pes_has_dts(p_pes) ? 0x30 : 0x20;
  p_pes[9] = marker | 0x1 | ((i_pts >> 29) & 0xe);
  p_pes[10] = (i_pts >> 22) & 0xff;
  p_pes[11] = 0x1 | ((i_pts >> 14) & 0xfe);
  p_pes[12] = (i_pts >> 7) & 0xff;
  p_pes[13] = 0x1 | ((i_pts << 1) & 0xfe);
}


x86 assembly (clang, -O0):
<pes_set_pts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    0x1c(%rax),%ecx
or     $0x80,%ecx
mov    %ecx,0x1c(%rax)
mov    -0x8(%rbp),%rax
cmpl   $0x5,0x20(%rax)
jge    1148 <pes_set_pts+0x38>
mov    -0x8(%rbp),%rax
movl   $0x5,0x20(%rax)
mov    -0x8(%rbp),%rdi
call   1030 <pes_has_dts@plt>
mov    %rax,%rdx
mov    $0x20,%eax
mov    $0x30,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%ecx
or     $0x1,%ecx
mov    -0xc(%rbp),%eax
sar    $0x1d,%eax
and    $0xe,%eax
or     %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x24(%rax)
mov    -0xc(%rbp),%ecx
sar    $0x16,%ecx
and    $0xff,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x28(%rax)
mov    -0xc(%rbp),%ecx
sar    $0xe,%ecx
and    $0xfe,%ecx
or     $0x1,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x2c(%rax)
mov    -0xc(%rbp),%ecx
sar    $0x7,%ecx
and    $0xff,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x30(%rax)
mov    -0xc(%rbp),%ecx
shl    $0x1,%ecx
and    $0xfe,%ecx
or     $0x1,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x34(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pes_set_pts>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
orb    $0x80,0x1c(%rdi)
mov    %esi,%r14d
cmpl   $0x4,0x20(%rdi)
jg     112b <pes_set_pts+0x1b>
movl   $0x5,0x20(%rbx)
mov    %rbx,%rdi
call   1030 <pes_has_dts@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
shl    $0x4,%ecx
mov    %r14d,%eax
sar    $0x1d,%eax
and    $0xe,%eax
add    %ecx,%eax
add    $0x21,%eax
mov    %eax,0x24(%rbx)
mov    %r14d,%eax
shr    $0x16,%eax
movzbl %al,%eax
mov    %eax,0x28(%rbx)
mov    %r14d,%eax
shr    $0xe,%eax
or     $0x1,%eax
movzbl %al,%eax
mov    %eax,0x2c(%rbx)
mov    %r14d,%eax
shr    $0x7,%eax
movzbl %al,%eax
mov    %eax,0x30(%rbx)
lea    (%r14,%r14,1),%eax
add    $0x1,%eax
movzbl %al,%eax
mov    %eax,0x34(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @pes_set_pts(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%6 = load i32*, i32** %3
%7 = getelementptr inbounds i32, i32* %6, i64 7
%8 = load i32, i32* %7
%9 = or i32 %8, 128
store i32 %9, i32* %7
%10 = load i32*, i32** %3
%11 = getelementptr inbounds i32, i32* %10, i64 8
%12 = load i32, i32* %11
%13 = icmp slt i32 %12, 5
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i32*, i32** %3
%16 = getelementptr inbounds i32, i32* %15, i64 8
store i32 5, i32* %16
br label %17
17: ; preds = %14, %2
%18 = load i32*, i32** %3
%19 = call i64 @pes_has_dts(i32* %18)
%20 = icmp ne i64 %19, 0
%21 = zext i1 %20 to i64
%22 = select i1 %20, i32 48, i32 32
store i32 %22, i32* %5
%23 = load i32, i32* %5
%24 = or i32 %23, 1
%25 = load i32, i32* %4
%26 = ashr i32 %25, 29
%27 = and i32 %26, 14
%28 = or i32 %24, %27
%29 = load i32*, i32** %3
%30 = getelementptr inbounds i32, i32* %29, i64 9
store i32 %28, i32* %30
%31 = load i32, i32* %4
%32 = ashr i32 %31, 22
%33 = and i32 %32, 255
%34 = load i32*, i32** %3
%35 = getelementptr inbounds i32, i32* %34, i64 10
store i32 %33, i32* %35
%36 = load i32, i32* %4
%37 = ashr i32 %36, 14
%38 = and i32 %37, 254
%39 = or i32 1, %38
%40 = load i32*, i32** %3
%41 = getelementptr inbounds i32, i32* %40, i64 11
store i32 %39, i32* %41
%42 = load i32, i32* %4
%43 = ashr i32 %42, 7
%44 = and i32 %43, 255
%45 = load i32*, i32** %3
%46 = getelementptr inbounds i32, i32* %45, i64 12
store i32 %44, i32* %46
%47 = load i32, i32* %4
%48 = shl i32 %47, 1
%49 = and i32 %48, 254
%50 = or i32 1, %49
%51 = load i32*, i32** %3
%52 = getelementptr inbounds i32, i32* %51, i64 13
store i32 %50, i32* %52
ret void
}

LLVM IR (-O2):
define void @pes_set_pts(i32* %0, i32 %1) {
%3 = getelementptr inbounds i32, i32* %0, i64 7
%4 = load i32, i32* %3
%5 = or i32 %4, 128
store i32 %5, i32* %3
%6 = getelementptr inbounds i32, i32* %0, i64 8
%7 = load i32, i32* %6
%8 = icmp slt i32 %7, 5
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 5, i32* %6
br label %10
10: ; preds = %9, %2
%11 = tail call i64 @pes_has_dts(i32* %0)
%12 = icmp eq i64 %11, 0
%13 = select i1 %12, i32 33, i32 49
%14 = ashr i32 %1, 29
%15 = and i32 %14, 14
%16 = or i32 %13, %15
%17 = getelementptr inbounds i32, i32* %0, i64 9
store i32 %16, i32* %17
%18 = lshr i32 %1, 22
%19 = and i32 %18, 255
%20 = getelementptr inbounds i32, i32* %0, i64 10
store i32 %19, i32* %20
%21 = lshr i32 %1, 14
%22 = and i32 %21, 254
%23 = or i32 %22, 1
%24 = getelementptr inbounds i32, i32* %0, i64 11
store i32 %23, i32* %24
%25 = lshr i32 %1, 7
%26 = and i32 %25, 255
%27 = getelementptr inbounds i32, i32* %0, i64 12
store i32 %26, i32* %27
%28 = shl i32 %1, 1
%29 = and i32 %28, 254
%30 = or i32 %29, 1
%31 = getelementptr inbounds i32, i32* %0, i64 13
store i32 %30, i32* %31
ret void
}