#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 uint16_t;

/* Variables and functions */
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ exit(int);
unsigned long get_millis();
int /*<<< orphan*/ perror(char *);
int pid_control(int);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int read_register(int);
int /*<<< orphan*/ reset_pid();
int write(int, ...);
int write_register(int, int);
void procesar_request(int sock) {
  int n;
  uint16_t speed;
  int rc;
  int error;
  uint16_t res, feed;
  char buffer[256];
  char res_buf[30];
  unsigned long t, tao, init_time;
  bzero(buffer, 256);
  n = write(sock, buffer, 1);
  if (n < 0)
    exit(0);
  else
    printf("N: %d\n", n);
  n = read(sock, buffer, 255);
  if (n < 0) {
    perror("ERROR reading from socket");
    exit(1);
  }
  switch (buffer[0]) {
  case 0x31:
    printf("GET_STATUS REQUEST\n");
    res = read_register(8448);
    res_buf[0] = 0x31;
    res_buf[1] = (res >> 8) & 0x00FF;
    res_buf[2] = res & 0x00FF;
    res = read_register(8451);
    res_buf[3] = (res >> 8) & 0x00FF;
    res_buf[4] = res & 0x00FF;
    printf("0: %x, %x, %x\n", res_buf[0], res_buf[3], res_buf[4]);
    res = read_register(8450);
    res_buf[5] = (res >> 8) & 0x00FF;
    res_buf[6] = res & 0x00FF;
    printf("0: %x, %x, %x\n", res_buf[0], res_buf[5], res_buf[6]);
    res = read_register(8453);
    res_buf[7] = (res >> 8) & 0x00FF;
    res_buf[8] = res & 0x00FF;
    printf("0: %x, %x, %x\n", res_buf[0], res_buf[7], res_buf[8]);
    res = read_register(8452);
    res_buf[9] = (res >> 8) & 0x00FF;
    res_buf[10] = res & 0x00FF;
    printf("0: %x, %x, %x\n", res_buf[0], res_buf[9], res_buf[10]);
    res_buf[11] = '\n';
    n = write(sock, &res_buf, 12);
    break;
  case 0x33:
    printf("START MOTOR\n");
    rc = write_register(8192, 0x02);
    break;
  case 0x34:
    printf("STOP MOTOR\n");
    reset_pid();
    rc = write_register(8192, 0x01);
    break;
  case 0x35:
    printf("SET REFERENCE CMD\n");
    speed = 0;
    speed = (buffer[1] << 8) | (buffer[2]);
    reset_pid();
    rc = write_register(8193, speed);
    break;
  case 0x36:
    printf("SET PID REFERENCE CMD\n");
    speed = (buffer[1] << 8) | (buffer[2]);
    res = read_register(8451);
    printf("RES; %d, setpoint: %d\n", res, speed);
    error = speed - res;
    rc = write_register(8193, pid_control(error));
    res = read_register(8448);
    res_buf[0] = 0x31;
    res_buf[1] = (res >> 8) & 0x00FF;
    res_buf[2] = res & 0x00FF;
    res = read_register(8451);
    res_buf[3] = (res >> 8) & 0x00FF;
    res_buf[4] = res & 0x00FF;
    printf("0: %x, %x, %x\n", res_buf[0], res_buf[3], res_buf[4]);
    res = read_register(8450);
    res_buf[5] = (res >> 8) & 0x00FF;
    res_buf[6] = res & 0x00FF;
    printf("0: %x, %x, %x\n", res_buf[0], res_buf[5], res_buf[6]);
    res = read_register(8453);
    res_buf[7] = (res >> 8) & 0x00FF;
    res_buf[8] = res & 0x00FF;
    printf("0: %x, %x, %x\n", res_buf[0], res_buf[7], res_buf[8]);
    res = read_register(8452);
    res_buf[9] = (res >> 8) & 0x00FF;
    res_buf[10] = res & 0x00FF;
    printf("0: %x, %x, %x\n", res_buf[0], res_buf[9], res_buf[10]);
    res_buf[11] = '\n';
    n = write(sock, &res_buf, 12);
    break;
  case 0x37:
    rc = write_register(8193, 100);
    do {
      res = read_register(8448);
    } while ((res & 0x0100) == 0);
    tao = 0;
    t = get_millis();
    init_time = get_millis();
    rc = write_register(8193, 400);
    do {
      if (get_millis() - t > 500) {
        feed = read_register(8448);
        if (feed >= 253)
          tao = get_millis();
        t = get_millis();
      }
      res = read_register(8448);
    } while ((res & 0x0100) == 0);
    printf("TAO = %lu milliseconds\n", tao - init_time);
    break;
  default:
    printf("UNRECOGNIZED COMMAND: %s\n", buffer);
    break;
  }
  if (n < 0) {
    perror("ERROR writing to socket");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<procesar_request>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x120(%rbp),%rdi
mov    $0x100,%esi
call   10b0 <bzero@plt>
mov    -0x4(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1050 <write@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11f9 <procesar_request+0x49>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    -0x8(%rbp),%esi
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0xff,%edx
call   1070 <read@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1241 <procesar_request+0x91>
lea    0xdf1(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
movsbl -0x120(%rbp),%eax
add    $0xffffffcf,%eax
mov    %eax,%ecx
mov    %rcx,-0x160(%rbp)
sub    $0x6,%eax
ja     179f <procesar_request+0x5ef>
mov    -0x160(%rbp),%rax
lea    0xd95(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x2100,%edi
call   1040 <read_register@plt>
mov    %eax,-0x18(%rbp)
movb   $0x31,-0x140(%rbp)
mov    -0x18(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x13f(%rbp)
mov    -0x18(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x13e(%rbp)
mov    $0x2103,%edi
call   1040 <read_register@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x13d(%rbp)
mov    -0x18(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x13c(%rbp)
movsbl -0x140(%rbp),%esi
movsbl -0x13d(%rbp),%edx
movsbl -0x13c(%rbp),%ecx
lea    0xd54(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x2102,%edi
call   1040 <read_register@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x13b(%rbp)
mov    -0x18(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x13a(%rbp)
movsbl -0x140(%rbp),%esi
movsbl -0x13b(%rbp),%edx
movsbl -0x13a(%rbp),%ecx
lea    0xd05(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x2105,%edi
call   1040 <read_register@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x139(%rbp)
mov    -0x18(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x138(%rbp)
movsbl -0x140(%rbp),%esi
movsbl -0x139(%rbp),%edx
movsbl -0x138(%rbp),%ecx
lea    0xcb6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x2104,%edi
call   1040 <read_register@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x137(%rbp)
mov    -0x18(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x136(%rbp)
movsbl -0x140(%rbp),%esi
movsbl -0x137(%rbp),%edx
movsbl -0x136(%rbp),%ecx
lea    0xc67(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movb   $0xa,-0x135(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x140(%rbp),%rsi
mov    $0xc,%edx
mov    $0x0,%al
call   1050 <write@plt>
mov    %eax,-0x8(%rbp)
jmp    17b4 <procesar_request+0x604>
lea    0xc43(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x2000,%edi
mov    $0x2,%esi
call   1080 <write_register@plt>
mov    %eax,-0x10(%rbp)
jmp    17b4 <procesar_request+0x604>
lea    0xc2b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   10d0 <reset_pid@plt>
mov    $0x2000,%edi
mov    $0x1,%esi
call   1080 <write_register@plt>
mov    %eax,-0x10(%rbp)
jmp    17b4 <procesar_request+0x604>
lea    0xc0b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0xc(%rbp)
movsbl -0x11f(%rbp),%eax
shl    $0x8,%eax
movsbl -0x11e(%rbp),%ecx
or     %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   10d0 <reset_pid@plt>
mov    -0xc(%rbp),%esi
mov    $0x2001,%edi
call   1080 <write_register@plt>
mov    %eax,-0x10(%rbp)
jmp    17b4 <procesar_request+0x604>
lea    0xbd7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movsbl -0x11f(%rbp),%eax
shl    $0x8,%eax
movsbl -0x11e(%rbp),%ecx
or     %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    $0x2103,%edi
call   1040 <read_register@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xbb7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0xc(%rbp),%eax
sub    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <pid_control@plt>
mov    %eax,%esi
mov    $0x2001,%edi
call   1080 <write_register@plt>
mov    %eax,-0x10(%rbp)
mov    $0x2100,%edi
call   1040 <read_register@plt>
mov    %eax,-0x18(%rbp)
movb   $0x31,-0x140(%rbp)
mov    -0x18(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x13f(%rbp)
mov    -0x18(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x13e(%rbp)
mov    $0x2103,%edi
call   1040 <read_register@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x13d(%rbp)
mov    -0x18(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x13c(%rbp)
movsbl -0x140(%rbp),%esi
movsbl -0x13d(%rbp),%edx
movsbl -0x13c(%rbp),%ecx
lea    0xac3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x2102,%edi
call   1040 <read_register@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x13b(%rbp)
mov    -0x18(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x13a(%rbp)
movsbl -0x140(%rbp),%esi
movsbl -0x13b(%rbp),%edx
movsbl -0x13a(%rbp),%ecx
lea    0xa74(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x2105,%edi
call   1040 <read_register@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x139(%rbp)
mov    -0x18(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x138(%rbp)
movsbl -0x140(%rbp),%esi
movsbl -0x139(%rbp),%edx
movsbl -0x138(%rbp),%ecx
lea    0xa25(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x2104,%edi
call   1040 <read_register@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x137(%rbp)
mov    -0x18(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x136(%rbp)
movsbl -0x140(%rbp),%esi
movsbl -0x137(%rbp),%edx
movsbl -0x136(%rbp),%ecx
lea    0x9d6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movb   $0xa,-0x135(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x140(%rbp),%rsi
mov    $0xc,%edx
mov    $0x0,%al
call   1050 <write@plt>
mov    %eax,-0x8(%rbp)
jmp    17b4 <procesar_request+0x604>
mov    $0x2001,%edi
mov    $0x64,%esi
call   1080 <write_register@plt>
mov    %eax,-0x10(%rbp)
mov    $0x2100,%edi
call   1040 <read_register@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
and    $0x100,%eax
cmp    $0x0,%eax
je     16b9 <procesar_request+0x509>
movq   $0x0,-0x150(%rbp)
mov    $0x0,%al
call   1090 <get_millis@plt>
mov    %rax,-0x148(%rbp)
mov    $0x0,%al
call   1090 <get_millis@plt>
mov    %rax,-0x158(%rbp)
mov    $0x2001,%edi
mov    $0x190,%esi
call   1080 <write_register@plt>
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1090 <get_millis@plt>
sub    -0x148(%rbp),%rax
cmp    $0x1f4,%rax
jbe    1760 <procesar_request+0x5b0>
mov    $0x2100,%edi
call   1040 <read_register@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xfd,-0x1c(%rbp)
jl     1752 <procesar_request+0x5a2>
mov    $0x0,%al
call   1090 <get_millis@plt>
mov    %rax,-0x150(%rbp)
mov    $0x0,%al
call   1090 <get_millis@plt>
mov    %rax,-0x148(%rbp)
mov    $0x2100,%edi
call   1040 <read_register@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
and    $0x100,%eax
cmp    $0x0,%eax
je     1710 <procesar_request+0x560>
mov    -0x150(%rbp),%rsi
sub    -0x158(%rbp),%rsi
lea    0x927(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    17b4 <procesar_request+0x604>
lea    -0x120(%rbp),%rsi
lea    0x925(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
jge    17d4 <procesar_request+0x624>
lea    0x927(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<procesar_request>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x128,%rsp
mov    %edi,%r14d
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x100,%esi
call   10c0 <bzero@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1060 <write@plt>
test   %eax,%eax
js     14f0 <procesar_request+0x330>
lea    0xe19(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x20(%rsp),%rsi
mov    %r14d,%edi
mov    $0xff,%edx
call   1080 <read@plt>
test   %eax,%eax
js     14f7 <procesar_request+0x337>
mov    %eax,%r15d
movsbl 0x20(%rsp),%eax
add    $0xffffffcf,%eax
cmp    $0x6,%eax
ja     1257 <procesar_request+0x97>
lea    0xdc3(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe9f(%rip),%rdi
call   1050 <puts@plt>
jmp    1327 <procesar_request+0x167>
lea    0xe1d(%rip),%rdi
lea    0x20(%rsp),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1417 <procesar_request+0x257>
lea    0xe6a(%rip),%rdi
call   1050 <puts@plt>
mov    $0x2000,%edi
mov    $0x2,%esi
jmp    12cf <procesar_request+0x10f>
lea    0xe47(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   10e0 <reset_pid@plt>
mov    $0x2000,%edi
mov    $0x1,%esi
jmp    12cf <procesar_request+0x10f>
lea    0xe16(%rip),%rdi
call   1050 <puts@plt>
movsbl 0x21(%rsp),%eax
shl    $0x8,%eax
movsbl 0x22(%rsp),%ebx
or     %eax,%ebx
xor    %eax,%eax
call   10e0 <reset_pid@plt>
mov    $0x2001,%edi
mov    %ebx,%esi
call   1090 <write_register@plt>
jmp    1417 <procesar_request+0x257>
lea    0xdcd(%rip),%rdi
call   1050 <puts@plt>
movsbl 0x21(%rsp),%eax
shl    $0x8,%eax
movsbl 0x22(%rsp),%ebp
or     %eax,%ebp
mov    $0x2103,%edi
call   1040 <read_register@plt>
mov    %eax,%ebx
lea    0xd45(%rip),%rdi
mov    %eax,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <printf@plt>
sub    %ebx,%ebp
mov    %ebp,%edi
call   1030 <pid_control@plt>
mov    $0x2001,%edi
mov    %eax,%esi
call   1090 <write_register@plt>
mov    $0x2100,%edi
call   1040 <read_register@plt>
movb   $0x31,(%rsp)
mov    %ah,0x1(%rsp)
mov    %al,0x2(%rsp)
mov    $0x2103,%edi
call   1040 <read_register@plt>
mov    %eax,%edx
movsbl %al,%ecx
rol    $0x8,%dx
shr    $0x8,%eax
mov    %dx,0x3(%rsp)
movsbl (%rsp),%esi
movsbl %al,%edx
lea    0xcd7(%rip),%rbp
mov    %rbp,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x2102,%edi
call   1040 <read_register@plt>
mov    %eax,%edx
movsbl %al,%ecx
rol    $0x8,%dx
shr    $0x8,%eax
mov    %dx,0x5(%rsp)
movsbl (%rsp),%esi
movsbl %al,%edx
mov    %rbp,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x2105,%edi
call   1040 <read_register@plt>
mov    %eax,%edx
movsbl %al,%ecx
rol    $0x8,%dx
shr    $0x8,%eax
mov    %dx,0x7(%rsp)
movsbl (%rsp),%esi
movsbl %al,%edx
mov    %rbp,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x2104,%edi
call   1040 <read_register@plt>
mov    %eax,%edx
movsbl %al,%ecx
rol    $0x8,%dx
shr    $0x8,%eax
mov    %dx,0x9(%rsp)
movsbl (%rsp),%esi
movsbl %al,%edx
mov    %rbp,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
movb   $0xa,0xb(%rsp)
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0xc,%edx
xor    %eax,%eax
call   1060 <write@plt>
mov    %eax,%r15d
test   %r15d,%r15d
js     14e7 <procesar_request+0x327>
add    $0x128,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x2001,%edi
mov    $0x64,%esi
call   1090 <write_register@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x2100,%edi
call   1040 <read_register@plt>
test   $0x100,%eax
je     1440 <procesar_request+0x280>
xor    %eax,%eax
call   10a0 <get_millis@plt>
mov    %rax,%rbp
xor    %eax,%eax
call   10a0 <get_millis@plt>
mov    %rax,%r14
mov    $0x2001,%edi
mov    $0x190,%esi
call   1090 <write_register@plt>
xor    %ebx,%ebx
jmp    149b <procesar_request+0x2db>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10a0 <get_millis@plt>
mov    %rax,%rbp
mov    $0x2100,%edi
call   1040 <read_register@plt>
test   $0x100,%eax
jne    14ca <procesar_request+0x30a>
xor    %eax,%eax
call   10a0 <get_millis@plt>
sub    %rbp,%rax
cmp    $0x1f5,%rax
jb     148a <procesar_request+0x2ca>
mov    $0x2100,%edi
call   1040 <read_register@plt>
cmp    $0xfd,%eax
jl     1480 <procesar_request+0x2c0>
xor    %eax,%eax
call   10a0 <get_millis@plt>
mov    %rax,%rbx
jmp    1480 <procesar_request+0x2c0>
sub    %r14,%rbx
lea    0xb8f(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
test   %r15d,%r15d
jns    1417 <procesar_request+0x257>
lea    0xba7(%rip),%rdi
jmp    14fe <procesar_request+0x33e>
xor    %edi,%edi
call   10d0 <exit@plt>
lea    0xb25(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"N: %d\0A\00"
@.str.1 = [26 x i8] c"ERROR reading from socket\00"
@.str.2 = [20 x i8] c"GET_STATUS REQUEST\0A\00"
@.str.3 = [15 x i8] c"0: %x, %x, %x\0A\00"
@.str.4 = [13 x i8] c"START MOTOR\0A\00"
@.str.5 = [12 x i8] c"STOP MOTOR\0A\00"
@.str.6 = [19 x i8] c"SET REFERENCE CMD\0A\00"
@.str.7 = [23 x i8] c"SET PID REFERENCE CMD\0A\00"
@.str.8 = [23 x i8] c"RES; %d, setpoint: %d\0A\00"
@.str.9 = [24 x i8] c"TAO = %lu milliseconds\0A\00"
@.str.10 = [26 x i8] c"UNRECOGNIZED COMMAND: %s\0A\00"
@.str.11 = [24 x i8] c"ERROR writing to socket\00"
define void @procesar_request(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [256 x i8]
%10 = alloca [30 x i8]
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
store i32 %0, i32* %2
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%15 = call i32 @bzero(i8* %14, i32 256)
%16 = load i32, i32* %2
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%18 = call i32 (i32, ...) @write(i32 %16, i8* %17, i32 1)
store i32 %18, i32* %3
%19 = load i32, i32* %3
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %1
%22 = call i32 @exit(i32 0)
unreachable
23: ; preds = %1
%24 = load i32, i32* %3
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %23
%27 = load i32, i32* %2
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%29 = call i32 @read(i32 %27, i8* %28, i32 255)
store i32 %29, i32* %3
%30 = load i32, i32* %3
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %26
%33 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %26
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
switch i32 %38, label %305 [
i32 49, label %39
i32 51, label %135
i32 52, label %138
i32 53, label %142
i32 54, label %155
i32 55, label %269
]
39: ; preds = %35
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%41 = call i32 @read_register(i32 8448)
store i32 %41, i32* %7
%42 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 0
store i8 49, i8* %42
%43 = load i32, i32* %7
%44 = ashr i32 %43, 8
%45 = and i32 %44, 255
%46 = trunc i32 %45 to i8
%47 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 1
store i8 %46, i8* %47
%48 = load i32, i32* %7
%49 = and i32 %48, 255
%50 = trunc i32 %49 to i8
%51 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 2
store i8 %50, i8* %51
%52 = call i32 @read_register(i32 8451)
store i32 %52, i32* %7
%53 = load i32, i32* %7
%54 = ashr i32 %53, 8
%55 = and i32 %54, 255
%56 = trunc i32 %55 to i8
%57 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 3
store i8 %56, i8* %57
%58 = load i32, i32* %7
%59 = and i32 %58, 255
%60 = trunc i32 %59 to i8
%61 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 4
store i8 %60, i8* %61
%62 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 0
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 3
%66 = load i8, i8* %65
%67 = sext i8 %66 to i32
%68 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 4
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %64, i32 %67, i32 %70)
%72 = call i32 @read_register(i32 8450)
store i32 %72, i32* %7
%73 = load i32, i32* %7
%74 = ashr i32 %73, 8
%75 = and i32 %74, 255
%76 = trunc i32 %75 to i8
%77 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 5
store i8 %76, i8* %77
%78 = load i32, i32* %7
%79 = and i32 %78, 255
%80 = trunc i32 %79 to i8
%81 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 6
store i8 %80, i8* %81
%82 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 0
%83 = load i8, i8* %82
%84 = sext i8 %83 to i32
%85 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 5
%86 = load i8, i8* %85
%87 = sext i8 %86 to i32
%88 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 6
%89 = load i8, i8* %88
%90 = sext i8 %89 to i32
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %84, i32 %87, i32 %90)
%92 = call i32 @read_register(i32 8453)
store i32 %92, i32* %7
%93 = load i32, i32* %7
%94 = ashr i32 %93, 8
%95 = and i32 %94, 255
%96 = trunc i32 %95 to i8
%97 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 7
store i8 %96, i8* %97
%98 = load i32, i32* %7
%99 = and i32 %98, 255
%100 = trunc i32 %99 to i8
%101 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 8
store i8 %100, i8* %101
%102 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 0
%103 = load i8, i8* %102
%104 = sext i8 %103 to i32
%105 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 7
%106 = load i8, i8* %105
%107 = sext i8 %106 to i32
%108 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 8
%109 = load i8, i8* %108
%110 = sext i8 %109 to i32
%111 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %104, i32 %107, i32 %110)
%112 = call i32 @read_register(i32 8452)
store i32 %112, i32* %7
%113 = load i32, i32* %7
%114 = ashr i32 %113, 8
%115 = and i32 %114, 255
%116 = trunc i32 %115 to i8
%117 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 9
store i8 %116, i8* %117
%118 = load i32, i32* %7
%119 = and i32 %118, 255
%120 = trunc i32 %119 to i8
%121 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 10
store i8 %120, i8* %121
%122 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 0
%123 = load i8, i8* %122
%124 = sext i8 %123 to i32
%125 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 9
%126 = load i8, i8* %125
%127 = sext i8 %126 to i32
%128 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 10
%129 = load i8, i8* %128
%130 = sext i8 %129 to i32
%131 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %124, i32 %127, i32 %130)
%132 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 11
store i8 10, i8* %132
%133 = load i32, i32* %2
%134 = call i32 (i32, ...) @write(i32 %133, [30 x i8]* %10, i32 12)
store i32 %134, i32* %3
br label %308
135: ; preds = %35
%136 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%137 = call i32 @write_register(i32 8192, i32 2)
store i32 %137, i32* %5
br label %308
138: ; preds = %35
%139 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%140 = call i32 (...) @reset_pid()
%141 = call i32 @write_register(i32 8192, i32 1)
store i32 %141, i32* %5
br label %308
142: ; preds = %35
%143 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %4
%144 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 1
%145 = load i8, i8* %144
%146 = sext i8 %145 to i32
%147 = shl i32 %146, 8
%148 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 2
%149 = load i8, i8* %148
%150 = sext i8 %149 to i32
%151 = or i32 %147, %150
store i32 %151, i32* %4
%152 = call i32 (...) @reset_pid()
%153 = load i32, i32* %4
%154 = call i32 @write_register(i32 8193, i32 %153)
store i32 %154, i32* %5
br label %308
155: ; preds = %35
%156 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
%157 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 1
%158 = load i8, i8* %157
%159 = sext i8 %158 to i32
%160 = shl i32 %159, 8
%161 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 2
%162 = load i8, i8* %161
%163 = sext i8 %162 to i32
%164 = or i32 %160, %163
store i32 %164, i32* %4
%165 = call i32 @read_register(i32 8451)
store i32 %165, i32* %7
%166 = load i32, i32* %7
%167 = load i32, i32* %4
%168 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i32 %166, i32 %167)
%169 = load i32, i32* %4
%170 = load i32, i32* %7
%171 = sub nsw i32 %169, %170
store i32 %171, i32* %6
%172 = load i32, i32* %6
%173 = call i32 @pid_control(i32 %172)
%174 = call i32 @write_register(i32 8193, i32 %173)
store i32 %174, i32* %5
%175 = call i32 @read_register(i32 8448)
store i32 %175, i32* %7
%176 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 0
store i8 49, i8* %176
%177 = load i32, i32* %7
%178 = ashr i32 %177, 8
%179 = and i32 %178, 255
%180 = trunc i32 %179 to i8
%181 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 1
store i8 %180, i8* %181
%182 = load i32, i32* %7
%183 = and i32 %182, 255
%184 = trunc i32 %183 to i8
%185 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 2
store i8 %184, i8* %185
%186 = call i32 @read_register(i32 8451)
store i32 %186, i32* %7
%187 = load i32, i32* %7
%188 = ashr i32 %187, 8
%189 = and i32 %188, 255
%190 = trunc i32 %189 to i8
%191 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 3
store i8 %190, i8* %191
%192 = load i32, i32* %7
%193 = and i32 %192, 255
%194 = trunc i32 %193 to i8
%195 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 4
store i8 %194, i8* %195
%196 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 0
%197 = load i8, i8* %196
%198 = sext i8 %197 to i32
%199 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 3
%200 = load i8, i8* %199
%201 = sext i8 %200 to i32
%202 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 4
%203 = load i8, i8* %202
%204 = sext i8 %203 to i32
%205 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %198, i32 %201, i32 %204)
%206 = call i32 @read_register(i32 8450)
store i32 %206, i32* %7
%207 = load i32, i32* %7
%208 = ashr i32 %207, 8
%209 = and i32 %208, 255
%210 = trunc i32 %209 to i8
%211 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 5
store i8 %210, i8* %211
%212 = load i32, i32* %7
%213 = and i32 %212, 255
%214 = trunc i32 %213 to i8
%215 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 6
store i8 %214, i8* %215
%216 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 0
%217 = load i8, i8* %216
%218 = sext i8 %217 to i32
%219 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 5
%220 = load i8, i8* %219
%221 = sext i8 %220 to i32
%222 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 6
%223 = load i8, i8* %222
%224 = sext i8 %223 to i32
%225 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %218, i32 %221, i32 %224)
%226 = call i32 @read_register(i32 8453)
store i32 %226, i32* %7
%227 = load i32, i32* %7
%228 = ashr i32 %227, 8
%229 = and i32 %228, 255
%230 = trunc i32 %229 to i8
%231 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 7
store i8 %230, i8* %231
%232 = load i32, i32* %7
%233 = and i32 %232, 255
%234 = trunc i32 %233 to i8
%235 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 8
store i8 %234, i8* %235
%236 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 0
%237 = load i8, i8* %236
%238 = sext i8 %237 to i32
%239 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 7
%240 = load i8, i8* %239
%241 = sext i8 %240 to i32
%242 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 8
%243 = load i8, i8* %242
%244 = sext i8 %243 to i32
%245 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %238, i32 %241, i32 %244)
%246 = call i32 @read_register(i32 8452)
store i32 %246, i32* %7
%247 = load i32, i32* %7
%248 = ashr i32 %247, 8
%249 = and i32 %248, 255
%250 = trunc i32 %249 to i8
%251 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 9
store i8 %250, i8* %251
%252 = load i32, i32* %7
%253 = and i32 %252, 255
%254 = trunc i32 %253 to i8
%255 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 10
store i8 %254, i8* %255
%256 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 0
%257 = load i8, i8* %256
%258 = sext i8 %257 to i32
%259 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 9
%260 = load i8, i8* %259
%261 = sext i8 %260 to i32
%262 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 10
%263 = load i8, i8* %262
%264 = sext i8 %263 to i32
%265 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %258, i32 %261, i32 %264)
%266 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 11
store i8 10, i8* %266
%267 = load i32, i32* %2
%268 = call i32 (i32, ...) @write(i32 %267, [30 x i8]* %10, i32 12)
store i32 %268, i32* %3
br label %308
269: ; preds = %35
%270 = call i32 @write_register(i32 8193, i32 100)
store i32 %270, i32* %5
br label %271
271: ; preds = %273, %269
%272 = call i32 @read_register(i32 8448)
store i32 %272, i32* %7
br label %273
273: ; preds = %271
%274 = load i32, i32* %7
%275 = and i32 %274, 256
%276 = icmp eq i32 %275, 0
br i1 %276, label %271, label %277
277: ; preds = %273
store i64 0, i64* %12
%278 = call i64 (...) @get_millis()
store i64 %278, i64* %11
%279 = call i64 (...) @get_millis()
store i64 %279, i64* %13
%280 = call i32 @write_register(i32 8193, i32 400)
store i32 %280, i32* %5
br label %281
281: ; preds = %296, %277
%282 = call i64 (...) @get_millis()
%283 = load i64, i64* %11
%284 = sub i64 %282, %283
%285 = icmp ugt i64 %284, 500
br i1 %285, label %286, label %294
286: ; preds = %281
%287 = call i32 @read_register(i32 8448)
store i32 %287, i32* %8
%288 = load i32, i32* %8
%289 = icmp sge i32 %288, 253
br i1 %289, label %290, label %292
290: ; preds = %286
%291 = call i64 (...) @get_millis()
store i64 %291, i64* %12
br label %292
292: ; preds = %290, %286
%293 = call i64 (...) @get_millis()
store i64 %293, i64* %11
br label %294
294: ; preds = %292, %281
%295 = call i32 @read_register(i32 8448)
store i32 %295, i32* %7
br label %296
296: ; preds = %294
%297 = load i32, i32* %7
%298 = and i32 %297, 256
%299 = icmp eq i32 %298, 0
br i1 %299, label %281, label %300
300: ; preds = %296
%301 = load i64, i64* %12
%302 = load i64, i64* %13
%303 = sub i64 %301, %302
%304 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0), i64 %303)
br label %308
305: ; preds = %35
%306 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%307 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0), i8* %306)
br label %308
308: ; preds = %305, %300, %155, %142, %138, %135, %39
%309 = load i32, i32* %3
%310 = icmp slt i32 %309, 0
br i1 %310, label %311, label %314
311: ; preds = %308
%312 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.11, i64 0, i64 0))
%313 = call i32 @exit(i32 1)
unreachable
314: ; preds = %308
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"N: %d\0A\00"
@.str.1 = [26 x i8] c"ERROR reading from socket\00"
@.str.3 = [15 x i8] c"0: %x, %x, %x\0A\00"
@.str.8 = [23 x i8] c"RES; %d, setpoint: %d\0A\00"
@.str.9 = [24 x i8] c"TAO = %lu milliseconds\0A\00"
@.str.10 = [26 x i8] c"UNRECOGNIZED COMMAND: %s\0A\00"
@.str.11 = [24 x i8] c"ERROR writing to socket\00"
@str = [22 x i8] c"SET PID REFERENCE CMD\00"
@str.12 = [18 x i8] c"SET REFERENCE CMD\00"
@str.13 = [11 x i8] c"STOP MOTOR\00"
@str.14 = [12 x i8] c"START MOTOR\00"
@str.15 = [19 x i8] c"GET_STATUS REQUEST\00"
define void @procesar_request(i32 %0) {
%2 = alloca [256 x i8]
%3 = alloca [30 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%6 = call i32 @bzero(i8* %4, i32 256)
%7 = call i32 (i32, ...) @write(i32 %0, i8* %4, i32 1)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @exit(i32 0)
unreachable
11: ; preds = %1
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %7)
%13 = call i32 @read(i32 %0, i8* %4, i32 255)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %11
%19 = load i8, i8* %4
%20 = sext i8 %19 to i32
switch i32 %20, label %210 [
i32 49, label %21
i32 51, label %83
i32 52, label %86
i32 53, label %90
i32 54, label %102
i32 55, label %177
]
21: ; preds = %18
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.15, i64 0, i64 0))
%23 = call i32 @read_register(i32 8448)
store i8 49, i8* %5
%24 = lshr i32 %23, 8
%25 = trunc i32 %24 to i8
%26 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 1
store i8 %25, i8* %26
%27 = trunc i32 %23 to i8
%28 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 2
store i8 %27, i8* %28
%29 = call i32 @read_register(i32 8451)
%30 = lshr i32 %29, 8
%31 = trunc i32 %30 to i8
%32 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 3
store i8 %31, i8* %32
%33 = trunc i32 %29 to i8
%34 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 4
store i8 %33, i8* %34
%35 = load i8, i8* %5
%36 = sext i8 %35 to i32
%37 = shl i32 %30, 24
%38 = ashr exact i32 %37, 24
%39 = shl i32 %29, 24
%40 = ashr exact i32 %39, 24
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %36, i32 %38, i32 %40)
%42 = call i32 @read_register(i32 8450)
%43 = lshr i32 %42, 8
%44 = trunc i32 %43 to i8
%45 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 5
store i8 %44, i8* %45
%46 = trunc i32 %42 to i8
%47 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 6
store i8 %46, i8* %47
%48 = load i8, i8* %5
%49 = sext i8 %48 to i32
%50 = shl i32 %43, 24
%51 = ashr exact i32 %50, 24
%52 = shl i32 %42, 24
%53 = ashr exact i32 %52, 24
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %49, i32 %51, i32 %53)
%55 = call i32 @read_register(i32 8453)
%56 = lshr i32 %55, 8
%57 = trunc i32 %56 to i8
%58 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 7
store i8 %57, i8* %58
%59 = trunc i32 %55 to i8
%60 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 8
store i8 %59, i8* %60
%61 = load i8, i8* %5
%62 = sext i8 %61 to i32
%63 = shl i32 %56, 24
%64 = ashr exact i32 %63, 24
%65 = shl i32 %55, 24
%66 = ashr exact i32 %65, 24
%67 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %62, i32 %64, i32 %66)
%68 = call i32 @read_register(i32 8452)
%69 = lshr i32 %68, 8
%70 = trunc i32 %69 to i8
%71 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 9
store i8 %70, i8* %71
%72 = trunc i32 %68 to i8
%73 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 10
store i8 %72, i8* %73
%74 = load i8, i8* %5
%75 = sext i8 %74 to i32
%76 = shl i32 %69, 24
%77 = ashr exact i32 %76, 24
%78 = shl i32 %68, 24
%79 = ashr exact i32 %78, 24
%80 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %75, i32 %77, i32 %79)
%81 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 11
store i8 10, i8* %81
%82 = call i32 (i32, ...) @write(i32 %0, [30 x i8]* %3, i32 12)
br label %212
83: ; preds = %18
%84 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.14, i64 0, i64 0))
%85 = call i32 @write_register(i32 8192, i32 2)
br label %218
86: ; preds = %18
%87 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.13, i64 0, i64 0))
%88 = call i32 (...) @reset_pid()
%89 = call i32 @write_register(i32 8192, i32 1)
br label %218
90: ; preds = %18
%91 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.12, i64 0, i64 0))
%92 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 1
%93 = load i8, i8* %92
%94 = sext i8 %93 to i32
%95 = shl nsw i32 %94, 8
%96 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 2
%97 = load i8, i8* %96
%98 = sext i8 %97 to i32
%99 = or i32 %95, %98
%100 = call i32 (...) @reset_pid()
%101 = call i32 @write_register(i32 8193, i32 %99)
br label %218
102: ; preds = %18
%103 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%104 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 1
%105 = load i8, i8* %104
%106 = sext i8 %105 to i32
%107 = shl nsw i32 %106, 8
%108 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 2
%109 = load i8, i8* %108
%110 = sext i8 %109 to i32
%111 = or i32 %107, %110
%112 = call i32 @read_register(i32 8451)
%113 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i32 %112, i32 %111)
%114 = sub nsw i32 %111, %112
%115 = call i32 @pid_control(i32 %114)
%116 = call i32 @write_register(i32 8193, i32 %115)
%117 = call i32 @read_register(i32 8448)
store i8 49, i8* %5
%118 = lshr i32 %117, 8
%119 = trunc i32 %118 to i8
%120 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 1
store i8 %119, i8* %120
%121 = trunc i32 %117 to i8
%122 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 2
store i8 %121, i8* %122
%123 = call i32 @read_register(i32 8451)
%124 = lshr i32 %123, 8
%125 = trunc i32 %124 to i8
%126 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 3
store i8 %125, i8* %126
%127 = trunc i32 %123 to i8
%128 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 4
store i8 %127, i8* %128
%129 = load i8, i8* %5
%130 = sext i8 %129 to i32
%131 = shl i32 %124, 24
%132 = ashr exact i32 %131, 24
%133 = shl i32 %123, 24
%134 = ashr exact i32 %133, 24
%135 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %130, i32 %132, i32 %134)
%136 = call i32 @read_register(i32 8450)
%137 = lshr i32 %136, 8
%138 = trunc i32 %137 to i8
%139 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 5
store i8 %138, i8* %139
%140 = trunc i32 %136 to i8
%141 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 6
store i8 %140, i8* %141
%142 = load i8, i8* %5
%143 = sext i8 %142 to i32
%144 = shl i32 %137, 24
%145 = ashr exact i32 %144, 24
%146 = shl i32 %136, 24
%147 = ashr exact i32 %146, 24
%148 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %143, i32 %145, i32 %147)
%149 = call i32 @read_register(i32 8453)
%150 = lshr i32 %149, 8
%151 = trunc i32 %150 to i8
%152 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 7
store i8 %151, i8* %152
%153 = trunc i32 %149 to i8
%154 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 8
store i8 %153, i8* %154
%155 = load i8, i8* %5
%156 = sext i8 %155 to i32
%157 = shl i32 %150, 24
%158 = ashr exact i32 %157, 24
%159 = shl i32 %149, 24
%160 = ashr exact i32 %159, 24
%161 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %156, i32 %158, i32 %160)
%162 = call i32 @read_register(i32 8452)
%163 = lshr i32 %162, 8
%164 = trunc i32 %163 to i8
%165 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 9
store i8 %164, i8* %165
%166 = trunc i32 %162 to i8
%167 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 10
store i8 %166, i8* %167
%168 = load i8, i8* %5
%169 = sext i8 %168 to i32
%170 = shl i32 %163, 24
%171 = ashr exact i32 %170, 24
%172 = shl i32 %162, 24
%173 = ashr exact i32 %172, 24
%174 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %169, i32 %171, i32 %173)
%175 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 11
store i8 10, i8* %175
%176 = call i32 (i32, ...) @write(i32 %0, [30 x i8]* %3, i32 12)
br label %212
177: ; preds = %18
%178 = call i32 @write_register(i32 8193, i32 100)
br label %179
179: ; preds = %179, %177
%180 = call i32 @read_register(i32 8448)
%181 = and i32 %180, 256
%182 = icmp eq i32 %181, 0
br i1 %182, label %179, label %183
183: ; preds = %179
%184 = call i64 (...) @get_millis()
%185 = call i64 (...) @get_millis()
%186 = call i32 @write_register(i32 8193, i32 400)
br label %187
187: ; preds = %201, %183
%188 = phi i64 [ %184, %183 ], [ %202, %201 ]
%189 = phi i64 [ 0, %183 ], [ %203, %201 ]
%190 = call i64 (...) @get_millis()
%191 = sub i64 %190, %188
%192 = icmp ugt i64 %191, 500
br i1 %192, label %193, label %201
193: ; preds = %187
%194 = call i32 @read_register(i32 8448)
%195 = icmp sgt i32 %194, 252
br i1 %195, label %196, label %198
196: ; preds = %193
%197 = call i64 (...) @get_millis()
br label %198
198: ; preds = %196, %193
%199 = phi i64 [ %197, %196 ], [ %189, %193 ]
%200 = call i64 (...) @get_millis()
br label %201
201: ; preds = %198, %187
%202 = phi i64 [ %200, %198 ], [ %188, %187 ]
%203 = phi i64 [ %199, %198 ], [ %189, %187 ]
%204 = call i32 @read_register(i32 8448)
%205 = and i32 %204, 256
%206 = icmp eq i32 %205, 0
br i1 %206, label %187, label %207
207: ; preds = %201
%208 = sub i64 %203, %185
%209 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0), i64 %208)
br label %212
210: ; preds = %18
%211 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0), i8* %4)
br label %218
212: ; preds = %207, %102, %21
%213 = phi i32 [ %13, %207 ], [ %176, %102 ], [ %82, %21 ]
%214 = icmp slt i32 %213, 0
br i1 %214, label %215, label %218
215: ; preds = %212
%216 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.11, i64 0, i64 0))
%217 = call i32 @exit(i32 1)
unreachable
218: ; preds = %83, %86, %90, %210, %212
ret void
}