#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 */

/* Type definitions */
typedef char uint32_t;
struct stat {
  long st_size;
};
typedef long ssize_t;
typedef int /*<<< orphan*/ dim_file_net;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ clean_buff(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, ...);
int /*<<< orphan*/ free(char *);
int fstat(int, struct stat *);
int get_management_to_other_servers(int, char *, int);
char htonl(char);
scalar_t__ malloc(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
long send_file(int, int, long);
long send_stuff(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int strlen(char *);
int get_management(int sockfd, char *filename, int thread_id) {
  int fd;
  long int dim_file;
  char *buff;
  ssize_t nwrite;
  struct stat stat_buf;
  uint32_t dim_file_net;
  buff = (char *)malloc(1024 * sizeof(char));
  if (buff == NULL) {
    fprintf(stderr,
            "Thread %d -> ERROR 08: cannot allocate memory for buffer.\n",
            thread_id);
    return (-1);
  }
  fprintf(stdout, "Thread %d -> file selected: %s\n", thread_id, filename);
  fd = open(filename, O_RDONLY);
  if (fd == -1) {
    fprintf(stdout, "Thread %d -> file doesn't exist\n", thread_id);
    free(buff);
    close(fd);
    return (get_management_to_other_servers(sockfd, filename, thread_id));
  } else {
    fprintf(stdout, "Thread %d -> the file exists, sending notification...\n",
            thread_id);
    clean_buff(buff);
    nwrite = send_stuff(sockfd, "+OK\r\n", strlen("+OK\r\n"));
    if (nwrite < 0) {
      fprintf(stderr,
              "Thread %d -> ERROR 09: error during sending \"+OK\" reply.\n",
              thread_id);
      free(buff);
      return (-1);
    }
    fprintf(stdout, "Thread %d -> [OK]\n", thread_id);
    fprintf(stdout, "Thread %d -> get the information of the file...\n",
            thread_id);
    if (fstat(fd, &stat_buf) == -1) {
      perror("Cannot open file descriptor");
      free(buff);
      close(fd);
      return (-1);
    }
    dim_file = stat_buf.st_size;
    fprintf(stdout, "Thread %d -> [OK]\n", thread_id);
    dim_file_net = htonl((uint32_t)dim_file);
    fprintf(stdout, "Thread %d -> send dimension of the file...\n", thread_id);
    clean_buff(buff);
    nwrite = send_stuff(sockfd, &dim_file_net, sizeof(dim_file_net));
    if (nwrite < 0) {
      fprintf(stderr,
              "Thread %d -> ERROR 10: error during sending information about "
              "the file.\n",
              thread_id);
      free(buff);
      close(fd);
      return (-2);
    }
    fprintf(stdout, "Thread %d -> dimension sent, value:%ld\n", thread_id,
            dim_file);
    fprintf(stdout, "Thread %d -> [OK]\n", thread_id);
    fprintf(stdout, "Thread %d -> send the selected file...\n", thread_id);
    clean_buff(buff);
    nwrite = send_file(sockfd, fd, dim_file);
    if (nwrite != dim_file) {
      fprintf(stderr, "Thread %d -> ERROR 11: error during sending the file.\n",
              thread_id);
      return (-2);
    }
    fprintf(stdout, "Thread %d -> [OK]\n", thread_id);
    free(buff);
    close(fd);
    return (1);
  }
}


x86 assembly (clang, -O0):
<get_management>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    $0x400,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1221 <get_management+0x51>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xdf2(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1515 <get_management+0x345>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%rcx
lea    0xe03(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2d9e(%rip),%rax
mov    (%rax),%esi
call   10c0 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    12a0 <get_management+0xd0>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xdea(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%edi
call   1080 <close@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   10b0 <get_management_to_other_servers@plt>
mov    %eax,-0x4(%rbp)
jmp    1515 <get_management+0x345>
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xdc9(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <clean_buff@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x40(%rbp)
lea    0xde3(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x40(%rbp),%edi
mov    %eax,%edx
lea    0xdd2(%rip),%rsi
call   1060 <send_stuff@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jge    1324 <get_management+0x154>
mov    0x2cdc(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xdb1(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1515 <get_management+0x345>
mov    0x2ca5(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xdbc(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2c8b(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xdb5(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x18(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   10f0 <fstat@plt>
cmp    $0xffffffff,%eax
jne    1396 <get_management+0x1c6>
lea    0xdc3(%rip),%rdi
call   10d0 <perror@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1515 <get_management+0x345>
mov    -0x38(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2c2b(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xd42(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x20(%rbp),%rax
movsbl %al,%edi
call   1070 <htonl@plt>
mov    %al,-0x39(%rbp)
mov    0x2c02(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xd79(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <clean_buff@plt>
mov    -0x8(%rbp),%edi
lea    -0x39(%rbp),%rsi
mov    $0x1,%edx
call   1060 <send_stuff@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jge    1441 <get_management+0x271>
mov    0x2bc7(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xd62(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%edi
call   1080 <close@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1515 <get_management+0x345>
mov    0x2b88(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
lea    0xd70(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2b6a(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xc81(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2b50(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xd64(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <clean_buff@plt>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   10e0 <send_file@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     14e3 <get_management+0x313>
mov    0x2b14(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xd48(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1515 <get_management+0x345>
mov    0x2ae6(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xbfd(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%edi
call   1080 <close@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_management>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r12d
mov    %rsi,%rbp
mov    %edi,%r13d
mov    $0x400,%edi
call   10a0 <malloc@plt>
test   %rax,%rax
je     139d <get_management+0x1cd>
mov    %rax,%r14
mov    0x2dcc(%rip),%r15
mov    (%r15),%edi
lea    0xe2d(%rip),%rsi
mov    %r12d,%edx
mov    %rbp,%rcx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x2dc6(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   10c0 <open@plt>
mov    (%r15),%edi
cmp    $0xffffffff,%eax
je     13c1 <get_management+0x1f1>
mov    %eax,%ebx
lea    0xe3b(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r14,%rdi
call   1040 <clean_buff@plt>
lea    0xe59(%rip),%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1060 <send_stuff@plt>
test   %rax,%rax
js     1400 <get_management+0x230>
mov    (%r15),%edi
lea    0xe71(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    (%r15),%edi
lea    0xe70(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
call   10f0 <fstat@plt>
cmp    $0xffffffff,%eax
je     1482 <get_management+0x2b2>
mov    %ebx,%ebp
mov    0x10(%rsp),%rbx
mov    (%r15),%edi
lea    0xe2d(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
movsbl %bl,%edi
call   1070 <htonl@plt>
mov    %al,0xf(%rsp)
mov    (%r15),%edi
lea    0xe6d(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r14,%rdi
call   1040 <clean_buff@plt>
lea    0xf(%rsp),%rsi
mov    %r13d,%edi
mov    $0x1,%edx
call   1060 <send_stuff@plt>
test   %rax,%rax
js     1429 <get_management+0x259>
mov    (%r15),%edi
lea    0xeab(%rip),%rsi
mov    %r12d,%edx
mov    %rbx,%rcx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    (%r15),%edi
lea    0xdbf(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    (%r15),%edi
lea    0xea8(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r14,%rdi
call   1040 <clean_buff@plt>
mov    %r13d,%edi
mov    %ebp,%esi
mov    %rbx,%rdx
call   10e0 <send_file@plt>
cmp    %rbx,%rax
jne    1454 <get_management+0x284>
mov    (%r15),%edi
lea    0xd79(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebp,%edi
call   1080 <close@plt>
mov    $0x1,%eax
jmp    1473 <get_management+0x2a3>
mov    0x2c34(%rip),%rax
mov    (%rax),%edi
lea    0xc53(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1473 <get_management+0x2a3>
lea    0xc93(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    $0xffffffff,%edi
call   1080 <close@plt>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    %r12d,%edx
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10b0 <get_management_to_other_servers@plt>
mov    0x2bd1(%rip),%rax
mov    (%rax),%edi
lea    0xca9(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    $0xffffffff,%eax
jmp    1473 <get_management+0x2a3>
mov    0x2ba8(%rip),%rax
mov    (%rax),%edi
lea    0xd46(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebp,%edi
call   1080 <close@plt>
jmp    146e <get_management+0x29e>
mov    0x2b7d(%rip),%rax
mov    (%rax),%edi
lea    0xdb4(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0xfffffffe,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcae(%rip),%rdi
call   10d0 <perror@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebx,%edi
call   1080 <close@plt>
mov    $0xffffffff,%eax
jmp    1473 <get_management+0x2a3>

LLVM IR (-O0):
%struct.stat = type { i64 }
@stderr = global i32 0
@.str = [59 x i8] c"Thread %d -> ERROR 08: cannot allocate memory for buffer.\0A\00"
@stdout = global i32 0
@.str.1 = [32 x i8] c"Thread %d -> file selected: %s\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [33 x i8] c"Thread %d -> file doesn't exist\0A\00"
@.str.3 = [55 x i8] c"Thread %d -> the file exists, sending notification...\0A\00"
@.str.4 = [6 x i8] c"+OK\0D\0A\00"
@.str.5 = [58 x i8] c"Thread %d -> ERROR 09: error during sending \22+OK\22 reply.\0A\00"
@.str.6 = [19 x i8] c"Thread %d -> [OK]\0A\00"
@.str.7 = [49 x i8] c"Thread %d -> get the information of the file...\0A\00"
@.str.8 = [28 x i8] c"Cannot open file descriptor\00"
@.str.9 = [44 x i8] c"Thread %d -> send dimension of the file...\0A\00"
@.str.10 = [73 x i8] c"Thread %d -> ERROR 10: error during sending information about the file.\0A\00"
@.str.11 = [40 x i8] c"Thread %d -> dimension sent, value:%ld\0A\00"
@.str.12 = [40 x i8] c"Thread %d -> send the selected file...\0A\00"
@.str.13 = [55 x i8] c"Thread %d -> ERROR 11: error during sending the file.\0A\00"
define i32 @get_management(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i64
%12 = alloca %struct.stat
%13 = alloca i8
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%14 = call i64 @malloc(i32 1024)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %10
%16 = load i8*, i8** %10
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %22
18: ; preds = %3
%19 = load i32, i32* @stderr
%20 = load i32, i32* %7
%21 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i32 %20)
store i32 -1, i32* %4
br label %135
22: ; preds = %3
%23 = load i32, i32* @stdout
%24 = load i32, i32* %7
%25 = load i8*, i8** %6
%26 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %24, i8* %25)
%27 = load i8*, i8** %6
%28 = load i32, i32* @O_RDONLY
%29 = call i32 @open(i8* %27, i32 %28)
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %44
32: ; preds = %22
%33 = load i32, i32* @stdout
%34 = load i32, i32* %7
%35 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%36 = load i8*, i8** %10
%37 = call i32 @free(i8* %36)
%38 = load i32, i32* %8
%39 = call i32 @close(i32 %38)
%40 = load i32, i32* %5
%41 = load i8*, i8** %6
%42 = load i32, i32* %7
%43 = call i32 @get_management_to_other_servers(i32 %40, i8* %41, i32 %42)
store i32 %43, i32* %4
br label %135
44: ; preds = %22
%45 = load i32, i32* @stdout
%46 = load i32, i32* %7
%47 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0), i32 %46)
%48 = load i8*, i8** %10
%49 = call i32 @clean_buff(i8* %48)
%50 = load i32, i32* %5
%51 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%52 = call i64 @send_stuff(i32 %50, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %51)
store i64 %52, i64* %11
%53 = load i64, i64* %11
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %61
55: ; preds = %44
%56 = load i32, i32* @stderr
%57 = load i32, i32* %7
%58 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.5, i64 0, i64 0), i32 %57)
%59 = load i8*, i8** %10
%60 = call i32 @free(i8* %59)
store i32 -1, i32* %4
br label %135
61: ; preds = %44
%62 = load i32, i32* @stdout
%63 = load i32, i32* %7
%64 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i32 %63)
%65 = load i32, i32* @stdout
%66 = load i32, i32* %7
%67 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.7, i64 0, i64 0), i32 %66)
%68 = load i32, i32* %8
%69 = call i32 @fstat(i32 %68, %struct.stat* %12)
%70 = icmp eq i32 %69, -1
br i1 %70, label %71, label %77
71: ; preds = %61
%72 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0))
%73 = load i8*, i8** %10
%74 = call i32 @free(i8* %73)
%75 = load i32, i32* %8
%76 = call i32 @close(i32 %75)
store i32 -1, i32* %4
br label %135
77: ; preds = %61
%78 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 0
%79 = load i64, i64* %78
store i64 %79, i64* %9
%80 = load i32, i32* @stdout
%81 = load i32, i32* %7
%82 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i32 %81)
%83 = load i64, i64* %9
%84 = trunc i64 %83 to i8
%85 = call signext i8 @htonl(i8 signext %84)
store i8 %85, i8* %13
%86 = load i32, i32* @stdout
%87 = load i32, i32* %7
%88 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.9, i64 0, i64 0), i32 %87)
%89 = load i8*, i8** %10
%90 = call i32 @clean_buff(i8* %89)
%91 = load i32, i32* %5
%92 = call i64 @send_stuff(i32 %91, i8* %13, i32 1)
store i64 %92, i64* %11
%93 = load i64, i64* %11
%94 = icmp slt i64 %93, 0
br i1 %94, label %95, label %103
95: ; preds = %77
%96 = load i32, i32* @stderr
%97 = load i32, i32* %7
%98 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %96, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.10, i64 0, i64 0), i32 %97)
%99 = load i8*, i8** %10
%100 = call i32 @free(i8* %99)
%101 = load i32, i32* %8
%102 = call i32 @close(i32 %101)
store i32 -2, i32* %4
br label %135
103: ; preds = %77
%104 = load i32, i32* @stdout
%105 = load i32, i32* %7
%106 = load i64, i64* %9
%107 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %104, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.11, i64 0, i64 0), i32 %105, i64 %106)
%108 = load i32, i32* @stdout
%109 = load i32, i32* %7
%110 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %108, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i32 %109)
%111 = load i32, i32* @stdout
%112 = load i32, i32* %7
%113 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %111, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.12, i64 0, i64 0), i32 %112)
%114 = load i8*, i8** %10
%115 = call i32 @clean_buff(i8* %114)
%116 = load i32, i32* %5
%117 = load i32, i32* %8
%118 = load i64, i64* %9
%119 = call i64 @send_file(i32 %116, i32 %117, i64 %118)
store i64 %119, i64* %11
%120 = load i64, i64* %11
%121 = load i64, i64* %9
%122 = icmp ne i64 %120, %121
br i1 %122, label %123, label %127
123: ; preds = %103
%124 = load i32, i32* @stderr
%125 = load i32, i32* %7
%126 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %124, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.13, i64 0, i64 0), i32 %125)
store i32 -2, i32* %4
br label %135
127: ; preds = %103
%128 = load i32, i32* @stdout
%129 = load i32, i32* %7
%130 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %128, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i32 %129)
%131 = load i8*, i8** %10
%132 = call i32 @free(i8* %131)
%133 = load i32, i32* %8
%134 = call i32 @close(i32 %133)
store i32 1, i32* %4
br label %135
135: ; preds = %127, %123, %95, %71, %55, %32, %18
%136 = load i32, i32* %4
ret i32 %136
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@stderr = global i32 0
@.str = [59 x i8] c"Thread %d -> ERROR 08: cannot allocate memory for buffer.\0A\00"
@stdout = global i32 0
@.str.1 = [32 x i8] c"Thread %d -> file selected: %s\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [33 x i8] c"Thread %d -> file doesn't exist\0A\00"
@.str.3 = [55 x i8] c"Thread %d -> the file exists, sending notification...\0A\00"
@.str.4 = [6 x i8] c"+OK\0D\0A\00"
@.str.5 = [58 x i8] c"Thread %d -> ERROR 09: error during sending \22+OK\22 reply.\0A\00"
@.str.6 = [19 x i8] c"Thread %d -> [OK]\0A\00"
@.str.7 = [49 x i8] c"Thread %d -> get the information of the file...\0A\00"
@.str.8 = [28 x i8] c"Cannot open file descriptor\00"
@.str.9 = [44 x i8] c"Thread %d -> send dimension of the file...\0A\00"
@.str.10 = [73 x i8] c"Thread %d -> ERROR 10: error during sending information about the file.\0A\00"
@.str.11 = [40 x i8] c"Thread %d -> dimension sent, value:%ld\0A\00"
@.str.12 = [40 x i8] c"Thread %d -> send the selected file...\0A\00"
@.str.13 = [55 x i8] c"Thread %d -> ERROR 11: error during sending the file.\0A\00"
define i32 @get_management(i32 %0, i8* %1, i32 %2) {
%4 = alloca %struct.stat
%5 = alloca i8
%6 = bitcast %struct.stat* %4 to i8*
%7 = tail call i64 @malloc(i32 1024)
%8 = inttoptr i64 %7 to i8*
%9 = icmp eq i64 %7, 0
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i32 %2)
br label %81
13: ; preds = %3
%14 = load i32, i32* @stdout
%15 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %2, i8* %1)
%16 = load i32, i32* @O_RDONLY
%17 = tail call i32 @open(i8* %1, i32 %16)
%18 = icmp eq i32 %17, -1
%19 = load i32, i32* @stdout
br i1 %18, label %20, label %25
20: ; preds = %13
%21 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %2)
%22 = tail call i32 @free(i8* %8)
%23 = tail call i32 @close(i32 -1)
%24 = tail call i32 @get_management_to_other_servers(i32 %0, i8* %1, i32 %2)
br label %81
25: ; preds = %13
%26 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0), i32 %2)
%27 = tail call i32 @clean_buff(i8* %8)
%28 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%29 = tail call i64 @send_stuff(i32 %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %28)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %25
%32 = load i32, i32* @stderr
%33 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.5, i64 0, i64 0), i32 %2)
%34 = tail call i32 @free(i8* %8)
br label %81
35: ; preds = %25
%36 = load i32, i32* @stdout
%37 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i32 %2)
%38 = load i32, i32* @stdout
%39 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.7, i64 0, i64 0), i32 %2)
%40 = call i32 @fstat(i32 %17, %struct.stat* %4)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %46
42: ; preds = %35
%43 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0))
%44 = tail call i32 @free(i8* %8)
%45 = tail call i32 @close(i32 %17)
br label %81
46: ; preds = %35
%47 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%48 = load i64, i64* %47
%49 = load i32, i32* @stdout
%50 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i32 %2)
%51 = trunc i64 %48 to i8
%52 = tail call signext i8 @htonl(i8 signext %51)
store i8 %52, i8* %5
%53 = load i32, i32* @stdout
%54 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.9, i64 0, i64 0), i32 %2)
%55 = tail call i32 @clean_buff(i8* %8)
%56 = call i64 @send_stuff(i32 %0, i8* %5, i32 1)
%57 = icmp slt i64 %56, 0
br i1 %57, label %58, label %63
58: ; preds = %46
%59 = load i32, i32* @stderr
%60 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.10, i64 0, i64 0), i32 %2)
%61 = call i32 @free(i8* %8)
%62 = call i32 @close(i32 %17)
br label %81
63: ; preds = %46
%64 = load i32, i32* @stdout
%65 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.11, i64 0, i64 0), i32 %2, i64 %48)
%66 = load i32, i32* @stdout
%67 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i32 %2)
%68 = load i32, i32* @stdout
%69 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.12, i64 0, i64 0), i32 %2)
%70 = call i32 @clean_buff(i8* %8)
%71 = call i64 @send_file(i32 %0, i32 %17, i64 %48)
%72 = icmp eq i64 %71, %48
br i1 %72, label %76, label %73
73: ; preds = %63
%74 = load i32, i32* @stderr
%75 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.13, i64 0, i64 0), i32 %2)
br label %81
76: ; preds = %63
%77 = load i32, i32* @stdout
%78 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i32 %2)
%79 = call i32 @free(i8* %8)
%80 = call i32 @close(i32 %17)
br label %81
81: ; preds = %76, %73, %58, %42, %31, %20, %10
%82 = phi i32 [ -1, %10 ], [ %24, %20 ], [ -1, %31 ], [ -1, %42 ], [ -2, %58 ], [ -2, %73 ], [ 1, %76 ]
ret i32 %82
}