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

/* Variables and functions */
int alloc_pty_pair(char *, char *);
int connect_sock(char *);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ relay(int, int);
int /*<<< orphan*/ run_kermit(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int pty_fd;
  int sock_fd;
  int child_pid;
  char pty_master[25];
  char pty_slave[25];
  sock_fd = connect_sock(argv[1]);
  pty_fd = alloc_pty_pair(pty_master, pty_slave);
  if ((child_pid = fork()) < -1) {
    fprintf(stderr, "ERROR: failed to fork background worker.\n");
    exit(1);
  } else if (0 == child_pid) {
    relay(pty_fd, sock_fd);
  } else {
    run_kermit(pty_slave);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <connect_sock@plt>
mov    %eax,-0x18(%rbp)
lea    -0x40(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1050 <alloc_pty_pair@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jge    11d8 <main+0x68>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    0xe37(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
xor    %eax,%eax
cmp    -0x1c(%rbp),%eax
jne    11f3 <main+0x83>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1040 <relay@plt>
jmp    11fc <main+0x8c>
lea    -0x60(%rbp),%rdi
call   1030 <run_kermit@plt>
jmp    1201 <main+0x91>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x48,%rsp
mov    0x8(%rsi),%rdi
call   1070 <connect_sock@plt>
mov    %eax,%ebx
lea    0x20(%rsp),%rdi
mov    %rsp,%rsi
call   1050 <alloc_pty_pair@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xfffffffe,%eax
jle    11bc <main+0x4c>
test   %eax,%eax
je     11aa <main+0x3a>
mov    %rsp,%rdi
call   1030 <run_kermit@plt>
jmp    11b3 <main+0x43>
mov    %ebp,%edi
mov    %ebx,%esi
call   1040 <relay@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [42 x i8] c"ERROR: failed to fork background worker.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [25 x i8]
%10 = alloca [25 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @connect_sock(i8* %13)
store i32 %14, i32* %7
%15 = getelementptr inbounds [25 x i8], [25 x i8]* %9, i64 0, i64 0
%16 = getelementptr inbounds [25 x i8], [25 x i8]* %10, i64 0, i64 0
%17 = call i32 @alloc_pty_pair(i8* %15, i8* %16)
store i32 %17, i32* %6
%18 = call i32 (...) @fork()
store i32 %18, i32* %8
%19 = icmp slt i32 %18, -1
br i1 %19, label %20, label %24
20: ; preds = %2
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %2
%25 = load i32, i32* %8
%26 = icmp eq i32 0, %25
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = load i32, i32* %6
%29 = load i32, i32* %7
%30 = call i32 @relay(i32 %28, i32 %29)
br label %34
31: ; preds = %24
%32 = getelementptr inbounds [25 x i8], [25 x i8]* %10, i64 0, i64 0
%33 = call i32 @run_kermit(i8* %32)
br label %34
34: ; preds = %31, %27
br label %35
35: ; preds = %34
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [42 x i8] c"ERROR: failed to fork background worker.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [25 x i8]
%4 = alloca [25 x i8]
%5 = getelementptr inbounds [25 x i8], [25 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [25 x i8], [25 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @connect_sock(i8* %8)
%10 = call i32 @alloc_pty_pair(i8* %5, i8* %6)
%11 = call i32 (...) @fork()
%12 = icmp slt i32 %11, -1
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = icmp eq i32 %11, 0
br i1 %18, label %19, label %21
19: ; preds = %17
%20 = call i32 @relay(i32 %10, i32 %9)
br label %23
21: ; preds = %17
%22 = call i32 @run_kermit(i8* %6)
br label %23
23: ; preds = %19, %21
ret i32 0
}