#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*/ socklen_t;
typedef int /*<<< orphan*/ server;
typedef int /*<<< orphan*/ recv_nmr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(TYPE_1__);
scalar_t__ listen(int, int);
int ntohl(int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ recv(int, int *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int strlen(char const *);
int main() {
  int listen_sock, connect_sock;
  char *client_ip;
  char client_msg[1000];
  listen_sock = socket(AF_INET, SOCK_STREAM, 0);
  if (listen_sock == -1) {
    printf(
        "Server encountered an error when creating socket for communication\n");
    return 1;
  }
  struct sockaddr_in server, client;
  server.sin_family = AF_INET;
  server.sin_addr.s_addr = INADDR_ANY;
  server.sin_port = htons(2345);
  if (bind(listen_sock, (struct sockaddr *)&server, sizeof(server)) < 0) {
    printf("Server wasn't able to bind with socket\n");
    return 1;
  }
  printf("Server ready. Waiting for incoming connections.\n");
  if (listen(listen_sock, 5) != 0) {
    printf("Listen failed on server\n");
    return 1;
  }
  const char *message =
      "Look, just because I don't be givin' no man a foot massage don't make "
      "it right for Marsellus to throw Antwone into a glass motherfuckin' "
      "house, fuckin' up the way the nigger talks. Motherfucker do that shit "
      "to me, he better paralyze my ass, 'cause I'll kill the motherfucker, "
      "know what I'm sayin'?\n";
  printf("msg len: %d\n", strlen(message));
  int addr_len = sizeof(server);
  while (1) {
    if ((connect_sock = accept(listen_sock, (struct sockaddr *)&client,
                               (socklen_t *)&addr_len)) < 0) {
      printf("Accept connection has failed\n");
      return 1;
    }
    int recv_nmr = 0;
    if (recv(connect_sock, &recv_nmr, sizeof(recv_nmr), 0) < 0) {
      printf("Recieving of data has failed\n");
      return 1;
    }
    client_ip = inet_ntoa(client.sin_addr);
    printf("Connection accepted from ip address %s\n", client_ip);
    printf("%d\n", ntohl(recv_nmr));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
mov    0x2e0e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11f2 <main+0x52>
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    138c <main+0x1ec>
mov    0x2def(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x408(%rbp)
mov    0x2dd8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x410(%rbp)
mov    $0x929,%edi
call   1060 <htons@plt>
mov    %eax,-0x40c(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
cmp    $0x0,%rax
jge    1258 <main+0xb8>
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    138c <main+0x1ec>
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8(%rbp),%edi
mov    $0x5,%esi
call   1080 <listen@plt>
cmp    $0x0,%rax
je     1297 <main+0xf7>
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    138c <main+0x1ec>
lea    0xe18(%rip),%rax
mov    %rax,-0x428(%rbp)
mov    -0x428(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%esi
lea    0xf27(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xc,-0x42c(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rsi
lea    -0x42c(%rbp),%rdx
call   10a0 <accept@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    1307 <main+0x167>
lea    0xefa(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    138c <main+0x1ec>
movl   $0x0,-0x430(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0x0,%rax
jge    134b <main+0x1ab>
lea    0xed4(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    138c <main+0x1ec>
mov    -0x420(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x430(%rbp),%edi
call   10b0 <ntohl@plt>
mov    %eax,%esi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    12cb <main+0x12b>
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    0x2e23(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
cmp    $0xffffffff,%eax
je     1240 <main+0x90>
mov    %eax,%ebx
mov    0x0(%rbp),%eax
mov    %eax,0x10(%rsp)
mov    0x2df3(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    $0x929,%edi
call   1070 <htons@plt>
mov    %eax,0xc(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   10a0 <bind@plt>
test   %rax,%rax
js     124c <main+0x9c>
lea    0xf42(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
mov    $0x5,%esi
call   1090 <listen@plt>
test   %rax,%rax
je     1258 <main+0xa8>
lea    0xf8f(%rip),%rdi
jmp    1318 <main+0x168>
lea    0xfc2(%rip),%rdi
jmp    1318 <main+0x168>
lea    0xf8f(%rip),%rdi
jmp    1318 <main+0x168>
lea    0xda1(%rip),%rdi
call   1060 <strlen@plt>
lea    0xec0(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
movl   $0xc,0x4(%rsp)
lea    0x18(%rsp),%rsi
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
call   10b0 <accept@plt>
test   %eax,%eax
js     1308 <main+0x158>
mov    %rsp,%r14
lea    0xe99(%rip),%r15
lea    0xe8e(%rip),%r12
lea    0x18(%rsp),%r13
lea    0x4(%rsp),%rbp
movl   $0x0,(%rsp)
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
js     1311 <main+0x161>
mov    0x18(%rsp),%edi
call   1050 <inet_ntoa@plt>
mov    %r15,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    (%rsp),%edi
call   10c0 <ntohl@plt>
mov    %r12,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %ebx,%edi
mov    %r13,%rsi
mov    %rbp,%rdx
call   10b0 <accept@plt>
test   %eax,%eax
jns    12b0 <main+0x100>
lea    0xe9e(%rip),%rdi
jmp    1318 <main+0x168>
lea    0xe78(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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 = [68 x i8] c"Server encountered an error when creating socket for communication\0A\00"
@INADDR_ANY = global i32 0
@.str.1 = [40 x i8] c"Server wasn't able to bind with socket\0A\00"
@.str.2 = [49 x i8] c"Server ready. Waiting for incoming connections.\0A\00"
@.str.3 = [25 x i8] c"Listen failed on server\0A\00"
@.str.4 = [299 x i8] c"Look, just because I don't be givin' no man a foot massage don't make it right for Marsellus to throw Antwone into a glass motherfuckin' house, fuckin' up the way the nigger talks. Motherfucker do that shit to me, he better paralyze my ass, 'cause I'll kill the motherfucker, know what I'm sayin'?\0A\00"
@.str.5 = [13 x i8] c"msg len: %d\0A\00"
@.str.6 = [30 x i8] c"Accept connection has failed\0A\00"
@.str.7 = [30 x i8] c"Recieving of data has failed\0A\00"
@.str.8 = [40 x i8] c"Connection accepted from ip address %s\0A\00"
@.str.9 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [1000 x i8]
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.sockaddr_in
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %1
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %2
%14 = load i32, i32* %2
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %66
18: ; preds = %0
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %19, i32* %20
%21 = load i32, i32* @INADDR_ANY
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%23 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %22, i32 0, i32 0
store i32 %21, i32* %23
%24 = call i32 @htons(i32 2345)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %24, i32* %25
%26 = load i32, i32* %2
%27 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%28 = call i64 @bind(i32 %26, %struct.sockaddr* %27, i32 12)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %18
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %66
32: ; preds = %18
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
%34 = load i32, i32* %2
%35 = call i64 @listen(i32 %34, i32 5)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %32
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
br label %66
39: ; preds = %32
store i8* getelementptr inbounds ([299 x i8], [299 x i8]* @.str.4, i64 0, i64 0), i8** %8
%40 = load i8*, i8** %8
%41 = call i32 @strlen(i8* %40)
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %41)
store i32 12, i32* %9
br label %43
43: ; preds = %39, %56
%44 = load i32, i32* %2
%45 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%46 = call i32 @accept(i32 %44, %struct.sockaddr* %45, i32* %9)
store i32 %46, i32* %3
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %43
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %1
br label %66
50: ; preds = %43
store i32 0, i32* %10
%51 = load i32, i32* %3
%52 = call i64 @recv(i32 %51, i32* %10, i32 4, i32 0)
%53 = icmp slt i64 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %50
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %1
br label %66
56: ; preds = %50
%57 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%58 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %57, i32 0, i32 0
%59 = load i32, i32* %58
%60 = call i8* @inet_ntoa(i32 %59)
store i8* %60, i8** %4
%61 = load i8*, i8** %4
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.8, i64 0, i64 0), i8* %61)
%63 = load i32, i32* %10
%64 = call i32 @ntohl(i32 %63)
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %64)
br label %43
66: ; preds = %54, %48, %37, %30, %16
%67 = load i32, i32* %1
ret i32 %67
}

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
@INADDR_ANY = global i32 0
@.str.4 = [299 x i8] c"Look, just because I don't be givin' no man a foot massage don't make it right for Marsellus to throw Antwone into a glass motherfuckin' house, fuckin' up the way the nigger talks. Motherfucker do that shit to me, he better paralyze my ass, 'cause I'll kill the motherfucker, know what I'm sayin'?\0A\00"
@.str.5 = [13 x i8] c"msg len: %d\0A\00"
@.str.8 = [40 x i8] c"Connection accepted from ip address %s\0A\00"
@.str.9 = [4 x i8] c"%d\0A\00"
@str = [48 x i8] c"Server ready. Waiting for incoming connections.\00"
@str.10 = [29 x i8] c"Recieving of data has failed\00"
@str.11 = [29 x i8] c"Accept connection has failed\00"
@str.12 = [24 x i8] c"Listen failed on server\00"
@str.13 = [39 x i8] c"Server wasn't able to bind with socket\00"
@str.14 = [67 x i8] c"Server encountered an error when creating socket for communication\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = alloca i32
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @str.14, i64 0, i64 0))
br label %60
11: ; preds = %0
%12 = bitcast %struct.sockaddr_in* %1 to i8*
%13 = bitcast %struct.sockaddr_in* %2 to i8*
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %14, i32* %15
%16 = load i32, i32* @INADDR_ANY
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %16, i32* %17
%18 = tail call i32 @htons(i32 2345)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %18, i32* %19
%20 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%21 = call i64 @bind(i32 %7, %struct.sockaddr* %20, i32 12)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %11
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.13, i64 0, i64 0))
br label %59
25: ; preds = %11
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str, i64 0, i64 0))
%27 = call i64 @listen(i32 %7, i32 5)
%28 = icmp eq i64 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %25
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.12, i64 0, i64 0))
br label %59
31: ; preds = %25
%32 = call i32 @strlen(i8* getelementptr inbounds ([299 x i8], [299 x i8]* @.str.4, i64 0, i64 0))
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %32)
%34 = bitcast i32* %3 to i8*
store i32 12, i32* %3
%35 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%36 = call i32 @accept(i32 %7, %struct.sockaddr* %35, i32* %3)
%37 = icmp slt i32 %36, 0
br i1 %37, label %41, label %38
38: ; preds = %31
%39 = bitcast i32* %4 to i8*
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0, i32 0
br label %43
41: ; preds = %49, %31
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.11, i64 0, i64 0))
br label %58
43: ; preds = %38, %49
%44 = phi i32 [ %36, %38 ], [ %56, %49 ]
store i32 0, i32* %4
%45 = call i64 @recv(i32 %44, i32* %4, i32 4, i32 0)
%46 = icmp slt i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %43
%48 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.10, i64 0, i64 0))
br label %58
49: ; preds = %43
%50 = load i32, i32* %40
%51 = call i8* @inet_ntoa(i32 %50)
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.8, i64 0, i64 0), i8* %51)
%53 = load i32, i32* %4
%54 = call i32 @ntohl(i32 %53)
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %54)
%56 = call i32 @accept(i32 %7, %struct.sockaddr* %35, i32* %3)
%57 = icmp slt i32 %56, 0
br i1 %57, label %41, label %43
58: ; preds = %47, %41
br label %59
59: ; preds = %58, %29, %23
br label %60
60: ; preds = %59, %9
ret i32 1
}