#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_zero;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ WNOHANG;
int accept(int, struct sockaddr *, int *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(TYPE_1__);
int listen(int, int);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
scalar_t__ waitpid(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(void) {
  int sockfd, conn_fd;
  struct sockaddr_in my_addr;
  struct sockaddr_in their_addr;
  int sin_size;
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    fprintf(stderr, "socket error!\n");
    return 0;
  }
  my_addr.sin_family = AF_INET;
  my_addr.sin_port = htons(8848);
  my_addr.sin_addr.s_addr = INADDR_ANY;
  bzero(&(my_addr.sin_zero), 8);
  if (bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)) ==
      -1) {
    fprintf(stderr, "bind error!\n");
    return 0;
  }
  if (listen(sockfd, 10) == -1) {
    fprintf(stderr, "listen error!\n");
    return 0;
  }
  FILE *fp = fopen("wow.jpg", "wb+");
  if (fp == NULL) {
    printf("fopen error\n");
    return -1;
  }
  int i = 0;
  while (1) {
    sin_size = sizeof(struct sockaddr_in);
    if ((conn_fd = accept(sockfd, (struct sockaddr *)&their_addr, &sin_size)) ==
        -1) {
      fprintf(stderr, "accept error!\n");
      continue;
    }
    printf("server: got connection from %s\n", inet_ntoa(their_addr.sin_addr));
    if (!fork()) {
      while (1) {
        char buf[1024] = {0};
        int in = recv(conn_fd, buf, 1024, 0);
        if (in <= 0) {
          break;
        }
        fwrite(buf, 1, in, fp);
        i++;
        printf("receive len = %d i = %d\n", in, i);
      }
    }
    close(conn_fd);
    while (waitpid(-1, NULL, WNOHANG) > 0)
      ;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
mov    0x2d9e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    1258 <main+0x58>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
lea    0xdb9(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1468 <main+0x268>
mov    0x2d89(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    $0x2290,%edi
call   1050 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    0x2d60(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
add    $0x4,%rdi
mov    $0x8,%esi
call   10e0 <bzero@plt>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   10b0 <bind@plt>
cmp    $0xffffffff,%eax
jne    12ca <main+0xca>
mov    0x2d18(%rip),%rax
mov    (%rax),%edi
lea    0xd56(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1468 <main+0x268>
mov    -0x8(%rbp),%edi
mov    $0xa,%esi
call   10a0 <listen@plt>
cmp    $0xffffffff,%eax
jne    1301 <main+0x101>
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
lea    0xd2c(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1468 <main+0x268>
lea    0xd23(%rip),%rdi
lea    0xd24(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    133d <main+0x13d>
lea    0xd0d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1468 <main+0x268>
movl   $0x0,-0x44(%rbp)
movl   $0x10,-0x34(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x34(%rbp),%rdx
call   10f0 <accept@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    1381 <main+0x181>
mov    0x2c5a(%rip),%rax
mov    (%rax),%edi
lea    0xccd(%rip),%rsi
call   1090 <fprintf@plt>
jmp    1344 <main+0x144>
mov    -0x30(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xcc0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1110 <fork@plt>
cmp    $0x0,%eax
jne    1435 <main+0x235>
jmp    13af <main+0x1af>
lea    -0x450(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
mov    -0xc(%rbp),%edi
lea    -0x450(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x454(%rbp)
cmpl   $0x0,-0x454(%rbp)
jg     13f0 <main+0x1f0>
jmp    1430 <main+0x230>
lea    -0x450(%rbp),%rdi
mov    -0x454(%rbp),%edx
mov    -0x40(%rbp),%rcx
mov    $0x1,%esi
call   1100 <fwrite@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
mov    -0x454(%rbp),%esi
mov    -0x44(%rbp),%edx
lea    0xc4f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    13af <main+0x1af>
jmp    1435 <main+0x235>
mov    -0xc(%rbp),%edi
call   1080 <close@plt>
mov    0x2b9c(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%edi
xor    %eax,%eax
mov    %eax,%esi
call   10c0 <waitpid@plt>
cmp    $0x0,%rax
jle    1463 <main+0x263>
jmp    143d <main+0x23d>
jmp    1344 <main+0x144>
mov    -0x4(%rbp),%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
mov    0x2dc0(%rip),%r14
mov    (%r14),%edi
mov    0x2d8e(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
xor    %edx,%edx
call   1130 <socket@plt>
cmp    $0xffffffff,%eax
je     1432 <main+0x222>
mov    %eax,%ebp
mov    (%r14),%eax
mov    %eax,0x14(%rsp)
mov    $0x2290,%edi
call   1060 <htons@plt>
mov    %eax,0x10(%rsp)
mov    0x2d74(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
lea    0xc(%rsp),%rdi
mov    $0x8,%esi
call   10f0 <bzero@plt>
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
call   10c0 <bind@plt>
cmp    $0xffffffff,%eax
je     1449 <main+0x239>
mov    %ebp,%edi
mov    $0xa,%esi
call   10b0 <listen@plt>
cmp    $0xffffffff,%eax
je     145b <main+0x24b>
lea    0xd7c(%rip),%rdi
lea    0xd7d(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     1474 <main+0x264>
mov    %rax,0x18(%rsp)
lea    0x20(%rsp),%rsi
mov    %rsp,%r12
lea    0x30(%rsp),%r14
xor    %r13d,%r13d
mov    %ebp,0x4(%rsp)
nopl   (%rax)
movl   $0x10,(%rsp)
mov    %ebp,%edi
mov    %r12,%rdx
call   1100 <accept@plt>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
jne    1343 <main+0x133>
lea    0xd37(%rip),%rbp
mov    0x4(%rsp),%r14d
lea    0x20(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    0x2cb1(%rip),%rax
mov    (%rax),%edi
mov    %rbp,%rsi
call   10a0 <fprintf@plt>
movl   $0x10,(%rsp)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1100 <accept@plt>
cmp    $0xffffffff,%eax
je     1310 <main+0x100>
mov    %eax,%r15d
lea    0x30(%rsp),%r14
mov    0x20(%rsp),%edi
call   1050 <inet_ntoa@plt>
lea    0xcf3(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   1120 <fork@plt>
test   %eax,%eax
jne    13f2 <main+0x1e2>
lea    0xcf3(%rip),%rbp
mov    $0x400,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1080 <memset@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%r12d
test   %eax,%eax
mov    0x18(%rsp),%rbx
jle    13ef <main+0x1df>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %r12d,%edx
mov    %rbx,%rcx
call   1110 <fwrite@plt>
add    $0x1,%r13d
mov    %rbp,%rdi
mov    %r12d,%esi
mov    %r13d,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x400,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1080 <memset@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%r12d
test   %eax,%eax
jg     13a0 <main+0x190>
mov    %rsp,%r12
mov    %r15d,%edi
call   1090 <close@plt>
mov    0x2bdf(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x0(%rbp),%edx
mov    $0xffffffff,%edi
xor    %esi,%esi
call   10d0 <waitpid@plt>
test   %rax,%rax
jg     1410 <main+0x200>
mov    0x4(%rsp),%ebp
lea    0x20(%rsp),%rsi
jmp    12e0 <main+0xd0>
mov    0x2b8f(%rip),%rax
mov    (%rax),%edi
lea    0xbbe(%rip),%rsi
call   10a0 <fprintf@plt>
jmp    1485 <main+0x275>
mov    0x2b78(%rip),%rax
mov    (%rax),%edi
lea    0xbb6(%rip),%rsi
jmp    146b <main+0x25b>
mov    0x2b66(%rip),%rax
mov    (%rax),%edi
lea    0xbb1(%rip),%rsi
call   10a0 <fprintf@plt>
xor    %ebx,%ebx
jmp    1485 <main+0x275>
lea    0xc04(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x438,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [15 x i8] c"socket error!\0A\00"
@INADDR_ANY = global i32 0
@.str.1 = [13 x i8] c"bind error!\0A\00"
@.str.2 = [15 x i8] c"listen error!\0A\00"
@.str.3 = [8 x i8] c"wow.jpg\00"
@.str.4 = [4 x i8] c"wb+\00"
@.str.5 = [13 x i8] c"fopen error\0A\00"
@.str.6 = [15 x i8] c"accept error!\0A\00"
@.str.7 = [32 x i8] c"server: got connection from %s\0A\00"
@.str.8 = [25 x i8] c"receive len = %d i = %d\0A\00"
@WNOHANG = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca [1024 x i8]
%10 = alloca i32
store i32 0, i32* %1
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %2
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %0
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %94
18: ; preds = %0
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 3
store i32 %19, i32* %20
%21 = call i32 @htons(i32 8848)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i32 %21, i32* %22
%23 = load i32, i32* @INADDR_ANY
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%25 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %24, i32 0, i32 0
store i32 %23, i32* %25
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
%27 = call i32 @bzero(i32* %26, i32 8)
%28 = load i32, i32* %2
%29 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%30 = call i32 @bind(i32 %28, %struct.sockaddr* %29, i32 4)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %35
32: ; preds = %18
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %94
35: ; preds = %18
%36 = load i32, i32* %2
%37 = call i32 @listen(i32 %36, i32 10)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %42
39: ; preds = %35
%40 = load i32, i32* @stderr
%41 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %94
42: ; preds = %35
%43 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
store i32* %43, i32** %7
%44 = load i32*, i32** %7
%45 = icmp eq i32* %44, null
br i1 %45, label %46, label %48
46: ; preds = %42
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %1
br label %94
48: ; preds = %42
store i32 0, i32* %8
br label %49
49: ; preds = %48, %54, %93
store i32 16, i32* %6
%50 = load i32, i32* %2
%51 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%52 = call i32 @accept(i32 %50, %struct.sockaddr* %51, i32* %6)
store i32 %52, i32* %3
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %57
54: ; preds = %49
%55 = load i32, i32* @stderr
%56 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
br label %49
57: ; preds = %49
%58 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%59 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %58, i32 0, i32 0
%60 = load i32, i32* %59
%61 = call i8* @inet_ntoa(i32 %60)
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i8* %61)
%63 = call i32 (...) @fork()
%64 = icmp ne i32 %63, 0
br i1 %64, label %85, label %65
65: ; preds = %57
br label %66
66: ; preds = %65, %74
%67 = bitcast [1024 x i8]* %9 to i8*
%68 = load i32, i32* %3
%69 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%70 = call i32 @recv(i32 %68, i8* %69, i32 1024, i32 0)
store i32 %70, i32* %10
%71 = load i32, i32* %10
%72 = icmp sle i32 %71, 0
br i1 %72, label %73, label %74
73: ; preds = %66
br label %84
74: ; preds = %66
%75 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%76 = load i32, i32* %10
%77 = load i32*, i32** %7
%78 = call i32 @fwrite(i8* %75, i32 1, i32 %76, i32* %77)
%79 = load i32, i32* %8
%80 = add nsw i32 %79, 1
store i32 %80, i32* %8
%81 = load i32, i32* %10
%82 = load i32, i32* %8
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), i32 %81, i32 %82)
br label %66
84: ; preds = %73
br label %85
85: ; preds = %84, %57
%86 = load i32, i32* %3
%87 = call i32 @close(i32 %86)
br label %88
88: ; preds = %92, %85
%89 = load i32, i32* @WNOHANG
%90 = call i64 @waitpid(i32 -1, i32* null, i32 %89)
%91 = icmp sgt i64 %90, 0
br i1 %91, label %92, label %93
92: ; preds = %88
br label %88
93: ; preds = %88
br label %49
94: ; preds = %46, %39, %32, %15
%95 = load i32, i32* %1
ret i32 %95
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [15 x i8] c"socket error!\0A\00"
@INADDR_ANY = global i32 0
@.str.1 = [13 x i8] c"bind error!\0A\00"
@.str.2 = [15 x i8] c"listen error!\0A\00"
@.str.3 = [8 x i8] c"wow.jpg\00"
@.str.4 = [4 x i8] c"wb+\00"
@.str.6 = [15 x i8] c"accept error!\0A\00"
@.str.7 = [32 x i8] c"server: got connection from %s\0A\00"
@.str.8 = [25 x i8] c"receive len = %d i = %d\0A\00"
@WNOHANG = global i32 0
@str = [12 x i8] c"fopen error\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = bitcast %struct.sockaddr_in* %1 to i8*
%6 = bitcast %struct.sockaddr_in* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_STREAM
%10 = tail call i32 @socket(i32 %8, i32 %9, i32 0)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %81
15: ; preds = %0
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 3
store i32 %16, i32* %17
%18 = tail call i32 @htons(i32 8848)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %18, i32* %19
%20 = load i32, i32* @INADDR_ANY
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %20, i32* %21
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
%23 = call i32 @bzero(i32* %22, i32 8)
%24 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%25 = call i32 @bind(i32 %10, %struct.sockaddr* %24, i32 4)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %30
27: ; preds = %15
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %81
30: ; preds = %15
%31 = call i32 @listen(i32 %10, i32 10)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %81
36: ; preds = %30
%37 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%38 = icmp eq i32* %37, null
br i1 %38, label %43, label %39
39: ; preds = %36
%40 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0, i32 0
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
br label %45
43: ; preds = %36
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %81
45: ; preds = %77, %39
%46 = phi i32 [ 0, %39 ], [ %75, %77 ]
store i32 16, i32* %3
%47 = call i32 @accept(i32 %10, %struct.sockaddr* %40, i32* %3)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %54
49: ; preds = %45, %49
%50 = load i32, i32* @stderr
%51 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
store i32 16, i32* %3
%52 = call i32 @accept(i32 %10, %struct.sockaddr* %40, i32* %3)
%53 = icmp eq i32 %52, -1
br i1 %53, label %49, label %54
54: ; preds = %49, %45
%55 = phi i32 [ %47, %45 ], [ %52, %49 ]
%56 = load i32, i32* %41
%57 = call i8* @inet_ntoa(i32 %56)
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i8* %57)
%59 = call i32 (...) @fork()
%60 = icmp eq i32 %59, 0
br i1 %60, label %61, label %74
61: ; preds = %54
%62 = call i32 @recv(i32 %55, i8* %42, i32 1024, i32 0)
%63 = icmp slt i32 %62, 1
br i1 %63, label %64, label %66
64: ; preds = %66, %61
%65 = phi i32 [ %46, %61 ], [ %70, %66 ]
br label %74
66: ; preds = %61, %66
%67 = phi i32 [ %72, %66 ], [ %62, %61 ]
%68 = phi i32 [ %70, %66 ], [ %46, %61 ]
%69 = call i32 @fwrite(i8* %42, i32 1, i32 %67, i32* %37)
%70 = add nsw i32 %68, 1
%71 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), i32 %67, i32 %70)
%72 = call i32 @recv(i32 %55, i8* %42, i32 1024, i32 0)
%73 = icmp slt i32 %72, 1
br i1 %73, label %64, label %66
74: ; preds = %64, %54
%75 = phi i32 [ %46, %54 ], [ %65, %64 ]
%76 = call i32 @close(i32 %55)
br label %77
77: ; preds = %77, %74
%78 = load i32, i32* @WNOHANG
%79 = call i64 @waitpid(i32 -1, i32* null, i32 %78)
%80 = icmp sgt i64 %79, 0
br i1 %80, label %77, label %45
81: ; preds = %43, %33, %27, %12
%82 = phi i32 [ 0, %12 ], [ 0, %27 ], [ 0, %33 ], [ -1, %43 ]
ret i32 %82
}