#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 */
typedef int /*<<< orphan*/ zerb_helb;
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;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int bind(int, struct sockaddr *, int);
int close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int listen(int, int);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int write(int, char *, int);
int main() {
  int sock, elkarrizketa;
  int n;
  struct sockaddr_in zerb_helb;
  char buf[1024];
  if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    printf("ERROREA SOCKETA SORTZERAKOAN");
  }
  zerb_helb.sin_family = AF_INET;
  zerb_helb.sin_addr.s_addr = htonl(INADDR_ANY);
  zerb_helb.sin_port = htons(50002);
  if (bind(sock, (struct sockaddr *)&zerb_helb, sizeof(zerb_helb)) == -1) {
    printf("ERROREA SOCKETARI PARAMETRO ETA PORTUAK ASIGNATZEAN");
    exit(1);
  }
  if (listen(sock, 5) == -1) {
    printf("KONEXIOA EZARTZERAKO MOMENTUAN ERROREA!!!!");
    exit(1);
  }
  while (1) {
    if ((elkarrizketa = accept(sock, NULL, NULL)) == -1) {
      printf("ERROREA KONEXIOA ONARTZERAKOAN");
      exit(1);
    }
    while (elkarrizketa != 0) {
      n = read(elkarrizketa, buf, 1024);
      if (write(elkarrizketa, buf, n) == -1) {
        printf("ERROREA BEZEROARI BUF BIDALTZEAN");
        exit(1);
      }
    }
    if (close(elkarrizketa) == -1) {
      printf("ERROREA KONEXIOA IXTEAN");
      exit(1);
    }
  }
  if (close(sock) == -1) {
    printf("ERROREA KONEXIOA IXTEAN");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    11f3 <main+0x43>
lea    0xe12(%rip),%rdi
call   1050 <printf@plt>
mov    0x2dee(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,-0x1c(%rbp)
mov    $0xc352,%edi
call   1040 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <bind@plt>
cmp    $0xffffffff,%eax
jne    124d <main+0x9d>
lea    0xddf(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x8(%rbp),%edi
mov    $0x5,%esi
call   1090 <listen@plt>
cmp    $0xffffffff,%eax
jne    1279 <main+0xc9>
lea    0xde7(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    127e <main+0xce>
mov    -0x8(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   10b0 <accept@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    12af <main+0xff>
lea    0xddc(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    12b4 <main+0x104>
cmpl   $0x0,-0xc(%rbp)
je     130b <main+0x15b>
mov    -0xc(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1080 <read@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    1306 <main+0x156>
lea    0xda4(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    12b4 <main+0x104>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
jne    1332 <main+0x182>
lea    0xd99(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    127e <main+0xce>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x418,%rsp
mov    0x2e28(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2e06(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    11e6 <main+0x36>
lea    0xe1f(%rip),%rdi
call   1050 <printf@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x8(%rsp)
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,0x4(%rsp)
mov    $0xc352,%edi
call   1040 <htons@plt>
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   10a0 <bind@plt>
cmp    $0xffffffff,%eax
jne    122c <main+0x7c>
lea    0xdf6(%rip),%rdi
jmp    12b7 <main+0x107>
mov    %ebx,%edi
mov    $0x5,%esi
call   1090 <listen@plt>
cmp    $0xffffffff,%eax
jne    1250 <main+0xa0>
lea    0xe0d(%rip),%rdi
jmp    12b7 <main+0x107>
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10b0 <accept@plt>
test   %eax,%eax
jne    1274 <main+0xc4>
xor    %edi,%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
jne    1250 <main+0xa0>
lea    0xe4a(%rip),%rdi
jmp    12b7 <main+0x107>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1284 <main+0xd4>
lea    0xdfa(%rip),%rdi
jmp    12b7 <main+0x107>
lea    0x10(%rsp),%rbx
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1080 <read@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    1290 <main+0xe0>
lea    0xde4(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10c0 <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 = [29 x i8] c"ERROREA SOCKETA SORTZERAKOAN\00"
@INADDR_ANY = global i32 0
@.str.1 = [52 x i8] c"ERROREA SOCKETARI PARAMETRO ETA PORTUAK ASIGNATZEAN\00"
@.str.2 = [43 x i8] c"KONEXIOA EZARTZERAKO MOMENTUAN ERROREA!!!!\00"
@.str.3 = [31 x i8] c"ERROREA KONEXIOA ONARTZERAKOAN\00"
@.str.4 = [33 x i8] c"ERROREA BEZEROARI BUF BIDALTZEAN\00"
@.str.5 = [24 x i8] c"ERROREA KONEXIOA IXTEAN\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca [1024 x i8]
store i32 0, i32* %1
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %2
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %0
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i32 %14, i32* %15
%16 = load i32, i32* @INADDR_ANY
%17 = call i32 @htonl(i32 %16)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
%19 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %18, i32 0, i32 0
store i32 %17, i32* %19
%20 = call i32 @htons(i32 50002)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
store i32 %20, i32* %21
%22 = load i32, i32* %2
%23 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%24 = call i32 @bind(i32 %22, %struct.sockaddr* %23, i32 12)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %13
%27 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %13
%30 = load i32, i32* %2
%31 = call i32 @listen(i32 %30, i32 5)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %29
br label %37
37: ; preds = %36, %68
%38 = load i32, i32* %2
%39 = call i32 @accept(i32 %38, i32* null, i32* null)
store i32 %39, i32* %3
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %37
br label %45
45: ; preds = %60, %44
%46 = load i32, i32* %3
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %61
48: ; preds = %45
%49 = load i32, i32* %3
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%51 = call i32 @read(i32 %49, i8* %50, i32 1024)
store i32 %51, i32* %4
%52 = load i32, i32* %3
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%54 = load i32, i32* %4
%55 = call i32 @write(i32 %52, i8* %53, i32 %54)
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %60
57: ; preds = %48
%58 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %48
br label %45
61: ; preds = %45
%62 = load i32, i32* %3
%63 = call i32 @close(i32 %62)
%64 = icmp eq i32 %63, -1
br i1 %64, label %65, label %68
65: ; preds = %61
%66 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%67 = call i32 @exit(i32 1)
unreachable
68: ; preds = %61
br label %37
}

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 = [29 x i8] c"ERROREA SOCKETA SORTZERAKOAN\00"
@INADDR_ANY = global i32 0
@.str.1 = [52 x i8] c"ERROREA SOCKETARI PARAMETRO ETA PORTUAK ASIGNATZEAN\00"
@.str.2 = [43 x i8] c"KONEXIOA EZARTZERAKO MOMENTUAN ERROREA!!!!\00"
@.str.3 = [31 x i8] c"ERROREA KONEXIOA ONARTZERAKOAN\00"
@.str.4 = [33 x i8] c"ERROREA BEZEROARI BUF BIDALTZEAN\00"
@.str.5 = [24 x i8] c"ERROREA KONEXIOA IXTEAN\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [1024 x i8]
%3 = bitcast %struct.sockaddr_in* %1 to i8*
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%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 @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %0
%12 = load i32, i32* @AF_INET
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %12, i32* %13
%14 = load i32, i32* @INADDR_ANY
%15 = tail call i32 @htonl(i32 %14)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %15, i32* %16
%17 = tail call i32 @htons(i32 50002)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %17, i32* %18
%19 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%20 = call i32 @bind(i32 %7, %struct.sockaddr* %19, i32 12)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %11
%23 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %11
%26 = call i32 @listen(i32 %7, i32 5)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %25, %43
%32 = call i32 @accept(i32 %7, i32* null, i32* null)
switch i32 %32, label %36 [
i32 -1, label %33
i32 0, label %43
]
33: ; preds = %31
%34 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %31, %36
%37 = call i32 @read(i32 %32, i8* %4, i32 1024)
%38 = call i32 @write(i32 %32, i8* %4, i32 %37)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %36
40: ; preds = %36
%41 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %31
%44 = call i32 @close(i32 0)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %31
46: ; preds = %43
%47 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%48 = call i32 @exit(i32 1)
unreachable
}