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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int be16toh(int);
int /*<<< orphan*/ close(int);
int htobe16(int);
int htole16(int);
int le16toh(int);
int /*<<< orphan*/ memcpy(char *, ...);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ print_message(char *, char *, int);
int /*<<< orphan*/ printf(char *);
scalar_t__ read(int, char *, int);
int strlen(char *);
int /*<<< orphan*/ write(int, ...);
int main(int argc, char *argv[]) {
  int fd_in = open(argv[2], O_RDONLY);
  int fd_out = open(argv[3], O_WRONLY);
  char buf[2];
  while (read(fd_in, buf, sizeof buf)) {
    uint16_t msg_len = le16toh(*(uint16_t *)buf);
    if (msg_len < 2) {
      printf("ERROR: Message size recieved is invalid.\n");
      break;
    }
    char msg[msg_len];
    if (!read(fd_in, msg, msg_len)) {
      printf("ERROR: Failed to read a message.\n");
      break;
    }
    char msg_id[2] = {msg[0], msg[1]};
    uint16_t id = be16toh(*(uint16_t *)msg_id);
    print_message("GOT", msg, msg_len);
    if (id == 0x0000) {
      int glen = strlen(argv[1]), tlen = strlen("RuneScape"), g2len = 2 * glen;
      uint16_t reply_size = htole16(g2len + tlen + 32);
      char reply[reply_size];
      uint16_t min_w = htobe16(765), min_h = htobe16(540),
               max_w = htobe16(3840), max_h = htobe16(2160),
               width = htobe16(1366), height = htobe16(768);
      memset(reply, 0, reply_size);
      memcpy(reply, "\0\1\0\4\0\0\0\0\0\0\0\0", 12);
      memcpy(reply + 12, argv[1], glen);
      memcpy(reply + 13 + glen, argv[1], glen);
      memcpy(reply + 14 + g2len, "\0\4\0\0\7", 5);
      memcpy(reply + 19 + g2len, "RuneScape", tlen);
      memcpy(reply + 20 + g2len + tlen, &min_w, 2);
      memcpy(reply + 22 + g2len + tlen, &min_h, 2);
      memcpy(reply + 24 + g2len + tlen, &max_w, 2);
      memcpy(reply + 26 + g2len + tlen, &max_h, 2);
      memcpy(reply + 28 + g2len + tlen, &width, 2);
      memcpy(reply + 30 + g2len + tlen, &height, 2);
      write(fd_out, &reply_size, 2);
      write(fd_out, reply, reply_size);
      print_message("SENT", reply, reply_size);
    } else if (id == 0x0020) {
      write(fd_out, "\4\0\0\v\0\1", 6);
    }
  }
  printf("Ended communication with client.\n");
  close(fd_in);
  close(fd_out);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2df0(%rip),%rax
mov    (%rax),%esi
call   10d0 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    0x2dbf(%rip),%rax
mov    (%rax),%esi
call   10d0 <open@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x1a(%rbp),%rsi
mov    $0x2,%edx
call   10a0 <read@plt>
cmp    $0x0,%rax
je     15da <main+0x40a>
mov    -0x1a(%rbp),%edi
call   10c0 <le16toh@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x2,-0x20(%rbp)
jge    125c <main+0x8c>
lea    0xdae(%rip),%rdi
call   1060 <printf@plt>
jmp    15da <main+0x40a>
mov    -0x20(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x80(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%edx
call   10a0 <read@plt>
cmp    $0x0,%rax
jne    12af <main+0xdf>
lea    0xd8c(%rip),%rdi
call   1060 <printf@plt>
movl   $0x3,-0x34(%rbp)
jmp    15b9 <main+0x3e9>
mov    -0x80(%rbp),%rax
mov    (%rax),%cl
mov    %cl,-0x36(%rbp)
mov    0x1(%rax),%al
mov    %al,-0x35(%rbp)
mov    -0x36(%rbp),%edi
call   10e0 <be16toh@plt>
mov    -0x80(%rbp),%rsi
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%edx
lea    0xd75(%rip),%rdi
call   1050 <print_message@plt>
cmpl   $0x0,-0x3c(%rbp)
jne    158d <main+0x3bd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x40(%rbp)
lea    0xd53(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x44(%rbp)
mov    -0x40(%rbp),%eax
add    %eax,%eax
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%edx
mov    -0x44(%rbp),%eax
mov    %eax,%ecx
mov    %edx,%eax
lea    0x20(%rax,%rcx,1),%edi
call   1070 <htole16@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x88(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x60(%rbp)
mov    $0x2fd,%edi
call   10f0 <htobe16@plt>
mov    %eax,-0x64(%rbp)
mov    $0x21c,%edi
call   10f0 <htobe16@plt>
mov    %eax,-0x68(%rbp)
mov    $0xf00,%edi
call   10f0 <htobe16@plt>
mov    %eax,-0x6c(%rbp)
mov    $0x870,%edi
call   10f0 <htobe16@plt>
mov    %eax,-0x70(%rbp)
mov    $0x556,%edi
call   10f0 <htobe16@plt>
mov    %eax,-0x74(%rbp)
mov    $0x300,%edi
call   10f0 <htobe16@plt>
mov    -0x88(%rbp),%rdi
mov    %eax,-0x78(%rbp)
mov    -0x4c(%rbp),%edx
xor    %esi,%esi
call   1080 <memset@plt>
mov    -0x88(%rbp),%rdi
lea    0xcc8(%rip),%rsi
xor    %eax,%eax
mov    $0xc,%edx
call   10b0 <memcpy@plt>
mov    -0x88(%rbp),%rdi
add    $0xc,%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x40(%rbp),%edx
xor    %eax,%eax
call   10b0 <memcpy@plt>
mov    -0x88(%rbp),%rdi
add    $0xd,%rdi
movslq -0x40(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x40(%rbp),%edx
xor    %eax,%eax
call   10b0 <memcpy@plt>
mov    -0x88(%rbp),%rdi
add    $0xe,%rdi
movslq -0x48(%rbp),%rax
add    %rax,%rdi
lea    0xc6f(%rip),%rsi
xor    %eax,%eax
mov    $0x5,%edx
call   10b0 <memcpy@plt>
mov    -0x88(%rbp),%rdi
add    $0x13,%rdi
movslq -0x48(%rbp),%rax
add    %rax,%rdi
mov    -0x44(%rbp),%edx
lea    0xc09(%rip),%rsi
xor    %eax,%eax
call   10b0 <memcpy@plt>
mov    -0x88(%rbp),%rdi
add    $0x14,%rdi
movslq -0x48(%rbp),%rax
add    %rax,%rdi
movslq -0x44(%rbp),%rax
add    %rax,%rdi
xor    %eax,%eax
lea    -0x64(%rbp),%rsi
mov    $0x2,%edx
call   10b0 <memcpy@plt>
mov    -0x88(%rbp),%rdi
add    $0x16,%rdi
movslq -0x48(%rbp),%rax
add    %rax,%rdi
movslq -0x44(%rbp),%rax
add    %rax,%rdi
xor    %eax,%eax
lea    -0x68(%rbp),%rsi
mov    $0x2,%edx
call   10b0 <memcpy@plt>
mov    -0x88(%rbp),%rdi
add    $0x18,%rdi
movslq -0x48(%rbp),%rax
add    %rax,%rdi
movslq -0x44(%rbp),%rax
add    %rax,%rdi
xor    %eax,%eax
lea    -0x6c(%rbp),%rsi
mov    $0x2,%edx
call   10b0 <memcpy@plt>
mov    -0x88(%rbp),%rdi
add    $0x1a,%rdi
movslq -0x48(%rbp),%rax
add    %rax,%rdi
movslq -0x44(%rbp),%rax
add    %rax,%rdi
xor    %eax,%eax
lea    -0x70(%rbp),%rsi
mov    $0x2,%edx
call   10b0 <memcpy@plt>
mov    -0x88(%rbp),%rdi
add    $0x1c,%rdi
movslq -0x48(%rbp),%rax
add    %rax,%rdi
movslq -0x44(%rbp),%rax
add    %rax,%rdi
xor    %eax,%eax
lea    -0x74(%rbp),%rsi
mov    $0x2,%edx
call   10b0 <memcpy@plt>
mov    -0x88(%rbp),%rdi
add    $0x1e,%rdi
movslq -0x48(%rbp),%rax
add    %rax,%rdi
movslq -0x44(%rbp),%rax
add    %rax,%rdi
xor    %eax,%eax
lea    -0x78(%rbp),%rsi
mov    $0x2,%edx
call   10b0 <memcpy@plt>
mov    -0x18(%rbp),%edi
lea    -0x4c(%rbp),%rsi
mov    $0x2,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x88(%rbp),%rsi
mov    -0x18(%rbp),%edi
mov    -0x4c(%rbp),%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x88(%rbp),%rsi
mov    -0x4c(%rbp),%edx
lea    0xade(%rip),%rdi
call   1050 <print_message@plt>
mov    -0x58(%rbp),%rax
mov    %rax,%rsp
jmp    15b2 <main+0x3e2>
cmpl   $0x20,-0x3c(%rbp)
jne    15ad <main+0x3dd>
mov    -0x18(%rbp),%edi
lea    0xaf3(%rip),%rsi
mov    $0x6,%edx
mov    $0x0,%al
call   1030 <write@plt>
jmp    15b2 <main+0x3e2>
movl   $0x0,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x34(%rbp),%eax
test   %eax,%eax
je     15d5 <main+0x405>
jmp    15d0 <main+0x400>
jmp    15da <main+0x40a>
jmp    121b <main+0x4b>
lea    0xa7e(%rip),%rdi
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%rbx
mov    0x10(%rsi),%rdi
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
call   10d0 <open@plt>
mov    %eax,%r13d
mov    %rbx,-0x60(%rbp)
mov    0x18(%rbx),%rdi
mov    0x2dc8(%rip),%rax
mov    (%rax),%esi
call   10d0 <open@plt>
mov    %eax,-0x34(%rbp)
lea    -0x2c(%rbp),%rsi
mov    %r13d,%edi
mov    $0x2,%edx
call   10a0 <read@plt>
test   %rax,%rax
je     150a <main+0x33a>
mov    %r13d,-0x38(%rbp)
jmp    1273 <main+0xa3>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    -0x34(%rbp),%edi
lea    0xe47(%rip),%rsi
mov    $0x6,%edx
xor    %eax,%eax
call   1040 <write@plt>
mov    %r15,%rsp
mov    %r13d,%edi
lea    -0x2c(%rbp),%rsi
mov    $0x2,%edx
call   10a0 <read@plt>
test   %rax,%rax
je     150a <main+0x33a>
mov    -0x2c(%rbp),%edi
call   10c0 <le16toh@plt>
cmp    $0x1,%eax
jle    14ed <main+0x31d>
mov    %eax,%r14d
mov    %rsp,%r15
mov    %eax,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   10a0 <read@plt>
test   %rax,%rax
je     14fb <main+0x32b>
movzwl (%rbx),%edi
call   10e0 <be16toh@plt>
mov    %eax,%r12d
lea    0xd3a(%rip),%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1060 <print_message@plt>
cmp    $0x20,%r12d
je     1240 <main+0x70>
test   %r12d,%r12d
jne    1256 <main+0x86>
mov    -0x60(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <strlen@plt>
mov    %eax,%r14d
lea    0xd09(%rip),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x68(%rbp)
lea    (%r14,%r14,1),%ecx
mov    %ecx,-0x3c(%rbp)
lea    (%rax,%r14,2),%edi
add    $0x20,%edi
call   1070 <htole16@plt>
mov    %rsp,-0x70(%rbp)
mov    %eax,-0x30(%rbp)
mov    %eax,%ebx
add    $0xf,%rbx
and    $0xfffffffffffffff0,%rbx
mov    %rsp,%r13
mov    %r13,%r12
sub    %rbx,%r12
mov    %r12,%rsp
mov    $0x2fd,%edi
call   10f0 <htobe16@plt>
mov    %eax,-0x54(%rbp)
mov    $0x21c,%edi
call   10f0 <htobe16@plt>
mov    %eax,-0x50(%rbp)
mov    $0xf00,%edi
call   10f0 <htobe16@plt>
mov    %eax,-0x4c(%rbp)
mov    $0x870,%edi
call   10f0 <htobe16@plt>
mov    %eax,-0x48(%rbp)
mov    $0x556,%edi
call   10f0 <htobe16@plt>
mov    %eax,-0x44(%rbp)
mov    $0x300,%edi
call   10f0 <htobe16@plt>
mov    %eax,-0x40(%rbp)
mov    -0x30(%rbp),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1080 <memset@plt>
mov    %r12,%rdi
lea    0xce5(%rip),%rsi
mov    $0xc,%edx
xor    %eax,%eax
call   10b0 <memcpy@plt>
neg    %rbx
lea    (%rbx,%r13,1),%rdi
add    $0xc,%rdi
mov    -0x38(%rbp),%r13d
mov    -0x60(%rbp),%rbx
mov    0x8(%rbx),%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   10b0 <memcpy@plt>
movslq %r14d,%rdx
lea    (%rdx,%r12,1),%rdi
add    $0xd,%rdi
mov    0x8(%rbx),%rsi
xor    %eax,%eax
call   10b0 <memcpy@plt>
movslq -0x3c(%rbp),%rbx
lea    (%rbx,%r12,1),%rdi
add    $0xe,%rdi
lea    0xc9c(%rip),%rsi
mov    $0x5,%edx
xor    %eax,%eax
call   10b0 <memcpy@plt>
lea    (%rbx,%r12,1),%rdi
add    $0x13,%rdi
lea    0xbfa(%rip),%rsi
mov    -0x68(%rbp),%r14
mov    %r14d,%edx
xor    %eax,%eax
call   10b0 <memcpy@plt>
movslq %r14d,%r14
add    %r12,%rbx
lea    (%r14,%rbx,1),%rdi
add    $0x14,%rdi
lea    -0x54(%rbp),%rsi
mov    $0x2,%edx
xor    %eax,%eax
call   10b0 <memcpy@plt>
lea    (%r14,%rbx,1),%rdi
add    $0x16,%rdi
lea    -0x50(%rbp),%rsi
mov    $0x2,%edx
xor    %eax,%eax
call   10b0 <memcpy@plt>
lea    (%r14,%rbx,1),%rdi
add    $0x18,%rdi
lea    -0x4c(%rbp),%rsi
mov    $0x2,%edx
xor    %eax,%eax
call   10b0 <memcpy@plt>
lea    (%r14,%rbx,1),%rdi
add    $0x1a,%rdi
lea    -0x48(%rbp),%rsi
mov    $0x2,%edx
xor    %eax,%eax
call   10b0 <memcpy@plt>
lea    (%r14,%rbx,1),%rdi
add    $0x1c,%rdi
lea    -0x44(%rbp),%rsi
mov    $0x2,%edx
xor    %eax,%eax
call   10b0 <memcpy@plt>
lea    (%r14,%rbx,1),%rdi
add    $0x1e,%rdi
lea    -0x40(%rbp),%rsi
mov    $0x2,%edx
xor    %eax,%eax
call   10b0 <memcpy@plt>
mov    -0x34(%rbp),%ebx
mov    %ebx,%edi
lea    -0x30(%rbp),%rsi
mov    $0x2,%edx
xor    %eax,%eax
call   1040 <write@plt>
mov    -0x30(%rbp),%edx
mov    %ebx,%edi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <write@plt>
mov    -0x30(%rbp),%edx
lea    0xb32(%rip),%rdi
mov    %r12,%rsi
call   1060 <print_message@plt>
mov    -0x70(%rbp),%rsp
jmp    1256 <main+0x86>
lea    0xb61(%rip),%rdi
call   1030 <puts@plt>
jmp    150a <main+0x33a>
lea    0xb32(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rsp
lea    0xb02(%rip),%rdi
call   1030 <puts@plt>
mov    %r13d,%edi
call   1090 <close@plt>
mov    -0x34(%rbp),%edi
call   1090 <close@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@.str = [42 x i8] c"ERROR: Message size recieved is invalid.\0A\00"
@.str.1 = [34 x i8] c"ERROR: Failed to read a message.\0A\00"
@.str.2 = [4 x i8] c"GOT\00"
@.str.3 = [10 x i8] c"RuneScape\00"
@.str.4 = [13 x i8] c"\00\01\00\04\00\00\00\00\00\00\00\00\00"
@.str.5 = [6 x i8] c"\00\04\00\00\07\00"
@.str.6 = [5 x i8] c"SENT\00"
@.str.7 = [7 x i8] c"\04\00\00\0B\00\01\00"
@.str.8 = [34 x i8] c"Ended communication with client.\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 [2 x i8]
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
%13 = alloca [2 x i8]
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i8*
%20 = alloca i64
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = load i32, i32* @O_RDONLY
%31 = call i32 @open(i8* %29, i32 %30)
store i32 %31, i32* %6
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 3
%34 = load i8*, i8** %33
%35 = load i32, i32* @O_WRONLY
%36 = call i32 @open(i8* %34, i32 %35)
store i32 %36, i32* %7
br label %37
37: ; preds = %196, %2
%38 = load i32, i32* %6
%39 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%40 = call i64 @read(i32 %38, i8* %39, i32 2)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %197
42: ; preds = %37
%43 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%44 = bitcast i8* %43 to i32*
%45 = load i32, i32* %44
%46 = call i32 @le16toh(i32 %45)
store i32 %46, i32* %9
%47 = load i32, i32* %9
%48 = icmp slt i32 %47, 2
br i1 %48, label %49, label %51
49: ; preds = %42
%50 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
br label %197
51: ; preds = %42
%52 = load i32, i32* %9
%53 = zext i32 %52 to i64
%54 = call i8* @llvm.stacksave()
store i8* %54, i8** %10
%55 = alloca i8, i64 %53
store i64 %53, i64* %11
%56 = load i32, i32* %6
%57 = load i32, i32* %9
%58 = call i64 @read(i32 %56, i8* %55, i32 %57)
%59 = icmp ne i64 %58, 0
br i1 %59, label %62, label %60
60: ; preds = %51
%61 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
store i32 3, i32* %12
br label %193
62: ; preds = %51
%63 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 0
%64 = getelementptr inbounds i8, i8* %55, i64 0
%65 = load i8, i8* %64
store i8 %65, i8* %63
%66 = getelementptr inbounds i8, i8* %63, i64 1
%67 = getelementptr inbounds i8, i8* %55, i64 1
%68 = load i8, i8* %67
store i8 %68, i8* %66
%69 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 0
%70 = bitcast i8* %69 to i32*
%71 = load i32, i32* %70
%72 = call i32 @be16toh(i32 %71)
store i32 %72, i32* %14
%73 = load i32, i32* %9
%74 = call i32 @print_message(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %55, i32 %73)
%75 = load i32, i32* %14
%76 = icmp eq i32 %75, 0
br i1 %76, label %77, label %185
77: ; preds = %62
%78 = load i8**, i8*** %5
%79 = getelementptr inbounds i8*, i8** %78, i64 1
%80 = load i8*, i8** %79
%81 = call i32 @strlen(i8* %80)
store i32 %81, i32* %15
%82 = call i32 @strlen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
store i32 %82, i32* %16
%83 = load i32, i32* %15
%84 = mul nsw i32 2, %83
store i32 %84, i32* %17
%85 = load i32, i32* %17
%86 = load i32, i32* %16
%87 = add nsw i32 %85, %86
%88 = add nsw i32 %87, 32
%89 = call i32 @htole16(i32 %88)
store i32 %89, i32* %18
%90 = load i32, i32* %18
%91 = zext i32 %90 to i64
%92 = call i8* @llvm.stacksave()
store i8* %92, i8** %19
%93 = alloca i8, i64 %91
store i64 %91, i64* %20
%94 = call i32 @htobe16(i32 765)
store i32 %94, i32* %21
%95 = call i32 @htobe16(i32 540)
store i32 %95, i32* %22
%96 = call i32 @htobe16(i32 3840)
store i32 %96, i32* %23
%97 = call i32 @htobe16(i32 2160)
store i32 %97, i32* %24
%98 = call i32 @htobe16(i32 1366)
store i32 %98, i32* %25
%99 = call i32 @htobe16(i32 768)
store i32 %99, i32* %26
%100 = load i32, i32* %18
%101 = call i32 @memset(i8* %93, i32 0, i32 %100)
%102 = call i32 (i8*, ...) @memcpy(i8* %93, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 12)
%103 = getelementptr inbounds i8, i8* %93, i64 12
%104 = load i8**, i8*** %5
%105 = getelementptr inbounds i8*, i8** %104, i64 1
%106 = load i8*, i8** %105
%107 = load i32, i32* %15
%108 = call i32 (i8*, ...) @memcpy(i8* %103, i8* %106, i32 %107)
%109 = getelementptr inbounds i8, i8* %93, i64 13
%110 = load i32, i32* %15
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds i8, i8* %109, i64 %111
%113 = load i8**, i8*** %5
%114 = getelementptr inbounds i8*, i8** %113, i64 1
%115 = load i8*, i8** %114
%116 = load i32, i32* %15
%117 = call i32 (i8*, ...) @memcpy(i8* %112, i8* %115, i32 %116)
%118 = getelementptr inbounds i8, i8* %93, i64 14
%119 = load i32, i32* %17
%120 = sext i32 %119 to i64
%121 = getelementptr inbounds i8, i8* %118, i64 %120
%122 = call i32 (i8*, ...) @memcpy(i8* %121, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 5)
%123 = getelementptr inbounds i8, i8* %93, i64 19
%124 = load i32, i32* %17
%125 = sext i32 %124 to i64
%126 = getelementptr inbounds i8, i8* %123, i64 %125
%127 = load i32, i32* %16
%128 = call i32 (i8*, ...) @memcpy(i8* %126, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %127)
%129 = getelementptr inbounds i8, i8* %93, i64 20
%130 = load i32, i32* %17
%131 = sext i32 %130 to i64
%132 = getelementptr inbounds i8, i8* %129, i64 %131
%133 = load i32, i32* %16
%134 = sext i32 %133 to i64
%135 = getelementptr inbounds i8, i8* %132, i64 %134
%136 = call i32 (i8*, ...) @memcpy(i8* %135, i32* %21, i32 2)
%137 = getelementptr inbounds i8, i8* %93, i64 22
%138 = load i32, i32* %17
%139 = sext i32 %138 to i64
%140 = getelementptr inbounds i8, i8* %137, i64 %139
%141 = load i32, i32* %16
%142 = sext i32 %141 to i64
%143 = getelementptr inbounds i8, i8* %140, i64 %142
%144 = call i32 (i8*, ...) @memcpy(i8* %143, i32* %22, i32 2)
%145 = getelementptr inbounds i8, i8* %93, i64 24
%146 = load i32, i32* %17
%147 = sext i32 %146 to i64
%148 = getelementptr inbounds i8, i8* %145, i64 %147
%149 = load i32, i32* %16
%150 = sext i32 %149 to i64
%151 = getelementptr inbounds i8, i8* %148, i64 %150
%152 = call i32 (i8*, ...) @memcpy(i8* %151, i32* %23, i32 2)
%153 = getelementptr inbounds i8, i8* %93, i64 26
%154 = load i32, i32* %17
%155 = sext i32 %154 to i64
%156 = getelementptr inbounds i8, i8* %153, i64 %155
%157 = load i32, i32* %16
%158 = sext i32 %157 to i64
%159 = getelementptr inbounds i8, i8* %156, i64 %158
%160 = call i32 (i8*, ...) @memcpy(i8* %159, i32* %24, i32 2)
%161 = getelementptr inbounds i8, i8* %93, i64 28
%162 = load i32, i32* %17
%163 = sext i32 %162 to i64
%164 = getelementptr inbounds i8, i8* %161, i64 %163
%165 = load i32, i32* %16
%166 = sext i32 %165 to i64
%167 = getelementptr inbounds i8, i8* %164, i64 %166
%168 = call i32 (i8*, ...) @memcpy(i8* %167, i32* %25, i32 2)
%169 = getelementptr inbounds i8, i8* %93, i64 30
%170 = load i32, i32* %17
%171 = sext i32 %170 to i64
%172 = getelementptr inbounds i8, i8* %169, i64 %171
%173 = load i32, i32* %16
%174 = sext i32 %173 to i64
%175 = getelementptr inbounds i8, i8* %172, i64 %174
%176 = call i32 (i8*, ...) @memcpy(i8* %175, i32* %26, i32 2)
%177 = load i32, i32* %7
%178 = call i32 (i32, ...) @write(i32 %177, i32* %18, i32 2)
%179 = load i32, i32* %7
%180 = load i32, i32* %18
%181 = call i32 (i32, ...) @write(i32 %179, i8* %93, i32 %180)
%182 = load i32, i32* %18
%183 = call i32 @print_message(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %93, i32 %182)
%184 = load i8*, i8** %19
br label %192
185: ; preds = %62
%186 = load i32, i32* %14
%187 = icmp eq i32 %186, 32
br i1 %187, label %188, label %191
188: ; preds = %185
%189 = load i32, i32* %7
%190 = call i32 (i32, ...) @write(i32 %189, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i32 6)
br label %191
191: ; preds = %188, %185
br label %192
192: ; preds = %191, %77
store i32 0, i32* %12
br label %193
193: ; preds = %192, %60
%194 = load i8*, i8** %10
%195 = load i32, i32* %12
switch i32 %195, label %204 [
i32 0, label %196
i32 3, label %197
]
196: ; preds = %193
br label %37
197: ; preds = %193, %49, %37
%198 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0))
%199 = load i32, i32* %6
%200 = call i32 @close(i32 %199)
%201 = load i32, i32* %7
%202 = call i32 @close(i32 %201)
%203 = load i32, i32* %3
ret i32 %203
204: ; preds = %193
unreachable
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@.str.2 = [4 x i8] c"GOT\00"
@.str.3 = [10 x i8] c"RuneScape\00"
@.str.4 = [13 x i8] c"\00\01\00\04\00\00\00\00\00\00\00\00\00"
@.str.5 = [6 x i8] c"\00\04\00\00\07\00"
@.str.6 = [5 x i8] c"SENT\00"
@.str.7 = [7 x i8] c"\04\00\00\0B\00\01\00"
@str = [33 x i8] c"Ended communication with client.\00"
@str.9 = [33 x i8] c"ERROR: Failed to read a message.\00"
@str.10 = [41 x i8] c"ERROR: Message size recieved is invalid.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 @open(i8* %12, i32 %13)
%15 = getelementptr inbounds i8*, i8** %1, i64 3
%16 = load i8*, i8** %15
%17 = load i32, i32* @O_WRONLY
%18 = tail call i32 @open(i8* %16, i32 %17)
%19 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%20 = call i64 @read(i32 %14, i8* %19, i32 2)
%21 = icmp eq i64 %20, 0
br i1 %21, label %126, label %22
22: ; preds = %2
%23 = bitcast [2 x i8]* %3 to i32*
%24 = getelementptr inbounds i8*, i8** %1, i64 1
%25 = bitcast i32* %4 to i8*
%26 = bitcast i32* %5 to i8*
%27 = bitcast i32* %6 to i8*
%28 = bitcast i32* %7 to i8*
%29 = bitcast i32* %8 to i8*
%30 = bitcast i32* %9 to i8*
%31 = bitcast i32* %10 to i8*
br label %32
32: ; preds = %22, %123
%33 = load i32, i32* %23
%34 = call i32 @le16toh(i32 %33)
%35 = icmp slt i32 %34, 2
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.10, i64 0, i64 0))
br label %126
38: ; preds = %32
%39 = zext i32 %34 to i64
%40 = call i8* @llvm.stacksave()
%41 = alloca i8, i64 %39
%42 = call i64 @read(i32 %14, i8* %41, i32 %34)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %38
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.9, i64 0, i64 0))
br label %126
46: ; preds = %38
%47 = load i8, i8* %41
%48 = getelementptr inbounds i8, i8* %41, i64 1
%49 = load i8, i8* %48
%50 = zext i8 %49 to i32
%51 = shl nuw nsw i32 %50, 8
%52 = zext i8 %47 to i32
%53 = or i32 %51, %52
%54 = call i32 @be16toh(i32 %53)
%55 = call i32 @print_message(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %41, i32 %34)
switch i32 %54, label %123 [
i32 0, label %56
i32 32, label %121
]
56: ; preds = %46
%57 = load i8*, i8** %24
%58 = call i32 @strlen(i8* %57)
%59 = call i32 @strlen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%60 = shl nsw i32 %58, 1
%61 = add i32 %59, 32
%62 = add i32 %61, %60
%63 = call i32 @htole16(i32 %62)
store i32 %63, i32* %4
%64 = zext i32 %63 to i64
%65 = call i8* @llvm.stacksave()
%66 = alloca i8, i64 %64
%67 = call i32 @htobe16(i32 765)
store i32 %67, i32* %5
%68 = call i32 @htobe16(i32 540)
store i32 %68, i32* %6
%69 = call i32 @htobe16(i32 3840)
store i32 %69, i32* %7
%70 = call i32 @htobe16(i32 2160)
store i32 %70, i32* %8
%71 = call i32 @htobe16(i32 1366)
store i32 %71, i32* %9
%72 = call i32 @htobe16(i32 768)
store i32 %72, i32* %10
%73 = load i32, i32* %4
%74 = call i32 @memset(i8* %66, i32 0, i32 %73)
%75 = call i32 (i8*, ...) @memcpy(i8* %66, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 12)
%76 = getelementptr inbounds i8, i8* %66, i64 12
%77 = load i8*, i8** %24
%78 = call i32 (i8*, ...) @memcpy(i8* %76, i8* %77, i32 %58)
%79 = getelementptr inbounds i8, i8* %66, i64 13
%80 = sext i32 %58 to i64
%81 = getelementptr inbounds i8, i8* %79, i64 %80
%82 = load i8*, i8** %24
%83 = call i32 (i8*, ...) @memcpy(i8* %81, i8* %82, i32 %58)
%84 = getelementptr inbounds i8, i8* %66, i64 14
%85 = sext i32 %60 to i64
%86 = getelementptr inbounds i8, i8* %84, i64 %85
%87 = call i32 (i8*, ...) @memcpy(i8* %86, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 5)
%88 = getelementptr inbounds i8, i8* %66, i64 19
%89 = getelementptr inbounds i8, i8* %88, i64 %85
%90 = call i32 (i8*, ...) @memcpy(i8* %89, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %59)
%91 = getelementptr inbounds i8, i8* %66, i64 20
%92 = getelementptr inbounds i8, i8* %91, i64 %85
%93 = sext i32 %59 to i64
%94 = getelementptr inbounds i8, i8* %92, i64 %93
%95 = call i32 (i8*, ...) @memcpy(i8* %94, i32* %5, i32 2)
%96 = getelementptr inbounds i8, i8* %66, i64 22
%97 = getelementptr inbounds i8, i8* %96, i64 %85
%98 = getelementptr inbounds i8, i8* %97, i64 %93
%99 = call i32 (i8*, ...) @memcpy(i8* %98, i32* %6, i32 2)
%100 = getelementptr inbounds i8, i8* %66, i64 24
%101 = getelementptr inbounds i8, i8* %100, i64 %85
%102 = getelementptr inbounds i8, i8* %101, i64 %93
%103 = call i32 (i8*, ...) @memcpy(i8* %102, i32* %7, i32 2)
%104 = getelementptr inbounds i8, i8* %66, i64 26
%105 = getelementptr inbounds i8, i8* %104, i64 %85
%106 = getelementptr inbounds i8, i8* %105, i64 %93
%107 = call i32 (i8*, ...) @memcpy(i8* %106, i32* %8, i32 2)
%108 = getelementptr inbounds i8, i8* %66, i64 28
%109 = getelementptr inbounds i8, i8* %108, i64 %85
%110 = getelementptr inbounds i8, i8* %109, i64 %93
%111 = call i32 (i8*, ...) @memcpy(i8* %110, i32* %9, i32 2)
%112 = getelementptr inbounds i8, i8* %66, i64 30
%113 = getelementptr inbounds i8, i8* %112, i64 %85
%114 = getelementptr inbounds i8, i8* %113, i64 %93
%115 = call i32 (i8*, ...) @memcpy(i8* %114, i32* %10, i32 2)
%116 = call i32 (i32, ...) @write(i32 %18, i32* %4, i32 2)
%117 = load i32, i32* %4
%118 = call i32 (i32, ...) @write(i32 %18, i8* %66, i32 %117)
%119 = load i32, i32* %4
%120 = call i32 @print_message(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %66, i32 %119)
br label %123
121: ; preds = %46
%122 = call i32 (i32, ...) @write(i32 %18, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i32 6)
br label %123
123: ; preds = %46, %121, %56
%124 = call i64 @read(i32 %14, i8* %19, i32 2)
%125 = icmp eq i64 %124, 0
br i1 %125, label %126, label %32
126: ; preds = %123, %2, %44, %36
%127 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%128 = call i32 @close(i32 %14)
%129 = call i32 @close(i32 %18)
ret i32 0
}