#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;
};
typedef int ssize_t;
typedef int socklen_t;
typedef int /*<<< orphan*/ cliaddr;

/* Variables and functions */
scalar_t__ EINTR;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
scalar_t__ memcmp(char *, char *, int);
int read(int, char *, int);
int snprintf(char *, int, char *, int);
int tcp_listen(char *, char *);
int /*<<< orphan*/ write_all(int, char *, int);
int main() {
  int listenfd, connfd;
  socklen_t len;
  struct sockaddr_storage cliaddr;
  ssize_t n, siz = 4 + 128;
  char cmd[siz];
  size_t got = 0;
  while (got < (size_t)siz) {
    n = read(0, cmd + got, siz - got);
    if (n < 0 && errno == EINTR)
      continue;
    if (n <= 0)
      break;
    got += n;
  }
  if (memcmp(cmd, "1001", 4))
    exit(1);
  char *addr = cmd + 4;
  char *port = addr;
  while (*port && *port != ':')
    port++;
  if (*port == ':') {
    *port = 0;
    ++port;
  }
  listenfd = tcp_listen(addr, *port ? port : "4242");
  write_all(1, "2003", 4);
  for (;;) {
    len = sizeof(cliaddr);
    connfd = accept(listenfd, (struct sockaddr *)&cliaddr, &len);
    if (connfd >= 0) {
      siz = 0;
      char c = '0';
      do {
        if (c < '0' || c > '9')
          break;
        siz *= 10;
        siz += c - '0';
        if (siz > 999999)
          break;
        do {
          n = read(connfd, &c, 1);
        } while (n < 0 && errno == EINTR);
      } while (n == 1);
      if (c != '\n' || siz < 0 || siz > 999999) {
        close(connfd);
        continue;
      }
      char buf[siz];
      got = 0;
      while (got < (size_t)siz) {
        n = read(connfd, buf + got, siz - got);
        if (n < 0 && errno == EINTR)
          continue;
        if (n <= 0)
          break;
        got += n;
      }
      close(connfd);
      int sizlen = snprintf(0, 0, "%zd\n", siz);
      char sizbuf[sizlen + 1];
      snprintf(sizbuf, sizlen + 1, "%zd\n", siz);
      write_all(1, "2002", 4);
      write_all(1, sizbuf, sizlen);
      write_all(1, buf, siz);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x84,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x78(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movslq -0x20(%rbp),%rcx
cmp    %rcx,%rax
jae    123d <main+0xbd>
mov    -0x78(%rbp),%rsi
add    -0x38(%rbp),%rsi
movslq -0x20(%rbp),%rax
sub    -0x38(%rbp),%rax
mov    %eax,%edx
xor    %edi,%edi
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    121d <main+0x9d>
mov    0x2ddb(%rip),%rax
mov    (%rax),%rax
mov    0x2dc9(%rip),%rcx
cmp    (%rcx),%rax
jne    121d <main+0x9d>
jmp    11c7 <main+0x47>
cmpl   $0x0,-0x1c(%rbp)
jg     122c <main+0xac>
jmp    123d <main+0xbd>
movslq -0x1c(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    11c7 <main+0x47>
mov    -0x78(%rbp),%rdi
lea    0xdb8(%rip),%rsi
mov    $0x4,%edx
call   1060 <memcmp@plt>
cmp    $0x0,%rax
je     1266 <main+0xe6>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x78(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x79(%rbp)
je     129f <main+0x11f>
mov    -0x48(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
setne  %al
mov    %al,-0x79(%rbp)
mov    -0x79(%rbp),%al
test   $0x1,%al
jne    12af <main+0x12f>
jmp    12c0 <main+0x140>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    127a <main+0xfa>
mov    -0x48(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    12e3 <main+0x163>
mov    -0x48(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x48(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     130e <main+0x18e>
mov    -0x48(%rbp),%rax
mov    %rax,-0x90(%rbp)
jmp    1321 <main+0x1a1>
lea    0xcf0(%rip),%rax
mov    %rax,-0x90(%rbp)
jmp    1321 <main+0x1a1>
mov    -0x88(%rbp),%rdi
mov    -0x90(%rbp),%rsi
call   1080 <tcp_listen@plt>
mov    %eax,-0x8(%rbp)
mov    $0x1,%edi
lea    0xcc7(%rip),%rsi
mov    $0x4,%edx
call   1070 <write_all@plt>
movl   $0x4,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1090 <accept@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     159f <main+0x41f>
movl   $0x0,-0x20(%rbp)
movb   $0x30,-0x49(%rbp)
movsbl -0x49(%rbp),%eax
cmp    $0x30,%eax
jl     1396 <main+0x216>
movsbl -0x49(%rbp),%eax
cmp    $0x39,%eax
jle    139b <main+0x21b>
jmp    1426 <main+0x2a6>
imul   $0xa,-0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
movsbl -0x49(%rbp),%eax
sub    $0x30,%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0xf423f,-0x20(%rbp)
jle    13c1 <main+0x241>
jmp    1426 <main+0x2a6>
jmp    13c6 <main+0x246>
mov    -0xc(%rbp),%edi
lea    -0x49(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x91(%rbp)
jge    1409 <main+0x289>
mov    0x2bed(%rip),%rax
mov    (%rax),%rax
mov    0x2bdb(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x91(%rbp)
mov    -0x91(%rbp),%al
test   $0x1,%al
jne    13c6 <main+0x246>
jmp    141c <main+0x29c>
cmpl   $0x1,-0x1c(%rbp)
je     137c <main+0x1fc>
movsbl -0x49(%rbp),%eax
cmp    $0xa,%eax
jne    144a <main+0x2ca>
cmpl   $0x0,-0x20(%rbp)
jl     144a <main+0x2ca>
cmpl   $0xf423f,-0x20(%rbp)
jle    1457 <main+0x2d7>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
jmp    134d <main+0x1cd>
mov    -0x20(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xa0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x60(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movslq -0x20(%rbp),%rcx
cmp    %rcx,%rax
jae    1502 <main+0x382>
mov    -0xa0(%rbp),%rsi
mov    -0xc(%rbp),%edi
add    -0x38(%rbp),%rsi
movslq -0x20(%rbp),%rax
sub    -0x38(%rbp),%rax
mov    %eax,%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    14e2 <main+0x362>
mov    0x2b16(%rip),%rax
mov    (%rax),%rax
mov    0x2b04(%rip),%rcx
cmp    (%rcx),%rax
jne    14e2 <main+0x362>
jmp    1488 <main+0x308>
cmpl   $0x0,-0x1c(%rbp)
jg     14f1 <main+0x371>
jmp    1502 <main+0x382>
movslq -0x1c(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    1488 <main+0x308>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x20(%rbp),%ecx
lea    0xafb(%rip),%rdx
xor    %esi,%esi
mov    %esi,%edi
call   1030 <snprintf@plt>
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0xa8(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x70(%rbp)
mov    -0x64(%rbp),%esi
add    $0x1,%esi
mov    -0x20(%rbp),%ecx
lea    0xaba(%rip),%rdx
call   1030 <snprintf@plt>
mov    $0x1,%edi
lea    0xaae(%rip),%rsi
mov    $0x4,%edx
call   1070 <write_all@plt>
mov    -0xa8(%rbp),%rsi
mov    -0x64(%rbp),%edx
mov    $0x1,%edi
call   1070 <write_all@plt>
mov    -0xa0(%rbp),%rsi
mov    -0x20(%rbp),%edx
mov    $0x1,%edi
call   1070 <write_all@plt>
mov    -0x58(%rbp),%rax
mov    %rax,%rsp
jmp    134d <main+0x1cd>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xd8,%rsp
xor    %r13d,%r13d
mov    0x2e42(%rip),%r12
mov    0x2e33(%rip),%r15
cmp    $0x83,%r13
ja     11f9 <main+0x79>
mov    $0x84,%ebx
sub    %r13d,%ebx
lea    -0x100(,%r13,1),%r14
ff
add    %rbp,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1050 <read@plt>
test   %eax,%eax
jns    11f0 <main+0x70>
mov    (%r12),%rax
cmp    (%r15),%rax
je     11d0 <main+0x50>
jmp    11f9 <main+0x79>
nopl   0x0(%rax,%rax,1)
mov    %eax,%ecx
add    %rcx,%r13
test   %eax,%eax
jne    11a5 <main+0x25>
lea    0xe00(%rip),%rsi
lea    -0x100(%rbp),%rdi
mov    $0x4,%edx
call   1060 <memcmp@plt>
test   %rax,%rax
jne    1430 <main+0x2b0>
lea    -0xfc(%rbp),%rdi
lea    -0xfb(%rbp),%rax
nopl   0x0(%rax,%rax,1)
movzbl -0x1(%rax),%ecx
test   %cl,%cl
je     1257 <main+0xd7>
cmp    $0x3a,%cl
je     1243 <main+0xc3>
add    $0x1,%rax
jmp    1230 <main+0xb0>
movb   $0x0,-0x1(%rax)
cmpb   $0x0,(%rax)
lea    0xdb4(%rip),%rsi
cmovne %rax,%rsi
jmp    125e <main+0xde>
lea    0xda7(%rip),%rsi
call   1080 <tcp_listen@plt>
mov    %eax,-0x44(%rbp)
lea    0xd9d(%rip),%rsi
mov    $0x1,%edi
mov    $0x4,%edx
call   1070 <write_all@plt>
lea    -0x29(%rbp),%rbx
jmp    1298 <main+0x118>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14d,%edi
call   1040 <close@plt>
movl   $0x4,-0x4c(%rbp)
mov    -0x44(%rbp),%edi
lea    -0x70(%rbp),%rsi
lea    -0x4c(%rbp),%rdx
call   1090 <accept@plt>
test   %eax,%eax
js     1298 <main+0x118>
mov    %eax,%r14d
movb   $0x30,-0x29(%rbp)
mov    $0x30,%cl
xor    %r13d,%r13d
nop
movzbl %cl,%eax
lea    0x0(%r13,%r13,4),%ecx
lea    (%rax,%rcx,2),%r13d
add    $0xffffffd0,%r13d
cmp    $0xf423f,%r13d
jg     1290 <main+0x110>
nopl   0x0(%rax)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
test   %eax,%eax
jns    12fd <main+0x17d>
mov    (%r15),%rcx
cmp    %rcx,(%r12)
je     12e0 <main+0x160>
mov    -0x29(%rbp),%cl
cmp    $0x1,%eax
jne    130c <main+0x18c>
lea    -0x3a(%rcx),%eax
cmp    $0xf5,%al
ja     12c0 <main+0x140>
cmp    $0xa,%cl
jne    1290 <main+0x110>
test   %r13d,%r13d
js     1290 <main+0x110>
cmp    $0xf423f,%r13d
jg     1290 <main+0x110>
mov    %rsp,-0x60(%rbp)
mov    %r13d,%eax
mov    %rsp,%rcx
mov    %rax,-0x68(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
xor    %eax,%eax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x68(%rbp),%rax
jae    13aa <main+0x22a>
mov    -0x58(%rbp),%rax
mov    -0x38(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    %r13d,%eax
sub    %ecx,%eax
mov    %eax,-0x48(%rbp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14d,%edi
mov    -0x40(%rbp),%rsi
mov    -0x48(%rbp),%edx
call   1050 <read@plt>
test   %eax,%eax
jns    13a0 <main+0x220>
mov    (%r12),%rax
cmp    (%r15),%rax
je     1380 <main+0x200>
jmp    13aa <main+0x22a>
xchg   %ax,%ax
mov    %eax,%ecx
add    %rcx,-0x38(%rbp)
test   %eax,%eax
jne    1351 <main+0x1d1>
mov    %r14d,%edi
call   1040 <close@plt>
xor    %edi,%edi
xor    %esi,%esi
lea    0xc52(%rip),%rdx
mov    %r13d,%ecx
call   1030 <snprintf@plt>
mov    %rax,-0x40(%rbp)
lea    0x1(%rax),%esi
lea    0xf(%rsi),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r14
sub    %rax,%r14
mov    %r14,%rsp
mov    %r14,%rdi
lea    0xc28(%rip),%rdx
mov    %r13d,%ecx
call   1030 <snprintf@plt>
mov    $0x1,%edi
lea    0xc19(%rip),%rsi
mov    $0x4,%edx
call   1070 <write_all@plt>
mov    $0x1,%edi
mov    %r14,%rsi
mov    -0x40(%rbp),%rdx
call   1070 <write_all@plt>
mov    $0x1,%edi
mov    -0x58(%rbp),%rsi
mov    %r13d,%edx
call   1070 <write_all@plt>
mov    -0x60(%rbp),%rsp
jmp    1298 <main+0x118>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
@.str = [5 x i8] c"1001\00"
@.str.1 = [5 x i8] c"4242\00"
@.str.2 = [5 x i8] c"2003\00"
@.str.3 = [5 x i8] c"%zd\0A\00"
@.str.4 = [5 x i8] c"2002\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_storage
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8
%14 = alloca i8*
%15 = alloca i64
%16 = alloca i32
%17 = alloca i64
store i32 0, i32* %1
store i32 132, i32* %7
%18 = load i32, i32* %7
%19 = zext i32 %18 to i64
%20 = call i8* @llvm.stacksave()
store i8* %20, i8** %8
%21 = alloca i8, i64 %19
store i64 %19, i64* %9
store i64 0, i64* %10
br label %22
22: ; preds = %47, %42, %0
%23 = load i64, i64* %10
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = icmp ult i64 %23, %25
br i1 %26, label %27, label %52
27: ; preds = %22
%28 = load i64, i64* %10
%29 = getelementptr inbounds i8, i8* %21, i64 %28
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = load i64, i64* %10
%33 = sub i64 %31, %32
%34 = trunc i64 %33 to i32
%35 = call i32 @read(i32 0, i8* %29, i32 %34)
store i32 %35, i32* %6
%36 = load i32, i32* %6
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %27
%39 = load i64, i64* @errno
%40 = load i64, i64* @EINTR
%41 = icmp eq i64 %39, %40
br i1 %41, label %42, label %43
42: ; preds = %38
br label %22
43: ; preds = %38, %27
%44 = load i32, i32* %6
%45 = icmp sle i32 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %43
br label %52
47: ; preds = %43
%48 = load i32, i32* %6
%49 = sext i32 %48 to i64
%50 = load i64, i64* %10
%51 = add i64 %50, %49
store i64 %51, i64* %10
br label %22
52: ; preds = %46, %22
%53 = call i64 @memcmp(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %52
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %52
%58 = getelementptr inbounds i8, i8* %21, i64 4
store i8* %58, i8** %11
%59 = load i8*, i8** %11
store i8* %59, i8** %12
br label %60
60: ; preds = %72, %57
%61 = load i8*, i8** %12
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
%64 = icmp ne i32 %63, 0
br i1 %64, label %65, label %70
65: ; preds = %60
%66 = load i8*, i8** %12
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = icmp ne i32 %68, 58
br label %70
70: ; preds = %65, %60
%71 = phi i1 [ false, %60 ], [ %69, %65 ]
br i1 %71, label %72, label %75
72: ; preds = %70
%73 = load i8*, i8** %12
%74 = getelementptr inbounds i8, i8* %73, i32 1
store i8* %74, i8** %12
br label %60
75: ; preds = %70
%76 = load i8*, i8** %12
%77 = load i8, i8* %76
%78 = sext i8 %77 to i32
%79 = icmp eq i32 %78, 58
br i1 %79, label %80, label %84
80: ; preds = %75
%81 = load i8*, i8** %12
store i8 0, i8* %81
%82 = load i8*, i8** %12
%83 = getelementptr inbounds i8, i8* %82, i32 1
store i8* %83, i8** %12
br label %84
84: ; preds = %80, %75
%85 = load i8*, i8** %11
%86 = load i8*, i8** %12
%87 = load i8, i8* %86
%88 = sext i8 %87 to i32
%89 = icmp ne i32 %88, 0
br i1 %89, label %90, label %92
90: ; preds = %84
%91 = load i8*, i8** %12
br label %93
92: ; preds = %84
br label %93
93: ; preds = %92, %90
%94 = phi i8* [ %91, %90 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %92 ]
%95 = call i32 @tcp_listen(i8* %85, i8* %94)
store i32 %95, i32* %2
%96 = call i32 @write_all(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
br label %97
97: ; preds = %209, %151, %93
store i32 4, i32* %4
%98 = load i32, i32* %2
%99 = bitcast %struct.sockaddr_storage* %5 to %struct.sockaddr*
%100 = call i32 @accept(i32 %98, %struct.sockaddr* %99, i32* %4)
store i32 %100, i32* %3
%101 = load i32, i32* %3
%102 = icmp sge i32 %101, 0
br i1 %102, label %103, label %209
103: ; preds = %97
store i32 0, i32* %7
store i8 48, i8* %13
br label %104
104: ; preds = %138, %103
%105 = load i8, i8* %13
%106 = sext i8 %105 to i32
%107 = icmp slt i32 %106, 48
br i1 %107, label %112, label %108
108: ; preds = %104
%109 = load i8, i8* %13
%110 = sext i8 %109 to i32
%111 = icmp sgt i32 %110, 57
br i1 %111, label %112, label %113
112: ; preds = %108, %104
br label %141
113: ; preds = %108
%114 = load i32, i32* %7
%115 = mul nsw i32 %114, 10
store i32 %115, i32* %7
%116 = load i8, i8* %13
%117 = sext i8 %116 to i32
%118 = sub nsw i32 %117, 48
%119 = load i32, i32* %7
%120 = add nsw i32 %119, %118
store i32 %120, i32* %7
%121 = load i32, i32* %7
%122 = icmp sgt i32 %121, 999999
br i1 %122, label %123, label %124
123: ; preds = %113
br label %141
124: ; preds = %113
br label %125
125: ; preds = %135, %124
%126 = load i32, i32* %3
%127 = call i32 @read(i32 %126, i8* %13, i32 1)
store i32 %127, i32* %6
br label %128
128: ; preds = %125
%129 = load i32, i32* %6
%130 = icmp slt i32 %129, 0
br i1 %130, label %131, label %135
131: ; preds = %128
%132 = load i64, i64* @errno
%133 = load i64, i64* @EINTR
%134 = icmp eq i64 %132, %133
br label %135
135: ; preds = %131, %128
%136 = phi i1 [ false, %128 ], [ %134, %131 ]
br i1 %136, label %125, label %137
137: ; preds = %135
br label %138
138: ; preds = %137
%139 = load i32, i32* %6
%140 = icmp eq i32 %139, 1
br i1 %140, label %104, label %141
141: ; preds = %138, %123, %112
%142 = load i8, i8* %13
%143 = sext i8 %142 to i32
%144 = icmp ne i32 %143, 10
br i1 %144, label %151, label %145
145: ; preds = %141
%146 = load i32, i32* %7
%147 = icmp slt i32 %146, 0
br i1 %147, label %151, label %148
148: ; preds = %145
%149 = load i32, i32* %7
%150 = icmp sgt i32 %149, 999999
br i1 %150, label %151, label %154
151: ; preds = %148, %145, %141
%152 = load i32, i32* %3
%153 = call i32 @close(i32 %152)
br label %97
154: ; preds = %148
%155 = load i32, i32* %7
%156 = zext i32 %155 to i64
%157 = call i8* @llvm.stacksave()
store i8* %157, i8** %14
%158 = alloca i8, i64 %156
store i64 %156, i64* %15
store i64 0, i64* %10
br label %159
159: ; preds = %185, %180, %154
%160 = load i64, i64* %10
%161 = load i32, i32* %7
%162 = sext i32 %161 to i64
%163 = icmp ult i64 %160, %162
br i1 %163, label %164, label %190
164: ; preds = %159
%165 = load i32, i32* %3
%166 = load i64, i64* %10
%167 = getelementptr inbounds i8, i8* %158, i64 %166
%168 = load i32, i32* %7
%169 = sext i32 %168 to i64
%170 = load i64, i64* %10
%171 = sub i64 %169, %170
%172 = trunc i64 %171 to i32
%173 = call i32 @read(i32 %165, i8* %167, i32 %172)
store i32 %173, i32* %6
%174 = load i32, i32* %6
%175 = icmp slt i32 %174, 0
br i1 %175, label %176, label %181
176: ; preds = %164
%177 = load i64, i64* @errno
%178 = load i64, i64* @EINTR
%179 = icmp eq i64 %177, %178
br i1 %179, label %180, label %181
180: ; preds = %176
br label %159
181: ; preds = %176, %164
%182 = load i32, i32* %6
%183 = icmp sle i32 %182, 0
br i1 %183, label %184, label %185
184: ; preds = %181
br label %190
185: ; preds = %181
%186 = load i32, i32* %6
%187 = sext i32 %186 to i64
%188 = load i64, i64* %10
%189 = add i64 %188, %187
store i64 %189, i64* %10
br label %159
190: ; preds = %184, %159
%191 = load i32, i32* %3
%192 = call i32 @close(i32 %191)
%193 = load i32, i32* %7
%194 = call i32 @snprintf(i8* null, i32 0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %193)
store i32 %194, i32* %16
%195 = load i32, i32* %16
%196 = add nsw i32 %195, 1
%197 = zext i32 %196 to i64
%198 = alloca i8, i64 %197
store i64 %197, i64* %17
%199 = load i32, i32* %16
%200 = add nsw i32 %199, 1
%201 = load i32, i32* %7
%202 = call i32 @snprintf(i8* %198, i32 %200, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %201)
%203 = call i32 @write_all(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%204 = load i32, i32* %16
%205 = call i32 @write_all(i32 1, i8* %198, i32 %204)
%206 = load i32, i32* %7
%207 = call i32 @write_all(i32 1, i8* %158, i32 %206)
%208 = load i8*, i8** %14
br label %209
209: ; preds = %190, %97
br label %97
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
@.str = [5 x i8] c"1001\00"
@.str.1 = [5 x i8] c"4242\00"
@.str.2 = [5 x i8] c"2003\00"
@.str.3 = [5 x i8] c"%zd\0A\00"
@.str.4 = [5 x i8] c"2002\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_storage
%3 = alloca i8
%4 = bitcast i32* %1 to i8*
%5 = bitcast %struct.sockaddr_storage* %2 to i8*
%6 = alloca [132 x i8]
%7 = getelementptr inbounds [132 x i8], [132 x i8]* %6, i64 0, i64 0
br label %8
8: ; preds = %21, %0
%9 = phi i64 [ %24, %21 ], [ 0, %0 ]
%10 = icmp ult i64 %9, 132
%11 = getelementptr inbounds [132 x i8], [132 x i8]* %6, i64 0, i64 %9
%12 = trunc i64 %9 to i32
%13 = sub nuw nsw i32 132, %12
br i1 %10, label %14, label %25
14: ; preds = %8, %17
%15 = call i32 @read(i32 0, i8* %11, i32 %13)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i64, i64* @errno
%19 = load i64, i64* @EINTR
%20 = icmp eq i64 %18, %19
br i1 %20, label %14, label %25
21: ; preds = %14
%22 = icmp eq i32 %15, 0
%23 = zext i32 %15 to i64
%24 = add nuw nsw i64 %9, %23
br i1 %22, label %25, label %8
25: ; preds = %21, %8, %17
%26 = call i64 @memcmp(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%27 = icmp eq i64 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %25
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %25
%31 = getelementptr inbounds [132 x i8], [132 x i8]* %6, i64 0, i64 4
br label %32
32: ; preds = %35, %30
%33 = phi i8* [ %31, %30 ], [ %36, %35 ]
%34 = load i8, i8* %33
switch i8 %34, label %35 [
i8 58, label %37
i8 0, label %42
]
35: ; preds = %32
%36 = getelementptr inbounds i8, i8* %33, i64 1
br label %32
37: ; preds = %32
store i8 0, i8* %33
%38 = getelementptr inbounds i8, i8* %33, i64 1
%39 = load i8, i8* %38
%40 = icmp eq i8 %39, 0
%41 = select i1 %40, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %38
br label %42
42: ; preds = %32, %37
%43 = phi i8* [ %41, %37 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %32 ]
%44 = call i32 @tcp_listen(i8* %31, i8* %43)
%45 = call i32 @write_all(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%46 = bitcast %struct.sockaddr_storage* %2 to %struct.sockaddr*
br label %47
47: ; preds = %50, %42
store i32 4, i32* %1
%48 = call i32 @accept(i32 %44, %struct.sockaddr* %46, i32* %1)
%49 = icmp sgt i32 %48, -1
br i1 %49, label %51, label %50
50: ; preds = %47, %101, %111
br label %47
51: ; preds = %47
store i8 48, i8* %3
br label %52
52: ; preds = %67, %51
%53 = phi i32 [ 0, %51 ], [ %58, %67 ]
%54 = phi i8 [ 48, %51 ], [ %69, %67 ]
%55 = zext i8 %54 to i32
%56 = mul nsw i32 %53, 10
%57 = add i32 %56, -48
%58 = add i32 %57, %55
%59 = icmp sgt i32 %58, 999999
br i1 %59, label %111, label %60
60: ; preds = %52, %60
%61 = call i32 @read(i32 %48, i8* %3, i32 1)
%62 = icmp slt i32 %61, 0
%63 = load i64, i64* @errno
%64 = load i64, i64* @EINTR
%65 = icmp eq i64 %63, %64
%66 = select i1 %62, i1 %65, i1 false
br i1 %66, label %60, label %67
67: ; preds = %60
%68 = icmp ne i32 %61, 1
%69 = load i8, i8* %3
%70 = add i8 %69, -58
%71 = icmp ult i8 %70, -10
%72 = select i1 %68, i1 true, i1 %71
br i1 %72, label %73, label %52
73: ; preds = %67
%74 = icmp ne i8 %69, 10
%75 = icmp slt i32 %58, 0
%76 = select i1 %74, i1 true, i1 %75
%77 = icmp sgt i32 %58, 999999
%78 = select i1 %76, i1 true, i1 %77
br i1 %78, label %111, label %79
79: ; preds = %73
%80 = zext i32 %58 to i64
%81 = call i8* @llvm.stacksave()
%82 = alloca i8, i64 %80
%83 = zext i32 %58 to i64
br label %84
84: ; preds = %97, %79
%85 = phi i64 [ %100, %97 ], [ 0, %79 ]
%86 = icmp ult i64 %85, %83
%87 = getelementptr inbounds i8, i8* %82, i64 %85
%88 = trunc i64 %85 to i32
%89 = sub i32 %58, %88
br i1 %86, label %90, label %101
90: ; preds = %84, %93
%91 = call i32 @read(i32 %48, i8* %87, i32 %89)
%92 = icmp slt i32 %91, 0
br i1 %92, label %93, label %97
93: ; preds = %90
%94 = load i64, i64* @errno
%95 = load i64, i64* @EINTR
%96 = icmp eq i64 %94, %95
br i1 %96, label %90, label %101
97: ; preds = %90
%98 = icmp eq i32 %91, 0
%99 = zext i32 %91 to i64
%100 = add i64 %85, %99
br i1 %98, label %101, label %84
101: ; preds = %97, %84, %93
%102 = call i32 @close(i32 %48)
%103 = call i32 @snprintf(i8* null, i32 0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %58)
%104 = add nsw i32 %103, 1
%105 = zext i32 %104 to i64
%106 = alloca i8, i64 %105
%107 = call i32 @snprintf(i8* %106, i32 %104, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %58)
%108 = call i32 @write_all(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%109 = call i32 @write_all(i32 1, i8* %106, i32 %103)
%110 = call i32 @write_all(i32 1, i8* %82, i32 %58)
br label %50
111: ; preds = %52, %73
%112 = call i32 @close(i32 %48)
br label %50
}