#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 */
void ts_encode_pts_dts(uint8_t *data, int guard, uint64_t value) {
  while (value > 0x1FFFFFFFFLL)
    value -= 0x1FFFFFFFFLL;
  unsigned int pts1 = (unsigned int)((value >> 30) & 0x07);
  unsigned int pts2 = (unsigned int)((value >> 15) & 0x7FFF);
  unsigned int pts3 = (unsigned int)(value & 0x7FFF);
  data[0] = (guard << 4) | (pts1 << 1) | 0x01;
  data[1] = (pts2 & 0x7F80) >> 7;
  data[2] = ((pts2 & 0x007F) << 1) | 0x01;
  data[3] = (pts3 & 0x7F80) >> 7;
  data[4] = ((pts3 & 0x007F) << 1) | 0x01;
}


x86 assembly (clang, -O0):
<ts_encode_pts_dts>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movslq -0x10(%rbp),%rax
movabs $0x1ffffffff,%rcx
cmp    %rcx,%rax
jle    113e <ts_encode_pts_dts+0x3e>
movslq -0x10(%rbp),%rax
movabs $0x1ffffffff,%rcx
sub    %rcx,%rax
mov    %eax,-0x10(%rbp)
jmp    110e <ts_encode_pts_dts+0xe>
mov    -0x10(%rbp),%eax
sar    $0x1e,%eax
and    $0x7,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
sar    $0xf,%eax
and    $0x7fff,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
and    $0x7fff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%ecx
shl    $0x4,%ecx
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
or     %eax,%ecx
or     $0x1,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%ecx
and    $0x7f80,%ecx
shr    $0x7,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x18(%rbp),%ecx
and    $0x7f,%ecx
shl    $0x1,%ecx
or     $0x1,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x1c(%rbp),%ecx
and    $0x7f80,%ecx
shr    $0x7,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0xc(%rax)
mov    -0x1c(%rbp),%ecx
and    $0x7f,%ecx
shl    $0x1,%ecx
or     $0x1,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x10(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<ts_encode_pts_dts>:
shl    $0x4,%esi
mov    %edx,%r8d
mov    %edx,%ecx
mov    %edx,%eax
lea    (%rdx,%rdx,1),%r9d
add    $0x1,%r9d
sar    $0x1d,%edx
and    $0xe,%edx
add    %esi,%edx
add    $0x1,%edx
mov    %edx,(%rdi)
shr    $0x16,%r8d
movzbl %r8b,%edx
mov    %edx,0x4(%rdi)
shr    $0xe,%ecx
or     $0x1,%ecx
movzbl %cl,%ecx
mov    %ecx,0x8(%rdi)
shr    $0x7,%eax
movzbl %al,%eax
mov    %eax,0xc(%rdi)
movzbl %r9b,%eax
mov    %eax,0x10(%rdi)
ret

LLVM IR (-O0):
define void @ts_encode_pts_dts(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
br label %10
10: ; preds = %14, %3
%11 = load i32, i32* %6
%12 = sext i32 %11 to i64
%13 = icmp sgt i64 %12, 8589934591
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = sub nsw i64 %16, 8589934591
%18 = trunc i64 %17 to i32
store i32 %18, i32* %6
br label %10
19: ; preds = %10
%20 = load i32, i32* %6
%21 = ashr i32 %20, 30
%22 = and i32 %21, 7
store i32 %22, i32* %7
%23 = load i32, i32* %6
%24 = ashr i32 %23, 15
%25 = and i32 %24, 32767
store i32 %25, i32* %8
%26 = load i32, i32* %6
%27 = and i32 %26, 32767
store i32 %27, i32* %9
%28 = load i32, i32* %5
%29 = shl i32 %28, 4
%30 = load i32, i32* %7
%31 = shl i32 %30, 1
%32 = or i32 %29, %31
%33 = or i32 %32, 1
%34 = load i32*, i32** %4
%35 = getelementptr inbounds i32, i32* %34, i64 0
store i32 %33, i32* %35
%36 = load i32, i32* %8
%37 = and i32 %36, 32640
%38 = lshr i32 %37, 7
%39 = load i32*, i32** %4
%40 = getelementptr inbounds i32, i32* %39, i64 1
store i32 %38, i32* %40
%41 = load i32, i32* %8
%42 = and i32 %41, 127
%43 = shl i32 %42, 1
%44 = or i32 %43, 1
%45 = load i32*, i32** %4
%46 = getelementptr inbounds i32, i32* %45, i64 2
store i32 %44, i32* %46
%47 = load i32, i32* %9
%48 = and i32 %47, 32640
%49 = lshr i32 %48, 7
%50 = load i32*, i32** %4
%51 = getelementptr inbounds i32, i32* %50, i64 3
store i32 %49, i32* %51
%52 = load i32, i32* %9
%53 = and i32 %52, 127
%54 = shl i32 %53, 1
%55 = or i32 %54, 1
%56 = load i32*, i32** %4
%57 = getelementptr inbounds i32, i32* %56, i64 4
store i32 %55, i32* %57
ret void
}

LLVM IR (-O2):
define void @ts_encode_pts_dts(i32* nocapture writeonly %0, i32 %1, i32 %2) {
%4 = shl i32 %1, 4
%5 = ashr i32 %2, 29
%6 = and i32 %5, 14
%7 = or i32 %6, %4
%8 = or i32 %7, 1
store i32 %8, i32* %0
%9 = lshr i32 %2, 22
%10 = and i32 %9, 255
%11 = getelementptr inbounds i32, i32* %0, i64 1
store i32 %10, i32* %11
%12 = lshr i32 %2, 14
%13 = and i32 %12, 254
%14 = or i32 %13, 1
%15 = getelementptr inbounds i32, i32* %0, i64 2
store i32 %14, i32* %15
%16 = lshr i32 %2, 7
%17 = and i32 %16, 255
%18 = getelementptr inbounds i32, i32* %0, i64 3
store i32 %17, i32* %18
%19 = shl i32 %2, 1
%20 = and i32 %19, 254
%21 = or i32 %20, 1
%22 = getelementptr inbounds i32, i32* %0, i64 4
store i32 %21, i32* %22
ret void
}