#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 timeval {
  int tv_sec;
  int /*<<< orphan*/ tv_usec;
};
struct sockaddr_storage {
  int /*<<< orphan*/ ss_family;
};
struct sockaddr {
  int dummy;
};
struct rlimit {
  int rlim_cur;
  int rlim_max;
};
struct addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  int /*<<< orphan*/ ai_flags;
};
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ echoClntAddr;

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ AI_PASSIVE;
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ RLIMIT_AS;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, unsigned int *);
int backup();
scalar_t__ bind(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ echoMessage(int);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int /*<<< orphan*/ getInAddr(struct sockaddr *);
scalar_t__ getaddrinfo(int /*<<< orphan*/ *, char *, struct addrinfo *,
                       struct addrinfo **);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/, char *,
                             int);
scalar_t__ isPipeClosed();
scalar_t__ listen(int, int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printErrorAndQuit(char *);
int /*<<< orphan*/ printf(char *, char *);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
scalar_t__ setrlimit(int /*<<< orphan*/, struct rlimit *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ usage(char *);
int main(int argc, char *argv[]) {
  struct rlimit rlim;
  rlim.rlim_cur = 32 * 1024 * 1024;
  rlim.rlim_max = 32 * 1024 * 1024;
  if (0 != setrlimit(RLIMIT_AS, &rlim))
    printErrorAndQuit("setrlimit failed");
  int servSock;
  struct addrinfo hints;
  struct addrinfo *servinfo;
  if (argc != 2)
    usage(argv[0]);
  memset(&hints, 0, sizeof hints);
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = AI_PASSIVE;
  if ((getaddrinfo(NULL, argv[1], &hints, &servinfo)) != 0)
    printErrorAndQuit("getaddrinfo() failed");
  if ((servSock = socket(servinfo->ai_family, servinfo->ai_socktype,
                         servinfo->ai_protocol)) < 0)
    printErrorAndQuit("socket() failed");
  if (bind(servSock, servinfo->ai_addr, servinfo->ai_addrlen) < 0)
    printErrorAndQuit("bind() failed");
  freeaddrinfo(servinfo);
  if (listen(servSock, 5) < 0)
    printErrorAndQuit("listen() failed");
  char s[INET6_ADDRSTRLEN];
  int clntSock;
  unsigned int clntLen;
  struct sockaddr_storage echoClntAddr;
  clntLen = sizeof(echoClntAddr);
  int ft = backup();
  for (;;) {
    struct timeval tv = {.tv_sec = 5, .tv_usec = 0};
    fd_set rfds;
    FD_ZERO(&rfds);
    FD_SET(servSock, &rfds);
    int retval = select(servSock + 1, &rfds, NULL, NULL, &tv);
    if (retval) {
      if ((clntSock = accept(servSock, (struct sockaddr *)&echoClntAddr,
                             &clntLen)) < 0)
        printErrorAndQuit("accept() returned error");
      inet_ntop(echoClntAddr.ss_family,
                getInAddr((struct sockaddr *)&echoClntAddr), s, sizeof s);
      printf("Handling client %s\n", s);
      echoMessage(clntSock);
    }
    if (ft < 0 || isPipeClosed()) {
      ft = backup();
    }
  }
}


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)
movl   $0x2000000,-0x18(%rbp)
movl   $0x2000000,-0x14(%rbp)
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   10e0 <setrlimit@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1283 <main+0x53>
lea    0xd82(%rip),%rdi
call   1090 <printErrorAndQuit@plt>
cmpl   $0x2,-0x8(%rbp)
je     1299 <main+0x69>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10f0 <usage@plt>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1080 <memset@plt>
mov    0x2d28(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d0c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d18(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    -0x38(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   1120 <getaddrinfo@plt>
cmp    $0x0,%rax
je     12fc <main+0xcc>
lea    0xd1a(%rip),%rdi
call   1090 <printErrorAndQuit@plt>
mov    -0x40(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x40(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%edx
call   1150 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    132e <main+0xfe>
lea    0xcfd(%rip),%rdi
call   1090 <printErrorAndQuit@plt>
mov    -0x1c(%rbp),%edi
mov    -0x40(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x40(%rbp),%rax
mov    (%rax),%edx
call   1100 <bind@plt>
cmp    $0x0,%rax
jge    1359 <main+0x129>
lea    0xce2(%rip),%rdi
call   1090 <printErrorAndQuit@plt>
mov    -0x40(%rbp),%rdi
call   1140 <freeaddrinfo@plt>
mov    -0x1c(%rbp),%edi
mov    $0x5,%esi
call   10d0 <listen@plt>
cmp    $0x0,%rax
jge    1385 <main+0x155>
lea    0xcc4(%rip),%rdi
call   1090 <printErrorAndQuit@plt>
mov    0x2c5c(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x88(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x80(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x50(%rbp)
movl   $0x4,-0x58(%rbp)
mov    $0x0,%al
call   10a0 <backup@plt>
mov    %eax,-0x64(%rbp)
mov    0xcb0(%rip),%rax
mov    %rax,-0x70(%rbp)
lea    -0x74(%rbp),%rdi
call   10b0 <FD_ZERO@plt>
mov    -0x1c(%rbp),%edi
lea    -0x74(%rbp),%rsi
call   1130 <FD_SET@plt>
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
lea    -0x74(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x70(%rbp),%r8
mov    %rcx,%rdx
call   10c0 <select@plt>
mov    %eax,-0x78(%rbp)
cmpl   $0x0,-0x78(%rbp)
je     147c <main+0x24c>
mov    -0x1c(%rbp),%edi
lea    -0x60(%rbp),%rsi
lea    -0x58(%rbp),%rdx
call   1110 <accept@plt>
mov    %eax,-0x54(%rbp)
cmp    $0x0,%eax
jge    1438 <main+0x208>
lea    0xc21(%rip),%rdi
call   1090 <printErrorAndQuit@plt>
mov    -0x60(%rbp),%eax
mov    %eax,-0x8c(%rbp)
lea    -0x60(%rbp),%rdi
call   1050 <getInAddr@plt>
mov    -0x8c(%rbp),%edi
mov    -0x80(%rbp),%rdx
mov    %eax,%esi
mov    -0x88(%rbp),%rax
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0x80(%rbp),%rsi
lea    0xbfd(%rip),%rdi
call   1060 <printf@plt>
mov    -0x54(%rbp),%edi
call   1070 <echoMessage@plt>
cmpl   $0x0,-0x64(%rbp)
jl     1497 <main+0x267>
mov    $0x0,%al
call   1040 <isPipeClosed@plt>
cmp    $0x0,%rax
je     14a1 <main+0x271>
mov    $0x0,%al
call   10a0 <backup@plt>
mov    %eax,-0x64(%rbp)
jmp    13c9 <main+0x199>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
movabs $0x200000002000000,%rax
mov    %rax,-0x60(%rbp)
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
lea    -0x60(%rbp),%rsi
call   10e0 <setrlimit@plt>
test   %rax,%rax
je     1277 <main+0x47>
lea    0xd8e(%rip),%rdi
call   1090 <printErrorAndQuit@plt>
cmp    $0x2,%ebx
je     1284 <main+0x54>
mov    (%r14),%rdi
call   10f0 <usage@plt>
lea    -0x80(%rbp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1080 <memset@plt>
mov    0x2d3a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x70(%rbp)
mov    0x2d1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    0x2d2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    0x8(%r14),%rsi
lea    -0x38(%rbp),%rcx
xor    %edi,%edi
mov    %rbx,%rdx
call   1120 <getaddrinfo@plt>
test   %rax,%rax
je     12de <main+0xae>
lea    0xd38(%rip),%rdi
call   1090 <printErrorAndQuit@plt>
mov    -0x38(%rbp),%rax
mov    0x10(%rax),%edi
mov    0x8(%rax),%edx
mov    0xc(%rax),%esi
call   1150 <socket@plt>
mov    %eax,%r15d
test   %eax,%eax
jns    1303 <main+0xd3>
lea    0xd28(%rip),%rdi
call   1090 <printErrorAndQuit@plt>
mov    -0x38(%rbp),%rax
mov    (%rax),%edx
mov    0x4(%rax),%esi
mov    %r15d,%edi
call   1100 <bind@plt>
test   %rax,%rax
jns    1325 <main+0xf5>
lea    0xd16(%rip),%rdi
call   1090 <printErrorAndQuit@plt>
mov    -0x38(%rbp),%rdi
call   1140 <freeaddrinfo@plt>
mov    %r15d,%edi
mov    $0x5,%esi
call   10d0 <listen@plt>
test   %rax,%rax
jns    134c <main+0x11c>
lea    0xcfd(%rip),%rdi
call   1090 <printErrorAndQuit@plt>
mov    0x2c95(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rax,-0x50(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
movl   $0x4,-0x40(%rbp)
xor    %eax,%eax
call   10a0 <backup@plt>
mov    %eax,%r14d
mov    %r15d,%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    139a <main+0x16a>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10a0 <backup@plt>
mov    %eax,%r14d
movq   $0x5,-0x58(%rbp)
lea    -0x64(%rbp),%rbx
mov    %rbx,%rdi
call   10b0 <FD_ZERO@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
call   1130 <FD_SET@plt>
mov    -0x3c(%rbp),%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
lea    -0x58(%rbp),%r8
call   10c0 <select@plt>
test   %eax,%eax
je     1434 <main+0x204>
mov    %r15d,%r13d
mov    %r15d,%edi
lea    -0x30(%rbp),%rbx
mov    %rbx,%rsi
lea    -0x40(%rbp),%rdx
call   1110 <accept@plt>
mov    %eax,%r12d
test   %eax,%eax
jns    13f9 <main+0x1c9>
lea    0xc60(%rip),%rdi
call   1090 <printErrorAndQuit@plt>
mov    -0x30(%rbp),%r15d
mov    %rbx,%rdi
call   1050 <getInAddr@plt>
mov    %r15d,%edi
mov    %eax,%esi
mov    -0x48(%rbp),%rbx
mov    %rbx,%rdx
mov    -0x50(%rbp),%rcx
call   1030 <inet_ntop@plt>
lea    0xc4b(%rip),%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    %r12d,%edi
call   1070 <echoMessage@plt>
mov    %r13d,%r15d
test   %r14d,%r14d
js     1390 <main+0x160>
xor    %eax,%eax
call   1040 <isPipeClosed@plt>
test   %rax,%rax
jne    1390 <main+0x160>
jmp    139a <main+0x16a>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.rlimit = type { i32, i32 }
%struct.addrinfo = type { i32, i32, i32, i32, i32, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@RLIMIT_AS = global i32 0
@.str = [17 x i8] c"setrlimit failed\00"
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@.str.1 = [21 x i8] c"getaddrinfo() failed\00"
@.str.2 = [16 x i8] c"socket() failed\00"
@.str.3 = [14 x i8] c"bind() failed\00"
@.str.4 = [16 x i8] c"listen() failed\00"
@INET6_ADDRSTRLEN = global i32 0
@__const.main.tv = %struct.timeval { i32 5, i32 0 }
@.str.5 = [24 x i8] c"accept() returned error\00"
@.str.6 = [20 x i8] c"Handling client %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.rlimit
%7 = alloca i32
%8 = alloca %struct.addrinfo
%9 = alloca %struct.addrinfo*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
%13 = alloca i32
%14 = alloca %struct.sockaddr_storage
%15 = alloca i32
%16 = alloca %struct.timeval
%17 = alloca i32
%18 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%19 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %6, i32 0, i32 0
store i32 33554432, i32* %19
%20 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %6, i32 0, i32 1
store i32 33554432, i32* %20
%21 = load i32, i32* @RLIMIT_AS
%22 = call i64 @setrlimit(i32 %21, %struct.rlimit* %6)
%23 = icmp ne i64 0, %22
br i1 %23, label %24, label %26
24: ; preds = %2
%25 = call i32 @printErrorAndQuit(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %24, %2
%27 = load i32, i32* %4
%28 = icmp ne i32 %27, 2
br i1 %28, label %29, label %34
29: ; preds = %26
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 0
%32 = load i8*, i8** %31
%33 = call i32 @usage(i8* %32)
br label %34
34: ; preds = %29, %26
%35 = call i32 @memset(%struct.addrinfo* %8, i32 0, i32 24)
%36 = load i32, i32* @AF_UNSPEC
%37 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 4
store i32 %36, i32* %37
%38 = load i32, i32* @SOCK_STREAM
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 3
store i32 %38, i32* %39
%40 = load i32, i32* @AI_PASSIVE
%41 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 5
store i32 %40, i32* %41
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
%45 = call i64 @getaddrinfo(i32* null, i8* %44, %struct.addrinfo* %8, %struct.addrinfo** %9)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %34
%48 = call i32 @printErrorAndQuit(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %49
49: ; preds = %47, %34
%50 = load %struct.addrinfo*, %struct.addrinfo** %9
%51 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %50, i32 0, i32 4
%52 = load i32, i32* %51
%53 = load %struct.addrinfo*, %struct.addrinfo** %9
%54 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %53, i32 0, i32 3
%55 = load i32, i32* %54
%56 = load %struct.addrinfo*, %struct.addrinfo** %9
%57 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %56, i32 0, i32 2
%58 = load i32, i32* %57
%59 = call i32 @socket(i32 %52, i32 %55, i32 %58)
store i32 %59, i32* %7
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %49
%62 = call i32 @printErrorAndQuit(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %63
63: ; preds = %61, %49
%64 = load i32, i32* %7
%65 = load %struct.addrinfo*, %struct.addrinfo** %9
%66 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %65, i32 0, i32 1
%67 = load i32, i32* %66
%68 = load %struct.addrinfo*, %struct.addrinfo** %9
%69 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %68, i32 0, i32 0
%70 = load i32, i32* %69
%71 = call i64 @bind(i32 %64, i32 %67, i32 %70)
%72 = icmp slt i64 %71, 0
br i1 %72, label %73, label %75
73: ; preds = %63
%74 = call i32 @printErrorAndQuit(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %75
75: ; preds = %73, %63
%76 = load %struct.addrinfo*, %struct.addrinfo** %9
%77 = call i32 @freeaddrinfo(%struct.addrinfo* %76)
%78 = load i32, i32* %7
%79 = call i64 @listen(i32 %78, i32 5)
%80 = icmp slt i64 %79, 0
br i1 %80, label %81, label %83
81: ; preds = %75
%82 = call i32 @printErrorAndQuit(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %83
83: ; preds = %81, %75
%84 = load i32, i32* @INET6_ADDRSTRLEN
%85 = zext i32 %84 to i64
%86 = call i8* @llvm.stacksave()
store i8* %86, i8** %10
%87 = alloca i8, i64 %85
store i64 %85, i64* %11
store i32 4, i32* %13
%88 = call i32 (...) @backup()
store i32 %88, i32* %15
br label %89
89: ; preds = %124, %83
%90 = bitcast %struct.timeval* %16 to i8*
%91 = call i32 @FD_ZERO(i32* %17)
%92 = load i32, i32* %7
%93 = call i32 @FD_SET(i32 %92, i32* %17)
%94 = load i32, i32* %7
%95 = add nsw i32 %94, 1
%96 = call i32 @select(i32 %95, i32* %17, i32* null, i32* null, %struct.timeval* %16)
store i32 %96, i32* %18
%97 = load i32, i32* %18
%98 = icmp ne i32 %97, 0
br i1 %98, label %99, label %116
99: ; preds = %89
%100 = load i32, i32* %7
%101 = bitcast %struct.sockaddr_storage* %14 to %struct.sockaddr*
%102 = call i32 @accept(i32 %100, %struct.sockaddr* %101, i32* %13)
store i32 %102, i32* %12
%103 = icmp slt i32 %102, 0
br i1 %103, label %104, label %106
104: ; preds = %99
%105 = call i32 @printErrorAndQuit(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
br label %106
106: ; preds = %104, %99
%107 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %14, i32 0, i32 0
%108 = load i32, i32* %107
%109 = bitcast %struct.sockaddr_storage* %14 to %struct.sockaddr*
%110 = call i32 @getInAddr(%struct.sockaddr* %109)
%111 = trunc i64 %85 to i32
%112 = call i32 @inet_ntop(i32 %108, i32 %110, i8* %87, i32 %111)
%113 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i8* %87)
%114 = load i32, i32* %12
%115 = call i32 @echoMessage(i32 %114)
br label %116
116: ; preds = %106, %89
%117 = load i32, i32* %15
%118 = icmp slt i32 %117, 0
br i1 %118, label %122, label %119
119: ; preds = %116
%120 = call i64 (...) @isPipeClosed()
%121 = icmp ne i64 %120, 0
br i1 %121, label %122, label %124
122: ; preds = %119, %116
%123 = call i32 (...) @backup()
store i32 %123, i32* %15
br label %124
124: ; preds = %122, %119
br label %89
}

LLVM IR (-O2):
%struct.rlimit = type { i32, i32 }
%struct.addrinfo = type { i32, i32, i32, i32, i32, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.timeval = type { i32, i32 }
%struct.sockaddr = type { i32 }
@RLIMIT_AS = global i32 0
@.str = [17 x i8] c"setrlimit failed\00"
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@.str.1 = [21 x i8] c"getaddrinfo() failed\00"
@.str.2 = [16 x i8] c"socket() failed\00"
@.str.3 = [14 x i8] c"bind() failed\00"
@.str.4 = [16 x i8] c"listen() failed\00"
@INET6_ADDRSTRLEN = global i32 0
@.str.5 = [24 x i8] c"accept() returned error\00"
@.str.6 = [20 x i8] c"Handling client %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.rlimit
%4 = alloca %struct.addrinfo
%5 = alloca %struct.addrinfo*
%6 = alloca i32
%7 = alloca %struct.sockaddr_storage
%8 = alloca i64
%9 = bitcast i64* %8 to %struct.timeval*
%10 = alloca i32
%11 = bitcast %struct.rlimit* %3 to i8*
%12 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i64 0, i32 0
store i32 33554432, i32* %12
%13 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i64 0, i32 1
store i32 33554432, i32* %13
%14 = load i32, i32* @RLIMIT_AS
%15 = call i64 @setrlimit(i32 %14, %struct.rlimit* %3)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %2
%18 = call i32 @printErrorAndQuit(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %2
%20 = bitcast %struct.addrinfo* %4 to i8*
%21 = bitcast %struct.addrinfo** %5 to i8*
%22 = icmp eq i32 %0, 2
br i1 %22, label %26, label %23
23: ; preds = %19
%24 = load i8*, i8** %1
%25 = call i32 @usage(i8* %24)
br label %26
26: ; preds = %23, %19
%27 = call i32 @memset(%struct.addrinfo* %4, i32 0, i32 24)
%28 = load i32, i32* @AF_UNSPEC
%29 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 4
store i32 %28, i32* %29
%30 = load i32, i32* @SOCK_STREAM
%31 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 3
store i32 %30, i32* %31
%32 = load i32, i32* @AI_PASSIVE
%33 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 5
store i32 %32, i32* %33
%34 = getelementptr inbounds i8*, i8** %1, i64 1
%35 = load i8*, i8** %34
%36 = call i64 @getaddrinfo(i32* null, i8* %35, %struct.addrinfo* %4, %struct.addrinfo** %5)
%37 = icmp eq i64 %36, 0
br i1 %37, label %40, label %38
38: ; preds = %26
%39 = call i32 @printErrorAndQuit(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %40
40: ; preds = %38, %26
%41 = load %struct.addrinfo*, %struct.addrinfo** %5
%42 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %41, i64 0, i32 4
%43 = load i32, i32* %42
%44 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %41, i64 0, i32 3
%45 = load i32, i32* %44
%46 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %41, i64 0, i32 2
%47 = load i32, i32* %46
%48 = call i32 @socket(i32 %43, i32 %45, i32 %47)
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %40
%51 = call i32 @printErrorAndQuit(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %52
52: ; preds = %50, %40
%53 = load %struct.addrinfo*, %struct.addrinfo** %5
%54 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %53, i64 0, i32 1
%55 = load i32, i32* %54
%56 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %53, i64 0, i32 0
%57 = load i32, i32* %56
%58 = call i64 @bind(i32 %48, i32 %55, i32 %57)
%59 = icmp slt i64 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %52
%61 = call i32 @printErrorAndQuit(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %62
62: ; preds = %60, %52
%63 = load %struct.addrinfo*, %struct.addrinfo** %5
%64 = call i32 @freeaddrinfo(%struct.addrinfo* %63)
%65 = call i64 @listen(i32 %48, i32 5)
%66 = icmp slt i64 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %62
%68 = call i32 @printErrorAndQuit(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %69
69: ; preds = %67, %62
%70 = load i32, i32* @INET6_ADDRSTRLEN
%71 = zext i32 %70 to i64
%72 = alloca i8, i64 %71
%73 = bitcast i32* %6 to i8*
%74 = bitcast %struct.sockaddr_storage* %7 to i8*
store i32 4, i32* %6
%75 = call i32 (...) @backup()
%76 = bitcast i64* %8 to i8*
%77 = bitcast i32* %10 to i8*
%78 = add nsw i32 %48, 1
%79 = bitcast %struct.sockaddr_storage* %7 to %struct.sockaddr*
%80 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %7, i64 0, i32 0
br label %81
81: ; preds = %105, %69
%82 = phi i32 [ %75, %69 ], [ %106, %105 ]
store i64 5, i64* %8
%83 = call i32 @FD_ZERO(i32* %10)
%84 = call i32 @FD_SET(i32 %48, i32* %10)
%85 = call i32 @select(i32 %78, i32* %10, i32* null, i32* null, %struct.timeval* %9)
%86 = icmp eq i32 %85, 0
br i1 %86, label %98, label %87
87: ; preds = %81
%88 = call i32 @accept(i32 %48, %struct.sockaddr* %79, i32* %6)
%89 = icmp slt i32 %88, 0
br i1 %89, label %90, label %92
90: ; preds = %87
%91 = call i32 @printErrorAndQuit(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
br label %92
92: ; preds = %90, %87
%93 = load i32, i32* %80
%94 = call i32 @getInAddr(%struct.sockaddr* %79)
%95 = call i32 @inet_ntop(i32 %93, i32 %94, i8* %72, i32 %70)
%96 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i8* %72)
%97 = call i32 @echoMessage(i32 %88)
br label %98
98: ; preds = %92, %81
%99 = icmp slt i32 %82, 0
br i1 %99, label %103, label %100
100: ; preds = %98
%101 = call i64 (...) @isPipeClosed()
%102 = icmp eq i64 %101, 0
br i1 %102, label %105, label %103
103: ; preds = %100, %98
%104 = call i32 (...) @backup()
br label %105
105: ; preds = %103, %100
%106 = phi i32 [ %104, %103 ], [ %82, %100 ]
br label %81
}