#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*/ self;
typedef int /*<<< orphan*/ client_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
char *inet_ntoa(TYPE_1__);
scalar_t__ listen(int, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int Count, char *Strings[]) {
  int sockfd;
  struct sockaddr_in self;
  char buffer[16384];
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    perror("Socket");
    exit(errno);
  }
  bzero(&self, sizeof(self));
  self.sin_family = AF_INET;
  self.sin_port = htons(8000);
  self.sin_addr.s_addr = inet_addr("10.0.0.2");
  if (bind(sockfd, (struct sockaddr *)&self, sizeof(self)) != 0) {
    perror("socket--bind");
    exit(errno);
  }
  if (listen(sockfd, 4096) != 0) {
    perror("socket--listen");
    exit(errno);
  }
  while (1) {
    int clientfd;
    int bytes_recvd = 0;
    struct sockaddr_in client_addr;
    int addrlen = sizeof(client_addr);
    printf("wait accept\n");
    clientfd = accept(sockfd, (struct sockaddr *)&client_addr, &addrlen);
    printf("%s:%d connected\n", inet_ntoa(client_addr.sin_addr),
           ntohs(client_addr.sin_port));
    while (recv(clientfd, buffer, 16384, 0) > 1) {
    }
  }
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4050,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
mov    0x2ddf(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1228 <main+0x58>
lea    0xdeb(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   10c0 <bzero@plt>
mov    0x2dab(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x1f40,%edi
call   1050 <htons@plt>
mov    %eax,-0x20(%rbp)
lea    0xdb1(%rip),%rdi
call   1070 <inet_addr@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <bind@plt>
cmp    $0x0,%rax
je     1293 <main+0xc3>
lea    0xd90(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2d44(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x1000,%esi
call   1080 <listen@plt>
cmp    $0x0,%rax
je     12c4 <main+0xf4>
lea    0xd6c(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2d13(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
jmp    12c9 <main+0xf9>
movl   $0x0,-0x4028(%rbp)
movl   $0xc,-0x403c(%rbp)
lea    0xd48(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x4038(%rbp),%rsi
lea    -0x403c(%rbp),%rdx
call   10d0 <accept@plt>
mov    %eax,-0x4024(%rbp)
mov    -0x4034(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,-0x4048(%rbp)
mov    -0x4038(%rbp),%edi
call   1090 <ntohs@plt>
mov    -0x4048(%rbp),%rsi
mov    %eax,%edx
lea    0xd05(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x4024(%rbp),%edi
lea    -0x4020(%rbp),%rsi
mov    $0x4000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0x1,%eax
jle    1362 <main+0x192>
jmp    133b <main+0x16b>
jmp    12c9 <main+0xf9>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4038,%rsp
mov    0x2df0(%rip),%r14
mov    (%r14),%edi
mov    0x2dd6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
test   %eax,%eax
js     12f9 <main+0x119>
mov    %eax,%ebx
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    (%r14),%eax
mov    %eax,0x18(%rsp)
mov    $0x1f40,%edi
call   1060 <htons@plt>
mov    %eax,0x10(%rsp)
lea    0xdc4(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,0x14(%rsp)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   10b0 <bind@plt>
test   %rax,%rax
jne    1302 <main+0x122>
mov    %ebx,%edi
mov    $0x1000,%esi
call   1090 <listen@plt>
test   %rax,%rax
jne    130b <main+0x12b>
lea    0xc(%rsp),%r12
lea    0xda7(%rip),%r13
lea    0x30(%rsp),%rbp
nopw   0x0(%rax,%rax,1)
movl   $0xc,0xc(%rsp)
lea    0xd9e(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
lea    0x20(%rsp),%rsi
mov    %r12,%rdx
call   10e0 <accept@plt>
mov    %eax,%r14d
mov    0x24(%rsp),%edi
call   1050 <inet_ntoa@plt>
mov    %rax,%r15
mov    0x20(%rsp),%edi
call   10a0 <ntohs@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <printf@plt>
nopw   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x4000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0x1,%eax
jg     12e0 <main+0x100>
jmp    1290 <main+0xb0>
lea    0xd00(%rip),%rdi
jmp    1312 <main+0x132>
lea    0xd07(%rip),%rdi
jmp    1312 <main+0x132>
lea    0xd0b(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2cb2(%rip),%rax
mov    (%rax),%edi
call   10f0 <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"
@errno = global i32 0
@.str.1 = [9 x i8] c"10.0.0.2\00"
@.str.2 = [13 x i8] c"socket--bind\00"
@.str.3 = [15 x i8] c"socket--listen\00"
@.str.4 = [13 x i8] c"wait accept\0A\00"
@.str.5 = [17 x i8] c"%s:%d connected\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca [16384 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.sockaddr_in
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_STREAM
%15 = call i32 @socket(i32 %13, i32 %14, i32 0)
store i32 %15, i32* %6
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @errno
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = call i32 @bzero(%struct.sockaddr_in* %7, i32 12)
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %23, i32* %24
%25 = call i32 @htons(i32 8000)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %25, i32* %26
%27 = call i32 @inet_addr(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%29 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %28, i32 0, i32 0
store i32 %27, i32* %29
%30 = load i32, i32* %6
%31 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%32 = call i64 @bind(i32 %30, %struct.sockaddr* %31, i32 12)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %21
%35 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%36 = load i32, i32* @errno
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %21
%39 = load i32, i32* %6
%40 = call i64 @listen(i32 %39, i32 4096)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %38
%43 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%44 = load i32, i32* @errno
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %38
br label %47
47: ; preds = %46, %66
store i32 0, i32* %10
store i32 12, i32* %12
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%49 = load i32, i32* %6
%50 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%51 = call i32 @accept(i32 %49, %struct.sockaddr* %50, i32* %12)
store i32 %51, i32* %9
%52 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
%53 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %52, i32 0, i32 0
%54 = load i32, i32* %53
%55 = call i8* @inet_ntoa(i32 %54)
%56 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
%57 = load i32, i32* %56
%58 = call i32 @ntohs(i32 %57)
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %55, i32 %58)
br label %60
60: ; preds = %65, %47
%61 = load i32, i32* %9
%62 = getelementptr inbounds [16384 x i8], [16384 x i8]* %8, i64 0, i64 0
%63 = call i32 @recv(i32 %61, i8* %62, i32 16384, i32 0)
%64 = icmp sgt i32 %63, 1
br i1 %64, label %65, label %66
65: ; preds = %60
br label %60
66: ; preds = %60
br label %47
}

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"
@errno = global i32 0
@.str.1 = [9 x i8] c"10.0.0.2\00"
@.str.2 = [13 x i8] c"socket--bind\00"
@.str.3 = [15 x i8] c"socket--listen\00"
@.str.5 = [17 x i8] c"%s:%d connected\0A\00"
@str = [12 x i8] c"wait accept\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [16384 x i8]
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = getelementptr inbounds [16384 x i8], [16384 x i8]* %4, i64 0, i64 0
%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 slt i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @errno
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = call i32 @bzero(%struct.sockaddr_in* %3, 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 = tail call i32 @htons(i32 8000)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %21, i32* %22
%23 = tail call i32 @inet_addr(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %23, i32* %24
%25 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%26 = call i64 @bind(i32 %11, %struct.sockaddr* %25, i32 12)
%27 = icmp eq i64 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %17
%29 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%30 = load i32, i32* @errno
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %17
%33 = call i64 @listen(i32 %11, i32 4096)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %32
%36 = bitcast %struct.sockaddr_in* %5 to i8*
%37 = bitcast i32* %6 to i8*
%38 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1, i32 0
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
br label %45
41: ; preds = %32
%42 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%43 = load i32, i32* @errno
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %35, %56
store i32 12, i32* %6
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%47 = call i32 @accept(i32 %11, %struct.sockaddr* %38, i32* %6)
%48 = load i32, i32* %39
%49 = call i8* @inet_ntoa(i32 %48)
%50 = load i32, i32* %40
%51 = call i32 @ntohs(i32 %50)
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %49, i32 %51)
br label %53
53: ; preds = %53, %45
%54 = call i32 @recv(i32 %47, i8* %8, i32 16384, i32 0)
%55 = icmp sgt i32 %54, 1
br i1 %55, label %53, label %56
56: ; preds = %53
br label %45
}