#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ srv_addr;
typedef int socklen_t;
typedef int /*<<< orphan*/ optval;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ EINTR;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SHUT_RDWR;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int accept(int, struct sockaddr *, int *);
int bind(int, struct sockaddr const *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(TYPE_1__);
int listen(int, int);
int /*<<< orphan*/ ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int shutdown(int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
char toupper(char);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int sock_fd, iret;
  socklen_t srv_addr_len, cli_addr_len;
  sock_fd = socket(PF_INET, SOCK_STREAM, 0);
  if (sock_fd == -1)
    do {
      perror("socket");
      exit(-1);
    } while (0);
  int optval = 1;
  iret = setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval));
  if (iret == -1) {
    do {
      perror("setsockopt");
      exit(-1);
    } while (0);
  }
  struct sockaddr_in srv_addr, cli_addr;
  bzero(&srv_addr, sizeof(srv_addr));
  srv_addr.sin_family = AF_INET;
  srv_addr.sin_port = htons(8888);
  srv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  srv_addr_len = sizeof(srv_addr);
  iret = bind(sock_fd, (const struct sockaddr *)&srv_addr, srv_addr_len);
  if (iret == -1)
    do {
      perror("bind");
      exit(-1);
    } while (0);
  iret = listen(sock_fd, 10);
  if (iret == -1)
    do {
      perror("listen");
      exit(-1);
    } while (0);
  int conn_fd, n;
  char buf[4096] = {0};
  while (1) {
    conn_fd = accept(sock_fd, (struct sockaddr *)&cli_addr, &cli_addr_len);
    if (conn_fd == -1) {
      perror("accept");
      continue;
    }
    while ((n = read(conn_fd, buf, 4096 - 1)) < 0 && errno == EINTR)
      ;
    if (n < 0) {
      perror("read");
      break;
    } else if (n == 0) {
      printf("connect closed by peer\n");
      break;
    } else {
      buf[n - 2] = '\0';
      printf("receive from %s:%hu# %s\n", inet_ntoa(cli_addr.sin_addr),
             ntohs(cli_addr.sin_port), buf);
      int i;
      for (i = 0; i < n; ++i) {
        buf[i] = toupper(buf[i]);
      }
      write(conn_fd, buf, n - 1);
    }
    close(conn_fd);
  }
  close(conn_fd);
  iret = shutdown(sock_fd, SHUT_RDWR);
  if (iret == -1)
    do {
      perror("shutdown");
      exit(-1);
    } while (0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1050,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
mov    0x2d6e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1283 <main+0x53>
jmp    126d <main+0x3d>
lea    0xd8c(%rip),%rdi
call   1110 <perror@plt>
mov    $0xffffffff,%edi
call   1140 <exit@plt>
movl   $0x1,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d4c(%rip),%rax
mov    (%rax),%esi
mov    0x2d03(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    12d6 <main+0xa6>
jmp    12c0 <main+0x90>
lea    0xd40(%rip),%rdi
call   1110 <perror@plt>
mov    $0xffffffff,%edi
call   1140 <exit@plt>
lea    -0x28(%rbp),%rdi
mov    $0xc,%esi
call   1120 <bzero@plt>
mov    0x2ced(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    $0x22b8,%edi
call   1080 <htons@plt>
mov    %eax,-0x24(%rbp)
mov    0x2ccc(%rip),%rax
mov    (%rax),%edi
call   10a0 <htonl@plt>
mov    %eax,-0x28(%rbp)
movl   $0xc,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1100 <bind@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    134c <main+0x11c>
jmp    1336 <main+0x106>
lea    0xcd5(%rip),%rdi
call   1110 <perror@plt>
mov    $0xffffffff,%edi
call   1140 <exit@plt>
mov    -0x8(%rbp),%edi
mov    $0xa,%esi
call   10e0 <listen@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1381 <main+0x151>
jmp    136b <main+0x13b>
lea    0xca5(%rip),%rdi
call   1110 <perror@plt>
mov    $0xffffffff,%edi
call   1140 <exit@plt>
lea    -0x1040(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   10b0 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x38(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1130 <accept@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x3c(%rbp)
jne    13c2 <main+0x192>
lea    0xc66(%rip),%rdi
call   1110 <perror@plt>
jmp    1394 <main+0x164>
jmp    13c7 <main+0x197>
mov    -0x3c(%rbp),%edi
lea    -0x1040(%rbp),%rsi
mov    $0xfff,%edx
call   10d0 <read@plt>
mov    %eax,%ecx
mov    %ecx,-0x40(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1045(%rbp)
jge    140e <main+0x1de>
mov    0x2bc0(%rip),%rax
mov    (%rax),%rax
mov    0x2ba6(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x1045(%rbp)
mov    -0x1045(%rbp),%al
test   $0x1,%al
jne    1421 <main+0x1f1>
jmp    1426 <main+0x1f6>
jmp    13c7 <main+0x197>
cmpl   $0x0,-0x40(%rbp)
jge    1441 <main+0x211>
lea    0xbee(%rip),%rdi
call   1110 <perror@plt>
jmp    151b <main+0x2eb>
cmpl   $0x0,-0x40(%rbp)
jne    145e <main+0x22e>
lea    0xbd8(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
jmp    151b <main+0x2eb>
mov    -0x40(%rbp),%eax
sub    $0x2,%eax
cltq
movb   $0x0,-0x1040(%rbp,%rax,1)
mov    -0x38(%rbp),%edi
call   1060 <inet_ntoa@plt>
mov    %rax,-0x1050(%rbp)
mov    -0x34(%rbp),%edi
call   10f0 <ntohs@plt>
mov    -0x1050(%rbp),%rsi
mov    %eax,%edx
lea    -0x1040(%rbp),%rcx
lea    0xba6(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
movl   $0x0,-0x1044(%rbp)
mov    -0x1044(%rbp),%eax
cmp    -0x40(%rbp),%eax
jge    14f4 <main+0x2c4>
movslq -0x1044(%rbp),%rax
movsbl -0x1040(%rbp,%rax,1),%edi
ff
call   1030 <toupper@plt>
mov    %al,%cl
movslq -0x1044(%rbp),%rax
mov    %cl,-0x1040(%rbp,%rax,1)
mov    -0x1044(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1044(%rbp)
jmp    14ad <main+0x27d>
mov    -0x3c(%rbp),%edi
lea    -0x1040(%rbp),%rsi
mov    -0x40(%rbp),%edx
sub    $0x1,%edx
call   1050 <write@plt>
jmp    150e <main+0x2de>
mov    -0x3c(%rbp),%edi
call   10c0 <close@plt>
jmp    1394 <main+0x164>
mov    -0x3c(%rbp),%edi
call   10c0 <close@plt>
mov    -0x8(%rbp),%edi
mov    0x2ac3(%rip),%rax
mov    (%rax),%esi
call   1070 <shutdown@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    155c <main+0x32c>
jmp    1546 <main+0x316>
lea    0xb0e(%rip),%rdi
call   1110 <perror@plt>
mov    $0xffffffff,%edi
call   1140 <exit@plt>
xor    %eax,%eax
add    $0x1050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1038,%rsp
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
mov    0x2d5f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1160 <socket@plt>
cmp    $0xffffffff,%eax
je     1470 <main+0x230>
mov    %eax,%r15d
movl   $0x1,0xc(%rsp)
mov    0x2d5b(%rip),%rax
mov    (%rax),%esi
mov    0x2d12(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %r15d,%edi
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     1479 <main+0x239>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xc,%esi
call   1130 <bzero@plt>
mov    0x2d13(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    $0x22b8,%edi
call   1090 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2cf0(%rip),%rax
mov    (%rax),%edi
call   10b0 <htonl@plt>
mov    %eax,0x10(%rsp)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   1110 <bind@plt>
cmp    $0xffffffff,%eax
je     1482 <main+0x242>
mov    %r15d,%edi
mov    $0xa,%esi
call   10f0 <listen@plt>
cmp    $0xffffffff,%eax
je     148b <main+0x24b>
lea    0x30(%rsp),%rbx
mov    $0x1000,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10c0 <memset@plt>
mov    0x2c83(%rip),%rbp
mov    0x2c6c(%rip),%r14
mov    %r15d,0x8(%rsp)
jmp    1350 <main+0x110>
lea    0xcd4(%rip),%rdi
call   1120 <perror@plt>
nop
mov    %r15d,%edi
lea    0x20(%rsp),%rsi
lea    0x2c(%rsp),%rdx
call   1140 <accept@plt>
mov    %eax,%r12d
cmp    $0xffffffff,%eax
je     1343 <main+0x103>
nopw   0x0(%rax,%rax,1)
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0xfff,%edx
call   10e0 <read@plt>
mov    %eax,%r13d
test   %eax,%eax
jns    1390 <main+0x150>
mov    (%r14),%rax
cmp    %rax,0x0(%rbp)
je     1370 <main+0x130>
test   %r13d,%r13d
js     1462 <main+0x222>
je     1424 <main+0x1e4>
movslq %r13d,%rax
movb   $0x0,-0x2(%rax,%rbx,1)
mov    0x20(%rsp),%edi
call   1070 <inet_ntoa@plt>
mov    %rax,%rbp
mov    0x24(%rsp),%edi
call   1100 <ntohs@plt>
lea    0xc67(%rip),%rdi
mov    %rbp,%rsi
mov    %eax,%edx
mov    %rbx,%rcx
xor    %eax,%eax
call   10a0 <printf@plt>
mov    %r13d,%ebp
xor    %r15d,%r15d
nopl   0x0(%rax,%rax,1)
movsbl 0x30(%rsp,%r15,1),%edi
call   1030 <toupper@plt>
mov    %al,0x30(%rsp,%r15,1)
add    $0x1,%r15
cmp    %r15,%rbp
jne    13e0 <main+0x1a0>
add    $0xffffffff,%r13d
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %r13d,%edx
call   1060 <write@plt>
mov    %r12d,%edi
call   10d0 <close@plt>
mov    0x8(%rsp),%r15d
mov    0x2b99(%rip),%rbp
jmp    1350 <main+0x110>
lea    0xc21(%rip),%rdi
call   1040 <puts@plt>
mov    %r12d,%edi
call   10d0 <close@plt>
mov    0x2bb1(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
call   1080 <shutdown@plt>
cmp    $0xffffffff,%eax
je     1494 <main+0x254>
xor    %eax,%eax
add    $0x1038,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xbbc(%rip),%rdi
call   1120 <perror@plt>
jmp    1430 <main+0x1f0>
lea    0xb89(%rip),%rdi
jmp    149b <main+0x25b>
lea    0xb87(%rip),%rdi
jmp    149b <main+0x25b>
lea    0xb89(%rip),%rdi
jmp    149b <main+0x25b>
lea    0xb85(%rip),%rdi
jmp    149b <main+0x25b>
lea    0xba8(%rip),%rdi
call   1120 <perror@plt>
mov    $0xffffffff,%edi
call   1150 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [11 x i8] c"setsockopt\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.2 = [5 x i8] c"bind\00"
@.str.3 = [7 x i8] c"listen\00"
@.str.4 = [7 x i8] c"accept\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.5 = [5 x i8] c"read\00"
@.str.6 = [24 x i8] c"connect closed by peer\0A\00"
@.str.7 = [25 x i8] c"receive from %s:%hu# %s\0A\00"
@SHUT_RDWR = global i32 0
@.str.8 = [9 x i8] c"shutdown\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca %struct.sockaddr_in
%9 = alloca i32
%10 = alloca i32
%11 = alloca [4096 x i8]
%12 = alloca i32
store i32 0, i32* %1
%13 = load i32, i32* @PF_INET
%14 = load i32, i32* @SOCK_STREAM
%15 = call i32 @socket(i32 %13, i32 %14, i32 0)
store i32 %15, i32* %2
%16 = load i32, i32* %2
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %23
18: ; preds = %0
br label %19
19: ; preds = %18
%20 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 -1)
unreachable
22: ; No predecessors!
br label %23
23: ; preds = %22, %0
store i32 1, i32* %6
%24 = load i32, i32* %2
%25 = load i32, i32* @SOL_SOCKET
%26 = load i32, i32* @SO_REUSEADDR
%27 = call i32 @setsockopt(i32 %24, i32 %25, i32 %26, i32* %6, i32 4)
store i32 %27, i32* %3
%28 = load i32, i32* %3
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %35
30: ; preds = %23
br label %31
31: ; preds = %30
%32 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%33 = call i32 @exit(i32 -1)
unreachable
34: ; No predecessors!
br label %35
35: ; preds = %34, %23
%36 = call i32 @bzero(%struct.sockaddr_in* %7, i32 12)
%37 = load i32, i32* @AF_INET
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %37, i32* %38
%39 = call i32 @htons(i32 8888)
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %39, i32* %40
%41 = load i32, i32* @INADDR_ANY
%42 = call i32 @htonl(i32 %41)
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%44 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %43, i32 0, i32 0
store i32 %42, i32* %44
store i32 12, i32* %4
%45 = load i32, i32* %2
%46 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%47 = load i32, i32* %4
%48 = call i32 @bind(i32 %45, %struct.sockaddr* %46, i32 %47)
store i32 %48, i32* %3
%49 = load i32, i32* %3
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %56
51: ; preds = %35
br label %52
52: ; preds = %51
%53 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%54 = call i32 @exit(i32 -1)
unreachable
55: ; No predecessors!
br label %56
56: ; preds = %55, %35
%57 = load i32, i32* %2
%58 = call i32 @listen(i32 %57, i32 10)
store i32 %58, i32* %3
%59 = load i32, i32* %3
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %66
61: ; preds = %56
br label %62
62: ; preds = %61
%63 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%64 = call i32 @exit(i32 -1)
unreachable
65: ; No predecessors!
br label %66
66: ; preds = %65, %56
%67 = bitcast [4096 x i8]* %11 to i8*
br label %68
68: ; preds = %66, %74, %136
%69 = load i32, i32* %2
%70 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%71 = call i32 @accept(i32 %69, %struct.sockaddr* %70, i32* %5)
store i32 %71, i32* %9
%72 = load i32, i32* %9
%73 = icmp eq i32 %72, -1
br i1 %73, label %74, label %76
74: ; preds = %68
%75 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %68
76: ; preds = %68
br label %77
77: ; preds = %88, %76
%78 = load i32, i32* %9
%79 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%80 = call i32 @read(i32 %78, i8* %79, i32 4095)
store i32 %80, i32* %10
%81 = icmp slt i32 %80, 0
br i1 %81, label %82, label %86
82: ; preds = %77
%83 = load i64, i64* @errno
%84 = load i64, i64* @EINTR
%85 = icmp eq i64 %83, %84
br label %86
86: ; preds = %82, %77
%87 = phi i1 [ false, %77 ], [ %85, %82 ]
br i1 %87, label %88, label %89
88: ; preds = %86
br label %77
89: ; preds = %86
%90 = load i32, i32* %10
%91 = icmp slt i32 %90, 0
br i1 %91, label %92, label %94
92: ; preds = %89
%93 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %139
94: ; preds = %89
%95 = load i32, i32* %10
%96 = icmp eq i32 %95, 0
br i1 %96, label %97, label %99
97: ; preds = %94
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
br label %139
99: ; preds = %94
%100 = load i32, i32* %10
%101 = sub nsw i32 %100, 2
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 %102
store i8 0, i8* %103
%104 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%105 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %104, i32 0, i32 0
%106 = load i32, i32* %105
%107 = call i8* @inet_ntoa(i32 %106)
%108 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%109 = load i32, i32* %108
%110 = call i32 @ntohs(i32 %109)
%111 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %107, i32 %110, i8* %111)
store i32 0, i32* %12
br label %113
113: ; preds = %126, %99
%114 = load i32, i32* %12
%115 = load i32, i32* %10
%116 = icmp slt i32 %114, %115
br i1 %116, label %117, label %129
117: ; preds = %113
%118 = load i32, i32* %12
%119 = sext i32 %118 to i64
%120 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 %119
%121 = load i8, i8* %120
%122 = call signext i8 @toupper(i8 signext %121)
%123 = load i32, i32* %12
%124 = sext i32 %123 to i64
%125 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 %124
store i8 %122, i8* %125
br label %126
126: ; preds = %117
%127 = load i32, i32* %12
%128 = add nsw i32 %127, 1
store i32 %128, i32* %12
br label %113
129: ; preds = %113
%130 = load i32, i32* %9
%131 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%132 = load i32, i32* %10
%133 = sub nsw i32 %132, 1
%134 = call i32 @write(i32 %130, i8* %131, i32 %133)
br label %135
135: ; preds = %129
br label %136
136: ; preds = %135
%137 = load i32, i32* %9
%138 = call i32 @close(i32 %137)
br label %68
139: ; preds = %97, %92
%140 = load i32, i32* %9
%141 = call i32 @close(i32 %140)
%142 = load i32, i32* %2
%143 = load i32, i32* @SHUT_RDWR
%144 = call i32 @shutdown(i32 %142, i32 %143)
store i32 %144, i32* %3
%145 = load i32, i32* %3
%146 = icmp eq i32 %145, -1
br i1 %146, label %147, label %152
147: ; preds = %139
br label %148
148: ; preds = %147
%149 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
%150 = call i32 @exit(i32 -1)
unreachable
151: ; No predecessors!
br label %152
152: ; preds = %151, %139
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [11 x i8] c"setsockopt\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.2 = [5 x i8] c"bind\00"
@.str.3 = [7 x i8] c"listen\00"
@.str.4 = [7 x i8] c"accept\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.5 = [5 x i8] c"read\00"
@.str.7 = [25 x i8] c"receive from %s:%hu# %s\0A\00"
@SHUT_RDWR = global i32 0
@.str.8 = [9 x i8] c"shutdown\00"
@str = [23 x i8] c"connect closed by peer\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca [4096 x i8]
%6 = bitcast i32* %1 to i8*
%7 = load i32, i32* @PF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %0
%15 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%16 = load i32, i32* @SOL_SOCKET
%17 = load i32, i32* @SO_REUSEADDR
%18 = call i32 @setsockopt(i32 %9, i32 %16, i32 %17, i32* %2, i32 4)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @exit(i32 -1)
unreachable
23: ; preds = %14
%24 = bitcast %struct.sockaddr_in* %3 to i8*
%25 = bitcast %struct.sockaddr_in* %4 to i8*
%26 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%27 = load i32, i32* @AF_INET
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %27, i32* %28
%29 = call i32 @htons(i32 8888)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %29, i32* %30
%31 = load i32, i32* @INADDR_ANY
%32 = call i32 @htonl(i32 %31)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %32, i32* %33
%34 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%35 = call i32 @bind(i32 %9, %struct.sockaddr* %34, i32 12)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %40
37: ; preds = %23
%38 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%39 = call i32 @exit(i32 -1)
unreachable
40: ; preds = %23
%41 = call i32 @listen(i32 %9, i32 10)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%45 = call i32 @exit(i32 -1)
unreachable
46: ; preds = %40
%47 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%48 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
br label %51
51: ; preds = %56, %46
%52 = call i32 @accept(i32 %9, %struct.sockaddr* %48, i32* %1)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %57
54: ; preds = %51
%55 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %56
56: ; preds = %54, %88
br label %51
57: ; preds = %51, %57
%58 = call i32 @read(i32 %52, i8* %47, i32 4095)
%59 = icmp slt i32 %58, 0
%60 = load i64, i64* @errno
%61 = load i64, i64* @EINTR
%62 = icmp eq i64 %60, %61
%63 = select i1 %59, i1 %62, i1 false
br i1 %63, label %57, label %64
64: ; preds = %57
br i1 %59, label %65, label %67
65: ; preds = %64
%66 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %92
67: ; preds = %64
%68 = icmp eq i32 %58, 0
br i1 %68, label %69, label %71
69: ; preds = %67
%70 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %92
71: ; preds = %67
%72 = add nsw i32 %58, -2
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 %73
store i8 0, i8* %74
%75 = load i32, i32* %49
%76 = call i8* @inet_ntoa(i32 %75)
%77 = load i32, i32* %50
%78 = call i32 @ntohs(i32 %77)
%79 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %76, i32 %78, i8* %47)
%80 = zext i32 %58 to i64
br label %81
81: ; preds = %71, %81
%82 = phi i64 [ 0, %71 ], [ %86, %81 ]
%83 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 %82
%84 = load i8, i8* %83
%85 = call signext i8 @toupper(i8 signext %84)
store i8 %85, i8* %83
%86 = add nuw nsw i64 %82, 1
%87 = icmp eq i64 %86, %80
br i1 %87, label %88, label %81
88: ; preds = %81
%89 = add nsw i32 %58, -1
%90 = call i32 @write(i32 %52, i8* %47, i32 %89)
%91 = call i32 @close(i32 %52)
br label %56
92: ; preds = %69, %65
%93 = call i32 @close(i32 %52)
%94 = load i32, i32* @SHUT_RDWR
%95 = call i32 @shutdown(i32 %9, i32 %94)
%96 = icmp eq i32 %95, -1
br i1 %96, label %97, label %100
97: ; preds = %92
%98 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
%99 = call i32 @exit(i32 -1)
unreachable
100: ; preds = %92
ret i32 0
}