#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 timeval {
  int tv_sec;
  int /*<<< orphan*/ tv_usec;
};
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 socklen_t;
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ bez_helb;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SIGCHLD;
scalar_t__ SIG_ERR;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ SOCK_DGRAM;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int select(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
scalar_t__ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int write(int, char *, int);
int main() {
  int sock, elkarrizketa;
  int pid, i, n;
  struct sockaddr_in zerb_helb, bez_helb;
  socklen_t helb_tam;
  struct timeval denbora;
  fd_set readfds;
  char buf[1024];
  if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
    perror("Errorea socketa sortzean");
    exit(1);
  }
  memset(&zerb_helb, 0, sizeof(zerb_helb));
  zerb_helb.sin_family = AF_INET;
  zerb_helb.sin_addr.s_addr = htonl(INADDR_ANY);
  zerb_helb.sin_port = htons(50005);
  if (bind(sock, (struct sockaddr *)&zerb_helb, sizeof(zerb_helb)) < 0) {
    perror("Errorea socketari helbide bat esleitzean");
    exit(1);
  }
  if (signal(SIGCHLD, SIG_IGN) == SIG_ERR) {
    printf("errorea signalean");
  }
  while (1) {
    helb_tam = sizeof(bez_helb);
    if ((n = recvfrom(sock, buf, 1024, 0, (struct sockaddr *)&bez_helb,
                      &helb_tam)) < 0) {
      perror("Errorea datuak jasotzean");
      exit(1);
    }
    pid = fork();
    switch (pid) {
    case (0):
      close(sock);
      if ((elkarrizketa = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
        printf("errorea ume socketa sortzean");
        exit(1);
      }
      if (connect(elkarrizketa, (struct sockaddr *)&bez_helb,
                  sizeof(bez_helb)) == -1) {
        printf("errorea connect egitean");
        exit(1);
      }
      while (n > 0) {
        FD_ZERO(&readfds);
        FD_SET(elkarrizketa, &readfds);
        denbora.tv_sec = 120;
        denbora.tv_usec = 0;
        if (write(elkarrizketa, buf, n) == -1) {
          printf("errorea idaztean");
          exit(1);
        }
        i = select(elkarrizketa + 1, &readfds, NULL, NULL, &denbora);
        switch (i) {
        case (0):
          printf("Bukatu da itxarote denbora");
          close(elkarrizketa);
          exit(1);
        case (-1):
          printf("errorea selectean");
          exit(1);
        default:
          if ((n = read(elkarrizketa, buf, 1024)) == -1) {
            printf("errorea mezua jasotzean");
            exit(1);
          }
        }
      }
      close(elkarrizketa);
      exit(0);
    case (-1):
      printf("ERROREA FORK");
    default:
      break;
    }
  }
  close(sock);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
mov    0x2d8e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    126d <main+0x4d>
lea    0xda2(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2d64(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,-0x24(%rbp)
mov    $0xc355,%edi
call   1040 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   10e0 <bind@plt>
cmp    $0x0,%rax
jge    12d8 <main+0xb8>
lea    0xd50(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    0x2cf9(%rip),%rax
mov    (%rax),%edi
mov    0x2ce0(%rip),%rax
mov    (%rax),%esi
call   10a0 <signal@plt>
mov    0x2cc2(%rip),%rcx
cmp    (%rcx),%rax
jne    130b <main+0xeb>
lea    0xd3c(%rip),%rdi
call   1050 <printf@plt>
jmp    1310 <main+0xf0>
movl   $0xc,-0x3c(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x450(%rbp),%rsi
lea    -0x38(%rbp),%r8
mov    $0x400,%edx
xor    %ecx,%ecx
lea    -0x3c(%rbp),%r9
call   10d0 <recvfrom@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1357 <main+0x137>
lea    0xd0c(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
xor    %eax,%eax
call   1130 <fork@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x454(%rbp)
sub    $0xffffffff,%eax
je     152b <main+0x30b>
jmp    1378 <main+0x158>
mov    -0x454(%rbp),%eax
test   %eax,%eax
jne    1537 <main+0x317>
jmp    138b <main+0x16b>
mov    -0x8(%rbp),%edi
call   1080 <close@plt>
mov    0x2c4e(%rip),%rax
mov    (%rax),%edi
mov    0x2c2d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    13ce <main+0x1ae>
lea    0xcae(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0xc(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0xc,%edx
call   1110 <connect@plt>
cmp    $0xffffffff,%eax
jne    13fe <main+0x1de>
lea    0xc9b(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
jmp    1403 <main+0x1e3>
cmpl   $0x0,-0x18(%rbp)
jle    151c <main+0x2fc>
lea    -0x4c(%rbp),%rdi
call   10b0 <FD_ZERO@plt>
mov    -0xc(%rbp),%edi
lea    -0x4c(%rbp),%rsi
call   1120 <FD_SET@plt>
movl   $0x78,-0x48(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x450(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    1461 <main+0x241>
lea    0xc50(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0xc(%rbp),%edi
add    $0x1,%edi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x4c(%rbp),%rsi
lea    -0x48(%rbp),%r8
mov    %rcx,%rdx
call   10c0 <select@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x458(%rbp)
sub    $0xffffffff,%eax
je     14c6 <main+0x2a6>
jmp    1495 <main+0x275>
mov    -0x458(%rbp),%eax
test   %eax,%eax
jne    14dc <main+0x2bc>
jmp    14a8 <main+0x288>
lea    0xc04(%rip),%rdi
call   1050 <printf@plt>
mov    -0xc(%rbp),%edi
call   1080 <close@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    0xc01(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0xc(%rbp),%edi
lea    -0x450(%rbp),%rsi
mov    $0x400,%edx
call   1090 <read@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    1512 <main+0x2f2>
lea    0xbdd(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
jmp    1517 <main+0x2f7>
jmp    1403 <main+0x1e3>
mov    -0xc(%rbp),%edi
call   1080 <close@plt>
xor    %edi,%edi
call   1100 <exit@plt>
lea    0xbc6(%rip),%rdi
call   1050 <printf@plt>
jmp    153c <main+0x31c>
jmp    1310 <main+0xf0>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
mov    0x2db0(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2d8e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
test   %eax,%eax
jns    125b <main+0x3b>
lea    0xdaa(%rip),%rdi
jmp    1317 <main+0xf7>
mov    %eax,%r15d
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x10(%rsp)
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,0xc(%rsp)
mov    $0xc355,%edi
call   1040 <htons@plt>
mov    %eax,0x8(%rsp)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   10e0 <bind@plt>
test   %rax,%rax
jns    12b7 <main+0x97>
lea    0xd64(%rip),%rdi
jmp    1317 <main+0xf7>
mov    0x2d1a(%rip),%rax
mov    (%rax),%edi
mov    0x2d01(%rip),%rax
mov    (%rax),%esi
call   10a0 <signal@plt>
mov    0x2ce3(%rip),%rcx
cmp    (%rcx),%rax
jne    12e6 <main+0xc6>
lea    0xd61(%rip),%rdi
call   1050 <printf@plt>
movl   $0xc,0x4(%rsp)
lea    0x30(%rsp),%rsi
lea    0x20(%rsp),%r8
lea    0x4(%rsp),%r9
mov    %r15d,%edi
mov    $0x400,%edx
xor    %ecx,%ecx
call   10d0 <recvfrom@plt>
test   %eax,%eax
jns    1326 <main+0x106>
lea    0xd3d(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    %eax,%ebp
lea    0xdc9(%rip),%r14
lea    0x30(%rsp),%r12
lea    0x20(%rsp),%r13
lea    0x4(%rsp),%rbx
jmp    136e <main+0x14e>
mov    %r14,%rdi
call   1050 <printf@plt>
movl   $0xc,0x4(%rsp)
mov    %r15d,%edi
mov    %r12,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
mov    %r13,%r8
mov    %rbx,%r9
call   10d0 <recvfrom@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1310 <main+0xf0>
xor    %eax,%eax
call   1130 <fork@plt>
cmp    $0xffffffff,%eax
je     1340 <main+0x120>
test   %eax,%eax
jne    1348 <main+0x128>
mov    %r15d,%edi
call   1080 <close@plt>
mov    0x2c5b(%rip),%rax
mov    (%rax),%edi
mov    0x2c3a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
cmp    $0xffffffff,%eax
jne    13ad <main+0x18d>
lea    0xcc2(%rip),%rdi
jmp    13cc <main+0x1ac>
mov    %eax,%ebx
lea    0x20(%rsp),%rsi
mov    %eax,%edi
mov    $0xc,%edx
call   1110 <connect@plt>
cmp    $0xffffffff,%eax
jne    13db <main+0x1bb>
lea    0xcbe(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    %ebx,%r14d
add    $0x1,%r14d
lea    0x2c(%rsp),%r15
lea    0x30(%rsp),%r12
lea    0x18(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
test   %ebp,%ebp
jle    146d <main+0x24d>
mov    %r15,%rdi
call   10b0 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %r15,%rsi
call   1120 <FD_SET@plt>
movq   $0x78,0x18(%rsp)
mov    %ebx,%edi
mov    %r12,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     147b <main+0x25b>
mov    %r14d,%edi
mov    %r15,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r13,%r8
call   10c0 <select@plt>
cmp    $0xffffffff,%eax
je     1487 <main+0x267>
test   %eax,%eax
je     1493 <main+0x273>
mov    %ebx,%edi
mov    %r12,%rsi
mov    $0x400,%edx
call   1090 <read@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1400 <main+0x1e0>
lea    0xc78(%rip),%rdi
jmp    13cc <main+0x1ac>
mov    %ebx,%edi
call   1080 <close@plt>
xor    %edi,%edi
call   1100 <exit@plt>
lea    0xc20(%rip),%rdi
jmp    13cc <main+0x1ac>
lea    0xc40(%rip),%rdi
jmp    13cc <main+0x1ac>
lea    0xc19(%rip),%rdi
call   1050 <printf@plt>
mov    %ebx,%edi
call   1080 <close@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.timeval = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [25 x i8] c"Errorea socketa sortzean\00"
@INADDR_ANY = global i32 0
@.str.1 = [41 x i8] c"Errorea socketari helbide bat esleitzean\00"
@SIGCHLD = global i32 0
@SIG_IGN = global i32 0
@SIG_ERR = global i64 0
@.str.2 = [18 x i8] c"errorea signalean\00"
@.str.3 = [25 x i8] c"Errorea datuak jasotzean\00"
@.str.4 = [29 x i8] c"errorea ume socketa sortzean\00"
@.str.5 = [24 x i8] c"errorea connect egitean\00"
@.str.6 = [17 x i8] c"errorea idaztean\00"
@.str.7 = [27 x i8] c"Bukatu da itxarote denbora\00"
@.str.8 = [18 x i8] c"errorea selectean\00"
@.str.9 = [24 x i8] c"errorea mezua jasotzean\00"
@.str.10 = [13 x i8] c"ERROREA FORK\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca %struct.sockaddr_in
%9 = alloca i32
%10 = alloca %struct.timeval
%11 = alloca i32
%12 = alloca [1024 x i8]
store i32 0, i32* %1
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_DGRAM
%15 = call i32 @socket(i32 %13, i32 %14, i32 0)
store i32 %15, i32* %2
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %0
%18 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %0
%21 = call i32 @memset(%struct.sockaddr_in* %7, i32 0, 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 = load i32, i32* @INADDR_ANY
%25 = call i32 @htonl(i32 %24)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%27 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %26, i32 0, i32 0
store i32 %25, i32* %27
%28 = call i32 @htons(i32 50005)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %28, i32* %29
%30 = load i32, i32* %2
%31 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%32 = call i64 @bind(i32 %30, %struct.sockaddr* %31, i32 12)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %20
%35 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %20
%38 = load i32, i32* @SIGCHLD
%39 = load i32, i32* @SIG_IGN
%40 = call i64 @signal(i32 %38, i32 %39)
%41 = load i64, i64* @SIG_ERR
%42 = icmp eq i64 %40, %41
br i1 %42, label %43, label %45
43: ; preds = %37
%44 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %45
45: ; preds = %43, %37
br label %46
46: ; preds = %45, %124
store i32 12, i32* %9
%47 = load i32, i32* %2
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%49 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%50 = call i32 @recvfrom(i32 %47, i8* %48, i32 1024, i32 0, %struct.sockaddr* %49, i32* %9)
store i32 %50, i32* %6
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %46
%53 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %46
%56 = call i32 (...) @fork()
store i32 %56, i32* %4
%57 = load i32, i32* %4
switch i32 %57, label %123 [
i32 0, label %58
i32 -1, label %121
]
58: ; preds = %55
%59 = load i32, i32* %2
%60 = call i32 @close(i32 %59)
%61 = load i32, i32* @AF_INET
%62 = load i32, i32* @SOCK_DGRAM
%63 = call i32 @socket(i32 %61, i32 %62, i32 0)
store i32 %63, i32* %3
%64 = icmp eq i32 %63, -1
br i1 %64, label %65, label %68
65: ; preds = %58
%66 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%67 = call i32 @exit(i32 1)
unreachable
68: ; preds = %58
%69 = load i32, i32* %3
%70 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%71 = call i32 @connect(i32 %69, %struct.sockaddr* %70, i32 12)
%72 = icmp eq i32 %71, -1
br i1 %72, label %73, label %76
73: ; preds = %68
%74 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%75 = call i32 @exit(i32 1)
unreachable
76: ; preds = %68
br label %77
77: ; preds = %116, %76
%78 = load i32, i32* %6
%79 = icmp sgt i32 %78, 0
br i1 %79, label %80, label %117
80: ; preds = %77
%81 = call i32 @FD_ZERO(i32* %11)
%82 = load i32, i32* %3
%83 = call i32 @FD_SET(i32 %82, i32* %11)
%84 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 0
store i32 120, i32* %84
%85 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 1
store i32 0, i32* %85
%86 = load i32, i32* %3
%87 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%88 = load i32, i32* %6
%89 = call i32 @write(i32 %86, i8* %87, i32 %88)
%90 = icmp eq i32 %89, -1
br i1 %90, label %91, label %94
91: ; preds = %80
%92 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%93 = call i32 @exit(i32 1)
unreachable
94: ; preds = %80
%95 = load i32, i32* %3
%96 = add nsw i32 %95, 1
%97 = call i32 @select(i32 %96, i32* %11, i32* null, i32* null, %struct.timeval* %10)
store i32 %97, i32* %5
%98 = load i32, i32* %5
switch i32 %98, label %107 [
i32 0, label %99
i32 -1, label %104
]
99: ; preds = %94
%100 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
%101 = load i32, i32* %3
%102 = call i32 @close(i32 %101)
%103 = call i32 @exit(i32 1)
unreachable
104: ; preds = %94
%105 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0))
%106 = call i32 @exit(i32 1)
unreachable
107: ; preds = %94
%108 = load i32, i32* %3
%109 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%110 = call i32 @read(i32 %108, i8* %109, i32 1024)
store i32 %110, i32* %6
%111 = icmp eq i32 %110, -1
br i1 %111, label %112, label %115
112: ; preds = %107
%113 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0))
%114 = call i32 @exit(i32 1)
unreachable
115: ; preds = %107
br label %116
116: ; preds = %115
br label %77
117: ; preds = %77
%118 = load i32, i32* %3
%119 = call i32 @close(i32 %118)
%120 = call i32 @exit(i32 0)
unreachable
121: ; preds = %55
%122 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
br label %123
123: ; preds = %55, %121
br label %124
124: ; preds = %123
br label %46
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.timeval = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [25 x i8] c"Errorea socketa sortzean\00"
@INADDR_ANY = global i32 0
@.str.1 = [41 x i8] c"Errorea socketari helbide bat esleitzean\00"
@SIGCHLD = global i32 0
@SIG_IGN = global i32 0
@SIG_ERR = global i64 0
@.str.2 = [18 x i8] c"errorea signalean\00"
@.str.3 = [25 x i8] c"Errorea datuak jasotzean\00"
@.str.4 = [29 x i8] c"errorea ume socketa sortzean\00"
@.str.5 = [24 x i8] c"errorea connect egitean\00"
@.str.6 = [17 x i8] c"errorea idaztean\00"
@.str.7 = [27 x i8] c"Bukatu da itxarote denbora\00"
@.str.8 = [18 x i8] c"errorea selectean\00"
@.str.9 = [24 x i8] c"errorea mezua jasotzean\00"
@.str.10 = [13 x i8] c"ERROREA FORK\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = alloca %struct.timeval
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = bitcast %struct.sockaddr_in* %1 to i8*
%8 = bitcast %struct.sockaddr_in* %2 to i8*
%9 = bitcast i32* %3 to i8*
%10 = bitcast %struct.timeval* %4 to i8*
%11 = bitcast i32* %5 to i8*
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_DGRAM
%15 = tail call i32 @socket(i32 %13, i32 %14, i32 0)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %0
%18 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %0
%21 = call i32 @memset(%struct.sockaddr_in* %1, i32 0, i32 12)
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %22, i32* %23
%24 = load i32, i32* @INADDR_ANY
%25 = call i32 @htonl(i32 %24)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %25, i32* %26
%27 = call i32 @htons(i32 50005)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %27, i32* %28
%29 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%30 = call i64 @bind(i32 %15, %struct.sockaddr* %29, i32 12)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %20
%33 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %20
%36 = load i32, i32* @SIGCHLD
%37 = load i32, i32* @SIG_IGN
%38 = call i64 @signal(i32 %36, i32 %37)
%39 = load i64, i64* @SIG_ERR
%40 = icmp eq i64 %38, %39
br i1 %40, label %41, label %43
41: ; preds = %35
%42 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %43
43: ; preds = %41, %35
%44 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
store i32 12, i32* %3
%45 = call i32 @recvfrom(i32 %15, i8* %12, i32 1024, i32 0, %struct.sockaddr* %44, i32* %3)
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %103, %43
%48 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %43, %103
%51 = phi i32 [ %104, %103 ], [ %45, %43 ]
%52 = call i32 (...) @fork()
switch i32 %52, label %103 [
i32 0, label %53
i32 -1, label %101
]
53: ; preds = %50
%54 = call i32 @close(i32 %15)
%55 = load i32, i32* @AF_INET
%56 = load i32, i32* @SOCK_DGRAM
%57 = call i32 @socket(i32 %55, i32 %56, i32 0)
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %62
59: ; preds = %53
%60 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%61 = call i32 @exit(i32 1)
unreachable
62: ; preds = %53
%63 = call i32 @connect(i32 %57, %struct.sockaddr* %44, i32 12)
%64 = icmp eq i32 %63, -1
br i1 %64, label %69, label %65
65: ; preds = %62
%66 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%67 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%68 = add nuw nsw i32 %57, 1
br label %72
69: ; preds = %62
%70 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%71 = call i32 @exit(i32 1)
unreachable
72: ; preds = %65, %92
%73 = phi i32 [ %93, %92 ], [ %51, %65 ]
%74 = icmp sgt i32 %73, 0
br i1 %74, label %75, label %98
75: ; preds = %72
%76 = call i32 @FD_ZERO(i32* %5)
%77 = call i32 @FD_SET(i32 %57, i32* %5)
store i32 120, i32* %66
store i32 0, i32* %67
%78 = call i32 @write(i32 %57, i8* %12, i32 %73)
%79 = icmp eq i32 %78, -1
br i1 %79, label %80, label %83
80: ; preds = %75
%81 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%82 = call i32 @exit(i32 1)
unreachable
83: ; preds = %75
%84 = call i32 @select(i32 %68, i32* %5, i32* null, i32* null, %struct.timeval* %4)
switch i32 %84, label %92 [
i32 0, label %85
i32 -1, label %89
]
85: ; preds = %83
%86 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
%87 = call i32 @close(i32 %57)
%88 = call i32 @exit(i32 1)
unreachable
89: ; preds = %83
%90 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0))
%91 = call i32 @exit(i32 1)
unreachable
92: ; preds = %83
%93 = call i32 @read(i32 %57, i8* %12, i32 1024)
%94 = icmp eq i32 %93, -1
br i1 %94, label %95, label %72
95: ; preds = %92
%96 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0))
%97 = call i32 @exit(i32 1)
unreachable
98: ; preds = %72
%99 = call i32 @close(i32 %57)
%100 = call i32 @exit(i32 0)
unreachable
101: ; preds = %50
%102 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
br label %103
103: ; preds = %101, %50
store i32 12, i32* %3
%104 = call i32 @recvfrom(i32 %15, i8* %12, i32 1024, i32 0, %struct.sockaddr* %44, i32* %3)
%105 = icmp slt i32 %104, 0
br i1 %105, label %47, label %50
}