#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_storage {
  int dummy;
};
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;
  int /*<<< orphan*/ ai_flags;
};
typedef scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ AI_PASSIVE;
int O_APPEND;
int O_CREAT;
int O_WRONLY;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ WNOHANG;
int accept(int, struct sockaddr *, unsigned int *);
scalar_t__ bind(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ capitalize(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup(int);
scalar_t__ fork();
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
scalar_t__ getaddrinfo(int /*<<< orphan*/ *, char *, struct addrinfo *,
                       struct addrinfo **);
scalar_t__ listen(int, int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int open(char *, int, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ waitpid(int, int *, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  if (argc < 2) {
    write(2, "port invalid\n", 13);
    return 1;
  }
  if (argc >= 3) {
    int logfd = open(argv[2], O_CREAT | O_WRONLY | O_APPEND, 0644);
    if (logfd < 0) {
      write(2, "unable to open logfile\n", 23);
    } else {
      close(2);
      dup(logfd);
      close(logfd);
    }
  }
  struct addrinfo hints, *srv;
  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, &srv)) {
    write(2, "addrinfo error\n", 15);
    return 2;
  }
  int s = socket(srv->ai_family, srv->ai_socktype, srv->ai_protocol);
  if (s < 0) {
    write(2, "socket creation failed\n", 23);
    freeaddrinfo(srv);
    return 3;
  }
  if (bind(s, srv->ai_addr, srv->ai_addrlen) < 0) {
    write(2, "could not bind to host\n", 23);
    freeaddrinfo(srv);
    return 4;
  }
  freeaddrinfo(srv);
  if (listen(s, 5) < 0) {
    write(2, "listen error\n", 13);
    return 5;
  }
  write(2, "server waiting for connections\n", 31);
  while (1) {
    struct sockaddr_storage client_addr;
    unsigned int addr_size = sizeof client_addr;
    int s_new = accept(s, (struct sockaddr *)&client_addr, &addr_size);
    if (s_new < 0) {
      write(2, "accept error\n", 13);
      continue;
    }
    pid_t child = fork();
    if (child < 0) {
      write(2, "fork error\n", 11);
      continue;
    } else if (child) {
      write(2, "forked child for new connection\n", 32);
      close(s_new);
      int child_status;
      waitpid(-1, &child_status, WNOHANG);
    } else {
      write(2, "new connection\n", 15);
      close(s);
      capitalize(s_new);
      close(s_new);
      return 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1222 <main+0x42>
mov    $0x2,%edi
lea    0xdf4(%rip),%rsi
mov    $0xd,%edx
call   1030 <write@plt>
movl   $0x1,-0x4(%rbp)
jmp    1506 <main+0x326>
cmpl   $0x3,-0x8(%rbp)
jl     12a0 <main+0xc0>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2dbd(%rip),%rax
mov    (%rax),%esi
mov    0x2d6c(%rip),%rax
or     (%rax),%esi
mov    0x2d5b(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   10a0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1281 <main+0xa1>
mov    $0x2,%edi
lea    0xd9c(%rip),%rsi
mov    $0x17,%edx
call   1030 <write@plt>
jmp    129b <main+0xbb>
mov    $0x2,%edi
call   1060 <close@plt>
mov    -0x14(%rbp),%edi
call   1040 <dup@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
jmp    12a0 <main+0xc0>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
mov    0x2d21(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2cfd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d11(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    -0x30(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   10c0 <getaddrinfo@plt>
cmp    $0x0,%rax
je     1319 <main+0x139>
mov    $0x2,%edi
lea    0xd23(%rip),%rsi
mov    $0xf,%edx
call   1030 <write@plt>
movl   $0x2,-0x4(%rbp)
jmp    1506 <main+0x326>
mov    -0x38(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x38(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%edx
call   1100 <socket@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jge    136b <main+0x18b>
mov    $0x2,%edi
lea    0xcea(%rip),%rsi
mov    $0x17,%edx
call   1030 <write@plt>
mov    -0x38(%rbp),%rdi
call   10f0 <freeaddrinfo@plt>
movl   $0x3,-0x4(%rbp)
jmp    1506 <main+0x326>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x38(%rbp),%rax
mov    (%rax),%edx
call   1080 <bind@plt>
cmp    $0x0,%rax
jge    13b5 <main+0x1d5>
mov    $0x2,%edi
lea    0xcb8(%rip),%rsi
mov    $0x17,%edx
call   1030 <write@plt>
mov    -0x38(%rbp),%rdi
call   10f0 <freeaddrinfo@plt>
movl   $0x4,-0x4(%rbp)
jmp    1506 <main+0x326>
mov    -0x38(%rbp),%rdi
call   10f0 <freeaddrinfo@plt>
mov    -0x3c(%rbp),%edi
mov    $0x5,%esi
call   1070 <listen@plt>
cmp    $0x0,%rax
jge    13f7 <main+0x217>
mov    $0x2,%edi
lea    0xc85(%rip),%rsi
mov    $0xd,%edx
call   1030 <write@plt>
movl   $0x5,-0x4(%rbp)
jmp    1506 <main+0x326>
mov    $0x2,%edi
lea    0xc71(%rip),%rsi
mov    $0x1f,%edx
call   1030 <write@plt>
movl   $0x4,-0x44(%rbp)
mov    -0x3c(%rbp),%edi
lea    -0x40(%rbp),%rsi
lea    -0x44(%rbp),%rdx
call   10b0 <accept@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
jge    144c <main+0x26c>
mov    $0x2,%edi
lea    0xc57(%rip),%rsi
mov    $0xd,%edx
call   1030 <write@plt>
jmp    140d <main+0x22d>
mov    $0x0,%al
call   10d0 <fork@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jge    147d <main+0x29d>
mov    $0x2,%edi
lea    0xc34(%rip),%rsi
mov    $0xb,%edx
call   1030 <write@plt>
jmp    140d <main+0x22d>
cmpq   $0x0,-0x50(%rbp)
je     14c2 <main+0x2e2>
mov    $0x2,%edi
lea    0xc1a(%rip),%rsi
mov    $0x20,%edx
call   1030 <write@plt>
mov    -0x48(%rbp),%edi
call   1060 <close@plt>
mov    0x2b23(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%edi
lea    -0x54(%rbp),%rsi
call   1090 <waitpid@plt>
jmp    14fc <main+0x31c>
mov    $0x2,%edi
lea    0xbf1(%rip),%rsi
mov    $0xf,%edx
call   1030 <write@plt>
mov    -0x3c(%rbp),%edi
call   1060 <close@plt>
mov    -0x48(%rbp),%edi
call   10e0 <capitalize@plt>
mov    -0x48(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    1506 <main+0x326>
jmp    1501 <main+0x321>
jmp    140d <main+0x22d>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
cmp    $0x1,%edi
jg     1213 <main+0x33>
lea    0xe06(%rip),%rsi
mov    $0x2,%edi
mov    $0xd,%edx
call   1030 <write@plt>
mov    $0x1,%ebp
jmp    12e8 <main+0x108>
mov    %rsi,%rbx
cmp    $0x2,%edi
je     127a <main+0x9a>
mov    0x2dd6(%rip),%rax
mov    0x2d87(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x10(%rbx),%rdi
mov    0x2d70(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   10a0 <open@plt>
test   %eax,%eax
js     1264 <main+0x84>
mov    %eax,%ebp
mov    $0x2,%edi
call   1060 <close@plt>
mov    %ebp,%edi
call   1040 <dup@plt>
mov    %ebp,%edi
call   1060 <close@plt>
jmp    127a <main+0x9a>
lea    0xda3(%rip),%rsi
mov    $0x2,%edi
mov    $0x17,%edx
call   1030 <write@plt>
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
mov    0x2d43(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x30(%rsp)
mov    0x2d1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x2c(%rsp)
mov    0x2d31(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x34(%rsp)
mov    0x8(%rbx),%rsi
lea    0x8(%rsp),%rcx
xor    %edi,%edi
mov    %rbp,%rdx
call   10c0 <getaddrinfo@plt>
test   %rax,%rax
je     12f9 <main+0x119>
lea    0xd52(%rip),%rsi
mov    $0x2,%ebp
mov    $0x2,%edi
mov    $0xf,%edx
call   1030 <write@plt>
mov    %ebp,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rsp),%rax
mov    0x10(%rax),%edi
mov    0x8(%rax),%edx
mov    0xc(%rax),%esi
call   1100 <socket@plt>
test   %eax,%eax
js     1418 <main+0x238>
mov    %eax,%ebx
mov    0x8(%rsp),%rax
mov    (%rax),%edx
mov    0x4(%rax),%esi
mov    %ebx,%edi
call   1080 <bind@plt>
test   %rax,%rax
js     1476 <main+0x296>
mov    0x8(%rsp),%rdi
call   10f0 <freeaddrinfo@plt>
mov    $0x5,%ebp
mov    %ebx,%edi
mov    $0x5,%esi
call   1070 <listen@plt>
test   %rax,%rax
js     14a0 <main+0x2c0>
lea    0xd19(%rip),%rsi
mov    $0x2,%edi
mov    $0x1f,%edx
call   1030 <write@plt>
lea    0x18(%rsp),%r14
lea    0x14(%rsp),%r15
mov    0x2c55(%rip),%rbp
lea    0x1c(%rsp),%r13
jmp    13a6 <main+0x1c6>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x2,%edi
lea    0xcf8(%rip),%rsi
mov    $0xd,%edx
call   1030 <write@plt>
movl   $0x4,0x14(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   10b0 <accept@plt>
test   %eax,%eax
js     1390 <main+0x1b0>
mov    %eax,%r12d
xor    %eax,%eax
call   10d0 <fork@plt>
test   %rax,%rax
js     1400 <main+0x220>
je     1442 <main+0x262>
mov    $0x2,%edi
lea    0xcd2(%rip),%rsi
mov    $0x20,%edx
call   1030 <write@plt>
mov    %r12d,%edi
call   1060 <close@plt>
mov    0x0(%rbp),%edx
mov    $0xffffffff,%edi
mov    %r13,%rsi
call   1090 <waitpid@plt>
jmp    13a6 <main+0x1c6>
mov    $0x2,%edi
lea    0xc96(%rip),%rsi
mov    $0xb,%edx
call   1030 <write@plt>
jmp    13a6 <main+0x1c6>
lea    0xc17(%rip),%rsi
mov    $0x2,%edi
mov    $0x17,%edx
call   1030 <write@plt>
mov    0x8(%rsp),%rdi
call   10f0 <freeaddrinfo@plt>
mov    $0x3,%ebp
jmp    12e8 <main+0x108>
lea    0xc76(%rip),%rsi
mov    $0x2,%edi
mov    $0xf,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    %r12d,%edi
call   10e0 <capitalize@plt>
mov    %r12d,%edi
call   1060 <close@plt>
xor    %ebp,%ebp
jmp    12e8 <main+0x108>
lea    0xbd1(%rip),%rsi
mov    $0x2,%edi
mov    $0x17,%edx
call   1030 <write@plt>
mov    0x8(%rsp),%rdi
call   10f0 <freeaddrinfo@plt>
mov    $0x4,%ebp
jmp    12e8 <main+0x108>
lea    0xbbf(%rip),%rsi
mov    $0x2,%edi
mov    $0xd,%edx
jmp    12e3 <main+0x103>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [14 x i8] c"port invalid\0A\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
@.str.1 = [24 x i8] c"unable to open logfile\0A\00"
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@.str.2 = [16 x i8] c"addrinfo error\0A\00"
@.str.3 = [24 x i8] c"socket creation failed\0A\00"
@.str.4 = [24 x i8] c"could not bind to host\0A\00"
@.str.5 = [14 x i8] c"listen error\0A\00"
@.str.6 = [32 x i8] c"server waiting for connections\0A\00"
@.str.7 = [14 x i8] c"accept error\0A\00"
@.str.8 = [12 x i8] c"fork error\0A\00"
@.str.9 = [33 x i8] c"forked child for new connection\0A\00"
@WNOHANG = global i32 0
@.str.10 = [16 x i8] c"new connection\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.addrinfo
%8 = alloca %struct.addrinfo*
%9 = alloca i32
%10 = alloca %struct.sockaddr_storage
%11 = alloca i32
%12 = alloca i32
%13 = alloca i64
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 2
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @write(i32 2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 13)
store i32 1, i32* %3
br label %132
19: ; preds = %2
%20 = load i32, i32* %4
%21 = icmp sge i32 %20, 3
br i1 %21, label %22, label %43
22: ; preds = %19
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = load i32, i32* @O_CREAT
%27 = load i32, i32* @O_WRONLY
%28 = or i32 %26, %27
%29 = load i32, i32* @O_APPEND
%30 = or i32 %28, %29
%31 = call i32 @open(i8* %25, i32 %30, i32 420)
store i32 %31, i32* %6
%32 = load i32, i32* %6
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %22
%35 = call i32 @write(i32 2, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 23)
br label %42
36: ; preds = %22
%37 = call i32 @close(i32 2)
%38 = load i32, i32* %6
%39 = call i32 @dup(i32 %38)
%40 = load i32, i32* %6
%41 = call i32 @close(i32 %40)
br label %42
42: ; preds = %36, %34
br label %43
43: ; preds = %42, %19
%44 = call i32 @memset(%struct.addrinfo* %7, i32 0, i32 24)
%45 = load i32, i32* @AF_UNSPEC
%46 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i32 0, i32 4
store i32 %45, i32* %46
%47 = load i32, i32* @SOCK_STREAM
%48 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i32 0, i32 3
store i32 %47, i32* %48
%49 = load i32, i32* @AI_PASSIVE
%50 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i32 0, i32 5
store i32 %49, i32* %50
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 1
%53 = load i8*, i8** %52
%54 = call i64 @getaddrinfo(i32* null, i8* %53, %struct.addrinfo* %7, %struct.addrinfo** %8)
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %58
56: ; preds = %43
%57 = call i32 @write(i32 2, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 15)
store i32 2, i32* %3
br label %132
58: ; preds = %43
%59 = load %struct.addrinfo*, %struct.addrinfo** %8
%60 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %59, i32 0, i32 4
%61 = load i32, i32* %60
%62 = load %struct.addrinfo*, %struct.addrinfo** %8
%63 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %62, i32 0, i32 3
%64 = load i32, i32* %63
%65 = load %struct.addrinfo*, %struct.addrinfo** %8
%66 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %65, i32 0, i32 2
%67 = load i32, i32* %66
%68 = call i32 @socket(i32 %61, i32 %64, i32 %67)
store i32 %68, i32* %9
%69 = load i32, i32* %9
%70 = icmp slt i32 %69, 0
br i1 %70, label %71, label %75
71: ; preds = %58
%72 = call i32 @write(i32 2, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 23)
%73 = load %struct.addrinfo*, %struct.addrinfo** %8
%74 = call i32 @freeaddrinfo(%struct.addrinfo* %73)
store i32 3, i32* %3
br label %132
75: ; preds = %58
%76 = load i32, i32* %9
%77 = load %struct.addrinfo*, %struct.addrinfo** %8
%78 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %77, i32 0, i32 1
%79 = load i32, i32* %78
%80 = load %struct.addrinfo*, %struct.addrinfo** %8
%81 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %80, i32 0, i32 0
%82 = load i32, i32* %81
%83 = call i64 @bind(i32 %76, i32 %79, i32 %82)
%84 = icmp slt i64 %83, 0
br i1 %84, label %85, label %89
85: ; preds = %75
%86 = call i32 @write(i32 2, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 23)
%87 = load %struct.addrinfo*, %struct.addrinfo** %8
%88 = call i32 @freeaddrinfo(%struct.addrinfo* %87)
store i32 4, i32* %3
br label %132
89: ; preds = %75
%90 = load %struct.addrinfo*, %struct.addrinfo** %8
%91 = call i32 @freeaddrinfo(%struct.addrinfo* %90)
%92 = load i32, i32* %9
%93 = call i64 @listen(i32 %92, i32 5)
%94 = icmp slt i64 %93, 0
br i1 %94, label %95, label %97
95: ; preds = %89
%96 = call i32 @write(i32 2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 13)
store i32 5, i32* %3
br label %132
97: ; preds = %89
%98 = call i32 @write(i32 2, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), i32 31)
br label %99
99: ; preds = %97, %105, %111, %131
store i32 4, i32* %11
%100 = load i32, i32* %9
%101 = bitcast %struct.sockaddr_storage* %10 to %struct.sockaddr*
%102 = call i32 @accept(i32 %100, %struct.sockaddr* %101, i32* %11)
store i32 %102, i32* %12
%103 = load i32, i32* %12
%104 = icmp slt i32 %103, 0
br i1 %104, label %105, label %107
105: ; preds = %99
%106 = call i32 @write(i32 2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i32 13)
br label %99
107: ; preds = %99
%108 = call i64 (...) @fork()
store i64 %108, i64* %13
%109 = load i64, i64* %13
%110 = icmp slt i64 %109, 0
br i1 %110, label %111, label %113
111: ; preds = %107
%112 = call i32 @write(i32 2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i32 11)
br label %99
113: ; preds = %107
%114 = load i64, i64* %13
%115 = icmp ne i64 %114, 0
br i1 %115, label %116, label %122
116: ; preds = %113
%117 = call i32 @write(i32 2, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.9, i64 0, i64 0), i32 32)
%118 = load i32, i32* %12
%119 = call i32 @close(i32 %118)
%120 = load i32, i32* @WNOHANG
%121 = call i32 @waitpid(i32 -1, i32* %14, i32 %120)
br label %130
122: ; preds = %113
%123 = call i32 @write(i32 2, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0), i32 15)
%124 = load i32, i32* %9
%125 = call i32 @close(i32 %124)
%126 = load i32, i32* %12
%127 = call i32 @capitalize(i32 %126)
%128 = load i32, i32* %12
%129 = call i32 @close(i32 %128)
store i32 0, i32* %3
br label %132
130: ; preds = %116
br label %131
131: ; preds = %130
br label %99
132: ; preds = %122, %95, %85, %71, %56, %17
%133 = load i32, i32* %3
ret i32 %133
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i32, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [14 x i8] c"port invalid\0A\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
@.str.1 = [24 x i8] c"unable to open logfile\0A\00"
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@.str.2 = [16 x i8] c"addrinfo error\0A\00"
@.str.3 = [24 x i8] c"socket creation failed\0A\00"
@.str.4 = [24 x i8] c"could not bind to host\0A\00"
@.str.5 = [14 x i8] c"listen error\0A\00"
@.str.6 = [32 x i8] c"server waiting for connections\0A\00"
@.str.7 = [14 x i8] c"accept error\0A\00"
@.str.8 = [12 x i8] c"fork error\0A\00"
@.str.9 = [33 x i8] c"forked child for new connection\0A\00"
@WNOHANG = global i32 0
@.str.10 = [16 x i8] c"new connection\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = alloca %struct.sockaddr_storage
%6 = alloca i32
%7 = alloca i32
%8 = icmp slt i32 %0, 2
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @write(i32 2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 13)
br label %109
11: ; preds = %2
%12 = icmp eq i32 %0, 2
br i1 %12, label %29, label %13
13: ; preds = %11
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = load i32, i32* @O_CREAT
%17 = load i32, i32* @O_WRONLY
%18 = or i32 %17, %16
%19 = load i32, i32* @O_APPEND
%20 = or i32 %18, %19
%21 = tail call i32 @open(i8* %15, i32 %20, i32 420)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %13
%24 = tail call i32 @write(i32 2, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 23)
br label %29
25: ; preds = %13
%26 = tail call i32 @close(i32 2)
%27 = tail call i32 @dup(i32 %21)
%28 = tail call i32 @close(i32 %21)
br label %29
29: ; preds = %23, %25, %11
%30 = bitcast %struct.addrinfo* %3 to i8*
%31 = bitcast %struct.addrinfo** %4 to i8*
%32 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 24)
%33 = load i32, i32* @AF_UNSPEC
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i32 %33, i32* %34
%35 = load i32, i32* @SOCK_STREAM
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %35, i32* %36
%37 = load i32, i32* @AI_PASSIVE
%38 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 5
store i32 %37, i32* %38
%39 = getelementptr inbounds i8*, i8** %1, i64 1
%40 = load i8*, i8** %39
%41 = call i64 @getaddrinfo(i32* null, i8* %40, %struct.addrinfo* %3, %struct.addrinfo** %4)
%42 = icmp eq i64 %41, 0
br i1 %42, label %45, label %43
43: ; preds = %29
%44 = call i32 @write(i32 2, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 15)
br label %107
45: ; preds = %29
%46 = load %struct.addrinfo*, %struct.addrinfo** %4
%47 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %46, i64 0, i32 4
%48 = load i32, i32* %47
%49 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %46, i64 0, i32 3
%50 = load i32, i32* %49
%51 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %46, i64 0, i32 2
%52 = load i32, i32* %51
%53 = call i32 @socket(i32 %48, i32 %50, i32 %52)
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %59
55: ; preds = %45
%56 = call i32 @write(i32 2, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 23)
%57 = load %struct.addrinfo*, %struct.addrinfo** %4
%58 = call i32 @freeaddrinfo(%struct.addrinfo* %57)
br label %107
59: ; preds = %45
%60 = load %struct.addrinfo*, %struct.addrinfo** %4
%61 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %60, i64 0, i32 1
%62 = load i32, i32* %61
%63 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %60, i64 0, i32 0
%64 = load i32, i32* %63
%65 = call i64 @bind(i32 %53, i32 %62, i32 %64)
%66 = icmp slt i64 %65, 0
br i1 %66, label %67, label %71
67: ; preds = %59
%68 = call i32 @write(i32 2, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 23)
%69 = load %struct.addrinfo*, %struct.addrinfo** %4
%70 = call i32 @freeaddrinfo(%struct.addrinfo* %69)
br label %107
71: ; preds = %59
%72 = load %struct.addrinfo*, %struct.addrinfo** %4
%73 = call i32 @freeaddrinfo(%struct.addrinfo* %72)
%74 = call i64 @listen(i32 %53, i32 5)
%75 = icmp slt i64 %74, 0
br i1 %75, label %76, label %78
76: ; preds = %71
%77 = call i32 @write(i32 2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 13)
br label %107
78: ; preds = %71
%79 = call i32 @write(i32 2, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), i32 31)
%80 = bitcast %struct.sockaddr_storage* %5 to i8*
%81 = bitcast i32* %6 to i8*
%82 = bitcast %struct.sockaddr_storage* %5 to %struct.sockaddr*
%83 = bitcast i32* %7 to i8*
br label %84
84: ; preds = %106, %78
store i32 4, i32* %6
%85 = call i32 @accept(i32 %53, %struct.sockaddr* %82, i32* %6)
%86 = icmp slt i32 %85, 0
br i1 %86, label %87, label %89
87: ; preds = %84
%88 = call i32 @write(i32 2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i32 13)
br label %106
89: ; preds = %84
%90 = call i64 (...) @fork()
%91 = icmp slt i64 %90, 0
br i1 %91, label %92, label %94
92: ; preds = %89
%93 = call i32 @write(i32 2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i32 11)
br label %106
94: ; preds = %89
%95 = icmp eq i64 %90, 0
br i1 %95, label %101, label %96
96: ; preds = %94
%97 = call i32 @write(i32 2, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.9, i64 0, i64 0), i32 32)
%98 = call i32 @close(i32 %85)
%99 = load i32, i32* @WNOHANG
%100 = call i32 @waitpid(i32 -1, i32* %7, i32 %99)
br label %106
101: ; preds = %94
%102 = call i32 @write(i32 2, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0), i32 15)
%103 = call i32 @close(i32 %53)
%104 = call i32 @capitalize(i32 %85)
%105 = call i32 @close(i32 %85)
br label %107
106: ; preds = %92, %96, %87
br label %84
107: ; preds = %101, %55, %67, %76, %43
%108 = phi i32 [ 2, %43 ], [ 3, %55 ], [ 4, %67 ], [ 5, %76 ], [ 0, %101 ]
br label %109
109: ; preds = %107, %9
%110 = phi i32 [ 1, %9 ], [ %108, %107 ]
ret i32 %110
}