#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 BUFSIZ;
int accept(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int make_server_socket(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ process_rq(char *, int);
int /*<<< orphan*/ read_til_crnl(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int main(int ac, char *av[]) {
  int sock, fd;
  FILE *fpin;
  char request[BUFSIZ];
  if (ac == 1) {
    fprintf(stderr, "useage: ws portnum\n");
    exit(1);
  }
  sock = make_server_socket(atoi(av[1]));
  if (sock == -1)
    exit(2);
  while (1) {
    fd = accept(sock, NULL, NULL);
    fpin = fdopen(fd, "r");
    fgets(request, BUFSIZ, fpin);
    printf("got a call: request = %s", request);
    read_til_crnl(fpin);
    process_rq(request, fd);
    fclose(fpin);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e0b(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    121b <main+0x6b>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
lea    0xdf4(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,%edi
call   1080 <make_server_socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1246 <main+0x96>
mov    $0x2,%edi
call   10d0 <exit@plt>
jmp    124b <main+0x9b>
jmp    1250 <main+0xa0>
mov    -0x14(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   10b0 <accept@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
lea    0xda8(%rip),%rsi
call   10a0 <fdopen@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,-0x20(%rbp)
mov    0x2d58(%rip),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%rdx
call   1070 <fgets@plt>
mov    -0x38(%rbp),%rsi
lea    0xd80(%rip),%rdi
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <read_til_crnl@plt>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1050 <process_rq@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
jmp    124b <main+0x9b>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e13(%rip),%r12
mov    (%r12),%eax
mov    %rsp,%r13
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
cmp    $0x1,%edi
je     1259 <main+0xa9>
mov    0x8(%rsi),%rdi
call   10c0 <atoi@plt>
mov    %eax,%edi
call   1080 <make_server_socket@plt>
cmp    $0xffffffff,%eax
je     1278 <main+0xc8>
mov    %eax,%r14d
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10b0 <accept@plt>
mov    %eax,%ebx
mov    %eax,%edi
lea    0xdfd(%rip),%rsi
call   10a0 <fdopen@plt>
mov    %rax,%r15
mov    (%r12),%esi
mov    %r13,%rdi
mov    %rax,%rdx
call   1070 <fgets@plt>
lea    0xde1(%rip),%rdi
mov    %r13,%rsi
call   1060 <printf@plt>
mov    %r15,%rdi
call   1040 <read_til_crnl@plt>
mov    %r13,%rdi
mov    %ebx,%esi
call   1050 <process_rq@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
jmp    1200 <main+0x50>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
lea    0xd97(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    $0x2,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@BUFSIZ = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"useage: ws portnum\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [25 x i8] c"got a call: request = %s\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 i8*
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @BUFSIZ
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %9
%14 = alloca i8, i64 %12
store i64 %12, i64* %10
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
%26 = call i32 @make_server_socket(i32 %25)
store i32 %26, i32* %6
%27 = load i32, i32* %6
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %31
29: ; preds = %21
%30 = call i32 @exit(i32 2)
unreachable
31: ; preds = %21
br label %32
32: ; preds = %33, %31
br label %33
33: ; preds = %32
%34 = load i32, i32* %6
%35 = call i32 @accept(i32 %34, i32* null, i32* null)
store i32 %35, i32* %7
%36 = load i32, i32* %7
%37 = call i32* @fdopen(i32 %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %37, i32** %8
%38 = load i32, i32* @BUFSIZ
%39 = load i32*, i32** %8
%40 = call i32 @fgets(i8* %14, i32 %38, i32* %39)
%41 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%42 = load i32*, i32** %8
%43 = call i32 @read_til_crnl(i32* %42)
%44 = load i32, i32* %7
%45 = call i32 @process_rq(i8* %14, i32 %44)
%46 = load i32*, i32** %8
%47 = call i32 @fclose(i32* %46)
br label %32
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"useage: ws portnum\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [25 x i8] c"got a call: request = %s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @BUFSIZ
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = icmp eq i32 %0, 1
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = tail call i32 @make_server_socket(i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = tail call i32 @exit(i32 2)
unreachable
19: ; preds = %11, %19
%20 = call i32 @accept(i32 %15, i32* null, i32* null)
%21 = call i32* @fdopen(i32 %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%22 = load i32, i32* @BUFSIZ
%23 = call i32 @fgets(i8* %5, i32 %22, i32* %21)
%24 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%25 = call i32 @read_til_crnl(i32* %21)
%26 = call i32 @process_rq(i8* %5, i32 %20)
%27 = call i32 @fclose(i32* %21)
br label %19
}