#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 {
  scalar_t__ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ server;
typedef int /*<<< orphan*/ in_name;
typedef int /*<<< orphan*/ client;
typedef int /*<<< orphan*/ c;
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr_in *, int *);
scalar_t__ bind(int, struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char getc(int /*<<< orphan*/ *);
scalar_t__ getsockname(int, struct sockaddr *, int *);
scalar_t__ listen(int, int);
int ntohs(scalar_t__);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
main() {
  int sockint, s;
  int namelen;
  int ns;
  struct sockaddr_in client;
  struct sockaddr_in server;
  char buf[32];
  s = socket(AF_INET, SOCK_STREAM, 0);
  if (s == -1) {
    fprintf(stderr, "SRV--ERRO em socket()\n");
    exit(2);
  } else
    fprintf(stderr, "SRV--Socket criado com sucesso\n");
  server.sin_family = AF_INET;
  server.sin_port = 0;
  server.sin_addr.s_addr = INADDR_ANY;
  if (bind(s, &server, sizeof(server)) < 0) {
    fprintf(stderr, "SRV--Erro em bind()\n");
    exit(3);
  }
  namelen = sizeof(server);
  if (getsockname(s, (struct sockaddr *)&server, &namelen) < 0) {
    fprintf(stderr, "SRV--Erro em getsockname()\n");
    exit(4);
  }
  fprintf(stderr, "SRV--Numero de porta : %d\n", ntohs(server.sin_port));
  if (listen(s, 1) != 0) {
    fprintf(stderr, "SRV--Erro em listen()\n");
    exit(5);
  }
  namelen = sizeof(client);
  if ((ns = accept(s, &client, &namelen)) == -1) {
    fprintf(stderr, "SRV--Erro em accept()\n");
    exit(6);
  }
  char in_name[25], out_name[25];
  FILE *in_file, *out_file, *fopen();
  char c;
  if (recv(ns, in_name, sizeof(in_name), 0) == -1) {
    fprintf(stderr, "SRV--Erro em recv() - 01\n");
    exit(7);
  }
  in_file = fopen(in_name, "r");
  printf("\nSRV--Arquivo para copiar: %s\n", in_name);
  if (in_file == NULL)
    printf("SRV--Cannot open %s for reading.\n", in_name);
  else {
    in_file = fopen(in_name, "r");
    if (in_file == NULL)
      printf("SRV--Can't open %s for writing.\n", in_name);
    else {
      if (in_file != NULL)
        printf("\narquivo %s aberto com sucesso\n", in_name);
      while (!feof(in_file)) {
        c = getc(in_file);
        printf("\nSRV--var c dentro do while: %c\n", c);
        if (!send(ns, c, sizeof(c), 0) < 0) {
          fprintf(stderr, "SRV--Erro em send() - dentro while\n");
          exit(8);
        }
        printf("\nSRV--var c dentro do while depois de send: %c\n", c);
        if (recv(ns, buf, sizeof(buf), 0) == -1) {
          fprintf(stderr, "SRV--Erro em recv()\n");
          exit(7);
        }
      }
      printf("SRV--O arquivo foi copiado.\n");
      fclose(in_file);
    }
    printf("\nSRV--fechando o arquivo!!!\n");
  }
  close(ns);
  close(s);
  printf("SRV--Servidor finalizado\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
mov    0x2da6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1259 <main+0x59>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
lea    0xdb8(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x2,%edi
call   1100 <exit@plt>
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
lea    0xdae(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2d71(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
movq   $0x0,-0x38(%rbp)
mov    0x2d55(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0x10,%edx
call   10c0 <bind@plt>
cmp    $0x0,%rax
jge    12cc <main+0xcc>
mov    0x2d1e(%rip),%rax
mov    (%rax),%edi
lea    0xd7c(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x3,%edi
call   1100 <exit@plt>
movl   $0x10,-0x10(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x38(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   10f0 <getsockname@plt>
cmp    $0x0,%rax
jge    130e <main+0x10e>
mov    0x2cdc(%rip),%rax
mov    (%rax),%edi
lea    0xd4f(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x4,%edi
call   1100 <exit@plt>
mov    0x2cbb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xb8(%rbp)
mov    -0x38(%rbp),%rdi
call   10b0 <ntohs@plt>
mov    -0xb8(%rbp),%edi
mov    %eax,%edx
lea    0xd33(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0xc(%rbp),%edi
mov    $0x1,%esi
call   10a0 <listen@plt>
cmp    $0x0,%rax
je     1374 <main+0x174>
mov    0x2c76(%rip),%rax
mov    (%rax),%edi
lea    0xd20(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x5,%edi
call   1100 <exit@plt>
movl   $0x10,-0x10(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   10e0 <accept@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    13b8 <main+0x1b8>
mov    0x2c32(%rip),%rax
mov    (%rax),%edi
lea    0xcf3(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x6,%edi
call   1100 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x19,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0xffffffff,%eax
jne    13f5 <main+0x1f5>
mov    0x2bf5(%rip),%rax
mov    (%rax),%edi
lea    0xccd(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x7,%edi
call   1100 <exit@plt>
lea    -0x80(%rbp),%rdi
lea    0xccb(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0xa8(%rbp)
lea    -0x80(%rbp),%rsi
lea    0xcb6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpq   $0x0,-0xa8(%rbp)
jne    1443 <main+0x243>
lea    -0x80(%rbp),%rsi
lea    0xcb5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    15b8 <main+0x3b8>
lea    -0x80(%rbp),%rdi
lea    0xc7d(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0xa8(%rbp)
cmpq   $0x0,-0xa8(%rbp)
jne    147f <main+0x27f>
lea    -0x80(%rbp),%rsi
lea    0xc9b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    15aa <main+0x3aa>
cmpq   $0x0,-0xa8(%rbp)
je     149f <main+0x29f>
lea    -0x80(%rbp),%rsi
lea    0xc97(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    14a4 <main+0x2a4>
mov    -0xa8(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    14c5 <main+0x2c5>
jmp    1590 <main+0x390>
mov    -0xa8(%rbp),%rdi
call   1110 <getc@plt>
mov    %al,-0xb1(%rbp)
movsbl -0xb1(%rbp),%esi
lea    0xc6a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
mov    $0x1,%edx
xor    %ecx,%ecx
movsbl -0xb1(%rbp),%esi
call   1050 <send@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
cmp    $0x0,%eax
jge    1539 <main+0x339>
mov    0x2ab1(%rip),%rax
mov    (%rax),%edi
lea    0xc48(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x8,%edi
call   1100 <exit@plt>
movsbl -0xb1(%rbp),%esi
lea    0xc4d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x20,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0xffffffff,%eax
jne    158b <main+0x38b>
mov    0x2a5f(%rip),%rax
mov    (%rax),%edi
lea    0xc4a(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x7,%edi
call   1100 <exit@plt>
jmp    14a4 <main+0x2a4>
lea    0xc42(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0xa8(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xc45(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
lea    0xc44(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   1100 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    0x2dc3(%rip),%rbx
mov    (%rbx),%edi
mov    0x2d9a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    0x2d92(%rip),%r15
mov    (%r15),%edi
cmp    $0xffffffff,%eax
jne    125e <main+0x4e>
lea    0xdb3(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x2,%edi
call   1110 <exit@plt>
mov    %eax,%r14d
lea    0xdaf(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    (%rbx),%eax
mov    %eax,0x1c(%rsp)
movq   $0x0,0x10(%rsp)
mov    0x2d5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
lea    0x10(%rsp),%rsi
mov    %r14d,%edi
mov    $0x10,%edx
call   10d0 <bind@plt>
test   %rax,%rax
jns    12bd <main+0xad>
mov    (%r15),%edi
lea    0xd8b(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x3,%edi
call   1110 <exit@plt>
movl   $0x10,0x8(%rsp)
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %r14d,%edi
call   1100 <getsockname@plt>
mov    (%r15),%ebx
test   %rax,%rax
jns    12f9 <main+0xe9>
lea    0xd66(%rip),%rsi
mov    %ebx,%edi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x4,%edi
call   1110 <exit@plt>
mov    0x10(%rsp),%rdi
call   10c0 <ntohs@plt>
lea    0xd5e(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r14d,%edi
mov    $0x1,%esi
call   10b0 <listen@plt>
test   %rax,%rax
jne    1361 <main+0x151>
movl   $0x10,0x8(%rsp)
lea    0x40(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %r14d,%edi
call   10f0 <accept@plt>
cmp    $0xffffffff,%eax
jne    137c <main+0x16c>
mov    (%r15),%edi
lea    0xd4a(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x6,%edi
call   1110 <exit@plt>
mov    (%r15),%edi
lea    0xd18(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x5,%edi
call   1110 <exit@plt>
mov    %eax,%ebp
lea    0x20(%rsp),%rsi
mov    %eax,%edi
mov    $0x19,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0xffffffff,%eax
jne    13b1 <main+0x1a1>
mov    (%r15),%edi
lea    0xd11(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x7,%edi
call   1110 <exit@plt>
lea    0xd13(%rip),%rsi
lea    0x20(%rsp),%r15
mov    %r15,%rdi
call   10e0 <fopen@plt>
mov    %rax,%rbx
lea    0xcfe(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
test   %rbx,%rbx
jne    13f6 <main+0x1e6>
lea    0xd07(%rip),%rdi
lea    0x20(%rsp),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    14f3 <main+0x2e3>
lea    0xcce(%rip),%rsi
lea    0x20(%rsp),%rdi
call   10e0 <fopen@plt>
test   %rax,%rax
jne    1424 <main+0x214>
lea    0xcfb(%rip),%rdi
lea    0x20(%rsp),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    14e7 <main+0x2d7>
mov    %rax,%rbx
mov    %r14d,0xc(%rsp)
lea    0xcfc(%rip),%rdi
lea    0x20(%rsp),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xd09(%rip),%r15
lea    0xd23(%rip),%r12
lea    0x50(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
jne    14ce <main+0x2be>
mov    %rbx,%rdi
call   1120 <getc@plt>
movsbl %al,%r14d
mov    %r15,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebp,%edi
mov    %r14d,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %r12,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebp,%edi
mov    %r13,%rsi
mov    $0x20,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0xffffffff,%eax
jne    1460 <main+0x250>
mov    0x2b10(%rip),%rax
mov    (%rax),%edi
lea    0xcd7(%rip),%rsi
jmp    13a0 <main+0x190>
lea    0xce0(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    0xc(%rsp),%r14d
lea    0xce3(%rip),%rdi
call   1040 <puts@plt>
mov    %ebp,%edi
call   1080 <close@plt>
mov    %r14d,%edi
call   1080 <close@plt>
lea    0xce4(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1110 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i64, %struct.TYPE_2__, 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 = [23 x i8] c"SRV--ERRO em socket()\0A\00"
@.str.1 = [32 x i8] c"SRV--Socket criado com sucesso\0A\00"
@INADDR_ANY = global i32 0
@.str.2 = [21 x i8] c"SRV--Erro em bind()\0A\00"
@.str.3 = [28 x i8] c"SRV--Erro em getsockname()\0A\00"
@.str.4 = [27 x i8] c"SRV--Numero de porta : %d\0A\00"
@.str.5 = [23 x i8] c"SRV--Erro em listen()\0A\00"
@.str.6 = [23 x i8] c"SRV--Erro em accept()\0A\00"
@.str.7 = [26 x i8] c"SRV--Erro em recv() - 01\0A\00"
@.str.8 = [2 x i8] c"r\00"
@.str.9 = [31 x i8] c"\0ASRV--Arquivo para copiar: %s\0A\00"
@.str.10 = [34 x i8] c"SRV--Cannot open %s for reading.\0A\00"
@.str.11 = [33 x i8] c"SRV--Can't open %s for writing.\0A\00"
@.str.12 = [32 x i8] c"\0Aarquivo %s aberto com sucesso\0A\00"
@.str.13 = [33 x i8] c"\0ASRV--var c dentro do while: %c\0A\00"
@.str.14 = [36 x i8] c"SRV--Erro em send() - dentro while\0A\00"
@.str.15 = [48 x i8] c"\0ASRV--var c dentro do while depois de send: %c\0A\00"
@.str.16 = [21 x i8] c"SRV--Erro em recv()\0A\00"
@.str.17 = [29 x i8] c"SRV--O arquivo foi copiado.\0A\00"
@.str.18 = [29 x i8] c"\0ASRV--fechando o arquivo!!!\0A\00"
@.str.19 = [26 x i8] c"SRV--Servidor finalizado\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]
%9 = alloca [25 x i8]
%10 = alloca [25 x i8]
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i8
store i32 0, i32* %1
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = call i32 @socket(i32 %14, i32 %15, i32 0)
store i32 %16, i32* %3
%17 = load i32, i32* %3
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %23
19: ; preds = %0
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @exit(i32 2)
unreachable
23: ; preds = %0
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %23
%27 = load i32, i32* @AF_INET
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %27, i32* %28
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i64 0, i64* %29
%30 = load i32, i32* @INADDR_ANY
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%32 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %31, i32 0, i32 0
store i32 %30, i32* %32
%33 = load i32, i32* %3
%34 = call i64 @bind(i32 %33, %struct.sockaddr_in* %7, i32 16)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %26
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%39 = call i32 @exit(i32 3)
unreachable
40: ; preds = %26
store i32 16, i32* %4
%41 = load i32, i32* %3
%42 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%43 = call i64 @getsockname(i32 %41, %struct.sockaddr* %42, i32* %4)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %40
%46 = load i32, i32* @stderr
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%48 = call i32 @exit(i32 4)
unreachable
49: ; preds = %40
%50 = load i32, i32* @stderr
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%52 = load i64, i64* %51
%53 = call i32 @ntohs(i64 %52)
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %53)
%55 = load i32, i32* %3
%56 = call i64 @listen(i32 %55, i32 1)
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %62
58: ; preds = %49
%59 = load i32, i32* @stderr
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%61 = call i32 @exit(i32 5)
unreachable
62: ; preds = %49
store i32 16, i32* %4
%63 = load i32, i32* %3
%64 = call i32 @accept(i32 %63, %struct.sockaddr_in* %6, i32* %4)
store i32 %64, i32* %5
%65 = icmp eq i32 %64, -1
br i1 %65, label %66, label %70
66: ; preds = %62
%67 = load i32, i32* @stderr
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
%69 = call i32 @exit(i32 6)
unreachable
70: ; preds = %62
%71 = load i32, i32* %5
%72 = getelementptr inbounds [25 x i8], [25 x i8]* %9, i64 0, i64 0
%73 = call i32 @recv(i32 %71, i8* %72, i32 25, i32 0)
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %79
75: ; preds = %70
%76 = load i32, i32* @stderr
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0))
%78 = call i32 @exit(i32 7)
unreachable
79: ; preds = %70
%80 = getelementptr inbounds [25 x i8], [25 x i8]* %9, i64 0, i64 0
%81 = call i32* @fopen(i8* %80, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
store i32* %81, i32** %11
%82 = getelementptr inbounds [25 x i8], [25 x i8]* %9, i64 0, i64 0
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i8* %82)
%84 = load i32*, i32** %11
%85 = icmp eq i32* %84, null
br i1 %85, label %86, label %89
86: ; preds = %79
%87 = getelementptr inbounds [25 x i8], [25 x i8]* %9, i64 0, i64 0
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.10, i64 0, i64 0), i8* %87)
br label %145
89: ; preds = %79
%90 = getelementptr inbounds [25 x i8], [25 x i8]* %9, i64 0, i64 0
%91 = call i32* @fopen(i8* %90, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
store i32* %91, i32** %11
%92 = load i32*, i32** %11
%93 = icmp eq i32* %92, null
br i1 %93, label %94, label %97
94: ; preds = %89
%95 = getelementptr inbounds [25 x i8], [25 x i8]* %9, i64 0, i64 0
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.11, i64 0, i64 0), i8* %95)
br label %143
97: ; preds = %89
%98 = load i32*, i32** %11
%99 = icmp ne i32* %98, null
br i1 %99, label %100, label %103
100: ; preds = %97
%101 = getelementptr inbounds [25 x i8], [25 x i8]* %9, i64 0, i64 0
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.12, i64 0, i64 0), i8* %101)
br label %103
103: ; preds = %100, %97
br label %104
104: ; preds = %138, %103
%105 = load i32*, i32** %11
%106 = call i32 @feof(i32* %105)
%107 = icmp ne i32 %106, 0
%108 = xor i1 %107, true
br i1 %108, label %109, label %139
109: ; preds = %104
%110 = load i32*, i32** %11
%111 = call signext i8 @getc(i32* %110)
store i8 %111, i8* %13
%112 = load i8, i8* %13
%113 = sext i8 %112 to i32
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.13, i64 0, i64 0), i32 %113)
%115 = load i32, i32* %5
%116 = load i8, i8* %13
%117 = call i32 @send(i32 %115, i8 signext %116, i32 1, i32 0)
%118 = icmp ne i32 %117, 0
%119 = xor i1 %118, true
%120 = zext i1 %119 to i32
%121 = icmp slt i32 %120, 0
br i1 %121, label %122, label %126
122: ; preds = %109
%123 = load i32, i32* @stderr
%124 = call i32 (i32, i8*, ...) @fprintf(i32 %123, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.14, i64 0, i64 0))
%125 = call i32 @exit(i32 8)
unreachable
126: ; preds = %109
%127 = load i8, i8* %13
%128 = sext i8 %127 to i32
%129 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.15, i64 0, i64 0), i32 %128)
%130 = load i32, i32* %5
%131 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%132 = call i32 @recv(i32 %130, i8* %131, i32 32, i32 0)
%133 = icmp eq i32 %132, -1
br i1 %133, label %134, label %138
134: ; preds = %126
%135 = load i32, i32* @stderr
%136 = call i32 (i32, i8*, ...) @fprintf(i32 %135, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.16, i64 0, i64 0))
%137 = call i32 @exit(i32 7)
unreachable
138: ; preds = %126
br label %104
139: ; preds = %104
%140 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.17, i64 0, i64 0))
%141 = load i32*, i32** %11
%142 = call i32 @fclose(i32* %141)
br label %143
143: ; preds = %139, %94
%144 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.18, i64 0, i64 0))
br label %145
145: ; preds = %143, %86
%146 = load i32, i32* %5
%147 = call i32 @close(i32 %146)
%148 = load i32, i32* %3
%149 = call i32 @close(i32 %148)
%150 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.19, i64 0, i64 0))
%151 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i64, %struct.TYPE_2__, 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 = [23 x i8] c"SRV--ERRO em socket()\0A\00"
@.str.1 = [32 x i8] c"SRV--Socket criado com sucesso\0A\00"
@INADDR_ANY = global i32 0
@.str.2 = [21 x i8] c"SRV--Erro em bind()\0A\00"
@.str.3 = [28 x i8] c"SRV--Erro em getsockname()\0A\00"
@.str.4 = [27 x i8] c"SRV--Numero de porta : %d\0A\00"
@.str.5 = [23 x i8] c"SRV--Erro em listen()\0A\00"
@.str.6 = [23 x i8] c"SRV--Erro em accept()\0A\00"
@.str.7 = [26 x i8] c"SRV--Erro em recv() - 01\0A\00"
@.str.8 = [2 x i8] c"r\00"
@.str.9 = [31 x i8] c"\0ASRV--Arquivo para copiar: %s\0A\00"
@.str.10 = [34 x i8] c"SRV--Cannot open %s for reading.\0A\00"
@.str.11 = [33 x i8] c"SRV--Can't open %s for writing.\0A\00"
@.str.12 = [32 x i8] c"\0Aarquivo %s aberto com sucesso\0A\00"
@.str.13 = [33 x i8] c"\0ASRV--var c dentro do while: %c\0A\00"
@.str.15 = [48 x i8] c"\0ASRV--var c dentro do while depois de send: %c\0A\00"
@.str.16 = [21 x i8] c"SRV--Erro em recv()\0A\00"
@str = [28 x i8] c"SRV--O arquivo foi copiado.\00"
@str.20 = [28 x i8] c"\0ASRV--fechando o arquivo!!!\00"
@str.21 = [25 x i8] c"SRV--Servidor finalizado\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca %struct.sockaddr_in
%4 = alloca [32 x i8]
%5 = alloca [25 x i8]
%6 = bitcast i32* %1 to i8*
%7 = bitcast %struct.sockaddr_in* %2 to i8*
%8 = bitcast %struct.sockaddr_in* %3 to i8*
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = tail call i32 @socket(i32 %10, i32 %11, i32 0)
%13 = icmp eq i32 %12, -1
%14 = load i32, i32* @stderr
br i1 %13, label %15, label %18
15: ; preds = %0
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 2)
unreachable
18: ; preds = %0
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %20, i32* %21
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i64 0, i64* %22
%23 = load i32, i32* @INADDR_ANY
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %23, i32* %24
%25 = call i64 @bind(i32 %12, %struct.sockaddr_in* %3, i32 16)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %18
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @exit(i32 3)
unreachable
31: ; preds = %18
store i32 16, i32* %1
%32 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%33 = call i64 @getsockname(i32 %12, %struct.sockaddr* %32, i32* %1)
%34 = icmp slt i64 %33, 0
%35 = load i32, i32* @stderr
br i1 %34, label %36, label %39
36: ; preds = %31
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%38 = call i32 @exit(i32 4)
unreachable
39: ; preds = %31
%40 = load i64, i64* %22
%41 = call i32 @ntohs(i64 %40)
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %41)
%43 = call i64 @listen(i32 %12, i32 1)
%44 = icmp eq i64 %43, 0
br i1 %44, label %49, label %45
45: ; preds = %39
%46 = load i32, i32* @stderr
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%48 = call i32 @exit(i32 5)
unreachable
49: ; preds = %39
store i32 16, i32* %1
%50 = call i32 @accept(i32 %12, %struct.sockaddr_in* %2, i32* %1)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %56
52: ; preds = %49
%53 = load i32, i32* @stderr
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
%55 = call i32 @exit(i32 6)
unreachable
56: ; preds = %49
%57 = getelementptr inbounds [25 x i8], [25 x i8]* %5, i64 0, i64 0
%58 = call i32 @recv(i32 %50, i8* %57, i32 25, i32 0)
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %64
60: ; preds = %56
%61 = load i32, i32* @stderr
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0))
%63 = call i32 @exit(i32 7)
unreachable
64: ; preds = %56
%65 = call i32* @fopen(i8* %57, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%66 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i8* %57)
%67 = icmp eq i32* %65, null
br i1 %67, label %68, label %70
68: ; preds = %64
%69 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.10, i64 0, i64 0), i8* %57)
br label %97
70: ; preds = %64
%71 = call i32* @fopen(i8* %57, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%72 = icmp eq i32* %71, null
br i1 %72, label %73, label %75
73: ; preds = %70
%74 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.11, i64 0, i64 0), i8* %57)
br label %95
75: ; preds = %70
%76 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.12, i64 0, i64 0), i8* %57)
br label %77
77: ; preds = %80, %75
%78 = call i32 @feof(i32* %71)
%79 = icmp eq i32 %78, 0
br i1 %79, label %80, label %92
80: ; preds = %77
%81 = call signext i8 @getc(i32* %71)
%82 = sext i8 %81 to i32
%83 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.13, i64 0, i64 0), i32 %82)
%84 = call i32 @send(i32 %50, i8 signext %81, i32 1, i32 0)
%85 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.15, i64 0, i64 0), i32 %82)
%86 = call i32 @recv(i32 %50, i8* %9, i32 32, i32 0)
%87 = icmp eq i32 %86, -1
br i1 %87, label %88, label %77
88: ; preds = %80
%89 = load i32, i32* @stderr
%90 = call i32 (i32, i8*, ...) @fprintf(i32 %89, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.16, i64 0, i64 0))
%91 = call i32 @exit(i32 7)
unreachable
92: ; preds = %77
%93 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%94 = call i32 @fclose(i32* %71)
br label %95
95: ; preds = %92, %73
%96 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.20, i64 0, i64 0))
br label %97
97: ; preds = %95, %68
%98 = call i32 @close(i32 %50)
%99 = call i32 @close(i32 %12)
%100 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.21, i64 0, i64 0))
%101 = call i32 @exit(i32 0)
unreachable
}