#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*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ expect(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int logchar(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror_with_name(char *);
int /*<<< orphan*/ play(int /*<<< orphan*/ *);
int /*<<< orphan*/ remote_close();
int /*<<< orphan*/ remote_open(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  FILE *fp;
  int ch;
  if (argc < 3) {
    fprintf(stderr, "Usage: gdbreplay <logfile> <host:port>\n");
    fflush(stderr);
    exit(1);
  }
  fp = fopen(argv[1], "r");
  if (fp == NULL) {
    perror_with_name(argv[1]);
  }
  remote_open(argv[2]);
  while ((ch = logchar(fp)) != EOF) {
    switch (ch) {
    case 'w':
      expect(fp);
      break;
    case 'r':
      play(fp);
      break;
    case 'c':
      while ((ch = logchar(fp)) != (EOF - 1))
        ;
      break;
    }
  }
  remote_close();
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11ed <main+0x4d>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe2c(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    121d <main+0x7d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <perror_with_name@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <remote_open@plt>
mov    -0x18(%rbp),%rdi
call   1070 <logchar@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2dab(%rip),%rcx
cmp    (%rcx),%eax
je     12cb <main+0x12b>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x63,%eax
je     1297 <main+0xf7>
jmp    1259 <main+0xb9>
mov    -0x20(%rbp),%eax
sub    $0x72,%eax
je     1289 <main+0xe9>
jmp    126a <main+0xca>
mov    -0x20(%rbp),%eax
sub    $0x77,%eax
jne    12c6 <main+0x126>
jmp    127b <main+0xdb>
mov    -0x18(%rbp),%rdi
call   1040 <expect@plt>
jmp    12c6 <main+0x126>
mov    -0x18(%rbp),%rdi
call   1090 <play@plt>
jmp    12c6 <main+0x126>
jmp    129c <main+0xfc>
mov    -0x18(%rbp),%rdi
call   1070 <logchar@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2d39(%rip),%rcx
mov    (%rcx),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     12c1 <main+0x121>
jmp    129c <main+0xfc>
jmp    12c6 <main+0x126>
jmp    122a <main+0x8a>
mov    $0x0,%al
call   1050 <remote_close@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jg     11cf <main+0x2f>
mov    0x2e28(%rip),%rbx
mov    (%rbx),%edi
lea    0xe47(%rip),%rsi
call   1080 <fprintf@plt>
mov    (%rbx),%edi
call   10a0 <fflush@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xe4b(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11f3 <main+0x53>
mov    0x8(%r14),%rdi
call   1060 <perror_with_name@plt>
mov    0x10(%r14),%rdi
call   1030 <remote_open@plt>
mov    %rbx,%rdi
call   1070 <logchar@plt>
mov    0x2ddd(%rip),%r14
jmp    1220 <main+0x80>
nopl   (%rax)
mov    %rbx,%rdi
call   1090 <play@plt>
mov    %rbx,%rdi
call   1070 <logchar@plt>
cmp    (%r14),%eax
je     126a <main+0xca>
cmp    $0x77,%eax
je     1260 <main+0xc0>
cmp    $0x72,%eax
je     1210 <main+0x70>
cmp    $0x63,%eax
jne    1218 <main+0x78>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1070 <logchar@plt>
mov    (%r14),%ecx
add    $0xffffffff,%ecx
cmp    %ecx,%eax
jne    1240 <main+0xa0>
jmp    1218 <main+0x78>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1040 <expect@plt>
jmp    1218 <main+0x78>
xor    %eax,%eax
call   1050 <remote_close@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [40 x i8] c"Usage: gdbreplay <logfile> <host:port>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 3
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @stderr
%14 = call i32 @fflush(i32 %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %6
%21 = load i32*, i32** %6
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %28
23: ; preds = %16
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @perror_with_name(i8* %26)
br label %28
28: ; preds = %23, %16
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i32 @remote_open(i8* %31)
br label %33
33: ; preds = %55, %28
%34 = load i32*, i32** %6
%35 = call i32 @logchar(i32* %34)
store i32 %35, i32* %7
%36 = load i32, i32* @EOF
%37 = icmp ne i32 %35, %36
br i1 %37, label %38, label %56
38: ; preds = %33
%39 = load i32, i32* %7
switch i32 %39, label %55 [
i32 119, label %40
i32 114, label %43
i32 99, label %46
]
40: ; preds = %38
%41 = load i32*, i32** %6
%42 = call i32 @expect(i32* %41)
br label %55
43: ; preds = %38
%44 = load i32*, i32** %6
%45 = call i32 @play(i32* %44)
br label %55
46: ; preds = %38
br label %47
47: ; preds = %53, %46
%48 = load i32*, i32** %6
%49 = call i32 @logchar(i32* %48)
store i32 %49, i32* %7
%50 = load i32, i32* @EOF
%51 = sub nsw i32 %50, 1
%52 = icmp ne i32 %49, %51
br i1 %52, label %53, label %54
53: ; preds = %47
br label %47
54: ; preds = %47
br label %55
55: ; preds = %38, %54, %43, %40
br label %33
56: ; preds = %33
%57 = call i32 (...) @remote_close()
%58 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [40 x i8] c"Usage: gdbreplay <logfile> <host:port>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %10
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @stderr
%8 = tail call i32 @fflush(i32 %7)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i8*, i8** %11
%17 = tail call i32 @perror_with_name(i8* %16)
br label %18
18: ; preds = %15, %10
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = tail call i32 @remote_open(i8* %20)
%22 = tail call i32 @logchar(i32* %13)
%23 = load i32, i32* @EOF
%24 = icmp eq i32 %22, %23
br i1 %24, label %40, label %25
25: ; preds = %18, %36
%26 = phi i32 [ %37, %36 ], [ %22, %18 ]
switch i32 %26, label %36 [
i32 119, label %27
i32 114, label %29
i32 99, label %31
]
27: ; preds = %25
%28 = tail call i32 @expect(i32* %13)
br label %36
29: ; preds = %25
%30 = tail call i32 @play(i32* %13)
br label %36
31: ; preds = %25, %31
%32 = tail call i32 @logchar(i32* %13)
%33 = load i32, i32* @EOF
%34 = add nsw i32 %33, -1
%35 = icmp eq i32 %32, %34
br i1 %35, label %36, label %31
36: ; preds = %31, %25, %29, %27
%37 = tail call i32 @logchar(i32* %13)
%38 = load i32, i32* @EOF
%39 = icmp eq i32 %37, %38
br i1 %39, label %40, label %25
40: ; preds = %36, %18
%41 = tail call i32 (...) @remote_close()
%42 = tail call i32 @exit(i32 0)
unreachable
}