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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, unsigned int *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ htons(int);
int listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main() {
  int sock_fd, err, client_fd;
  unsigned int addrlen;
  struct sockaddr_in local_addr, client_addr;
  sock_fd = socket(AF_INET, SOCK_STREAM, 0);
  if (sock_fd < 0) {
    fprintf(stderr, "Eroare! Nu am putut deschide socket!\n");
    exit(-1);
  }
  memset(&local_addr, 0, sizeof(local_addr));
  local_addr.sin_family = AF_INET;
  local_addr.sin_port = htons(5005);
  local_addr.sin_addr.s_addr = INADDR_ANY;
  err = bind(sock_fd, (struct sockaddr *)&local_addr, sizeof(local_addr));
  if (err < 0) {
    fprintf(stderr, "Eroare la bind!\n");
    exit(-1);
  }
  err = listen(sock_fd, 10);
  if (err < 0) {
    fprintf(stderr, "Eroare la listen\n");
    exit(-1);
  }
  memset(&client_addr, 0, sizeof(client_addr));
  addrlen = sizeof(client_addr);
  client_fd = accept(sock_fd, (struct sockaddr *)&client_addr, &addrlen);
  if (client_fd < 0) {
    fprintf(stderr, "Eroare la accept\n");
    exit(-1);
  }
  char buffer[32];
  read(client_fd, buffer, sizeof(buffer));
  printf("%s\n", buffer);
  close(client_fd);
  close(sock_fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1204 <main+0x54>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
lea    0xe0b(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x138d,%edi
call   1030 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2dac(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <bind@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1276 <main+0xc6>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
lea    0xdbf(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    -0x8(%rbp),%edi
mov    $0xa,%esi
call   1090 <listen@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    12af <main+0xff>
mov    0x2d39(%rip),%rax
mov    (%rax),%edi
lea    0xd97(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
movl   $0xc,-0x14(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   10b0 <accept@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1302 <main+0x152>
mov    0x2ce6(%rip),%rax
mov    (%rax),%edi
lea    0xd56(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x20,%edx
call   1070 <read@plt>
lea    -0x50(%rbp),%rsi
lea    0xd3d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%edi
call   1060 <close@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    0x2e29(%rip),%r14
mov    (%r14),%edi
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
test   %eax,%eax
js     12aa <main+0xfa>
mov    %eax,%ebx
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    (%r14),%eax
mov    %eax,0x18(%rsp)
mov    $0x138d,%edi
call   1030 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2dd4(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   10a0 <bind@plt>
test   %eax,%eax
js     12bc <main+0x10c>
mov    %ebx,%edi
mov    $0xa,%esi
call   1090 <listen@plt>
test   %eax,%eax
js     12ce <main+0x11e>
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
movl   $0xc,0xc(%rsp)
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
mov    %rbp,%rsi
call   10b0 <accept@plt>
test   %eax,%eax
js     12e0 <main+0x130>
mov    %eax,%ebp
lea    0x30(%rsp),%r14
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x20,%edx
call   1070 <read@plt>
lea    0xdd2(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2d1f(%rip),%rax
mov    (%rax),%edi
lea    0xd46(%rip),%rsi
jmp    12f0 <main+0x140>
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
lea    0xd5a(%rip),%rsi
jmp    12f0 <main+0x140>
mov    0x2cfb(%rip),%rax
mov    (%rax),%edi
lea    0xd59(%rip),%rsi
jmp    12f0 <main+0x140>
mov    0x2ce9(%rip),%rax
mov    (%rax),%edi
lea    0xd59(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0xffffffff,%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 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [38 x i8] c"Eroare! Nu am putut deschide socket!\0A\00"
@INADDR_ANY = global i32 0
@.str.1 = [17 x i8] c"Eroare la bind!\0A\00"
@.str.2 = [18 x i8] c"Eroare la listen\0A\00"
@.str.3 = [18 x i8] c"Eroare la accept\0A\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.sockaddr_in
%8 = alloca [32 x i8]
store i32 0, i32* %1
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = call i32 @socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %2
%12 = load i32, i32* %2
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %0
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %0
%19 = call i32 @memset(%struct.sockaddr_in* %6, i32 0, i32 12)
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %20, i32* %21
%22 = call i32 @htons(i32 5005)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %22, i32* %23
%24 = load i32, i32* @INADDR_ANY
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%26 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %25, i32 0, i32 0
store i32 %24, i32* %26
%27 = load i32, i32* %2
%28 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%29 = call i32 @bind(i32 %27, %struct.sockaddr* %28, i32 12)
store i32 %29, i32* %3
%30 = load i32, i32* %3
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %18
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%35 = call i32 @exit(i32 -1)
unreachable
36: ; preds = %18
%37 = load i32, i32* %2
%38 = call i32 @listen(i32 %37, i32 10)
store i32 %38, i32* %3
%39 = load i32, i32* %3
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %36
%42 = load i32, i32* @stderr
%43 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%44 = call i32 @exit(i32 -1)
unreachable
45: ; preds = %36
%46 = call i32 @memset(%struct.sockaddr_in* %7, i32 0, i32 12)
store i32 12, i32* %5
%47 = load i32, i32* %2
%48 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%49 = call i32 @accept(i32 %47, %struct.sockaddr* %48, i32* %5)
store i32 %49, i32* %4
%50 = load i32, i32* %4
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %45
%53 = load i32, i32* @stderr
%54 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%55 = call i32 @exit(i32 -1)
unreachable
56: ; preds = %45
%57 = load i32, i32* %4
%58 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%59 = call i32 @read(i32 %57, i8* %58, i32 32)
%60 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%61 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %60)
%62 = load i32, i32* %4
%63 = call i32 @close(i32 %62)
%64 = load i32, i32* %2
%65 = call i32 @close(i32 %64)
ret i32 0
}

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
@stderr = global i32 0
@.str = [38 x i8] c"Eroare! Nu am putut deschide socket!\0A\00"
@INADDR_ANY = global i32 0
@.str.1 = [17 x i8] c"Eroare la bind!\0A\00"
@.str.2 = [18 x i8] c"Eroare la listen\0A\00"
@.str.3 = [18 x i8] c"Eroare la accept\0A\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca %struct.sockaddr_in
%4 = alloca [32 x i8]
%5 = bitcast i32* %1 to i8*
%6 = bitcast %struct.sockaddr_in* %2 to i8*
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_STREAM
%10 = tail call i32 @socket(i32 %8, i32 %9, i32 0)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %0
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 -1)
unreachable
16: ; preds = %0
%17 = call i32 @memset(%struct.sockaddr_in* %2, i32 0, i32 12)
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %18, i32* %19
%20 = call i32 @htons(i32 5005)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %20, i32* %21
%22 = load i32, i32* @INADDR_ANY
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0, i32 0
store i32 %22, i32* %23
%24 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%25 = call i32 @bind(i32 %10, %struct.sockaddr* %24, i32 12)
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %16
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 @exit(i32 -1)
unreachable
31: ; preds = %16
%32 = call i32 @listen(i32 %10, i32 10)
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %31
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%37 = call i32 @exit(i32 -1)
unreachable
38: ; preds = %31
%39 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
store i32 12, i32* %1
%40 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%41 = call i32 @accept(i32 %10, %struct.sockaddr* %40, i32* %1)
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %38
%44 = load i32, i32* @stderr
%45 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%46 = call i32 @exit(i32 -1)
unreachable
47: ; preds = %38
%48 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%49 = call i32 @read(i32 %41, i8* %48, i32 32)
%50 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %48)
%51 = call i32 @close(i32 %41)
%52 = call i32 @close(i32 %10)
ret i32 0
}