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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ exit(int);
int fileno(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getopt(int, char **, char *);
int open(char *, int /*<<< orphan*/);
char *optarg;
int parse_playback_log_header(int, char *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int main(int argc, char *argv[]) {
  int opt;
  char *filename = NULL;
  int fd;
  while ((opt = getopt(argc, argv, "f:")) != -1) {
    switch (opt) {
    case 'f':
      filename = optarg;
      break;
    default:
      break;
    }
  }
  if (filename)
    fd = open(filename, O_RDONLY);
  else
    fd = fileno(stdin);
  if (fd == -1) {
    fprintf(stderr, "could not open %s for reading\n",
            (filename) ? filename : "stdin");
    exit(1);
  }
  do {
    char header[(1 + (6 * 4) + (2 * 8))];
    ssize_t header_sz = read(fd, header, (1 + (6 * 4) + (2 * 8)));
    if (header_sz == 0)
      break;
    if (header_sz != (1 + (6 * 4) + (2 * 8))) {
      fprintf(stderr, "ERROR: playback log header length mismatch %d !+ %d\n",
              (int)header_sz, (1 + (6 * 4) + (2 * 8)));
      break;
    }
    int r = parse_playback_log_header(fd, header);
    if (r != 0)
      break;
  } while (1);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe64(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     11db <main+0x6b>
mov    -0x14(%rbp),%eax
sub    $0x66,%eax
jne    11d1 <main+0x61>
jmp    11be <main+0x4e>
mov    0x2e33(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    11d6 <main+0x66>
jmp    11d6 <main+0x66>
jmp    118e <main+0x1e>
cmpq   $0x0,-0x20(%rbp)
je     1200 <main+0x90>
mov    -0x20(%rbp),%rdi
mov    0x2def(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x24(%rbp)
jmp    1211 <main+0xa1>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
call   1060 <fileno@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    126e <main+0xfe>
mov    0x2da6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     123f <main+0xcf>
mov    -0x20(%rbp),%rax
mov    %rax,-0x68(%rbp)
jmp    124f <main+0xdf>
lea    0xddc(%rip),%rax
mov    %rax,-0x68(%rbp)
jmp    124f <main+0xdf>
mov    -0x5c(%rbp),%edi
mov    -0x68(%rbp),%rdx
lea    0xda6(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    1273 <main+0x103>
mov    -0x24(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x29,%edx
call   1040 <read@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jne    1296 <main+0x126>
jmp    12f6 <main+0x186>
cmpl   $0x29,-0x54(%rbp)
je     12c4 <main+0x154>
mov    0x2d21(%rip),%rax
mov    (%rax),%edi
mov    -0x54(%rbp),%edx
lea    0xd75(%rip),%rsi
mov    $0x29,%ecx
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    12f6 <main+0x186>
mov    -0x24(%rbp),%edi
lea    -0x50(%rbp),%rsi
call   1030 <parse_playback_log_header@plt>
mov    %eax,-0x58(%rbp)
cmpl   $0x0,-0x58(%rbp)
je     12e2 <main+0x172>
jmp    12f6 <main+0x186>
jmp    12e7 <main+0x177>
mov    $0x1,%al
test   $0x1,%al
jne    1273 <main+0x103>
jmp    12f6 <main+0x186>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
xor    %r14d,%r14d
lea    0xe75(%rip),%r15
mov    0x2e66(%rip),%r12
jmp    11a0 <main+0x30>
mov    (%r12),%r14
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1080 <getopt@plt>
cmp    $0x66,%eax
je     1194 <main+0x24>
cmp    $0xffffffff,%eax
jne    11a0 <main+0x30>
test   %r14,%r14
jne    11cc <main+0x5c>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
call   1060 <fileno@plt>
jmp    11dd <main+0x6d>
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1070 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1213 <main+0xa3>
test   %r14,%r14
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
lea    0xe2b(%rip),%rdx
cmovne %r14,%rdx
lea    0xe01(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x29,%edx
call   1040 <read@plt>
cmp    $0x29,%eax
jne    1244 <main+0xd4>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <parse_playback_log_header@plt>
test   %eax,%eax
je     1220 <main+0xb0>
jmp    1248 <main+0xd8>
test   %eax,%eax
jne    124f <main+0xdf>
xor    %edi,%edi
call   1090 <exit@plt>
mov    0x2d72(%rip),%rcx
mov    (%rcx),%edi
lea    0xdc9(%rip),%rsi
mov    %eax,%edx
mov    $0x29,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"f:\00"
@optarg = global i8* null
@O_RDONLY = global i32 0
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [31 x i8] c"could not open %s for reading\0A\00"
@.str.2 = [6 x i8] c"stdin\00"
@.str.3 = [53 x i8] c"ERROR: playback log header length mismatch %d !+ %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [41 x i8]
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %7
br label %12
12: ; preds = %22, %2
%13 = load i32, i32* %4
%14 = load i8**, i8*** %5
%15 = call i32 @getopt(i32 %13, i8** %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %15, i32* %6
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %23
17: ; preds = %12
%18 = load i32, i32* %6
switch i32 %18, label %21 [
i32 102, label %19
]
19: ; preds = %17
%20 = load i8*, i8** @optarg
store i8* %20, i8** %7
br label %22
21: ; preds = %17
br label %22
22: ; preds = %21, %19
br label %12
23: ; preds = %12
%24 = load i8*, i8** %7
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %30
26: ; preds = %23
%27 = load i8*, i8** %7
%28 = load i32, i32* @O_RDONLY
%29 = call i32 @open(i8* %27, i32 %28)
store i32 %29, i32* %8
br label %33
30: ; preds = %23
%31 = load i32, i32* @stdin
%32 = call i32 @fileno(i32 %31)
store i32 %32, i32* %8
br label %33
33: ; preds = %30, %26
%34 = load i32, i32* %8
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %47
36: ; preds = %33
%37 = load i32, i32* @stderr
%38 = load i8*, i8** %7
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = load i8*, i8** %7
br label %43
42: ; preds = %36
br label %43
43: ; preds = %42, %40
%44 = phi i8* [ %41, %40 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), %42 ]
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %44)
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %33
br label %48
48: ; preds = %70, %47
%49 = load i32, i32* %8
%50 = getelementptr inbounds [41 x i8], [41 x i8]* %9, i64 0, i64 0
%51 = call i32 @read(i32 %49, i8* %50, i32 41)
store i32 %51, i32* %10
%52 = load i32, i32* %10
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %48
br label %71
55: ; preds = %48
%56 = load i32, i32* %10
%57 = icmp ne i32 %56, 41
br i1 %57, label %58, label %62
58: ; preds = %55
%59 = load i32, i32* @stderr
%60 = load i32, i32* %10
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i32 %60, i32 41)
br label %71
62: ; preds = %55
%63 = load i32, i32* %8
%64 = getelementptr inbounds [41 x i8], [41 x i8]* %9, i64 0, i64 0
%65 = call i32 @parse_playback_log_header(i32 %63, i8* %64)
store i32 %65, i32* %11
%66 = load i32, i32* %11
%67 = icmp ne i32 %66, 0
br i1 %67, label %68, label %69
68: ; preds = %62
br label %71
69: ; preds = %62
br label %70
70: ; preds = %69
br i1 true, label %48, label %71
71: ; preds = %70, %68, %58, %54
%72 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [3 x i8] c"f:\00"
@optarg = global i8* null
@O_RDONLY = global i32 0
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [31 x i8] c"could not open %s for reading\0A\00"
@.str.2 = [6 x i8] c"stdin\00"
@.str.3 = [53 x i8] c"ERROR: playback log header length mismatch %d !+ %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [41 x i8]
br label %4
4: ; preds = %8, %2
%5 = phi i8* [ %9, %8 ], [ null, %2 ]
br label %6
6: ; preds = %4, %6
%7 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
switch i32 %7, label %6 [
i32 -1, label %10
i32 102, label %8
]
8: ; preds = %6
%9 = load i8*, i8** @optarg
br label %4
10: ; preds = %6
%11 = icmp eq i8* %5, null
br i1 %11, label %15, label %12
12: ; preds = %10
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 @open(i8* %5, i32 %13)
br label %18
15: ; preds = %10
%16 = load i32, i32* @stdin
%17 = tail call i32 @fileno(i32 %16)
br label %18
18: ; preds = %15, %12
%19 = phi i32 [ %14, %12 ], [ %17, %15 ]
%20 = icmp eq i32 %19, -1
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = getelementptr inbounds [41 x i8], [41 x i8]* %3, i64 0, i64 0
br label %28
23: ; preds = %18
%24 = load i32, i32* @stderr
%25 = select i1 %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %5
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %21, %36
%29 = call i32 @read(i32 %19, i8* %22, i32 41)
switch i32 %29, label %30 [
i32 0, label %37
i32 41, label %33
]
30: ; preds = %28
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i32 %29, i32 41)
br label %37
33: ; preds = %28
%34 = call i32 @parse_playback_log_header(i32 %19, i8* %22)
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %33
br label %28
37: ; preds = %33, %28, %30
%38 = call i32 @exit(i32 0)
unreachable
}