#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*/ len;
typedef int /*<<< orphan*/ dr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ MSG_WAITALL;
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, int /*<<< orphan*/, int /*<<< orphan*/);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int listen(int, int);
int open(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int sfd;
  int cfd;
  int ffd;
  int r;
  int len;
  char buf[128];
  char filename[100];
  struct sockaddr_in dr;
  sfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sfd == -1) {
    printf("create socket error : %m\n");
    exit(-1);
  }
  printf("create socket success....\n");
  dr.sin_family = AF_INET;
  dr.sin_port = htons(8888);
  dr.sin_addr.s_addr = inet_addr("192.168.137.3");
  r = bind(sfd, (struct sockaddr *)&dr, sizeof(dr));
  if (r == -1) {
    printf("bind socket error : %m\n");
    exit(-1);
  }
  printf("bind socket success....\n");
  r = listen(sfd, 10);
  if (r == -1) {
    printf("listen socket error : %m\n");
    exit(-1);
  }
  printf("listen socket success....\n");
  cfd = accept(sfd, 0, 0);
  if (cfd == -1) {
    printf("receive connect error : %m\n");
    exit(-1);
  }
  printf("start receive file....\n");
  r = recv(cfd, &len, sizeof(len), MSG_WAITALL);
  if (r == -1) {
    printf("receive filename len error : %m\n");
    exit(-1);
  }
  r = recv(cfd, filename, len, MSG_WAITALL);
  if (r == -1) {
    printf("receive filename error : %m\n");
    exit(-1);
  }
  filename[len] = 0;
  printf("receive file : %s\n", filename);
  ffd = open(filename, O_RDWR | O_CREAT | 0666);
  if (ffd == -1) {
    printf("create file error : %m\n");
    exit(-1);
  }
  while (1) {
    r = recv(cfd, &len, sizeof(len), MSG_WAITALL);
    if (r == -1) {
      printf("receive file len error : %m\n");
      exit(-1);
    }
    if (len == 0) {
      break;
    }
    r = recv(cfd, buf, len, MSG_WAITALL);
    if (r == -1) {
      printf("receive file content error : %m\n");
      exit(-1);
    }
    write(ffd, buf, len);
  }
  close(ffd);
  close(cfd);
  close(sfd);
  printf("receive file complete!!!!!!!!!!!!!!!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1210 <main+0x50>
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2db3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x118(%rbp)
mov    $0x22b8,%edi
call   1050 <htons@plt>
mov    %eax,-0x11c(%rbp)
lea    0xdf1(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,-0x120(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <bind@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1288 <main+0xc8>
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%edi
mov    $0xa,%esi
call   1090 <listen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    12c8 <main+0x108>
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   10c0 <accept@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1307 <main+0x147>
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0xc(%rbp),%edi
mov    0x2c99(%rip),%rax
mov    (%rax),%ecx
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <recv@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1356 <main+0x196>
lea    0xd98(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    -0xc(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    0x2c4e(%rip),%rax
mov    (%rax),%ecx
mov    $0x0,%al
call   1030 <recv@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1398 <main+0x1d8>
lea    0xd77(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
movslq -0x18(%rbp),%rax
movb   $0x0,-0x110(%rbp,%rax,1)
lea    -0x110(%rbp),%rsi
lea    0xd69(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x110(%rbp),%rdi
mov    0x2c19(%rip),%rax
mov    (%rax),%esi
mov    0x2c28(%rip),%rax
or     (%rax),%esi
or     $0x1b6,%esi
call   10b0 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    1402 <main+0x242>
lea    0xd3d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
jmp    1407 <main+0x247>
mov    -0xc(%rbp),%edi
mov    0x2ba7(%rip),%rax
mov    (%rax),%ecx
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <recv@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1448 <main+0x288>
lea    0xd0f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
cmpl   $0x0,-0x18(%rbp)
jne    1457 <main+0x297>
jmp    14b0 <main+0x2f0>
mov    -0xc(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    0x2b4d(%rip),%rax
mov    (%rax),%ecx
mov    $0x0,%al
call   1030 <recv@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1499 <main+0x2d9>
lea    0xcdb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1040 <write@plt>
jmp    1407 <main+0x247>
mov    -0x10(%rbp),%edi
call   1070 <close@plt>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
lea    0xcb5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    0x2df0(%rip),%rbx
mov    (%rbx),%edi
mov    0x2dd7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
cmp    $0xffffffff,%eax
je     13fe <main+0x22e>
mov    %eax,%r14d
lea    0xf10(%rip),%rdi
call   1040 <puts@plt>
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    $0x22b8,%edi
call   1060 <htons@plt>
mov    %eax,0x14(%rsp)
lea    0xded(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %r14d,%edi
mov    $0xc,%edx
call   10b0 <bind@plt>
cmp    $0xffffffff,%eax
je     1407 <main+0x237>
lea    0xedf(%rip),%rdi
call   1040 <puts@plt>
mov    %r14d,%edi
mov    $0xa,%esi
call   10a0 <listen@plt>
cmp    $0xffffffff,%eax
je     1410 <main+0x240>
lea    0xed5(%rip),%rdi
call   1040 <puts@plt>
mov    %r14d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10d0 <accept@plt>
cmp    $0xffffffff,%eax
je     1419 <main+0x249>
mov    %eax,%ebp
lea    0xecc(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d0f(%rip),%r13
mov    0x0(%r13),%ecx
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
mov    %ebp,%edi
xor    %eax,%eax
call   1030 <recv@plt>
cmp    $0xffffffff,%eax
je     1422 <main+0x252>
mov    0xc(%rsp),%edx
mov    0x0(%r13),%ecx
lea    0x20(%rsp),%rsi
mov    %ebp,%edi
xor    %eax,%eax
call   1030 <recv@plt>
cmp    $0xffffffff,%eax
je     142b <main+0x25b>
movslq 0xc(%rsp),%rax
movb   $0x0,0x20(%rsp,%rax,1)
lea    0xdbb(%rip),%rdi
lea    0x20(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2cd1(%rip),%rax
mov    (%rax),%esi
mov    0x2ce0(%rip),%rax
or     (%rax),%esi
or     $0x1b6,%esi
mov    %rbx,%rdi
call   10c0 <open@plt>
cmp    $0xffffffff,%eax
je     1434 <main+0x264>
mov    %eax,%r15d
mov    0x0(%r13),%ecx
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
mov    %ebp,%edi
xor    %eax,%eax
call   1030 <recv@plt>
cmp    $0xffffffff,%eax
je     13a6 <main+0x1d6>
lea    0x90(%rsp),%rbx
lea    0xc(%rsp),%r12
nopl   (%rax)
mov    0xc(%rsp),%edx
test   %edx,%edx
je     13af <main+0x1df>
mov    0x0(%r13),%ecx
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <recv@plt>
cmp    $0xffffffff,%eax
je     13e6 <main+0x216>
mov    0xc(%rsp),%edx
mov    %r15d,%edi
mov    %rbx,%rsi
call   1050 <write@plt>
mov    0x0(%r13),%ecx
mov    $0x4,%edx
mov    %ebp,%edi
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <recv@plt>
cmp    $0xffffffff,%eax
jne    1360 <main+0x190>
lea    0xd32(%rip),%rdi
jmp    13ed <main+0x21d>
mov    %r15d,%edi
call   1080 <close@plt>
mov    %ebp,%edi
call   1080 <close@plt>
mov    %r14d,%edi
call   1080 <close@plt>
lea    0xdb3(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd0f(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
lea    0xbfb(%rip),%rdi
jmp    13ed <main+0x21d>
lea    0xc1a(%rip),%rdi
jmp    13ed <main+0x21d>
lea    0xc29(%rip),%rdi
jmp    13ed <main+0x21d>
lea    0xc3a(%rip),%rdi
jmp    13ed <main+0x21d>
lea    0xc4d(%rip),%rdi
jmp    13ed <main+0x21d>
lea    0xc65(%rip),%rdi
jmp    13ed <main+0x21d>
lea    0xc8c(%rip),%rdi
jmp    13ed <main+0x21d>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [26 x i8] c"create socket error : %m\0A\00"
@.str.1 = [27 x i8] c"create socket success....\0A\00"
@.str.2 = [14 x i8] c"192.168.137.3\00"
@.str.3 = [24 x i8] c"bind socket error : %m\0A\00"
@.str.4 = [25 x i8] c"bind socket success....\0A\00"
@.str.5 = [26 x i8] c"listen socket error : %m\0A\00"
@.str.6 = [27 x i8] c"listen socket success....\0A\00"
@.str.7 = [28 x i8] c"receive connect error : %m\0A\00"
@.str.8 = [24 x i8] c"start receive file....\0A\00"
@MSG_WAITALL = global i32 0
@.str.9 = [33 x i8] c"receive filename len error : %m\0A\00"
@.str.10 = [29 x i8] c"receive filename error : %m\0A\00"
@.str.11 = [19 x i8] c"receive file : %s\0A\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.12 = [24 x i8] c"create file error : %m\0A\00"
@.str.13 = [29 x i8] c"receive file len error : %m\0A\00"
@.str.14 = [33 x i8] c"receive file content error : %m\0A\00"
@.str.15 = [38 x i8] c"receive file complete!!!!!!!!!!!!!!!\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 [128 x i8]
%8 = alloca [100 x i8]
%9 = alloca %struct.sockaddr_in
store i32 0, i32* %1
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %2
%13 = load i32, i32* %2
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %20, i32* %21
%22 = call i32 @htons(i32 8888)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
store i32 %22, i32* %23
%24 = call i32 @inet_addr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%26 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %25, i32 0, i32 0
store i32 %24, i32* %26
%27 = load i32, i32* %2
%28 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%29 = call i32 @bind(i32 %27, %struct.sockaddr* %28, i32 12)
store i32 %29, i32* %5
%30 = load i32, i32* %5
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %35
32: ; preds = %18
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%34 = call i32 @exit(i32 -1)
unreachable
35: ; preds = %18
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%37 = load i32, i32* %2
%38 = call i32 @listen(i32 %37, i32 10)
store i32 %38, i32* %5
%39 = load i32, i32* %5
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %44
41: ; preds = %35
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
%43 = call i32 @exit(i32 -1)
unreachable
44: ; preds = %35
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
%46 = load i32, i32* %2
%47 = call i32 @accept(i32 %46, i32 0, i32 0)
store i32 %47, i32* %3
%48 = load i32, i32* %3
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %53
50: ; preds = %44
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
%52 = call i32 @exit(i32 -1)
unreachable
53: ; preds = %44
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0))
%55 = load i32, i32* %3
%56 = load i32, i32* @MSG_WAITALL
%57 = call i32 (i32, ...) @recv(i32 %55, i32* %6, i64 4, i32 %56)
store i32 %57, i32* %5
%58 = load i32, i32* %5
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %63
60: ; preds = %53
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.9, i64 0, i64 0))
%62 = call i32 @exit(i32 -1)
unreachable
63: ; preds = %53
%64 = load i32, i32* %3
%65 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%66 = load i32, i32* %6
%67 = load i32, i32* @MSG_WAITALL
%68 = call i32 (i32, ...) @recv(i32 %64, i8* %65, i32 %66, i32 %67)
store i32 %68, i32* %5
%69 = load i32, i32* %5
%70 = icmp eq i32 %69, -1
br i1 %70, label %71, label %74
71: ; preds = %63
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0))
%73 = call i32 @exit(i32 -1)
unreachable
74: ; preds = %63
%75 = load i32, i32* %6
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %76
store i8 0, i8* %77
%78 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0), i8* %78)
%80 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%81 = load i32, i32* @O_RDWR
%82 = load i32, i32* @O_CREAT
%83 = or i32 %81, %82
%84 = or i32 %83, 438
%85 = call i32 @open(i8* %80, i32 %84)
store i32 %85, i32* %4
%86 = load i32, i32* %4
%87 = icmp eq i32 %86, -1
br i1 %87, label %88, label %91
88: ; preds = %74
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.12, i64 0, i64 0))
%90 = call i32 @exit(i32 -1)
unreachable
91: ; preds = %74
br label %92
92: ; preds = %91, %116
%93 = load i32, i32* %3
%94 = load i32, i32* @MSG_WAITALL
%95 = call i32 (i32, ...) @recv(i32 %93, i32* %6, i64 4, i32 %94)
store i32 %95, i32* %5
%96 = load i32, i32* %5
%97 = icmp eq i32 %96, -1
br i1 %97, label %98, label %101
98: ; preds = %92
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.13, i64 0, i64 0))
%100 = call i32 @exit(i32 -1)
unreachable
101: ; preds = %92
%102 = load i32, i32* %6
%103 = icmp eq i32 %102, 0
br i1 %103, label %104, label %105
104: ; preds = %101
br label %121
105: ; preds = %101
%106 = load i32, i32* %3
%107 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%108 = load i32, i32* %6
%109 = load i32, i32* @MSG_WAITALL
%110 = call i32 (i32, ...) @recv(i32 %106, i8* %107, i32 %108, i32 %109)
store i32 %110, i32* %5
%111 = load i32, i32* %5
%112 = icmp eq i32 %111, -1
br i1 %112, label %113, label %116
113: ; preds = %105
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.14, i64 0, i64 0))
%115 = call i32 @exit(i32 -1)
unreachable
116: ; preds = %105
%117 = load i32, i32* %4
%118 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%119 = load i32, i32* %6
%120 = call i32 @write(i32 %117, i8* %118, i32 %119)
br label %92
121: ; preds = %104
%122 = load i32, i32* %4
%123 = call i32 @close(i32 %122)
%124 = load i32, i32* %3
%125 = call i32 @close(i32 %124)
%126 = load i32, i32* %2
%127 = call i32 @close(i32 %126)
%128 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.15, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [26 x i8] c"create socket error : %m\0A\00"
@.str.2 = [14 x i8] c"192.168.137.3\00"
@.str.3 = [24 x i8] c"bind socket error : %m\0A\00"
@.str.5 = [26 x i8] c"listen socket error : %m\0A\00"
@.str.7 = [28 x i8] c"receive connect error : %m\0A\00"
@MSG_WAITALL = global i32 0
@.str.9 = [33 x i8] c"receive filename len error : %m\0A\00"
@.str.10 = [29 x i8] c"receive filename error : %m\0A\00"
@.str.11 = [19 x i8] c"receive file : %s\0A\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.12 = [24 x i8] c"create file error : %m\0A\00"
@.str.13 = [29 x i8] c"receive file len error : %m\0A\00"
@.str.14 = [33 x i8] c"receive file content error : %m\0A\00"
@str = [26 x i8] c"create socket success....\00"
@str.16 = [24 x i8] c"bind socket success....\00"
@str.17 = [26 x i8] c"listen socket success....\00"
@str.18 = [23 x i8] c"start receive file....\00"
@str.19 = [37 x i8] c"receive file complete!!!!!!!!!!!!!!!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [128 x i8]
%3 = alloca [100 x i8]
%4 = alloca %struct.sockaddr_in
%5 = bitcast i32* %1 to i8*
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 -1)
unreachable
16: ; preds = %0
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %18, i32* %19
%20 = tail call i32 @htons(i32 8888)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %20, i32* %21
%22 = tail call i32 @inet_addr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
store i32 %22, i32* %23
%24 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%25 = call i32 @bind(i32 %11, %struct.sockaddr* %24, i32 12)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %30
27: ; preds = %16
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%29 = call i32 @exit(i32 -1)
unreachable
30: ; preds = %16
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.16, i64 0, i64 0))
%32 = call i32 @listen(i32 %11, i32 10)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
%36 = call i32 @exit(i32 -1)
unreachable
37: ; preds = %30
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.17, i64 0, i64 0))
%39 = call i32 @accept(i32 %11, i32 0, i32 0)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
%43 = call i32 @exit(i32 -1)
unreachable
44: ; preds = %37
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.18, i64 0, i64 0))
%46 = load i32, i32* @MSG_WAITALL
%47 = call i32 (i32, ...) @recv(i32 %39, i32* %1, i64 4, i32 %46)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %52
49: ; preds = %44
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.9, i64 0, i64 0))
%51 = call i32 @exit(i32 -1)
unreachable
52: ; preds = %44
%53 = load i32, i32* %1
%54 = load i32, i32* @MSG_WAITALL
%55 = call i32 (i32, ...) @recv(i32 %39, i8* %7, i32 %53, i32 %54)
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %60
57: ; preds = %52
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0))
%59 = call i32 @exit(i32 -1)
unreachable
60: ; preds = %52
%61 = load i32, i32* %1
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %62
store i8 0, i8* %63
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0), i8* %7)
%65 = load i32, i32* @O_RDWR
%66 = load i32, i32* @O_CREAT
%67 = or i32 %65, %66
%68 = or i32 %67, 438
%69 = call i32 @open(i8* %7, i32 %68)
%70 = icmp eq i32 %69, -1
br i1 %70, label %75, label %71
71: ; preds = %60
%72 = load i32, i32* @MSG_WAITALL
%73 = call i32 (i32, ...) @recv(i32 %39, i32* %1, i64 4, i32 %72)
%74 = icmp eq i32 %73, -1
br i1 %74, label %78, label %81
75: ; preds = %60
%76 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.12, i64 0, i64 0))
%77 = call i32 @exit(i32 -1)
unreachable
78: ; preds = %91, %71
%79 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.13, i64 0, i64 0))
%80 = call i32 @exit(i32 -1)
unreachable
81: ; preds = %71, %91
%82 = load i32, i32* %1
%83 = icmp eq i32 %82, 0
br i1 %83, label %97, label %84
84: ; preds = %81
%85 = load i32, i32* @MSG_WAITALL
%86 = call i32 (i32, ...) @recv(i32 %39, i8* %6, i32 %82, i32 %85)
%87 = icmp eq i32 %86, -1
br i1 %87, label %88, label %91
88: ; preds = %84
%89 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.14, i64 0, i64 0))
%90 = call i32 @exit(i32 -1)
unreachable
91: ; preds = %84
%92 = load i32, i32* %1
%93 = call i32 @write(i32 %69, i8* %6, i32 %92)
%94 = load i32, i32* @MSG_WAITALL
%95 = call i32 (i32, ...) @recv(i32 %39, i32* %1, i64 4, i32 %94)
%96 = icmp eq i32 %95, -1
br i1 %96, label %78, label %81
97: ; preds = %81
%98 = call i32 @close(i32 %69)
%99 = call i32 @close(i32 %39)
%100 = call i32 @close(i32 %11)
%101 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.19, i64 0, i64 0))
ret i32 0
}