#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 accept_connection(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ escape(char *, int, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getpid();
int /*<<< orphan*/ handle_request(int, char *);
int listen_on(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  char buffer[1024];
  char dir[1024];
  if (argc != 2) {
    fprintf(stderr, "usage: threeServer port-number\n");
    exit(1);
  }
  printf("\nThis is the server with pid %d listening on port %s\n", getpid(),
         argv[1]);
  int s = listen_on(argv[1]);
  while (1) {
    int msgsock = accept_connection(s);
    read(msgsock, buffer, 1024 - 1);
    printf("\nListing directory request: \"%s\"\n", buffer);
    escape(dir, 1024, buffer);
    handle_request(msgsock, dir);
  }
  close(s);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11d2 <main+0x42>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
lea    0xe3d(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <listen_on@plt>
mov    %eax,-0x814(%rbp)
mov    -0x814(%rbp),%edi
call   1090 <accept_connection@plt>
mov    %eax,-0x818(%rbp)
mov    -0x818(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x3ff,%edx
call   1060 <read@plt>
lea    -0x410(%rbp),%rsi
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x810(%rbp),%rdi
lea    -0x410(%rbp),%rdx
mov    $0x400,%esi
call   10b0 <escape@plt>
mov    -0x818(%rbp),%edi
lea    -0x810(%rbp),%rsi
call   1070 <handle_request@plt>
jmp    1204 <main+0x74>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x800,%rsp
cmp    $0x2,%edi
jne    1222 <main+0x92>
mov    %rsi,%rbx
xor    %eax,%eax
call   1040 <getpid@plt>
mov    0x8(%rbx),%rdx
lea    0xe67(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rbx),%rdi
call   1030 <listen_on@plt>
mov    %eax,%r15d
lea    0x400(%rsp),%rbx
lea    0xe79(%rip),%r14
mov    %rsp,%r12
mov    %r15d,%edi
call   1090 <accept_connection@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x3ff,%edx
call   1060 <read@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   10b0 <escape@plt>
mov    %ebp,%edi
mov    %r12,%rsi
call   1070 <handle_request@plt>
jmp    11e0 <main+0x50>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
lea    0xdce(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c"usage: threeServer port-number\0A\00"
@.str.1 = [54 x i8] c"\0AThis is the server with pid %d listening on port %s\0A\00"
@.str.2 = [34 x i8] c"\0AListing directory request: \22%s\22\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = call i32 (...) @getpid()
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i32 %17, i8* %20)
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @listen_on(i8* %24)
store i32 %25, i32* %8
br label %26
26: ; preds = %16, %26
%27 = load i32, i32* %8
%28 = call i32 @accept_connection(i32 %27)
store i32 %28, i32* %9
%29 = load i32, i32* %9
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%31 = call i32 @read(i32 %29, i8* %30, i32 1023)
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %32)
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%36 = call i32 @escape(i8* %34, i32 1024, i8* %35)
%37 = load i32, i32* %9
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%39 = call i32 @handle_request(i32 %37, i8* %38)
br label %26
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"usage: threeServer port-number\0A\00"
@.str.1 = [54 x i8] c"\0AThis is the server with pid %d listening on port %s\0A\00"
@.str.2 = [34 x i8] c"\0AListing directory request: \22%s\22\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 2
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = tail call i32 (...) @getpid()
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i32 %13, i8* %15)
%17 = load i8*, i8** %14
%18 = tail call i32 @listen_on(i8* %17)
br label %19
19: ; preds = %19, %12
%20 = call i32 @accept_connection(i32 %18)
%21 = call i32 @read(i32 %20, i8* %5, i32 1023)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%23 = call i32 @escape(i8* %6, i32 1024, i8* %5)
%24 = call i32 @handle_request(i32 %20, i8* %6)
br label %19
}