#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*/ v_short;
typedef int /*<<< orphan*/ v_long;
typedef int /*<<< orphan*/ v_byte;

/* Variables and functions */
int read(int, ...);
unsigned long read_marker_and_time(int fd, int *setp, int *errorp) {
  unsigned char v_byte;
  unsigned short v_short;
  unsigned long v_long;
  *errorp = *setp = 0;
read_long:
  *errorp = read(fd, &v_byte, sizeof(v_byte));
  if (*errorp <= 0)
    return 0;
  switch (v_byte) {
  case 0xf8:
    *setp = 1;
    goto read_long;
  case 0xfe:
    *errorp = read(fd, &v_short, sizeof(v_short));
    return v_short;
  case 0xff:
    *errorp = read(fd, &v_long, sizeof(v_long));
    return v_long;
  default:
    return v_byte;
  }
}


x86 assembly (clang, -O0):
<read_marker_and_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0xc(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1030 <read@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
jg     116c <read_marker_and_time+0x5c>
movq   $0x0,-0x8(%rbp)
jmp    1210 <read_marker_and_time+0x100>
movzbl -0x21(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0xf8,%eax
je     11a9 <read_marker_and_time+0x99>
jmp    1183 <read_marker_and_time+0x73>
mov    -0x34(%rbp),%eax
sub    $0xfe,%eax
je     11b8 <read_marker_and_time+0xa8>
jmp    1196 <read_marker_and_time+0x86>
mov    -0x34(%rbp),%eax
sub    $0xff,%eax
je     11e0 <read_marker_and_time+0xd0>
jmp    1208 <read_marker_and_time+0xf8>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
jmp    1137 <read_marker_and_time+0x27>
mov    -0xc(%rbp),%edi
lea    -0x24(%rbp),%rsi
mov    $0x2,%edx
mov    $0x0,%al
call   1030 <read@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movzwl -0x24(%rbp),%eax
mov    %rax,-0x8(%rbp)
jmp    1210 <read_marker_and_time+0x100>
mov    -0xc(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x8,%edx
mov    $0x0,%al
call   1030 <read@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1210 <read_marker_and_time+0x100>
movzbl -0x21(%rbp),%eax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_marker_and_time>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %edi,%r14d
movl   $0x0,(%rsi)
movl   $0x0,(%rdx)
xor    %ebp,%ebp
lea    0x5(%rsp),%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1030 <read@plt>
mov    %eax,(%r15)
test   %eax,%eax
jle    11c7 <read_marker_and_time+0xb7>
lea    0x5(%rsp),%r12
movzbl 0x5(%rsp),%ebp
cmp    $0xf8,%rbp
jne    1181 <read_marker_and_time+0x71>
movl   $0x1,(%rbx)
mov    $0x1,%edx
mov    %r14d,%edi
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <read@plt>
mov    %eax,(%r15)
test   %eax,%eax
jg     1150 <read_marker_and_time+0x40>
xor    %ebp,%ebp
jmp    11c7 <read_marker_and_time+0xb7>
cmp    $0xfe,%bpl
je     11ab <read_marker_and_time+0x9b>
cmp    $0xff,%bpl
jne    11c7 <read_marker_and_time+0xb7>
lea    0x8(%rsp),%rsi
mov    $0x8,%edx
mov    %r14d,%edi
xor    %eax,%eax
call   1030 <read@plt>
mov    %eax,(%r15)
mov    0x8(%rsp),%rbp
jmp    11c7 <read_marker_and_time+0xb7>
lea    0x6(%rsp),%rsi
mov    $0x2,%edx
mov    %r14d,%edi
xor    %eax,%eax
call   1030 <read@plt>
mov    %eax,(%r15)
movzwl 0x6(%rsp),%ebp
mov    %rbp,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i64 @read_marker_and_time(i32 %0, i32* %1, i32* %2) {
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8
%9 = alloca i16
%10 = alloca i64
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%11 = load i32*, i32** %6
store i32 0, i32* %11
%12 = load i32*, i32** %7
store i32 0, i32* %12
br label %13
13: ; preds = %24, %3
%14 = load i32, i32* %5
%15 = call i32 (i32, ...) @read(i32 %14, i8* %8, i64 1)
%16 = load i32*, i32** %7
store i32 %15, i32* %16
%17 = load i32*, i32** %7
%18 = load i32, i32* %17
%19 = icmp sle i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %13
store i64 0, i64* %4
br label %40
21: ; preds = %13
%22 = load i8, i8* %8
%23 = zext i8 %22 to i32
switch i32 %23, label %37 [
i32 248, label %24
i32 254, label %26
i32 255, label %32
]
24: ; preds = %21
%25 = load i32*, i32** %6
store i32 1, i32* %25
br label %13
26: ; preds = %21
%27 = load i32, i32* %5
%28 = call i32 (i32, ...) @read(i32 %27, i16* %9, i64 2)
%29 = load i32*, i32** %7
store i32 %28, i32* %29
%30 = load i16, i16* %9
%31 = zext i16 %30 to i64
store i64 %31, i64* %4
br label %40
32: ; preds = %21
%33 = load i32, i32* %5
%34 = call i32 (i32, ...) @read(i32 %33, i64* %10, i64 8)
%35 = load i32*, i32** %7
store i32 %34, i32* %35
%36 = load i64, i64* %10
store i64 %36, i64* %4
br label %40
37: ; preds = %21
%38 = load i8, i8* %8
%39 = zext i8 %38 to i64
store i64 %39, i64* %4
br label %40
40: ; preds = %37, %32, %26, %20
%41 = load i64, i64* %4
ret i64 %41
}

LLVM IR (-O2):
define i64 @read_marker_and_time(i32 %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = alloca i8
%5 = alloca i16
%6 = alloca i64
%7 = bitcast i16* %5 to i8*
%8 = bitcast i64* %6 to i8*
store i32 0, i32* %1
store i32 0, i32* %2
%9 = call i32 (i32, ...) @read(i32 %0, i8* %4, i64 1)
store i32 %9, i32* %2
%10 = icmp slt i32 %9, 1
br i1 %10, label %25, label %11
11: ; preds = %3, %13
%12 = load i8, i8* %4
switch i8 %12, label %23 [
i8 -8, label %13
i8 -2, label %16
i8 -1, label %20
]
13: ; preds = %11
store i32 1, i32* %1
%14 = call i32 (i32, ...) @read(i32 %0, i8* %4, i64 1)
store i32 %14, i32* %2
%15 = icmp slt i32 %14, 1
br i1 %15, label %25, label %11
16: ; preds = %11
%17 = call i32 (i32, ...) @read(i32 %0, i16* %5, i64 2)
store i32 %17, i32* %2
%18 = load i16, i16* %5
%19 = zext i16 %18 to i64
br label %25
20: ; preds = %11
%21 = call i32 (i32, ...) @read(i32 %0, i64* %6, i64 8)
store i32 %21, i32* %2
%22 = load i64, i64* %6
br label %25
23: ; preds = %11
%24 = zext i8 %12 to i64
br label %25
25: ; preds = %13, %3, %23, %20, %16
%26 = phi i64 [ %24, %23 ], [ %22, %20 ], [ %19, %16 ], [ 0, %3 ], [ 0, %13 ]
ret i64 %26
}