#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_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ raddr;
typedef int /*<<< orphan*/ laddr;
typedef int /*<<< orphan*/ ipstr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EAGAIN;
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, void *, int *);
int /*<<< orphan*/ atoi(char *);
int bind(int, void *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/ *, char *,
                             int);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ memset(char *, char, int);
int open(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int fd;
  int sockfd;
  int newfd;
  int ret;
  socklen_t len;
  char buf[1024];
  char fname[1024];
  struct sockaddr_in laddr, raddr;
  laddr.sin_family = AF_INET;
  laddr.sin_port = htons(atoi("10086"));
  inet_pton(AF_INET, "0.0.0.0", &laddr.sin_addr);
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd < 0) {
    perror("socket");
    exit(-1);
  }
  ret = bind(sockfd, (void *)&laddr, sizeof(laddr));
  if (ret < 0) {
    perror("bind");
    exit(-1);
  }
  listen(sockfd, 10);
  len = sizeof(raddr);
  while (1) {
    newfd = accept(sockfd, (void *)&raddr, &len);
    if (newfd < 0) {
      perror("accept");
      exit(-1);
    }
    if (newfd == EAGAIN)
      continue;
    char ipstr[1024];
    inet_ntop(AF_INET, &raddr.sin_addr, ipstr, sizeof(ipstr));
    printf("%s\r\n", ipstr);
    break;
  }
  int fnamelen;
  if (recv(newfd, &fnamelen, sizeof(int), 0) <= 0) {
    fprintf(stdout, "get filename failed\r\n");
    exit(-1);
  }
  memset(fname, '\0', 1024);
  if (recv(newfd, fname, fnamelen, 0) <= 0) {
    fprintf(stdout, "get filename failed\r\n");
    exit(-1);
  }
  strcat(&fname[fnamelen], "\0");
  printf("file: %s\r\n", fname);
  fd = open(fname, O_CREAT | O_TRUNC | O_RDWR, 444);
  if (fd < 0) {
    perror("open():");
    exit(-1);
  }
  int j = 0;
  int count = 0;
  while (1) {
    ret = recv(newfd, buf, 1024, 0);
    write(fd, buf, ret);
    count += ret;
    memset(buf, '\0', 1024);
    if (ret == EAGAIN)
      continue;
    if (ret <= 0) {
      break;
    }
  }
  fprintf(stdout, "file size: %d\r\n", count);
  printf("\r\nRECEIVE OK\r\n\r\n");
  close(fd);
  close(newfd);
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2d97(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x828(%rbp)
lea    0xdb8(%rip),%rdi
call   1110 <atoi@plt>
mov    %eax,%edi
call   1060 <htons@plt>
mov    %eax,-0x82c(%rbp)
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
lea    -0x830(%rbp),%rdx
lea    0xd95(%rip),%rsi
call   10b0 <inet_pton@plt>
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
mov    0x2d3a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    12b2 <main+0x92>
lea    0xd6b(%rip),%rdi
call   10f0 <perror@plt>
mov    $0xffffffff,%edi
call   1130 <exit@plt>
mov    -0xc(%rbp),%edi
lea    -0x830(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12e9 <main+0xc9>
lea    0xd3b(%rip),%rdi
call   10f0 <perror@plt>
mov    $0xffffffff,%edi
call   1130 <exit@plt>
mov    -0xc(%rbp),%edi
mov    $0xa,%esi
call   10c0 <listen@plt>
movl   $0xc,-0x18(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x840(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1100 <accept@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1333 <main+0x113>
lea    0xcf6(%rip),%rdi
call   10f0 <perror@plt>
mov    $0xffffffff,%edi
call   1130 <exit@plt>
mov    -0x10(%rbp),%eax
mov    0x2c6b(%rip),%rcx
cmp    (%rcx),%eax
jne    134a <main+0x12a>
jmp    12fd <main+0xdd>
mov    0x2c7f(%rip),%rax
mov    (%rax),%edi
lea    -0x840(%rbp),%rsi
lea    -0xc40(%rbp),%rdx
mov    $0x400,%ecx
call   1030 <inet_ntop@plt>
lea    -0xc40(%rbp),%rsi
lea    0xcc4(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%edi
lea    -0xc44(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
mov    $0x0,%al
call   1040 <recv@plt>
cmp    $0x0,%eax
jg     13c2 <main+0x1a2>
mov    0x2c10(%rip),%rax
mov    (%rax),%edi
lea    0xc70(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0xffffffff,%edi
call   1130 <exit@plt>
lea    -0x820(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
mov    -0x10(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    -0xc44(%rbp),%edx
xor    %ecx,%ecx
mov    $0x0,%al
call   1040 <recv@plt>
cmp    $0x0,%eax
jg     1418 <main+0x1f8>
mov    0x2bba(%rip),%rax
mov    (%rax),%edi
lea    0xc1a(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0xffffffff,%edi
call   1130 <exit@plt>
movslq -0xc44(%rbp),%rax
lea    -0x820(%rbp),%rdi
add    %rax,%rdi
lea    0xc3b(%rip),%rsi
call   1120 <strcat@plt>
lea    -0x820(%rbp),%rsi
lea    0xbf4(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x820(%rbp),%rdi
mov    0x2ba0(%rip),%rax
mov    (%rax),%esi
mov    0x2b8f(%rip),%rax
or     (%rax),%esi
mov    0x2b6e(%rip),%rax
or     (%rax),%esi
mov    $0x1bc,%edx
call   10e0 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1499 <main+0x279>
lea    0xbb8(%rip),%rdi
call   10f0 <perror@plt>
mov    $0xffffffff,%edi
call   1130 <exit@plt>
movl   $0x0,-0xc48(%rbp)
movl   $0x0,-0xc4c(%rbp)
mov    -0x10(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
mov    $0x0,%al
call   1040 <recv@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <write@plt>
mov    -0x14(%rbp),%eax
add    -0xc4c(%rbp),%eax
mov    %eax,-0xc4c(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
mov    -0x14(%rbp),%eax
mov    0x2aa2(%rip),%rcx
cmp    (%rcx),%eax
jne    1513 <main+0x2f3>
jmp    14ad <main+0x28d>
cmpl   $0x0,-0x14(%rbp)
jg     1522 <main+0x302>
jmp    1527 <main+0x307>
jmp    14ad <main+0x28d>
mov    0x2a8a(%rip),%rax
mov    (%rax),%edi
mov    -0xc4c(%rbp),%edx
lea    0xb0d(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
lea    0xb0f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8(%rbp),%edi
call   1090 <close@plt>
mov    -0x10(%rbp),%edi
call   1090 <close@plt>
mov    -0xc(%rbp),%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0xc50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x838,%rsp
mov    0x2d98(%rip),%r12
mov    (%r12),%eax
mov    %eax,0x18(%rsp)
mov    $0x2766,%edi
call   1070 <htons@plt>
mov    %eax,0x14(%rsp)
mov    (%r12),%edi
lea    0xda7(%rip),%rsi
lea    0x10(%rsp),%rdx
call   10c0 <inet_pton@plt>
mov    (%r12),%edi
mov    0x2d52(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
test   %eax,%eax
js     14ab <main+0x28b>
mov    %eax,%r14d
lea    0x10(%rsp),%rsi
mov    %eax,%edi
mov    $0xc,%edx
call   10e0 <bind@plt>
test   %eax,%eax
js     14b4 <main+0x294>
mov    %r14d,%edi
mov    $0xa,%esi
call   10d0 <listen@plt>
movl   $0xc,0xc(%rsp)
lea    0x20(%rsp),%r15
lea    0xc(%rsp),%rbx
mov    0x2ce7(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1110 <accept@plt>
test   %eax,%eax
js     1474 <main+0x254>
mov    %eax,%ebp
cmp    0x0(%r13),%eax
je     12d0 <main+0xb0>
mov    (%r12),%edi
lea    0x20(%rsp),%rsi
lea    0x430(%rsp),%rbx
mov    %rbx,%rdx
mov    $0x400,%ecx
call   1030 <inet_ntop@plt>
lea    0xd24(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0x8(%rsp),%rsi
mov    $0x4,%edx
mov    %ebp,%edi
xor    %ecx,%ecx
xor    %eax,%eax
call   1040 <recv@plt>
test   %eax,%eax
jle    148a <main+0x26a>
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1090 <memset@plt>
mov    0x8(%rsp),%edx
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
xor    %eax,%eax
call   1040 <recv@plt>
test   %eax,%eax
jle    148a <main+0x26a>
movslq 0x8(%rsp),%rax
lea    (%rsp,%rax,1),%rdi
add    $0x30,%rdi
lea    0xce8(%rip),%rsi
call   1120 <strcat@plt>
lea    0xca9(%rip),%rdi
lea    0x30(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x2c5a(%rip),%rax
mov    0x2c4b(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2c28(%rip),%rax
or     (%rax),%esi
mov    %rbx,%rdi
mov    $0x1bc,%edx
call   10f0 <open@plt>
test   %eax,%eax
js     14bd <main+0x29d>
mov    %eax,%r15d
lea    0x430(%rsp),%r12
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1040 <recv@plt>
mov    %eax,%ebx
mov    %r15d,%edi
mov    %r12,%rsi
mov    %eax,%edx
call   1060 <write@plt>
add    %ebx,%r13d
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1090 <memset@plt>
test   %ebx,%ebx
jg     13e0 <main+0x1c0>
mov    0x2b89(%rip),%rax
cmp    (%rax),%ebx
je     13e0 <main+0x1c0>
mov    0x2b8e(%rip),%rax
mov    (%rax),%edi
lea    0xc11(%rip),%rsi
mov    %r13d,%edx
xor    %eax,%eax
call   10b0 <fprintf@plt>
lea    0xc10(%rip),%rdi
call   1050 <puts@plt>
mov    %r15d,%edi
call   10a0 <close@plt>
mov    %ebp,%edi
call   10a0 <close@plt>
mov    %r14d,%edi
call   10a0 <close@plt>
xor    %eax,%eax
add    $0x838,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb99(%rip),%rdi
call   1100 <perror@plt>
mov    $0xffffffff,%edi
call   1130 <exit@plt>
mov    0x2b27(%rip),%rax
mov    (%rax),%edi
lea    0xb81(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0xffffffff,%edi
call   1130 <exit@plt>
lea    0xb56(%rip),%rdi
jmp    147b <main+0x25b>
lea    0xb54(%rip),%rdi
jmp    147b <main+0x25b>
lea    0xb78(%rip),%rdi
jmp    147b <main+0x25b>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
@AF_INET = global i32 0
@.str = [6 x i8] c"10086\00"
@.str.1 = [8 x i8] c"0.0.0.0\00"
@SOCK_STREAM = global i32 0
@.str.2 = [7 x i8] c"socket\00"
@.str.3 = [5 x i8] c"bind\00"
@.str.4 = [7 x i8] c"accept\00"
@EAGAIN = global i32 0
@.str.5 = [5 x i8] c"%s\0D\0A\00"
@stdout = global i32 0
@.str.6 = [22 x i8] c"get filename failed\0D\0A\00"
@.str.7 = [2 x i8] zeroinitializer
@.str.8 = [11 x i8] c"file: %s\0D\0A\00"
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_RDWR = global i32 0
@.str.9 = [8 x i8] c"open():\00"
@.str.10 = [16 x i8] c"file size: %d\0D\0A\00"
@.str.11 = [17 x i8] c"\0D\0ARECEIVE OK\0D\0A\0D\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca [1024 x i8]
%9 = alloca %struct.sockaddr_in
%10 = alloca %struct.sockaddr_in
%11 = alloca [1024 x i8]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %1
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %15, i32* %16
%17 = call i32 @atoi(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @htons(i32 %17)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
store i32 %18, i32* %19
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%22 = call i32 @inet_pton(i32 %20, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32* %21)
%23 = load i32, i32* @AF_INET
%24 = load i32, i32* @SOCK_STREAM
%25 = call i32 @socket(i32 %23, i32 %24, i32 0)
store i32 %25, i32* %3
%26 = load i32, i32* %3
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %0
%29 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @exit(i32 -1)
unreachable
31: ; preds = %0
%32 = load i32, i32* %3
%33 = bitcast %struct.sockaddr_in* %9 to i8*
%34 = call i32 @bind(i32 %32, i8* %33, i32 12)
store i32 %34, i32* %5
%35 = load i32, i32* %5
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %31
%38 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%39 = call i32 @exit(i32 -1)
unreachable
40: ; preds = %31
%41 = load i32, i32* %3
%42 = call i32 @listen(i32 %41, i32 10)
store i32 12, i32* %6
br label %43
43: ; preds = %40, %56
%44 = load i32, i32* %3
%45 = bitcast %struct.sockaddr_in* %10 to i8*
%46 = call i32 @accept(i32 %44, i8* %45, i32* %6)
store i32 %46, i32* %4
%47 = load i32, i32* %4
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %43
%50 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%51 = call i32 @exit(i32 -1)
unreachable
52: ; preds = %43
%53 = load i32, i32* %4
%54 = load i32, i32* @EAGAIN
%55 = icmp eq i32 %53, %54
br i1 %55, label %56, label %57
56: ; preds = %52
br label %43
57: ; preds = %52
%58 = load i32, i32* @AF_INET
%59 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%60 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%61 = call i32 @inet_ntop(i32 %58, i32* %59, i8* %60, i32 1024)
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %62)
br label %64
64: ; preds = %57
%65 = load i32, i32* %4
%66 = call i32 (i32, ...) @recv(i32 %65, i32* %12, i64 4, i32 0)
%67 = icmp sle i32 %66, 0
br i1 %67, label %68, label %72
68: ; preds = %64
%69 = load i32, i32* @stdout
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
%71 = call i32 @exit(i32 -1)
unreachable
72: ; preds = %64
%73 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%74 = call i32 @memset(i8* %73, i8 signext 0, i32 1024)
%75 = load i32, i32* %4
%76 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%77 = load i32, i32* %12
%78 = call i32 (i32, ...) @recv(i32 %75, i8* %76, i32 %77, i32 0)
%79 = icmp sle i32 %78, 0
br i1 %79, label %80, label %84
80: ; preds = %72
%81 = load i32, i32* @stdout
%82 = call i32 (i32, i8*, ...) @fprintf(i32 %81, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
%83 = call i32 @exit(i32 -1)
unreachable
84: ; preds = %72
%85 = load i32, i32* %12
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 %86
%88 = call i32 @strcat(i8* %87, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%89 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i8* %89)
%91 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%92 = load i32, i32* @O_CREAT
%93 = load i32, i32* @O_TRUNC
%94 = or i32 %92, %93
%95 = load i32, i32* @O_RDWR
%96 = or i32 %94, %95
%97 = call i32 @open(i8* %91, i32 %96, i32 444)
store i32 %97, i32* %2
%98 = load i32, i32* %2
%99 = icmp slt i32 %98, 0
br i1 %99, label %100, label %103
100: ; preds = %84
%101 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0))
%102 = call i32 @exit(i32 -1)
unreachable
103: ; preds = %84
store i32 0, i32* %13
store i32 0, i32* %14
br label %104
104: ; preds = %103, %120, %125
%105 = load i32, i32* %4
%106 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%107 = call i32 (i32, ...) @recv(i32 %105, i8* %106, i32 1024, i32 0)
store i32 %107, i32* %5
%108 = load i32, i32* %2
%109 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%110 = load i32, i32* %5
%111 = call i32 @write(i32 %108, i8* %109, i32 %110)
%112 = load i32, i32* %5
%113 = load i32, i32* %14
%114 = add nsw i32 %113, %112
store i32 %114, i32* %14
%115 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%116 = call i32 @memset(i8* %115, i8 signext 0, i32 1024)
%117 = load i32, i32* %5
%118 = load i32, i32* @EAGAIN
%119 = icmp eq i32 %117, %118
br i1 %119, label %120, label %121
120: ; preds = %104
br label %104
121: ; preds = %104
%122 = load i32, i32* %5
%123 = icmp sle i32 %122, 0
br i1 %123, label %124, label %125
124: ; preds = %121
br label %126
125: ; preds = %121
br label %104
126: ; preds = %124
%127 = load i32, i32* @stdout
%128 = load i32, i32* %14
%129 = call i32 (i32, i8*, ...) @fprintf(i32 %127, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0), i32 %128)
%130 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0))
%131 = load i32, i32* %2
%132 = call i32 @close(i32 %131)
%133 = load i32, i32* %4
%134 = call i32 @close(i32 %133)
%135 = load i32, i32* %3
%136 = call i32 @close(i32 %135)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
@AF_INET = global i32 0
@.str.1 = [8 x i8] c"0.0.0.0\00"
@SOCK_STREAM = global i32 0
@.str.2 = [7 x i8] c"socket\00"
@.str.3 = [5 x i8] c"bind\00"
@.str.4 = [7 x i8] c"accept\00"
@EAGAIN = global i32 0
@.str.5 = [5 x i8] c"%s\0D\0A\00"
@stdout = global i32 0
@.str.6 = [22 x i8] c"get filename failed\0D\0A\00"
@.str.7 = [2 x i8] zeroinitializer
@.str.8 = [11 x i8] c"file: %s\0D\0A\00"
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_RDWR = global i32 0
@.str.9 = [8 x i8] c"open():\00"
@.str.10 = [16 x i8] c"file size: %d\0D\0A\00"
@str = [16 x i8] c"\0D\0ARECEIVE OK\0D\0A\0D\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca [1024 x i8]
%7 = alloca i32
%8 = bitcast i32* %1 to i8*
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%11 = bitcast %struct.sockaddr_in* %4 to i8*
%12 = bitcast %struct.sockaddr_in* %5 to i8*
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %13, i32* %14
%15 = tail call i32 @htons(i32 10086)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %15, i32* %16
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%19 = call i32 @inet_pton(i32 %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32* %18)
%20 = load i32, i32* @AF_INET
%21 = load i32, i32* @SOCK_STREAM
%22 = call i32 @socket(i32 %20, i32 %21, i32 0)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %0
%25 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @exit(i32 -1)
unreachable
27: ; preds = %0
%28 = call i32 @bind(i32 %22, i8* %11, i32 12)
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%32 = call i32 @exit(i32 -1)
unreachable
33: ; preds = %27
%34 = call i32 @listen(i32 %22, i32 10)
store i32 12, i32* %1
br label %35
35: ; preds = %41, %33
%36 = call i32 @accept(i32 %22, i8* %12, i32* %1)
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%40 = call i32 @exit(i32 -1)
unreachable
41: ; preds = %35
%42 = load i32, i32* @EAGAIN
%43 = icmp eq i32 %36, %42
br i1 %43, label %35, label %44
44: ; preds = %41
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%46 = load i32, i32* @AF_INET
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
%48 = call i32 @inet_ntop(i32 %46, i32* %47, i8* %45, i32 1024)
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %45)
%50 = bitcast i32* %7 to i8*
%51 = call i32 (i32, ...) @recv(i32 %36, i32* %7, i64 4, i32 0)
%52 = icmp slt i32 %51, 1
br i1 %52, label %53, label %57
53: ; preds = %44
%54 = load i32, i32* @stdout
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
%56 = call i32 @exit(i32 -1)
unreachable
57: ; preds = %44
%58 = call i32 @memset(i8* %10, i8 signext 0, i32 1024)
%59 = load i32, i32* %7
%60 = call i32 (i32, ...) @recv(i32 %36, i8* %10, i32 %59, i32 0)
%61 = icmp slt i32 %60, 1
br i1 %61, label %62, label %66
62: ; preds = %57
%63 = load i32, i32* @stdout
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
%65 = call i32 @exit(i32 -1)
unreachable
66: ; preds = %57
%67 = load i32, i32* %7
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %68
%70 = call i32 @strcat(i8* %69, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%71 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i8* %10)
%72 = load i32, i32* @O_CREAT
%73 = load i32, i32* @O_TRUNC
%74 = or i32 %73, %72
%75 = load i32, i32* @O_RDWR
%76 = or i32 %74, %75
%77 = call i32 @open(i8* %10, i32 %76, i32 444)
%78 = icmp slt i32 %77, 0
br i1 %78, label %79, label %82
79: ; preds = %66
%80 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0))
%81 = call i32 @exit(i32 -1)
unreachable
82: ; preds = %66, %82
%83 = phi i32 [ %86, %82 ], [ 0, %66 ]
%84 = call i32 (i32, ...) @recv(i32 %36, i8* %9, i32 1024, i32 0)
%85 = call i32 @write(i32 %77, i8* %9, i32 %84)
%86 = add nsw i32 %84, %83
%87 = call i32 @memset(i8* %9, i8 signext 0, i32 1024)
%88 = load i32, i32* @EAGAIN
%89 = icmp ne i32 %84, %88
%90 = icmp slt i32 %84, 1
%91 = and i1 %90, %89
br i1 %91, label %92, label %82
92: ; preds = %82
%93 = load i32, i32* @stdout
%94 = call i32 (i32, i8*, ...) @fprintf(i32 %93, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0), i32 %86)
%95 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%96 = call i32 @close(i32 %77)
%97 = call i32 @close(i32 %36)
%98 = call i32 @close(i32 %22)
ret i32 0
}