#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*/ INADDR_ANY;
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);
char *inet_ntoa(TYPE_1__);
scalar_t__ listen(int, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int Count, char *Strings[]) {
  int sockfd;
  struct sockaddr_in self;
  char buffer[1024];
  int clientfd;
  struct sockaddr_in client_addr;
  int addrlen = sizeof(client_addr);
  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(60002);
  self.sin_addr.s_addr = INADDR_ANY;
  if (bind(sockfd, (struct sockaddr *)&self, sizeof(self)) != 0) {
    perror("socket--bind");
    exit(errno);
  }
  if (listen(sockfd, 20) != 0) {
    perror("socket--listen");
    exit(errno);
  }
  printf("Waiting on client connection...\n");
  while (1) {
    clientfd = accept(sockfd, (struct sockaddr *)&client_addr, &addrlen);
    printf("%s:%d connected\n", inet_ntoa(client_addr.sin_addr),
           ntohs(client_addr.sin_port));
    break;
  }
  while (1) {
    send(clientfd, buffer, recv(clientfd, buffer, 1024, 0), 0);
  }
  close(clientfd);
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xc,-0x434(%rbp)
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
mov    0x2dcd(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1232 <main+0x62>
lea    0xde1(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   10c0 <bzero@plt>
mov    0x2da1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0xea62,%edi
call   1050 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    0x2d80(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <bind@plt>
cmp    $0x0,%rax
je     129a <main+0xca>
lea    0xd80(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x14,%esi
call   1080 <listen@plt>
cmp    $0x0,%rax
je     12cb <main+0xfb>
lea    0xd5c(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2d04(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
lea    0xd51(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x430(%rbp),%rsi
lea    -0x434(%rbp),%rdx
call   10d0 <accept@plt>
mov    %eax,-0x424(%rbp)
mov    -0x42c(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,-0x440(%rbp)
mov    -0x430(%rbp),%edi
call   1090 <ntohs@plt>
mov    -0x440(%rbp),%rsi
mov    %eax,%edx
lea    0xd22(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    132e <main+0x15e>
mov    -0x424(%rbp),%eax
mov    %eax,-0x44c(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x448(%rbp)
mov    -0x424(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    -0x44c(%rbp),%edi
mov    -0x448(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
jmp    132e <main+0x15e>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x430,%rsp
movl   $0xc,0xc(%rsp)
mov    0x2ded(%rip),%r15
mov    (%r15),%edi
mov    0x2dcb(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
test   %eax,%eax
js     12f1 <main+0x111>
mov    %eax,%ebx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    (%r15),%eax
mov    %eax,0x18(%rsp)
mov    $0xea62,%edi
call   1060 <htons@plt>
mov    %eax,0x10(%rsp)
mov    0x2d9a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   10b0 <bind@plt>
test   %rax,%rax
jne    12fa <main+0x11a>
mov    %ebx,%edi
mov    $0x14,%esi
call   1090 <listen@plt>
test   %rax,%rax
jne    1303 <main+0x123>
lea    0xdb4(%rip),%rdi
call   1040 <puts@plt>
lea    0x20(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   10e0 <accept@plt>
mov    %eax,%ebx
mov    0x24(%rsp),%edi
call   1050 <inet_ntoa@plt>
mov    %rax,%r14
mov    0x20(%rsp),%edi
call   10a0 <ntohs@plt>
lea    0xd6f(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <printf@plt>
lea    0x30(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
jmp    12d0 <main+0xf0>
lea    0xd08(%rip),%rdi
jmp    130a <main+0x12a>
lea    0xd06(%rip),%rdi
jmp    130a <main+0x12a>
lea    0xd0a(%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
@INADDR_ANY = global i32 0
@.str.1 = [13 x i8] c"socket--bind\00"
@.str.2 = [15 x i8] c"socket--listen\00"
@.str.3 = [33 x i8] c"Waiting on client connection...\0A\00"
@.str.4 = [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 [1024 x i8]
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 12, 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* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @errno
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
%21 = call i32 @bzero(%struct.sockaddr_in* %7, i32 12)
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %22, i32* %23
%24 = call i32 @htons(i32 60002)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %24, i32* %25
%26 = load i32, i32* @INADDR_ANY
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%28 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %27, i32 0, i32 0
store i32 %26, i32* %28
%29 = load i32, i32* %6
%30 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%31 = call i64 @bind(i32 %29, %struct.sockaddr* %30, i32 12)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %20
%34 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%35 = load i32, i32* @errno
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %20
%38 = load i32, i32* %6
%39 = call i64 @listen(i32 %38, i32 20)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %37
%42 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%43 = load i32, i32* @errno
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %37
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
br label %47
47: ; preds = %45
%48 = load i32, i32* %6
%49 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%50 = call i32 @accept(i32 %48, %struct.sockaddr* %49, i32* %11)
store i32 %50, i32* %9
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%52 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %51, i32 0, i32 0
%53 = load i32, i32* %52
%54 = call i8* @inet_ntoa(i32 %53)
%55 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%56 = load i32, i32* %55
%57 = call i32 @ntohs(i32 %56)
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %54, i32 %57)
br label %59
59: ; preds = %47
br label %60
60: ; preds = %59, %60
%61 = load i32, i32* %9
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%63 = load i32, i32* %9
%64 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%65 = call i32 @recv(i32 %63, i8* %64, i32 1024, i32 0)
%66 = call i32 @send(i32 %61, i8* %62, i32 %65, i32 0)
br label %60
}

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