#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ *stdin;
char *strchr(char *, char);
size_t strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int /*<<< orphan*/ to_hex(long, char *);
int main(void) {
  float speed;
  char buffer[80], user[80], byt;
  char *pos;
  int log, link, ack;
  long i, siz;
  FILE *arch, *sal, *entr;
  sal = fopen("output.txt", "wb");
  entr = stdin;
  if (entr == NULL) {
    printf("***NO HAY CONEXIÓN DE ENTRADA***\n");
    return -1;
  }
  if (sal == NULL) {
    printf("***PROBLEMA CON LA CONEXIÓN DE SALIDA***\n");
    return -1;
  }
  printf("*** Servidor de archivos para minimOS, v0.5b1 ***\n");
  printf("(pulsar CONTROL + C para salir)\n");
  while (-1) {
    link = 0;
    printf("Esperando conexión...");
    while (!link) {
      byt = fgetc(entr);
      if (byt == 0x55) {
        link = 1;
        byt = fgetc(entr);
        speed = byt / 16.0;
      }
    }
    fputs("\"\xFF\0", sal);
    printf(" conectado a %f MHz\n", speed);
    fgets(buffer, 80, entr);
    log = 0;
    if (buffer[0] == '!') {
      pos = strchr(buffer + 1, ':');
      if (pos == NULL)
        pos = buffer + strlen(buffer) - 1;
      strncpy(user, buffer + 1, pos - buffer - 1);
      user[pos - buffer - 1] = '\0';
      log = 1;
      fputc('A', sal);
      printf(" Usuario: %s (OK)\n", user);
    }
    while (log) {
      byt = fgetc(entr);
      switch (byt) {
      case 'L':
        fgets(buffer, 80, entr);
        buffer[strlen(buffer) - 1] = '\0';
        printf(" >Solicita archivo %s ", buffer);
        arch = fopen(buffer, "rb");
        if (arch == NULL) {
          printf("*** NO EXISTE ***\n");
          fputc('x', sal);
        } else {
          fseek(arch, 0, SEEK_END);
          siz = ftell(arch);
          buffer[0] = '$';
          to_hex(siz, buffer + 1);
          fputs(buffer, sal);
          fputc('\n', sal);
          printf("(%ld bytes)...", siz);
          ack = 1;
          while ((byt = fgetc(entr)) != 'A') {
            if (byt == 'x') {
              ack = 0;
              break;
            }
          }
          if (ack) {
            printf(" aceptado.\n");
            fseek(arch, 0, SEEK_SET);
            for (i = 0; i < siz; i++) {
              fputc(fgetc(arch), sal);
              printf("\rEnviando byte %ld...", i);
            }
            printf(" OK\n");
          } else {
            printf("RECHAZADO.\n");
          }
        }
        break;
      case 'S':
        fgets(buffer, 80, entr);
        printf(" >Prentende SUBIR archivo %s ", buffer);
        fgets(buffer, 80, entr);
        buffer[strlen(buffer) - 1] = '\0';
        printf("(%s) ** NO IMPLEMENTADO **\n", buffer);
        fputc('x', sal);
        break;
      case '.':
        printf("<Usuario %s desconectado>\n", user);
        log = 0;
        break;
      case 'A':
        printf("ACK???\n");
      }
    }
    fflush(sal);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
lea    0xebb(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0xf0(%rbp)
mov    0x2ddd(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0xf8(%rbp)
cmpq   $0x0,-0xf8(%rbp)
jne    1235 <main+0x65>
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1746 <main+0x576>
cmpq   $0x0,-0xf0(%rbp)
jne    125d <main+0x8d>
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1746 <main+0x576>
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0xc8(%rbp)
lea    0xec6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpl   $0x0,-0xc8(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12aa <main+0xda>
jmp    130d <main+0x13d>
mov    -0xf8(%rbp),%rdi
call   1090 <fgetc@plt>
mov    %al,-0xb1(%rbp)
movsbl -0xb1(%rbp),%eax
cmp    $0x55,%eax
jne    1308 <main+0x138>
movl   $0x1,-0xc8(%rbp)
mov    -0xf8(%rbp),%rdi
call   1090 <fgetc@plt>
mov    %al,-0xb1(%rbp)
movsbl -0xb1(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  0xd05(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x8(%rbp)
jmp    1291 <main+0xc1>
mov    -0xf0(%rbp),%rsi
lea    0xf40(%rip),%rdi
call   1080 <fputs@plt>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe37(%rip),%rdi
mov    $0x1,%al
call   1070 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    -0xf8(%rbp),%rdx
mov    $0x50,%esi
call   10b0 <fgets@plt>
movl   $0x0,-0xc4(%rbp)
movsbl -0x60(%rbp),%eax
cmp    $0x21,%eax
jne    1428 <main+0x258>
lea    -0x60(%rbp),%rdi
add    $0x1,%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,-0xc0(%rbp)
cmpq   $0x0,-0xc0(%rbp)
jne    13b6 <main+0x1e6>
lea    -0x60(%rbp),%rax
mov    %rax,-0x100(%rbp)
lea    -0x60(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x100(%rbp),%rax
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0xc0(%rbp)
lea    -0xb0(%rbp),%rdi
lea    -0x60(%rbp),%rsi
add    $0x1,%rsi
mov    -0xc0(%rbp),%rax
lea    -0x60(%rbp),%rcx
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0xc0(%rbp),%rax
lea    -0x60(%rbp),%rcx
sub    %rcx,%rax
sub    $0x1,%rax
movb   $0x0,-0xb0(%rbp,%rax,1)
movl   $0x1,-0xc4(%rbp)
mov    -0xf0(%rbp),%rsi
mov    $0x41,%edi
call   10a0 <fputc@plt>
lea    -0xb0(%rbp),%rsi
lea    0xd5b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    142d <main+0x25d>
cmpl   $0x0,-0xc4(%rbp)
je     1735 <main+0x565>
mov    -0xf8(%rbp),%rdi
call   1090 <fgetc@plt>
mov    %al,-0xb1(%rbp)
movsbl -0xb1(%rbp),%eax
add    $0xffffffd2,%eax
mov    %eax,%ecx
mov    %rcx,-0x108(%rbp)
sub    $0x25,%eax
ja     1730 <main+0x560>
mov    -0x108(%rbp),%rax
lea    0xb92(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    -0x60(%rbp),%rdi
mov    -0xf8(%rbp),%rdx
mov    $0x50,%esi
call   10b0 <fgets@plt>
lea    -0x60(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%rax
movb   $0x0,-0x60(%rbp,%rax,1)
lea    -0x60(%rbp),%rsi
lea    0xcde(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x60(%rbp),%rdi
lea    0xce3(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0xe8(%rbp)
cmpq   $0x0,-0xe8(%rbp)
jne    1501 <main+0x331>
lea    0xcc5(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0xf0(%rbp),%rsi
mov    $0x78,%edi
call   10a0 <fputc@plt>
jmp    1683 <main+0x4b3>
mov    -0xe8(%rbp),%rdi
mov    0x2ad9(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10e0 <fseek@plt>
mov    -0xe8(%rbp),%rdi
call   10c0 <ftell@plt>
mov    %rax,-0xe0(%rbp)
movb   $0x24,-0x60(%rbp)
mov    -0xe0(%rbp),%rdi
lea    -0x60(%rbp),%rsi
add    $0x1,%rsi
call   1040 <to_hex@plt>
lea    -0x60(%rbp),%rdi
mov    -0xf0(%rbp),%rsi
call   1080 <fputs@plt>
mov    -0xf0(%rbp),%rsi
mov    $0xa,%edi
call   10a0 <fputc@plt>
mov    -0xe0(%rbp),%rsi
lea    0xc4a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0xcc(%rbp)
mov    -0xf8(%rbp),%rdi
call   1090 <fgetc@plt>
mov    %al,-0xb1(%rbp)
movsbl %al,%eax
cmp    $0x41,%eax
je     15c5 <main+0x3f5>
movsbl -0xb1(%rbp),%eax
cmp    $0x78,%eax
jne    15c0 <main+0x3f0>
movl   $0x0,-0xcc(%rbp)
jmp    15c5 <main+0x3f5>
jmp    1583 <main+0x3b3>
cmpl   $0x0,-0xcc(%rbp)
je     1670 <main+0x4a0>
lea    0xbf2(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0xe8(%rbp),%rdi
mov    0x29e2(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10e0 <fseek@plt>
movq   $0x0,-0xd8(%rbp)
mov    -0xd8(%rbp),%rax
cmp    -0xe0(%rbp),%rax
jge    165d <main+0x48d>
mov    -0xe8(%rbp),%rdi
call   1090 <fgetc@plt>
mov    -0xf0(%rbp),%rsi
movsbl %al,%edi
call   10a0 <fputc@plt>
mov    -0xd8(%rbp),%rsi
lea    0xb98(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0xd8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xd8(%rbp)
jmp    1602 <main+0x432>
lea    0xb89(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    167e <main+0x4ae>
lea    0xb7b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1683 <main+0x4b3>
jmp    1730 <main+0x560>
lea    -0x60(%rbp),%rdi
mov    -0xf8(%rbp),%rdx
mov    $0x50,%esi
call   10b0 <fgets@plt>
lea    -0x60(%rbp),%rsi
lea    0xb56(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    -0xf8(%rbp),%rdx
mov    $0x50,%esi
call   10b0 <fgets@plt>
lea    -0x60(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%rax
movb   $0x0,-0x60(%rbp,%rax,1)
lea    -0x60(%rbp),%rsi
lea    0xb3b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0xf0(%rbp),%rsi
mov    $0x78,%edi
call   10a0 <fputc@plt>
jmp    1730 <main+0x560>
lea    -0xb0(%rbp),%rsi
lea    0xb2c(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0xc4(%rbp)
jmp    1730 <main+0x560>
lea    0xb2a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    142d <main+0x25d>
mov    -0xf0(%rbp),%rdi
call   10d0 <fflush@plt>
jmp    1279 <main+0xa9>
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
lea    0xe98(%rip),%rdi
lea    0xe9c(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,%r14
mov    0x2dc2(%rip),%rax
mov    (%rax),%r12
test   %r12,%r12
je     157d <main+0x38d>
test   %r14,%r14
je     1586 <main+0x396>
lea    0xf47(%rip),%rdi
call   1040 <puts@plt>
lea    0xf6d(%rip),%rdi
call   1040 <puts@plt>
lea    0x11(%rsp),%r13
lea    0x10(%rsp),%r15
mov    %r15,%rax
not    %rax
mov    %rax,0x8(%rsp)
lea    0xe47(%rip),%rbp
jmp    1292 <main+0xa2>
nopl   0x0(%rax)
lea    0xeef(%rip),%rdi
lea    0x60(%rsp),%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xe24(%rip),%rbp
mov    %r14,%rdi
call   10e0 <fflush@plt>
mov    %rbp,%rdi
xor    %eax,%eax
call   1080 <printf@plt>
nopl   0x0(%rax)
mov    %r12,%rdi
call   10a0 <fgetc@plt>
cmp    $0x55,%al
jne    12a0 <main+0xb0>
mov    %r12,%rdi
call   10a0 <fgetc@plt>
movsbl %al,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xd3a(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x4(%rsp)
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xf71(%rip),%rdi
mov    %r14,%rcx
call   1110 <fwrite@plt>
movss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdcb(%rip),%rdi
mov    $0x1,%al
call   1080 <printf@plt>
mov    %r15,%rdi
mov    $0x50,%esi
mov    %r12,%rdx
call   10c0 <fgets@plt>
cmpb   $0x21,0x10(%rsp)
jne    128a <main+0x9a>
mov    %r13,%rdi
mov    $0x3a,%esi
call   1070 <strchr@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1341 <main+0x151>
mov    %r15,%rdi
call   1060 <strlen@plt>
lea    (%rsp,%rax,1),%rbp
add    $0xf,%rbp
add    0x8(%rsp),%rbp
lea    0x60(%rsp),%r15
mov    %r15,%rdi
mov    %r13,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x60(%rsp,%rbp,1)
mov    $0x41,%edi
mov    %r14,%rsi
call   10b0 <fputc@plt>
lea    0xd69(%rip),%rdi
mov    %r15,%rsi
lea    0x10(%rsp),%r15
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xc81(%rip),%rbx
jmp    139c <main+0x1ac>
nopl   0x0(%rax)
lea    0xe3c(%rip),%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
call   10a0 <fgetc@plt>
movsbl %al,%eax
add    $0xffffffd2,%eax
cmp    $0x25,%eax
ja     139c <main+0x1ac>
movslq (%rbx,%rax,4),%rax
add    %rbx,%rax
jmp    *%rax
mov    %r15,%rdi
mov    $0x50,%esi
mov    %r12,%rdx
call   10c0 <fgets@plt>
mov    %r15,%rdi
call   1060 <strlen@plt>
movb   $0x0,-0x1(%rax,%r15,1)
lea    0xd10(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r15,%rdi
lea    0xd13(%rip),%rsi
call   1100 <fopen@plt>
test   %rax,%rax
je     1542 <main+0x352>
mov    %rax,%rbp
mov    0x2bdf(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   10f0 <fseek@plt>
mov    %rbp,%rdi
call   10d0 <ftell@plt>
mov    %r15,%rbx
mov    %rax,%r15
movb   $0x24,0x10(%rsp)
mov    %rax,%rdi
mov    %r13,%rsi
call   1050 <to_hex@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <fputs@plt>
mov    $0xa,%edi
mov    %r14,%rsi
call   10b0 <fputc@plt>
lea    0xcb5(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xcb3(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
call   10a0 <fgetc@plt>
cmp    $0x78,%al
je     1560 <main+0x370>
cmp    $0x41,%al
jne    1470 <main+0x280>
lea    0xd5a(%rip),%rdi
call   1040 <puts@plt>
mov    0x2b39(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   10f0 <fseek@plt>
test   %r15,%r15
jle    14d9 <main+0x2e9>
xor    %r13d,%r13d
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   10a0 <fgetc@plt>
movsbl %al,%edi
mov    %r14,%rsi
call   10b0 <fputc@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
add    $0x1,%r13
cmp    %r13,%r15
jne    14b0 <main+0x2c0>
lea    0xd10(%rip),%rdi
call   1040 <puts@plt>
lea    0x11(%rsp),%r13
jmp    156c <main+0x37c>
nop
mov    %r15,%rdi
mov    $0x50,%esi
mov    %r12,%rdx
call   10c0 <fgets@plt>
lea    0xc25(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r15,%rdi
mov    $0x50,%esi
mov    %r12,%rdx
call   10c0 <fgets@plt>
mov    %r15,%rdi
call   1060 <strlen@plt>
movb   $0x0,-0x1(%rax,%r15,1)
lea    0xc14(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    154e <main+0x35e>
lea    0xcab(%rip),%rdi
call   1040 <puts@plt>
mov    $0x78,%edi
mov    %r14,%rsi
call   10b0 <fputc@plt>
jmp    139c <main+0x1ac>
lea    0xc73(%rip),%rdi
call   1040 <puts@plt>
lea    0xa95(%rip),%rbx
lea    0x10(%rsp),%r15
jmp    139c <main+0x1ac>
lea    0xcac(%rip),%rdi
jmp    158d <main+0x39d>
lea    0xc79(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"output.txt\00"
@.str.1 = [3 x i8] c"wb\00"
@stdin = global i32* null
@.str.2 = [35 x i8] c"***NO HAY CONEXI\C3\93N DE ENTRADA***\0A\00"
@.str.3 = [43 x i8] c"***PROBLEMA CON LA CONEXI\C3\93N DE SALIDA***\0A\00"
@.str.4 = [51 x i8] c"*** Servidor de archivos para minimOS, v0.5b1 ***\0A\00"
@.str.5 = [33 x i8] c"(pulsar CONTROL + C para salir)\0A\00"
@.str.6 = [23 x i8] c"Esperando conexi\C3\B3n...\00"
@.str.7 = [4 x i8] c"\22\FF\00\00"
@.str.8 = [21 x i8] c" conectado a %f MHz\0A\00"
@.str.9 = [19 x i8] c" Usuario: %s (OK)\0A\00"
@.str.10 = [23 x i8] c" >Solicita archivo %s \00"
@.str.11 = [3 x i8] c"rb\00"
@.str.12 = [19 x i8] c"*** NO EXISTE ***\0A\00"
@SEEK_END = global i32 0
@.str.13 = [15 x i8] c"(%ld bytes)...\00"
@.str.14 = [12 x i8] c" aceptado.\0A\00"
@SEEK_SET = global i32 0
@.str.15 = [22 x i8] c"\0DEnviando byte %ld...\00"
@.str.16 = [5 x i8] c" OK\0A\00"
@.str.17 = [12 x i8] c"RECHAZADO.\0A\00"
@.str.18 = [30 x i8] c" >Prentende SUBIR archivo %s \00"
@.str.19 = [28 x i8] c"(%s) ** NO IMPLEMENTADO **\0A\00"
@.str.20 = [27 x i8] c"<Usuario %s desconectado>\0A\00"
@.str.21 = [8 x i8] c"ACK???\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca [80 x i8]
%4 = alloca [80 x i8]
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64
%11 = alloca i64
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
store i32 0, i32* %1
%15 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %13
%16 = load i32*, i32** @stdin
store i32* %16, i32** %14
%17 = load i32*, i32** %14
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %0
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %208
21: ; preds = %0
%22 = load i32*, i32** %13
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %208
26: ; preds = %21
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0))
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0))
br label %29
29: ; preds = %26, %205
store i32 0, i32* %8
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
br label %31
31: ; preds = %49, %29
%32 = load i32, i32* %8
%33 = icmp ne i32 %32, 0
%34 = xor i1 %33, true
br i1 %34, label %35, label %50
35: ; preds = %31
%36 = load i32*, i32** %14
%37 = call signext i8 @fgetc(i32* %36)
store i8 %37, i8* %5
%38 = load i8, i8* %5
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 85
br i1 %40, label %41, label %49
41: ; preds = %35
store i32 1, i32* %8
%42 = load i32*, i32** %14
%43 = call signext i8 @fgetc(i32* %42)
store i8 %43, i8* %5
%44 = load i8, i8* %5
%45 = sext i8 %44 to i32
%46 = sitofp i32 %45 to double
%47 = fdiv double %46, 1.600000e+01
%48 = fptrunc double %47 to float
store float %48, float* %2
br label %49
49: ; preds = %41, %35
br label %31
50: ; preds = %31
%51 = load i32*, i32** %13
%52 = call i32 @fputs(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32* %51)
%53 = load float, float* %2
%54 = fpext float %53 to double
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), double %54)
%56 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%57 = load i32*, i32** %14
%58 = call i32 @fgets(i8* %56, i32 80, i32* %57)
store i32 0, i32* %7
%59 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = icmp eq i32 %61, 33
br i1 %62, label %63, label %98
63: ; preds = %50
%64 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%65 = getelementptr inbounds i8, i8* %64, i64 1
%66 = call i8* @strchr(i8* %65, i8 signext 58)
store i8* %66, i8** %6
%67 = load i8*, i8** %6
%68 = icmp eq i8* %67, null
br i1 %68, label %69, label %75
69: ; preds = %63
%70 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%71 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%72 = call i64 @strlen(i8* %71)
%73 = getelementptr inbounds i8, i8* %70, i64 %72
%74 = getelementptr inbounds i8, i8* %73, i64 -1
store i8* %74, i8** %6
br label %75
75: ; preds = %69, %63
%76 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%77 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%78 = getelementptr inbounds i8, i8* %77, i64 1
%79 = load i8*, i8** %6
%80 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%81 = ptrtoint i8* %79 to i64
%82 = ptrtoint i8* %80 to i64
%83 = sub i64 %81, %82
%84 = sub nsw i64 %83, 1
%85 = trunc i64 %84 to i32
%86 = call i32 @strncpy(i8* %76, i8* %78, i32 %85)
%87 = load i8*, i8** %6
%88 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%89 = ptrtoint i8* %87 to i64
%90 = ptrtoint i8* %88 to i64
%91 = sub i64 %89, %90
%92 = sub nsw i64 %91, 1
%93 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 %92
store i8 0, i8* %93
store i32 1, i32* %7
%94 = load i32*, i32** %13
%95 = call i32 @fputc(i8 signext 65, i32* %94)
%96 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0), i8* %96)
br label %98
98: ; preds = %75, %50
br label %99
99: ; preds = %204, %98
%100 = load i32, i32* %7
%101 = icmp ne i32 %100, 0
br i1 %101, label %102, label %205
102: ; preds = %99
%103 = load i32*, i32** %14
%104 = call signext i8 @fgetc(i32* %103)
store i8 %104, i8* %5
%105 = load i8, i8* %5
%106 = sext i8 %105 to i32
switch i32 %106, label %204 [
i32 76, label %107
i32 83, label %182
i32 46, label %199
i32 65, label %202
]
107: ; preds = %102
%108 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%109 = load i32*, i32** %14
%110 = call i32 @fgets(i8* %108, i32 80, i32* %109)
%111 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%112 = call i64 @strlen(i8* %111)
%113 = sub i64 %112, 1
%114 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 %113
store i8 0, i8* %114
%115 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%116 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0), i8* %115)
%117 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%118 = call i32* @fopen(i8* %117, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
store i32* %118, i32** %12
%119 = load i32*, i32** %12
%120 = icmp eq i32* %119, null
br i1 %120, label %121, label %125
121: ; preds = %107
%122 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.12, i64 0, i64 0))
%123 = load i32*, i32** %13
%124 = call i32 @fputc(i8 signext 120, i32* %123)
br label %181
125: ; preds = %107
%126 = load i32*, i32** %12
%127 = load i32, i32* @SEEK_END
%128 = call i32 @fseek(i32* %126, i32 0, i32 %127)
%129 = load i32*, i32** %12
%130 = call i64 @ftell(i32* %129)
store i64 %130, i64* %11
%131 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
store i8 36, i8* %131
%132 = load i64, i64* %11
%133 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%134 = getelementptr inbounds i8, i8* %133, i64 1
%135 = call i32 @to_hex(i64 %132, i8* %134)
%136 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%137 = load i32*, i32** %13
%138 = call i32 @fputs(i8* %136, i32* %137)
%139 = load i32*, i32** %13
%140 = call i32 @fputc(i8 signext 10, i32* %139)
%141 = load i64, i64* %11
%142 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.13, i64 0, i64 0), i64 %141)
store i32 1, i32* %9
br label %143
143: ; preds = %153, %125
%144 = load i32*, i32** %14
%145 = call signext i8 @fgetc(i32* %144)
store i8 %145, i8* %5
%146 = sext i8 %145 to i32
%147 = icmp ne i32 %146, 65
br i1 %147, label %148, label %154
148: ; preds = %143
%149 = load i8, i8* %5
%150 = sext i8 %149 to i32
%151 = icmp eq i32 %150, 120
br i1 %151, label %152, label %153
152: ; preds = %148
store i32 0, i32* %9
br label %154
153: ; preds = %148
br label %143
154: ; preds = %152, %143
%155 = load i32, i32* %9
%156 = icmp ne i32 %155, 0
br i1 %156, label %157, label %178
157: ; preds = %154
%158 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.14, i64 0, i64 0))
%159 = load i32*, i32** %12
%160 = load i32, i32* @SEEK_SET
%161 = call i32 @fseek(i32* %159, i32 0, i32 %160)
store i64 0, i64* %10
br label %162
162: ; preds = %173, %157
%163 = load i64, i64* %10
%164 = load i64, i64* %11
%165 = icmp slt i64 %163, %164
br i1 %165, label %166, label %176
166: ; preds = %162
%167 = load i32*, i32** %12
%168 = call signext i8 @fgetc(i32* %167)
%169 = load i32*, i32** %13
%170 = call i32 @fputc(i8 signext %168, i32* %169)
%171 = load i64, i64* %10
%172 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.15, i64 0, i64 0), i64 %171)
br label %173
173: ; preds = %166
%174 = load i64, i64* %10
%175 = add nsw i64 %174, 1
store i64 %175, i64* %10
br label %162
176: ; preds = %162
%177 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.16, i64 0, i64 0))
br label %180
178: ; preds = %154
%179 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.17, i64 0, i64 0))
br label %180
180: ; preds = %178, %176
br label %181
181: ; preds = %180, %121
br label %204
182: ; preds = %102
%183 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%184 = load i32*, i32** %14
%185 = call i32 @fgets(i8* %183, i32 80, i32* %184)
%186 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%187 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.18, i64 0, i64 0), i8* %186)
%188 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%189 = load i32*, i32** %14
%190 = call i32 @fgets(i8* %188, i32 80, i32* %189)
%191 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%192 = call i64 @strlen(i8* %191)
%193 = sub i64 %192, 1
%194 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 %193
store i8 0, i8* %194
%195 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%196 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.19, i64 0, i64 0), i8* %195)
%197 = load i32*, i32** %13
%198 = call i32 @fputc(i8 signext 120, i32* %197)
br label %204
199: ; preds = %102
%200 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%201 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.20, i64 0, i64 0), i8* %200)
store i32 0, i32* %7
br label %204
202: ; preds = %102
%203 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.21, i64 0, i64 0))
br label %204
204: ; preds = %202, %102, %199, %182, %181
br label %99
205: ; preds = %99
%206 = load i32*, i32** %13
%207 = call i32 @fflush(i32* %206)
br label %29
208: ; preds = %24, %19
%209 = load i32, i32* %1
ret i32 %209
}

LLVM IR (-O2):
@.str = [11 x i8] c"output.txt\00"
@.str.1 = [3 x i8] c"wb\00"
@stdin = global i32* null
@.str.6 = [23 x i8] c"Esperando conexi\C3\B3n...\00"
@.str.7 = [4 x i8] c"\22\FF\00\00"
@.str.8 = [21 x i8] c" conectado a %f MHz\0A\00"
@.str.9 = [19 x i8] c" Usuario: %s (OK)\0A\00"
@.str.10 = [23 x i8] c" >Solicita archivo %s \00"
@.str.11 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@.str.13 = [15 x i8] c"(%ld bytes)...\00"
@SEEK_SET = global i32 0
@.str.15 = [22 x i8] c"\0DEnviando byte %ld...\00"
@.str.18 = [30 x i8] c" >Prentende SUBIR archivo %s \00"
@.str.19 = [28 x i8] c"(%s) ** NO IMPLEMENTADO **\0A\00"
@.str.20 = [27 x i8] c"<Usuario %s desconectado>\0A\00"
@str = [50 x i8] c"*** Servidor de archivos para minimOS, v0.5b1 ***\00"
@str.22 = [32 x i8] c"(pulsar CONTROL + C para salir)\00"
@str.23 = [7 x i8] c"ACK???\00"
@str.24 = [11 x i8] c"RECHAZADO.\00"
@str.25 = [11 x i8] c" aceptado.\00"
@str.26 = [4 x i8] c" OK\00"
@str.27 = [18 x i8] c"*** NO EXISTE ***\00"
@str.28 = [42 x i8] c"***PROBLEMA CON LA CONEXI\C3\93N DE SALIDA***\00"
@str.29 = [34 x i8] c"***NO HAY CONEXI\C3\93N DE ENTRADA***\00"
define i32 @main() {
%1 = alloca [80 x i8]
%2 = alloca [80 x i8]
%3 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = load i32*, i32** @stdin
%7 = icmp eq i32* %6, null
br i1 %7, label %104, label %8
8: ; preds = %0
%9 = icmp eq i32* %5, null
br i1 %9, label %104, label %10
10: ; preds = %8
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.22, i64 0, i64 0))
%13 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 1
%14 = ptrtoint [80 x i8]* %1 to i64
%15 = xor i64 %14, -1
br label %16
16: ; preds = %102, %10
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
br label %18
18: ; preds = %18, %16
%19 = call signext i8 @fgetc(i32* %6)
%20 = icmp eq i8 %19, 85
br i1 %20, label %21, label %18
21: ; preds = %18
%22 = call signext i8 @fgetc(i32* %6)
%23 = sitofp i8 %22 to double
%24 = fmul double %23, 6.250000e-02
%25 = fptrunc double %24 to float
%26 = call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i64 2, i64 1, i32* %5)
%27 = fpext float %25 to double
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), double %27)
%29 = call i32 @fgets(i8* %3, i32 80, i32* %6)
%30 = load i8, i8* %3
%31 = icmp eq i8 %30, 33
br i1 %31, label %32, label %102
32: ; preds = %21
%33 = call i8* @strchr(i8* %13, i8 signext 58)
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %39
35: ; preds = %32
%36 = call i64 @strlen(i8* %3)
%37 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 %36
%38 = getelementptr inbounds i8, i8* %37, i64 -1
br label %39
39: ; preds = %32, %35
%40 = phi i8* [ %38, %35 ], [ %33, %32 ]
%41 = ptrtoint i8* %40 to i64
%42 = add i64 %41, %15
%43 = trunc i64 %42 to i32
%44 = call i32 @strncpy(i8* %4, i8* %13, i32 %43)
%45 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 %42
store i8 0, i8* %45
%46 = call i32 @fputc(i8 signext 65, i32* %5)
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0), i8* %4)
br label %48
48: ; preds = %62, %39
%49 = call signext i8 @fgetc(i32* %6)
%50 = sext i8 %49 to i32
switch i32 %50, label %62 [
i32 76, label %51
i32 83, label %89
i32 46, label %100
i32 65, label %98
]
51: ; preds = %48
%52 = call i32 @fgets(i8* %3, i32 80, i32* %6)
%53 = call i64 @strlen(i8* %3)
%54 = add i64 %53, -1
%55 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 %54
store i8 0, i8* %55
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0), i8* %3)
%57 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
%58 = icmp eq i32* %57, null
br i1 %58, label %59, label %63
59: ; preds = %51
%60 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.27, i64 0, i64 0))
%61 = call i32 @fputc(i8 signext 120, i32* %5)
br label %62
62: ; preds = %59, %87, %85, %98, %48, %89
br label %48
63: ; preds = %51
%64 = load i32, i32* @SEEK_END
%65 = call i32 @fseek(i32* %57, i32 0, i32 %64)
%66 = call i64 @ftell(i32* %57)
store i8 36, i8* %3
%67 = call i32 @to_hex(i64 %66, i8* %13)
%68 = call i32 @fputs(i8* %3, i32* %5)
%69 = call i32 @fputc(i8 signext 10, i32* %5)
%70 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.13, i64 0, i64 0), i64 %66)
br label %71
71: ; preds = %71, %63
%72 = call signext i8 @fgetc(i32* %6)
switch i8 %72, label %71 [
i8 65, label %73
i8 120, label %87
]
73: ; preds = %71
%74 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.25, i64 0, i64 0))
%75 = load i32, i32* @SEEK_SET
%76 = call i32 @fseek(i32* %57, i32 0, i32 %75)
%77 = icmp sgt i64 %66, 0
br i1 %77, label %78, label %85
78: ; preds = %73, %78
%79 = phi i64 [ %83, %78 ], [ 0, %73 ]
%80 = call signext i8 @fgetc(i32* %57)
%81 = call i32 @fputc(i8 signext %80, i32* %5)
%82 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.15, i64 0, i64 0), i64 %79)
%83 = add nuw nsw i64 %79, 1
%84 = icmp eq i64 %83, %66
br i1 %84, label %85, label %78
85: ; preds = %78, %73
%86 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.26, i64 0, i64 0))
br label %62
87: ; preds = %71
%88 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.24, i64 0, i64 0))
br label %62
89: ; preds = %48
%90 = call i32 @fgets(i8* %3, i32 80, i32* %6)
%91 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.18, i64 0, i64 0), i8* %3)
%92 = call i32 @fgets(i8* %3, i32 80, i32* %6)
%93 = call i64 @strlen(i8* %3)
%94 = add i64 %93, -1
%95 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 %94
store i8 0, i8* %95
%96 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.19, i64 0, i64 0), i8* %3)
%97 = call i32 @fputc(i8 signext 120, i32* %5)
br label %62
98: ; preds = %48
%99 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.23, i64 0, i64 0))
br label %62
100: ; preds = %48
%101 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.20, i64 0, i64 0), i8* %4)
br label %102
102: ; preds = %21, %100
%103 = call i32 @fflush(i32* %5)
br label %16
104: ; preds = %8, %0
%105 = phi i8* [ getelementptr inbounds ([34 x i8], [34 x i8]* @str.29, i64 0, i64 0), %0 ], [ getelementptr inbounds ([42 x i8], [42 x i8]* @str.28, i64 0, i64 0), %8 ]
%106 = tail call i32 @puts(i8* dereferenceable(1) %105)
ret i32 -1
}