#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*/ squared;
typedef int /*<<< orphan*/ number;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SIGCHLD;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int bind(int, struct sockaddr const *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int listen(int, int);
int /*<<< orphan*/ perror(char *);
int recv(int, int *, int, int /*<<< orphan*/);
int send(int, int *, int, int /*<<< orphan*/);
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main() {
  signal(SIGCHLD, SIG_IGN);
  int listen_fd = socket(PF_INET, SOCK_STREAM, 0);
  if (listen_fd == -1) {
    perror("Failed to create socket");
  }
  struct sockaddr_in addr;
  addr.sin_family = AF_INET;
  addr.sin_port = htons(4237);
  addr.sin_addr.s_addr = htonl(INADDR_ANY);
  if (bind(listen_fd, (const struct sockaddr *)&addr, sizeof(addr)) == -1) {
    perror("Bind error");
  }
  if (listen(listen_fd, 5) == -1) {
    perror("Failed to listen for incoming connexions");
  }
  while (1) {
    int client = accept(listen_fd, NULL, 0);
    if (client == -1) {
      perror("Failed to accept a call");
    }
    int pid = fork();
    if (!pid) {
      int number;
      int received = recv(client, &number, sizeof(number), 0);
      if (received == -1) {
        perror("Failed to receive the number");
      }
      int squared = number * number;
      int sent = send(client, &squared, sizeof(squared), 0);
      exit(0);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
mov    0x2df1(%rip),%rax
mov    (%rax),%esi
call   1070 <signal@plt>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
mov    0x2dca(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1218 <main+0x58>
lea    0xded(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2dc9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x108d,%edi
call   1040 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
cmp    $0xffffffff,%eax
jne    1268 <main+0xa8>
lea    0xdb5(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x8(%rbp),%edi
mov    $0x5,%esi
call   1080 <listen@plt>
cmp    $0xffffffff,%eax
jne    128a <main+0xca>
lea    0xd9e(%rip),%rdi
call   10a0 <perror@plt>
jmp    128f <main+0xcf>
mov    -0x8(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10b0 <accept@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    12b6 <main+0xf6>
lea    0xd9b(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x0,%al
call   10d0 <fork@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    131d <main+0x15d>
mov    -0x1c(%rbp),%edi
lea    -0x24(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    12f6 <main+0x136>
lea    0xd73(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x24(%rbp),%eax
imul   -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x2c(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %eax,-0x30(%rbp)
xor    %edi,%edi
call   10c0 <exit@plt>
jmp    128f <main+0xcf>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    0x2df8(%rip),%rax
mov    (%rax),%esi
call   1070 <signal@plt>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
mov    0x2dd1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    120b <main+0x4b>
lea    0xdfa(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2dd6(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    $0x108d,%edi
call   1040 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1090 <bind@plt>
cmp    $0xffffffff,%eax
jne    125a <main+0x9a>
lea    0xdc3(%rip),%rdi
call   10a0 <perror@plt>
mov    %ebx,%edi
mov    $0x5,%esi
call   1080 <listen@plt>
cmp    $0xffffffff,%eax
jne    1277 <main+0xb7>
lea    0xdb1(%rip),%rdi
call   10a0 <perror@plt>
lea    0xdce(%rip),%r14
jmp    128b <main+0xcb>
xor    %eax,%eax
call   10d0 <fork@plt>
test   %eax,%eax
je     12a7 <main+0xe7>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10b0 <accept@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1280 <main+0xc0>
mov    %r14,%rdi
call   10a0 <perror@plt>
jmp    1280 <main+0xc0>
lea    0xc(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0xffffffff,%eax
jne    12cb <main+0x10b>
lea    0xd9e(%rip),%rdi
call   10a0 <perror@plt>
mov    0xc(%rsp),%eax
imul   %eax,%eax
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@SIGCHLD = global i32 0
@SIG_IGN = global i32 0
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [24 x i8] c"Failed to create socket\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [11 x i8] c"Bind error\00"
@.str.2 = [41 x i8] c"Failed to listen for incoming connexions\00"
@.str.3 = [24 x i8] c"Failed to accept a call\00"
@.str.4 = [29 x i8] c"Failed to receive the number\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
%10 = load i32, i32* @SIGCHLD
%11 = load i32, i32* @SIG_IGN
%12 = call i32 @signal(i32 %10, i32 %11)
%13 = load i32, i32* @PF_INET
%14 = load i32, i32* @SOCK_STREAM
%15 = call i32 @socket(i32 %13, i32 %14, i32 0)
store i32 %15, i32* %2
%16 = load i32, i32* %2
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %0
%19 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %0
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %21, i32* %22
%23 = call i32 @htons(i32 4237)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %23, i32* %24
%25 = load i32, i32* @INADDR_ANY
%26 = call i32 @htonl(i32 %25)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%28 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %27, i32 0, i32 0
store i32 %26, i32* %28
%29 = load i32, i32* %2
%30 = bitcast %struct.sockaddr_in* %3 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 %35
33: ; preds = %20
%34 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %35
35: ; preds = %33, %20
%36 = load i32, i32* %2
%37 = call i32 @listen(i32 %36, i32 5)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
br label %41
41: ; preds = %39, %35
br label %42
42: ; preds = %41, %67
%43 = load i32, i32* %2
%44 = call i32 @accept(i32 %43, i32* null, i32 0)
store i32 %44, i32* %4
%45 = load i32, i32* %4
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %49
47: ; preds = %42
%48 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %49
49: ; preds = %47, %42
%50 = call i32 (...) @fork()
store i32 %50, i32* %5
%51 = load i32, i32* %5
%52 = icmp ne i32 %51, 0
br i1 %52, label %67, label %53
53: ; preds = %49
%54 = load i32, i32* %4
%55 = call i32 @recv(i32 %54, i32* %6, i32 4, i32 0)
store i32 %55, i32* %7
%56 = load i32, i32* %7
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %60
58: ; preds = %53
%59 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
br label %60
60: ; preds = %58, %53
%61 = load i32, i32* %6
%62 = load i32, i32* %6
%63 = mul nsw i32 %61, %62
store i32 %63, i32* %8
%64 = load i32, i32* %4
%65 = call i32 @send(i32 %64, i32* %8, i32 4, i32 0)
store i32 %65, i32* %9
%66 = call i32 @exit(i32 0)
unreachable
67: ; preds = %49
br label %42
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@SIGCHLD = global i32 0
@SIG_IGN = global i32 0
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [24 x i8] c"Failed to create socket\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [11 x i8] c"Bind error\00"
@.str.2 = [41 x i8] c"Failed to listen for incoming connexions\00"
@.str.3 = [24 x i8] c"Failed to accept a call\00"
@.str.4 = [29 x i8] c"Failed to receive the number\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca i32
%3 = alloca i32
%4 = load i32, i32* @SIGCHLD
%5 = load i32, i32* @SIG_IGN
%6 = tail call i32 @signal(i32 %4, i32 %5)
%7 = load i32, i32* @PF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %0
%14 = bitcast %struct.sockaddr_in* %1 to i8*
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %15, i32* %16
%17 = tail call i32 @htons(i32 4237)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %17, i32* %18
%19 = load i32, i32* @INADDR_ANY
%20 = tail call i32 @htonl(i32 %19)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %20, i32* %21
%22 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%23 = call i32 @bind(i32 %9, %struct.sockaddr* %22, i32 12)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %13
%26 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %13
%28 = call i32 @listen(i32 %9, i32 5)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %30, %27
br label %33
33: ; preds = %32, %38
%34 = call i32 @accept(i32 %9, i32* null, i32 0)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %38
38: ; preds = %36, %33
%39 = call i32 (...) @fork()
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %33
41: ; preds = %38
%42 = bitcast i32* %2 to i8*
%43 = call i32 @recv(i32 %34, i32* %2, i32 4, i32 0)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %47
45: ; preds = %41
%46 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
br label %47
47: ; preds = %45, %41
%48 = bitcast i32* %3 to i8*
%49 = load i32, i32* %2
%50 = mul nsw i32 %49, %49
store i32 %50, i32* %3
%51 = call i32 @send(i32 %34, i32* %3, i32 4, i32 0)
%52 = call i32 @exit(i32 0)
unreachable
}