#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 */
struct sockaddr {
  int dummy;
};
struct addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  struct addrinfo *ai_next;
  int /*<<< orphan*/ ai_flags;
};
typedef int /*<<< orphan*/ client_rqst;

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ AI_PASSIVE;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int accept(int, struct sockaddr *, int *);
int bind(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char *gai_strerror(int);
int getaddrinfo(int /*<<< orphan*/ *, char *, struct addrinfo *,
                struct addrinfo **);
int listen(int, int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ process_rqst(int, char *);
int recv(int, char *, int, int /*<<< orphan*/);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ start_msg();
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int sockfd, new_conn;
  int rc, yes = 1;
  int addrlen = sizeof(struct sockaddr);
  start_msg();
  struct addrinfo hints, *serv_info, *p;
  struct sockaddr conn_info;
  memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = AI_PASSIVE;
  rc = getaddrinfo(NULL, "8080", &hints, &serv_info);
  if (rc != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rc));
    return -1;
  }
  for (p = serv_info; p != NULL; p = p->ai_next) {
    sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol);
    if (sockfd == -1) {
      fprintf(stderr, "socket: %s\n", strerror(errno));
      continue;
    }
    rc = setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int));
    if (rc == -1) {
      fprintf(stderr, "setsockopt: %s\n", strerror(errno));
      return -1;
    }
    rc = bind(sockfd, p->ai_addr, p->ai_addrlen);
    if (rc == -1) {
      fprintf(stderr, "bind: %s\n", strerror(errno));
      continue;
    }
    break;
  }
  if (p == NULL) {
    fprintf(stderr, "Failed to create server socket. Exiting...\n");
    return -1;
  }
  rc = listen(sockfd, 10);
  if (rc == -1) {
    fprintf(stderr, "Failed to configure server socket. Exiting...\n");
    return -1;
  }
  printf("Sailfish ready to glide. Awaiting connections...\n");
  while (1) {
    new_conn = accept(sockfd, &conn_info, &addrlen);
    char client_rqst[10024];
    if (new_conn == -1) {
      fprintf(stderr, "accept: %s\n", strerror(errno));
      continue;
    }
    rc = recv(new_conn, client_rqst, sizeof(client_rqst), 0);
    if (rc == -1) {
      fprintf(stderr, "send: %s\n", strerror(errno));
      continue;
    }
    client_rqst[rc] = '\0';
    process_rqst(new_conn, client_rqst);
    close(new_conn);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x27b0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x20(%rbp)
movl   $0x4,-0x24(%rbp)
mov    $0x0,%al
call   10e0 <start_msg@plt>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1080 <memset@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2d7f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2d93(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xda3(%rip),%rsi
lea    -0x50(%rbp),%rdx
lea    -0x58(%rbp),%rcx
call   10f0 <getaddrinfo@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     12b1 <main+0xc1>
mov    0x2d4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2794(%rbp)
mov    -0x1c(%rbp),%edi
call   1070 <gai_strerror@plt>
mov    -0x2794(%rbp),%edi
mov    %rax,%rdx
lea    0xd67(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1557 <main+0x367>
mov    -0x58(%rbp),%rax
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
je     1406 <main+0x216>
mov    -0x60(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x60(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x60(%rbp),%rax
mov    0x8(%rax),%edx
call   1110 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1324 <main+0x134>
mov    0x2cd6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2798(%rbp)
mov    0x2cb7(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x2798(%rbp),%edi
mov    %rax,%rdx
lea    0xcfe(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    13f5 <main+0x205>
mov    -0x14(%rbp),%edi
mov    0x2cba(%rip),%rax
mov    (%rax),%esi
mov    0x2c79(%rip),%rax
mov    (%rax),%edx
lea    -0x20(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1395 <main+0x1a5>
mov    0x2c6c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x279c(%rbp)
mov    0x2c4d(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x279c(%rbp),%edi
mov    %rax,%rdx
lea    0xca0(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1557 <main+0x367>
mov    -0x14(%rbp),%edi
mov    -0x60(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x60(%rbp),%rax
mov    (%rax),%edx
call   10c0 <bind@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    13f0 <main+0x200>
mov    0x2c0a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x27a0(%rbp)
mov    0x2beb(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x27a0(%rbp),%edi
mov    %rax,%rdx
lea    0xc4e(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    13f5 <main+0x205>
jmp    1406 <main+0x216>
mov    -0x60(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x60(%rbp)
jmp    12b9 <main+0xc9>
cmpq   $0x0,-0x60(%rbp)
jne    1434 <main+0x244>
mov    0x2bb0(%rip),%rax
mov    (%rax),%edi
lea    0xc1b(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1557 <main+0x367>
mov    -0x14(%rbp),%edi
mov    $0xa,%esi
call   10b0 <listen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1471 <main+0x281>
mov    0x2b73(%rip),%rax
mov    (%rax),%edi
lea    0xc0a(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1557 <main+0x367>
lea    0xc1f(%rip),%rdi
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x68(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   10d0 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    14d3 <main+0x2e3>
mov    0x2b27(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x27a4(%rbp)
mov    0x2b08(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x27a4(%rbp),%edi
mov    %rax,%rdx
lea    0xc02(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    147d <main+0x28d>
mov    -0x18(%rbp),%edi
lea    -0x2790(%rbp),%rsi
mov    $0x2728,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    152f <main+0x33f>
mov    0x2acb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x27a8(%rbp)
mov    0x2aac(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x27a8(%rbp),%edi
mov    %rax,%rdx
lea    0xbb2(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    147d <main+0x28d>
movslq -0x1c(%rbp),%rax
movb   $0x0,-0x2790(%rbp,%rax,1)
mov    -0x18(%rbp),%edi
lea    -0x2790(%rbp),%rsi
call   1050 <process_rqst@plt>
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
jmp    147d <main+0x28d>
mov    -0x4(%rbp),%eax
add    $0x27b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2768,%rsp
movl   $0x1,0x4(%rsp)
movl   $0x4,(%rsp)
xor    %eax,%eax
call   10e0 <start_msg@plt>
lea    0x18(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1080 <memset@plt>
mov    0x2da6(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x28(%rsp)
mov    0x2d81(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x24(%rsp)
mov    0x2d94(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x38(%rsp)
lea    0xda7(%rip),%rsi
lea    0x10(%rsp),%rcx
xor    %edi,%edi
mov    %rbx,%rdx
call   10f0 <getaddrinfo@plt>
test   %eax,%eax
je     1294 <main+0xa4>
mov    0x2d55(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1070 <gai_strerror@plt>
lea    0xd82(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    1439 <main+0x249>
mov    0x10(%rsp),%rbp
test   %rbp,%rbp
je     1422 <main+0x232>
lea    0xd6d(%rip),%r12
lea    0x4(%rsp),%r14
lea    0xd7d(%rip),%r13
jmp    12f3 <main+0x103>
nopw   0x0(%rax,%rax,1)
mov    0x2d01(%rip),%rax
mov    (%rax),%ebx
mov    0x2ce8(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    0x18(%rbp),%rbp
test   %rbp,%rbp
je     1422 <main+0x232>
mov    0x10(%rbp),%edi
mov    0x8(%rbp),%edx
mov    0xc(%rbp),%esi
call   1110 <socket@plt>
mov    %r12,%r15
cmp    $0xffffffff,%eax
je     12c0 <main+0xd0>
mov    %eax,%ebx
mov    0x2cd6(%rip),%rax
mov    (%rax),%esi
mov    0x2c95(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    %r14,%rcx
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     1450 <main+0x260>
mov    0x0(%rbp),%edx
mov    0x4(%rbp),%esi
mov    %ebx,%edi
call   10c0 <bind@plt>
mov    %r13,%r15
cmp    $0xffffffff,%eax
je     12c0 <main+0xd0>
mov    %ebx,%edi
mov    $0xa,%esi
call   10b0 <listen@plt>
cmp    $0xffffffff,%eax
je     1473 <main+0x283>
lea    0xd42(%rip),%rdi
call   1040 <puts@plt>
lea    0x8(%rsp),%r14
mov    %rsp,%r15
lea    0xd18(%rip),%r12
lea    0x40(%rsp),%r13
jmp    13b6 <main+0x1c6>
cs nopw 0x0(%rax,%rax,1)
mov    0x2c31(%rip),%rax
mov    (%rax),%ebp
mov    0x2c18(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    %ebp,%edi
mov    %r12,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   10d0 <accept@plt>
cmp    $0xffffffff,%eax
je     1390 <main+0x1a0>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r13,%rsi
mov    $0x2728,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0xffffffff,%eax
je     1400 <main+0x210>
cltq
movb   $0x0,0x40(%rsp,%rax,1)
mov    %ebp,%edi
mov    %r13,%rsi
call   1060 <process_rqst@plt>
mov    %ebp,%edi
call   1090 <close@plt>
jmp    13b6 <main+0x1c6>
nopw   0x0(%rax,%rax,1)
mov    0x2bc1(%rip),%rax
mov    (%rax),%ebp
mov    0x2ba8(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    %ebp,%edi
lea    0xc83(%rip),%rsi
jmp    13ac <main+0x1bc>
mov    0x2b9f(%rip),%rax
mov    (%rax),%edi
lea    0xc0a(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x2768,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b71(%rip),%rax
mov    (%rax),%ebx
mov    0x2b58(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xbb4(%rip),%rsi
jmp    1283 <main+0x93>
mov    0x2b4e(%rip),%rax
mov    (%rax),%edi
lea    0xbe5(%rip),%rsi
jmp    1432 <main+0x242>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32, %struct.addrinfo*, i32 }
%struct.sockaddr = type { i32 }
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@.str = [5 x i8] c"8080\00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.2 = [12 x i8] c"socket: %s\0A\00"
@errno = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.3 = [16 x i8] c"setsockopt: %s\0A\00"
@.str.4 = [10 x i8] c"bind: %s\0A\00"
@.str.5 = [44 x i8] c"Failed to create server socket. Exiting...\0A\00"
@.str.6 = [47 x i8] c"Failed to configure server socket. Exiting...\0A\00"
@.str.7 = [50 x i8] c"Sailfish ready to glide. Awaiting connections...\0A\00"
@.str.8 = [12 x i8] c"accept: %s\0A\00"
@.str.9 = [10 x i8] c"send: %s\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 i32
%10 = alloca i32
%11 = alloca %struct.addrinfo
%12 = alloca %struct.addrinfo*
%13 = alloca %struct.addrinfo*
%14 = alloca %struct.sockaddr
%15 = alloca [10024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %9
store i32 4, i32* %10
%16 = call i32 (...) @start_msg()
%17 = call i32 @memset(%struct.addrinfo* %11, i32 0, i32 40)
%18 = load i32, i32* @AF_UNSPEC
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %11, i32 0, i32 4
store i32 %18, i32* %19
%20 = load i32, i32* @SOCK_STREAM
%21 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %11, i32 0, i32 3
store i32 %20, i32* %21
%22 = load i32, i32* @AI_PASSIVE
%23 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %11, i32 0, i32 6
store i32 %22, i32* %23
%24 = call i32 @getaddrinfo(i32* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %struct.addrinfo* %11, %struct.addrinfo** %12)
store i32 %24, i32* %8
%25 = load i32, i32* %8
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %2
%28 = load i32, i32* @stderr
%29 = load i32, i32* %8
%30 = call i8* @gai_strerror(i32 %29)
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %30)
store i32 -1, i32* %3
br label %134
32: ; preds = %2
%33 = load %struct.addrinfo*, %struct.addrinfo** %12
store %struct.addrinfo* %33, %struct.addrinfo** %13
br label %34
34: ; preds = %84, %32
%35 = load %struct.addrinfo*, %struct.addrinfo** %13
%36 = icmp ne %struct.addrinfo* %35, null
br i1 %36, label %37, label %88
37: ; preds = %34
%38 = load %struct.addrinfo*, %struct.addrinfo** %13
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %38, i32 0, i32 4
%40 = load i32, i32* %39
%41 = load %struct.addrinfo*, %struct.addrinfo** %13
%42 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %41, i32 0, i32 3
%43 = load i32, i32* %42
%44 = load %struct.addrinfo*, %struct.addrinfo** %13
%45 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %44, i32 0, i32 2
%46 = load i32, i32* %45
%47 = call i32 @socket(i32 %40, i32 %43, i32 %46)
store i32 %47, i32* %6
%48 = load i32, i32* %6
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %55
50: ; preds = %37
%51 = load i32, i32* @stderr
%52 = load i32, i32* @errno
%53 = call i8* @strerror(i32 %52)
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %53)
br label %84
55: ; preds = %37
%56 = load i32, i32* %6
%57 = load i32, i32* @SOL_SOCKET
%58 = load i32, i32* @SO_REUSEADDR
%59 = call i32 @setsockopt(i32 %56, i32 %57, i32 %58, i32* %9, i32 4)
store i32 %59, i32* %8
%60 = load i32, i32* %8
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %67
62: ; preds = %55
%63 = load i32, i32* @stderr
%64 = load i32, i32* @errno
%65 = call i8* @strerror(i32 %64)
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %65)
store i32 -1, i32* %3
br label %134
67: ; preds = %55
%68 = load i32, i32* %6
%69 = load %struct.addrinfo*, %struct.addrinfo** %13
%70 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %69, i32 0, i32 1
%71 = load i32, i32* %70
%72 = load %struct.addrinfo*, %struct.addrinfo** %13
%73 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %72, i32 0, i32 0
%74 = load i32, i32* %73
%75 = call i32 @bind(i32 %68, i32 %71, i32 %74)
store i32 %75, i32* %8
%76 = load i32, i32* %8
%77 = icmp eq i32 %76, -1
br i1 %77, label %78, label %83
78: ; preds = %67
%79 = load i32, i32* @stderr
%80 = load i32, i32* @errno
%81 = call i8* @strerror(i32 %80)
%82 = call i32 (i32, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %81)
br label %84
83: ; preds = %67
br label %88
84: ; preds = %78, %50
%85 = load %struct.addrinfo*, %struct.addrinfo** %13
%86 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %85, i32 0, i32 5
%87 = load %struct.addrinfo*, %struct.addrinfo** %86
store %struct.addrinfo* %87, %struct.addrinfo** %13
br label %34
88: ; preds = %83, %34
%89 = load %struct.addrinfo*, %struct.addrinfo** %13
%90 = icmp eq %struct.addrinfo* %89, null
br i1 %90, label %91, label %94
91: ; preds = %88
%92 = load i32, i32* @stderr
%93 = call i32 (i32, i8*, ...) @fprintf(i32 %92, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %3
br label %134
94: ; preds = %88
%95 = load i32, i32* %6
%96 = call i32 @listen(i32 %95, i32 10)
store i32 %96, i32* %8
%97 = load i32, i32* %8
%98 = icmp eq i32 %97, -1
br i1 %98, label %99, label %102
99: ; preds = %94
%100 = load i32, i32* @stderr
%101 = call i32 (i32, i8*, ...) @fprintf(i32 %100, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %3
br label %134
102: ; preds = %94
%103 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.7, i64 0, i64 0))
br label %104
104: ; preds = %102, %109, %120, %125
%105 = load i32, i32* %6
%106 = call i32 @accept(i32 %105, %struct.sockaddr* %14, i32* %10)
store i32 %106, i32* %7
%107 = load i32, i32* %7
%108 = icmp eq i32 %107, -1
br i1 %108, label %109, label %114
109: ; preds = %104
%110 = load i32, i32* @stderr
%111 = load i32, i32* @errno
%112 = call i8* @strerror(i32 %111)
%113 = call i32 (i32, i8*, ...) @fprintf(i32 %110, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i8* %112)
br label %104
114: ; preds = %104
%115 = load i32, i32* %7
%116 = getelementptr inbounds [10024 x i8], [10024 x i8]* %15, i64 0, i64 0
%117 = call i32 @recv(i32 %115, i8* %116, i32 10024, i32 0)
store i32 %117, i32* %8
%118 = load i32, i32* %8
%119 = icmp eq i32 %118, -1
br i1 %119, label %120, label %125
120: ; preds = %114
%121 = load i32, i32* @stderr
%122 = load i32, i32* @errno
%123 = call i8* @strerror(i32 %122)
%124 = call i32 (i32, i8*, ...) @fprintf(i32 %121, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i8* %123)
br label %104
125: ; preds = %114
%126 = load i32, i32* %8
%127 = sext i32 %126 to i64
%128 = getelementptr inbounds [10024 x i8], [10024 x i8]* %15, i64 0, i64 %127
store i8 0, i8* %128
%129 = load i32, i32* %7
%130 = getelementptr inbounds [10024 x i8], [10024 x i8]* %15, i64 0, i64 0
%131 = call i32 @process_rqst(i32 %129, i8* %130)
%132 = load i32, i32* %7
%133 = call i32 @close(i32 %132)
br label %104
134: ; preds = %99, %91, %62, %27
%135 = load i32, i32* %3
ret i32 %135
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i32, %struct.addrinfo*, i32 }
%struct.sockaddr = type { i32 }
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@.str = [5 x i8] c"8080\00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.2 = [12 x i8] c"socket: %s\0A\00"
@errno = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.3 = [16 x i8] c"setsockopt: %s\0A\00"
@.str.4 = [10 x i8] c"bind: %s\0A\00"
@.str.5 = [44 x i8] c"Failed to create server socket. Exiting...\0A\00"
@.str.6 = [47 x i8] c"Failed to configure server socket. Exiting...\0A\00"
@.str.8 = [12 x i8] c"accept: %s\0A\00"
@.str.9 = [10 x i8] c"send: %s\0A\00"
@str = [49 x i8] c"Sailfish ready to glide. Awaiting connections...\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.addrinfo
%6 = alloca %struct.addrinfo*
%7 = alloca %struct.sockaddr
%8 = alloca [10024 x i8]
%9 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%10 = bitcast i32* %4 to i8*
store i32 4, i32* %4
%11 = tail call i32 (...) @start_msg()
%12 = bitcast %struct.addrinfo* %5 to i8*
%13 = bitcast %struct.addrinfo** %6 to i8*
%14 = bitcast %struct.sockaddr* %7 to i8*
%15 = call i32 @memset(%struct.addrinfo* %5, i32 0, i32 40)
%16 = load i32, i32* @AF_UNSPEC
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 4
store i32 %16, i32* %17
%18 = load i32, i32* @SOCK_STREAM
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 3
store i32 %18, i32* %19
%20 = load i32, i32* @AI_PASSIVE
%21 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 6
store i32 %20, i32* %21
%22 = call i32 @getaddrinfo(i32* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %struct.addrinfo* %5, %struct.addrinfo** %6)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %2
%25 = load %struct.addrinfo*, %struct.addrinfo** %6
%26 = icmp eq %struct.addrinfo* %25, null
br i1 %26, label %67, label %31
27: ; preds = %2
%28 = load i32, i32* @stderr
%29 = call i8* @gai_strerror(i32 %22)
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %29)
br label %101
31: ; preds = %24, %58
%32 = phi %struct.addrinfo* [ %65, %58 ], [ %25, %24 ]
%33 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %32, i64 0, i32 4
%34 = load i32, i32* %33
%35 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %32, i64 0, i32 3
%36 = load i32, i32* %35
%37 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %32, i64 0, i32 2
%38 = load i32, i32* %37
%39 = call i32 @socket(i32 %34, i32 %36, i32 %38)
%40 = icmp eq i32 %39, -1
br i1 %40, label %58, label %41
41: ; preds = %31
%42 = load i32, i32* @SOL_SOCKET
%43 = load i32, i32* @SO_REUSEADDR
%44 = call i32 @setsockopt(i32 %39, i32 %42, i32 %43, i32* %3, i32 4)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %51
46: ; preds = %41
%47 = load i32, i32* @stderr
%48 = load i32, i32* @errno
%49 = call i8* @strerror(i32 %48)
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %49)
br label %101
51: ; preds = %41
%52 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %32, i64 0, i32 1
%53 = load i32, i32* %52
%54 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %32, i64 0, i32 0
%55 = load i32, i32* %54
%56 = call i32 @bind(i32 %39, i32 %53, i32 %55)
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %70
58: ; preds = %51, %31
%59 = phi i8* [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), %31 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), %51 ]
%60 = load i32, i32* @stderr
%61 = load i32, i32* @errno
%62 = call i8* @strerror(i32 %61)
%63 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* %59, i8* %62)
%64 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %32, i64 0, i32 5
%65 = load %struct.addrinfo*, %struct.addrinfo** %64
%66 = icmp eq %struct.addrinfo* %65, null
br i1 %66, label %67, label %31
67: ; preds = %58, %24
%68 = load i32, i32* @stderr
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0))
br label %101
70: ; preds = %51
%71 = call i32 @listen(i32 %39, i32 10)
%72 = icmp eq i32 %71, -1
br i1 %72, label %73, label %76
73: ; preds = %70
%74 = load i32, i32* @stderr
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.6, i64 0, i64 0))
br label %101
76: ; preds = %70
%77 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str, i64 0, i64 0))
%78 = getelementptr inbounds [10024 x i8], [10024 x i8]* %8, i64 0, i64 0
br label %79
79: ; preds = %100, %76
%80 = call i32 @accept(i32 %39, %struct.sockaddr* %7, i32* %4)
%81 = icmp eq i32 %80, -1
br i1 %81, label %82, label %87
82: ; preds = %79
%83 = load i32, i32* @stderr
%84 = load i32, i32* @errno
%85 = call i8* @strerror(i32 %84)
%86 = call i32 (i32, i8*, ...) @fprintf(i32 %83, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i8* %85)
br label %100
87: ; preds = %79
%88 = call i32 @recv(i32 %80, i8* %78, i32 10024, i32 0)
%89 = icmp eq i32 %88, -1
br i1 %89, label %90, label %95
90: ; preds = %87
%91 = load i32, i32* @stderr
%92 = load i32, i32* @errno
%93 = call i8* @strerror(i32 %92)
%94 = call i32 (i32, i8*, ...) @fprintf(i32 %91, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i8* %93)
br label %100
95: ; preds = %87
%96 = sext i32 %88 to i64
%97 = getelementptr inbounds [10024 x i8], [10024 x i8]* %8, i64 0, i64 %96
store i8 0, i8* %97
%98 = call i32 @process_rqst(i32 %80, i8* %78)
%99 = call i32 @close(i32 %80)
br label %100
100: ; preds = %95, %90, %82
br label %79
101: ; preds = %73, %67, %46, %27
ret i32 -1
}