#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 {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ sin;
typedef int /*<<< orphan*/ pin;
typedef int /*<<< orphan*/ dir;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
int listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
main() {
  char dir[8192];
  int sd, sd_current, cc, fromlen, tolen;
  int addrlen;
  struct sockaddr_in sin;
  struct sockaddr_in pin;
  int result;
  int enable_keep_alive = 1;
  if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    perror("socket");
    exit(1);
  }
  printf("sock sucess\n");
  memset(&sin, 0, sizeof(sin));
  sin.sin_family = AF_INET;
  sin.sin_addr.s_addr = INADDR_ANY;
  sin.sin_port = htons(9999);
  if (bind(sd, (struct sockaddr *)&sin, sizeof(sin)) == -1) {
    perror("bind");
    exit(1);
  }
  printf("bind sucess\n");
  if (listen(sd, 5) == -1) {
    perror("listen");
    exit(1);
  }
  printf("listen sucess\n");
  addrlen = sizeof(pin);
  if ((sd_current = accept(sd, (struct sockaddr *)&pin, &addrlen)) == -1) {
    perror("accept");
    exit(1);
  }
  printf("accept sucess\n");
  sleep(10000);
  if (recv(sd_current, dir, sizeof(dir), 0) == -1) {
    perror("recv");
    exit(1);
  }
  close(sd_current);
  close(sd);
  sleep(1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2040,%rsp
movl   $0x1,-0x2040(%rbp)
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
mov    0x2deb(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x2004(%rbp)
cmp    $0xffffffff,%eax
jne    1213 <main+0x53>
lea    0xdfc(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    0xded(%rip),%rdi
call   1050 <printf@plt>
lea    -0x2028(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2020(%rbp)
mov    0x2d98(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2024(%rbp)
mov    $0x270f,%edi
call   1040 <htons@plt>
mov    %eax,-0x2028(%rbp)
mov    -0x2004(%rbp),%edi
lea    -0x2028(%rbp),%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
cmp    $0xffffffff,%eax
jne    1296 <main+0xd6>
lea    0xd8d(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    0xd7c(%rip),%rdi
call   1050 <printf@plt>
mov    -0x2004(%rbp),%edi
mov    $0x5,%esi
call   1080 <listen@plt>
cmp    $0xffffffff,%eax
jne    12d1 <main+0x111>
lea    0xd64(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    0xd55(%rip),%rdi
call   1050 <printf@plt>
movl   $0xc,-0x2018(%rbp)
mov    -0x2004(%rbp),%edi
lea    -0x2038(%rbp),%rsi
lea    -0x2018(%rbp),%rdx
call   10b0 <accept@plt>
mov    %eax,-0x2008(%rbp)
cmp    $0xffffffff,%eax
jne    1325 <main+0x165>
lea    0xd26(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    0xd17(%rip),%rdi
call   1050 <printf@plt>
mov    $0x2710,%edi
call   10d0 <sleep@plt>
mov    -0x2008(%rbp),%edi
lea    -0x2000(%rbp),%rsi
mov    $0x2000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0xffffffff,%eax
jne    1373 <main+0x1b3>
lea    0xcee(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x2008(%rbp),%edi
call   1070 <close@plt>
mov    -0x2004(%rbp),%edi
call   1070 <close@plt>
mov    $0x1,%edi
call   10d0 <sleep@plt>
xor    %eax,%eax
add    $0x2040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x2030,%rsp
mov    0x2e16(%rip),%r14
mov    (%r14),%edi
mov    0x2df4(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
cmp    $0xffffffff,%eax
je     12eb <main+0x12b>
mov    %eax,%ebx
lea    0xe28(%rip),%rdi
call   1040 <puts@plt>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    (%r14),%eax
mov    %eax,0x18(%rsp)
mov    0x2dc2(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    $0x270f,%edi
call   1050 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
cmp    $0xffffffff,%eax
je     12f4 <main+0x134>
lea    0xdda(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
mov    $0x5,%esi
call   1080 <listen@plt>
cmp    $0xffffffff,%eax
je     12fd <main+0x13d>
lea    0xdc5(%rip),%rdi
call   1040 <puts@plt>
movl   $0xc,0xc(%rsp)
lea    0x20(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   10b0 <accept@plt>
cmp    $0xffffffff,%eax
je     1306 <main+0x146>
mov    %eax,%ebp
lea    0xda7(%rip),%rdi
call   1040 <puts@plt>
mov    $0x2710,%edi
call   10d0 <sleep@plt>
lea    0x30(%rsp),%rsi
mov    %ebp,%edi
mov    $0x2000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0xffffffff,%eax
je     130f <main+0x14f>
mov    %ebp,%edi
call   1070 <close@plt>
mov    %ebx,%edi
call   1070 <close@plt>
mov    $0x1,%edi
call   10d0 <sleep@plt>
xor    %eax,%eax
add    $0x2030,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd0e(%rip),%rdi
jmp    1316 <main+0x156>
lea    0xd0c(%rip),%rdi
jmp    1316 <main+0x156>
lea    0xd08(%rip),%rdi
jmp    1316 <main+0x156>
lea    0xd06(%rip),%rdi
jmp    1316 <main+0x156>
lea    0xd04(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [13 x i8] c"sock sucess\0A\00"
@INADDR_ANY = global i32 0
@.str.2 = [5 x i8] c"bind\00"
@.str.3 = [13 x i8] c"bind sucess\0A\00"
@.str.4 = [7 x i8] c"listen\00"
@.str.5 = [15 x i8] c"listen sucess\0A\00"
@.str.6 = [7 x i8] c"accept\00"
@.str.7 = [15 x i8] c"accept sucess\0A\00"
@.str.8 = [5 x i8] c"recv\00"
define i32 @main() {
%1 = alloca [8192 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
%9 = alloca %struct.sockaddr_in
%10 = alloca i32
%11 = alloca i32
store i32 1, i32* %11
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = call i32 @socket(i32 %12, i32 %13, i32 0)
store i32 %14, i32* %2
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %0
%17 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %0
%20 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @memset(%struct.sockaddr_in* %8, i32 0, i32 12)
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %22, i32* %23
%24 = load i32, i32* @INADDR_ANY
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%26 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %25, i32 0, i32 0
store i32 %24, i32* %26
%27 = call i32 @htons(i32 9999)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i32 %27, i32* %28
%29 = load i32, i32* %2
%30 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%31 = call i32 @bind(i32 %29, %struct.sockaddr* %30, i32 12)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %36
33: ; preds = %19
%34 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %19
%37 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%38 = load i32, i32* %2
%39 = call i32 @listen(i32 %38, i32 5)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %44
41: ; preds = %36
%42 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %36
%45 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
store i32 12, i32* %7
%46 = load i32, i32* %2
%47 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%48 = call i32 @accept(i32 %46, %struct.sockaddr* %47, i32* %7)
store i32 %48, i32* %3
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %53
50: ; preds = %44
%51 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %44
%54 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
%55 = call i32 @sleep(i32 10000)
%56 = load i32, i32* %3
%57 = getelementptr inbounds [8192 x i8], [8192 x i8]* %1, i64 0, i64 0
%58 = call i32 @recv(i32 %56, i8* %57, i32 8192, i32 0)
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %63
60: ; preds = %53
%61 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%62 = call i32 @exit(i32 1)
unreachable
63: ; preds = %53
%64 = load i32, i32* %3
%65 = call i32 @close(i32 %64)
%66 = load i32, i32* %2
%67 = call i32 @close(i32 %66)
%68 = call i32 @sleep(i32 1)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@INADDR_ANY = global i32 0
@.str.2 = [5 x i8] c"bind\00"
@.str.4 = [7 x i8] c"listen\00"
@.str.6 = [7 x i8] c"accept\00"
@.str.8 = [5 x i8] c"recv\00"
@str = [12 x i8] c"sock sucess\00"
@str.9 = [12 x i8] c"bind sucess\00"
@str.10 = [14 x i8] c"listen sucess\00"
@str.11 = [14 x i8] c"accept sucess\00"
define i32 @main() {
%1 = alloca [8192 x i8]
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = getelementptr inbounds [8192 x i8], [8192 x i8]* %1, i64 0, i64 0
%6 = bitcast i32* %2 to i8*
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%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 @perror(i8* getelementptr inbounds ([7 x i8], [7 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 ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%18 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %19, i32* %20
%21 = load i32, i32* @INADDR_ANY
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %21, i32* %22
%23 = call i32 @htons(i32 9999)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %23, i32* %24
%25 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%26 = call i32 @bind(i32 %11, %struct.sockaddr* %25, i32 12)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %31
28: ; preds = %16
%29 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %16
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.9, i64 0, i64 0))
%33 = call i32 @listen(i32 %11, i32 5)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %38
35: ; preds = %31
%36 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %31
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.10, i64 0, i64 0))
store i32 12, i32* %2
%40 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%41 = call i32 @accept(i32 %11, %struct.sockaddr* %40, i32* %2)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %46
43: ; preds = %38
%44 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %38
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.11, i64 0, i64 0))
%48 = call i32 @sleep(i32 10000)
%49 = call i32 @recv(i32 %41, i8* %5, i32 8192, i32 0)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %54
51: ; preds = %46
%52 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %46
%55 = call i32 @close(i32 %41)
%56 = call i32 @close(i32 %11)
%57 = call i32 @sleep(i32 1)
ret i32 0
}