#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 */
struct termios {
  int c_cflag;
  int c_lflag;
  int c_iflag;
  scalar_t__ *c_cc;
  int /*<<< orphan*/ c_oflag;
};
typedef int /*<<< orphan*/ pattr;

/* Variables and functions */
int B4800;
int CBAUD;
int CLOCAL;
int CREAD;
int CRTSCTS;
int CS8;
int CSIZE;
int CSTOPB;
int ECHO;
int ECHOE;
int ICANON;
int ICRNL;
int INPCK;
int ISIG;
int ISTRIP;
int IXANY;
int IXOFF;
int IXON;
int /*<<< orphan*/ OPOST;
int O_NDELAY;
int O_NOCTTY;
int O_RDWR;
int PARENB;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ cfsetispeed(struct termios *, int);
int /*<<< orphan*/ cfsetospeed(struct termios *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ memset(struct termios *, int /*<<< orphan*/, int);
int open(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
scalar_t__ tcgetattr(int, struct termios *);
int tcsetattr(int, int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ usleep(int);
int main(int argc, char *argv[]) {
  char config[] = {0xA0, 0xA3, 0x81, 2, 1,    1,    0, 1,    1,    1,
                   5,    1,    1,    1, 0,    1,    0, 1,    0,    0,
                   0,    1,    0,    0, 0x25, 0x80, 1, 0x3A, 0xB0, 0xB3};
  int speed = B4800;
  int iaux = 0;
  struct termios pattr;
  memset(&pattr, 0, sizeof(pattr));
  int icom = open("/dev/ttyAMA0", O_RDWR | O_NOCTTY | O_NDELAY);
  if (icom < 0) {
    printf("No se pudo abrir la uart.\r\n");
    return -1;
  }
  if (tcgetattr(icom, &pattr) < 0) {
    printf("No se pudo leer la configuración actual de puerto.\r\n");
    close(icom);
    return -1;
  }
  pattr.c_cflag &= ~PARENB;
  pattr.c_cflag &= ~CSTOPB;
  pattr.c_cflag |= CLOCAL | CREAD;
  pattr.c_cflag &= ~CSIZE;
  pattr.c_cflag |= CS8;
  pattr.c_cflag &= ~CBAUD;
  pattr.c_cflag |= speed;
  cfsetispeed(&pattr, speed);
  cfsetospeed(&pattr, speed);
  pattr.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
  pattr.c_oflag &= ~OPOST;
  pattr.c_iflag &= ~(IXON | IXOFF | IXANY);
  pattr.c_cflag &= ~CRTSCTS;
  pattr.c_iflag &= ~(INPCK | ISTRIP);
  pattr.c_iflag &= ~ICRNL;
  pattr.c_cc[VMIN] = 0;
  pattr.c_cc[VTIME] = 0;
  if (tcsetattr(icom, TCSANOW, &pattr) == -1) {
    printf("No se pudo configurar la UART\r\n");
    close(icom);
    return -1;
  }
  char buffer[10001];
  while (1) {
    usleep(1000000);
    int leido = read(icom, buffer, 10000);
    if (leido < 0)
      break;
    if (leido == 0)
      continue;
    for (iaux = 0; iaux < leido; iaux++) {
      if (buffer[iaux] == 0xA0 && buffer[iaux + 1] == 0xA2) {
        printf("\r\n!!!\r\n");
      }
    }
    buffer[leido] = 0;
    for (iaux = 0; iaux < leido; iaux++) {
      printf("0x%02X,", buffer[iaux]);
    }
    printf("\r\n%d\r\n", leido);
    printf("%s\r\n", buffer);
  }
  printf("Fin\r\n");
  close(icom);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2780,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe40(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe3d(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe3a(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe38(%rip),%eax
mov    %eax,-0x18(%rbp)
mov    0xe32(%rip),%ax
mov    %ax,-0x14(%rbp)
mov    0x2da3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
lea    -0x58(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%esi
mov    0x2d3f(%rip),%rax
or     (%rax),%esi
mov    0x2d26(%rip),%rax
or     (%rax),%esi
lea    0xdeb(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jge    125f <main+0xbf>
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1583 <main+0x3e3>
mov    -0x5c(%rbp),%edi
lea    -0x58(%rbp),%rsi
call   1080 <tcgetattr@plt>
cmp    $0x0,%rax
jge    1297 <main+0xf7>
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x5c(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1583 <main+0x3e3>
mov    0x2d22(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x58(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    0x2c68(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x58(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    0x2c4e(%rip),%rax
mov    (%rax),%eax
mov    0x2cc5(%rip),%rcx
or     (%rcx),%eax
or     -0x58(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    0x2c9e(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x58(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    0x2c9c(%rip),%rax
mov    (%rax),%eax
or     -0x58(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    0x2c2d(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x58(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x34(%rbp),%eax
or     -0x58(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x34(%rbp),%esi
lea    -0x58(%rbp),%rdi
call   10b0 <cfsetispeed@plt>
mov    -0x34(%rbp),%esi
lea    -0x58(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    0x2c0a(%rip),%rax
mov    (%rax),%eax
mov    0x2c79(%rip),%rcx
or     (%rcx),%eax
mov    0x2c68(%rip),%rcx
or     (%rcx),%eax
mov    0x2c57(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x54(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    0x2c75(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x40(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    0x2c5b(%rip),%rax
mov    (%rax),%eax
mov    0x2c62(%rip),%rcx
or     (%rcx),%eax
mov    0x2be9(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x50(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    0x2b8f(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x58(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    0x2bb5(%rip),%rax
mov    (%rax),%eax
mov    0x2b9c(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x50(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    0x2c22(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x50(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0x48(%rbp),%rax
mov    0x2bac(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x48(%rbp),%rax
mov    0x2b56(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x5c(%rbp),%edi
mov    0x2bb9(%rip),%rax
mov    (%rax),%esi
lea    -0x58(%rbp),%rdx
call   1090 <tcsetattr@plt>
cmp    $0xffffffff,%eax
jne    1435 <main+0x295>
lea    0xc63(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x5c(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1583 <main+0x3e3>
jmp    143a <main+0x29a>
mov    $0xf4240,%edi
call   10c0 <usleep@plt>
mov    -0x5c(%rbp),%edi
lea    -0x2770(%rbp),%rsi
mov    $0x2710,%edx
call   1070 <read@plt>
mov    %eax,-0x2774(%rbp)
cmpl   $0x0,-0x2774(%rbp)
jge    1470 <main+0x2d0>
jmp    1566 <main+0x3c6>
cmpl   $0x0,-0x2774(%rbp)
jne    1482 <main+0x2e2>
jmp    143a <main+0x29a>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x2774(%rbp),%eax
jge    14eb <main+0x34b>
movslq -0x38(%rbp),%rax
movsbl -0x2770(%rbp,%rax,1),%eax
ff
cmp    $0xa0,%eax
jne    14d8 <main+0x338>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
cltq
movsbl -0x2770(%rbp,%rax,1),%eax
ff
cmp    $0xa2,%eax
jne    14d8 <main+0x338>
lea    0xbcc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    14dd <main+0x33d>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1489 <main+0x2e9>
movslq -0x2774(%rbp),%rax
movb   $0x0,-0x2770(%rbp,%rax,1)
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x2774(%rbp),%eax
jge    1538 <main+0x398>
movslq -0x38(%rbp),%rax
movsbl -0x2770(%rbp,%rax,1),%esi
ff
lea    0xb82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1501 <main+0x361>
mov    -0x2774(%rbp),%esi
lea    0xb68(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x2770(%rbp),%rsi
lea    0xb5a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    143a <main+0x29a>
lea    0xb4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x5c(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2780,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2738,%rsp
mov    0x2dd0(%rip),%rax
mov    (%rax),%ebp
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    0x2e08(%rip),%rax
mov    0x2d79(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d5e(%rip),%rax
or     (%rax),%esi
lea    0xe05(%rip),%rdi
call   10b0 <open@plt>
test   %eax,%eax
js     13fc <main+0x24c>
mov    %eax,%r15d
mov    %rsp,%rsi
mov    %eax,%edi
call   1090 <tcgetattr@plt>
test   %rax,%rax
js     1422 <main+0x272>
mov    0x2d9b(%rip),%rax
mov    (%rax),%eax
mov    0x2cea(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    (%rsp),%eax
mov    0x2cd4(%rip),%rcx
or     (%rcx),%eax
mov    0x2d4b(%rip),%rcx
or     (%rcx),%eax
mov    0x2d2a(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %eax,%ecx
mov    0x2d2d(%rip),%rax
or     (%rax),%ecx
mov    0x2cc4(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %ecx,%eax
or     %ebp,%eax
mov    %eax,(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
mov    %ebp,%esi
call   10c0 <cfsetispeed@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <cfsetospeed@plt>
mov    0x2cab(%rip),%rax
mov    0x2d1c(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d09(%rip),%rax
or     (%rax),%ecx
mov    0x2cf8(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x4(%rsp)
mov    0x2d19(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x18(%rsp)
mov    0x2d02(%rip),%rax
mov    0x2d0b(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2c90(%rip),%rax
mov    0x2c41(%rip),%rdx
mov    (%rdx),%edx
not    %edx
and    %edx,(%rsp)
or     (%rax),%ecx
mov    0x2c69(%rip),%rax
mov    0x2c52(%rip),%rdx
mov    (%rdx),%edx
or     (%rax),%edx
or     %ecx,%edx
mov    0x2cdd(%rip),%rax
or     (%rax),%edx
not    %edx
and    %edx,0x8(%rsp)
mov    0x10(%rsp),%rax
mov    0x2c69(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2c17(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2c7d(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
mov    %r14,%rdx
call   10a0 <tcsetattr@plt>
cmp    $0xffffffff,%eax
je     142b <main+0x27b>
mov    $0xf4240,%edi
call   10d0 <usleep@plt>
lea    0x20(%rsp),%rsi
mov    %r15d,%edi
mov    $0x2710,%edx
call   1080 <read@plt>
test   %eax,%eax
js     140a <main+0x25a>
mov    %eax,%ebp
lea    0x20(%rsp),%r13
lea    0xc8a(%rip),%rbx
jmp    13b0 <main+0x200>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0xf4240,%edi
call   10d0 <usleep@plt>
mov    %r15d,%edi
mov    %r13,%rsi
mov    $0x2710,%edx
call   1080 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
js     140a <main+0x25a>
test   %ebp,%ebp
je     1390 <main+0x1e0>
mov    %ebp,%r14d
movb   $0x0,0x20(%rsp,%r14,1)
xor    %r12d,%r12d
movsbl 0x20(%rsp,%r12,1),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%r12
cmp    %r12,%r14
jne    13c0 <main+0x210>
lea    0xc35(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xc2c(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1390 <main+0x1e0>
lea    0xc77(%rip),%rdi
call   1030 <puts@plt>
jmp    143f <main+0x28f>
lea    0xc10(%rip),%rdi
call   1030 <puts@plt>
mov    %r15d,%edi
call   1070 <close@plt>
xor    %eax,%eax
jmp    1444 <main+0x294>
lea    0xc1c(%rip),%rdi
jmp    1432 <main+0x282>
lea    0xbf4(%rip),%rdi
call   1030 <puts@plt>
mov    %r15d,%edi
call   1070 <close@plt>
mov    $0xffffffff,%eax
add    $0x2738,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32, i64*, i32 }
@__const.main.config = [30 x i8] c"\A0\A3\81\02\01\01\00\01\01\01\05\01\01\01\00\01\00\01\00\00\00\01\00\00%\80\01:\B0\B3"
@B4800 = global i32 0
@.str = [13 x i8] c"/dev/ttyAMA0\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@.str.1 = [28 x i8] c"No se pudo abrir la uart.\0D\0A\00"
@.str.2 = [54 x i8] c"No se pudo leer la configuraci\C3\B3n actual de puerto.\0D\0A\00"
@PARENB = global i32 0
@CSTOPB = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@CBAUD = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@OPOST = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = global i32 0
@CRTSCTS = global i32 0
@INPCK = global i32 0
@ISTRIP = global i32 0
@ICRNL = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
@.str.3 = [32 x i8] c"No se pudo configurar la UART\0D\0A\00"
@.str.4 = [8 x i8] c"\0D\0A!!!\0D\0A\00"
@.str.5 = [8 x i8] c"0x%02X,\00"
@.str.6 = [7 x i8] c"\0D\0A%d\0D\0A\00"
@.str.7 = [5 x i8] c"%s\0D\0A\00"
@.str.8 = [6 x i8] c"Fin\0D\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [30 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.termios
%10 = alloca i32
%11 = alloca [10001 x i8]
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = bitcast [30 x i8]* %6 to i8*
%14 = load i32, i32* @B4800
store i32 %14, i32* %7
store i32 0, i32* %8
%15 = call i32 @memset(%struct.termios* %9, i32 0, i32 32)
%16 = load i32, i32* @O_RDWR
%17 = load i32, i32* @O_NOCTTY
%18 = or i32 %16, %17
%19 = load i32, i32* @O_NDELAY
%20 = or i32 %18, %19
%21 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %20)
store i32 %21, i32* %10
%22 = load i32, i32* %10
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %2
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %197
26: ; preds = %2
%27 = load i32, i32* %10
%28 = call i64 @tcgetattr(i32 %27, %struct.termios* %9)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0))
%32 = load i32, i32* %10
%33 = call i32 @close(i32 %32)
store i32 -1, i32* %3
br label %197
34: ; preds = %26
%35 = load i32, i32* @PARENB
%36 = xor i32 %35, -1
%37 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 0
%38 = load i32, i32* %37
%39 = and i32 %38, %36
store i32 %39, i32* %37
%40 = load i32, i32* @CSTOPB
%41 = xor i32 %40, -1
%42 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 0
%43 = load i32, i32* %42
%44 = and i32 %43, %41
store i32 %44, i32* %42
%45 = load i32, i32* @CLOCAL
%46 = load i32, i32* @CREAD
%47 = or i32 %45, %46
%48 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 0
%49 = load i32, i32* %48
%50 = or i32 %49, %47
store i32 %50, i32* %48
%51 = load i32, i32* @CSIZE
%52 = xor i32 %51, -1
%53 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 0
%54 = load i32, i32* %53
%55 = and i32 %54, %52
store i32 %55, i32* %53
%56 = load i32, i32* @CS8
%57 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 0
%58 = load i32, i32* %57
%59 = or i32 %58, %56
store i32 %59, i32* %57
%60 = load i32, i32* @CBAUD
%61 = xor i32 %60, -1
%62 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 0
%63 = load i32, i32* %62
%64 = and i32 %63, %61
store i32 %64, i32* %62
%65 = load i32, i32* %7
%66 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 0
%67 = load i32, i32* %66
%68 = or i32 %67, %65
store i32 %68, i32* %66
%69 = load i32, i32* %7
%70 = call i32 @cfsetispeed(%struct.termios* %9, i32 %69)
%71 = load i32, i32* %7
%72 = call i32 @cfsetospeed(%struct.termios* %9, i32 %71)
%73 = load i32, i32* @ICANON
%74 = load i32, i32* @ECHO
%75 = or i32 %73, %74
%76 = load i32, i32* @ECHOE
%77 = or i32 %75, %76
%78 = load i32, i32* @ISIG
%79 = or i32 %77, %78
%80 = xor i32 %79, -1
%81 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 1
%82 = load i32, i32* %81
%83 = and i32 %82, %80
store i32 %83, i32* %81
%84 = load i32, i32* @OPOST
%85 = xor i32 %84, -1
%86 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 4
%87 = load i32, i32* %86
%88 = and i32 %87, %85
store i32 %88, i32* %86
%89 = load i32, i32* @IXON
%90 = load i32, i32* @IXOFF
%91 = or i32 %89, %90
%92 = load i32, i32* @IXANY
%93 = or i32 %91, %92
%94 = xor i32 %93, -1
%95 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 2
%96 = load i32, i32* %95
%97 = and i32 %96, %94
store i32 %97, i32* %95
%98 = load i32, i32* @CRTSCTS
%99 = xor i32 %98, -1
%100 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 0
%101 = load i32, i32* %100
%102 = and i32 %101, %99
store i32 %102, i32* %100
%103 = load i32, i32* @INPCK
%104 = load i32, i32* @ISTRIP
%105 = or i32 %103, %104
%106 = xor i32 %105, -1
%107 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 2
%108 = load i32, i32* %107
%109 = and i32 %108, %106
store i32 %109, i32* %107
%110 = load i32, i32* @ICRNL
%111 = xor i32 %110, -1
%112 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 2
%113 = load i32, i32* %112
%114 = and i32 %113, %111
store i32 %114, i32* %112
%115 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 3
%116 = load i64*, i64** %115
%117 = load i64, i64* @VMIN
%118 = getelementptr inbounds i64, i64* %116, i64 %117
store i64 0, i64* %118
%119 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 3
%120 = load i64*, i64** %119
%121 = load i64, i64* @VTIME
%122 = getelementptr inbounds i64, i64* %120, i64 %121
store i64 0, i64* %122
%123 = load i32, i32* %10
%124 = load i32, i32* @TCSANOW
%125 = call i32 @tcsetattr(i32 %123, i32 %124, %struct.termios* %9)
%126 = icmp eq i32 %125, -1
br i1 %126, label %127, label %131
127: ; preds = %34
%128 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%129 = load i32, i32* %10
%130 = call i32 @close(i32 %129)
store i32 -1, i32* %3
br label %197
131: ; preds = %34
br label %132
132: ; preds = %131, %143, %188
%133 = call i32 @usleep(i32 1000000)
%134 = load i32, i32* %10
%135 = getelementptr inbounds [10001 x i8], [10001 x i8]* %11, i64 0, i64 0
%136 = call i32 @read(i32 %134, i8* %135, i32 10000)
store i32 %136, i32* %12
%137 = load i32, i32* %12
%138 = icmp slt i32 %137, 0
br i1 %138, label %139, label %140
139: ; preds = %132
br label %193
140: ; preds = %132
%141 = load i32, i32* %12
%142 = icmp eq i32 %141, 0
br i1 %142, label %143, label %144
143: ; preds = %140
br label %132
144: ; preds = %140
store i32 0, i32* %8
br label %145
145: ; preds = %167, %144
%146 = load i32, i32* %8
%147 = load i32, i32* %12
%148 = icmp slt i32 %146, %147
br i1 %148, label %149, label %170
149: ; preds = %145
%150 = load i32, i32* %8
%151 = sext i32 %150 to i64
%152 = getelementptr inbounds [10001 x i8], [10001 x i8]* %11, i64 0, i64 %151
%153 = load i8, i8* %152
%154 = sext i8 %153 to i32
%155 = icmp eq i32 %154, 160
br i1 %155, label %156, label %166
156: ; preds = %149
%157 = load i32, i32* %8
%158 = add nsw i32 %157, 1
%159 = sext i32 %158 to i64
%160 = getelementptr inbounds [10001 x i8], [10001 x i8]* %11, i64 0, i64 %159
%161 = load i8, i8* %160
%162 = sext i8 %161 to i32
%163 = icmp eq i32 %162, 162
br i1 %163, label %164, label %166
164: ; preds = %156
%165 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %166
166: ; preds = %164, %156, %149
br label %167
167: ; preds = %166
%168 = load i32, i32* %8
%169 = add nsw i32 %168, 1
store i32 %169, i32* %8
br label %145
170: ; preds = %145
%171 = load i32, i32* %12
%172 = sext i32 %171 to i64
%173 = getelementptr inbounds [10001 x i8], [10001 x i8]* %11, i64 0, i64 %172
store i8 0, i8* %173
store i32 0, i32* %8
br label %174
174: ; preds = %185, %170
%175 = load i32, i32* %8
%176 = load i32, i32* %12
%177 = icmp slt i32 %175, %176
br i1 %177, label %178, label %188
178: ; preds = %174
%179 = load i32, i32* %8
%180 = sext i32 %179 to i64
%181 = getelementptr inbounds [10001 x i8], [10001 x i8]* %11, i64 0, i64 %180
%182 = load i8, i8* %181
%183 = sext i8 %182 to i32
%184 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %183)
br label %185
185: ; preds = %178
%186 = load i32, i32* %8
%187 = add nsw i32 %186, 1
store i32 %187, i32* %8
br label %174
188: ; preds = %174
%189 = load i32, i32* %12
%190 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 %189)
%191 = getelementptr inbounds [10001 x i8], [10001 x i8]* %11, i64 0, i64 0
%192 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* %191)
br label %132
193: ; preds = %139
%194 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%195 = load i32, i32* %10
%196 = call i32 @close(i32 %195)
store i32 0, i32* %3
br label %197
197: ; preds = %193, %127, %30, %24
%198 = load i32, i32* %3
ret i32 %198
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32, i64*, i32 }
@B4800 = global i32 0
@.str = [13 x i8] c"/dev/ttyAMA0\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@CBAUD = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@OPOST = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = global i32 0
@CRTSCTS = global i32 0
@INPCK = global i32 0
@ISTRIP = global i32 0
@ICRNL = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
@.str.5 = [8 x i8] c"0x%02X,\00"
@.str.6 = [7 x i8] c"\0D\0A%d\0D\0A\00"
@.str.7 = [5 x i8] c"%s\0D\0A\00"
@str = [5 x i8] c"Fin\0D\00"
@str.9 = [31 x i8] c"No se pudo configurar la UART\0D\00"
@str.10 = [53 x i8] c"No se pudo leer la configuraci\C3\B3n actual de puerto.\0D\00"
@str.11 = [27 x i8] c"No se pudo abrir la uart.\0D\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.termios
%4 = alloca [10001 x i8]
%5 = load i32, i32* @B4800
%6 = bitcast %struct.termios* %3 to i8*
%7 = call i32 @memset(%struct.termios* %3, i32 0, i32 32)
%8 = load i32, i32* @O_RDWR
%9 = load i32, i32* @O_NOCTTY
%10 = or i32 %9, %8
%11 = load i32, i32* @O_NDELAY
%12 = or i32 %10, %11
%13 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.11, i64 0, i64 0))
br label %123
17: ; preds = %2
%18 = call i64 @tcgetattr(i32 %13, %struct.termios* %3)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str.10, i64 0, i64 0))
%22 = call i32 @close(i32 %13)
br label %123
23: ; preds = %17
%24 = load i32, i32* @PARENB
%25 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%26 = load i32, i32* %25
%27 = load i32, i32* @CSTOPB
%28 = or i32 %24, %27
%29 = xor i32 %28, -1
%30 = and i32 %26, %29
%31 = load i32, i32* @CLOCAL
%32 = load i32, i32* @CREAD
%33 = or i32 %31, %30
%34 = or i32 %33, %32
%35 = load i32, i32* @CSIZE
%36 = xor i32 %35, -1
%37 = and i32 %34, %36
%38 = load i32, i32* @CS8
%39 = or i32 %38, %37
%40 = load i32, i32* @CBAUD
%41 = xor i32 %40, -1
%42 = and i32 %39, %41
%43 = or i32 %42, %5
store i32 %43, i32* %25
%44 = call i32 @cfsetispeed(%struct.termios* %3, i32 %5)
%45 = call i32 @cfsetospeed(%struct.termios* %3, i32 %5)
%46 = load i32, i32* @ICANON
%47 = load i32, i32* @ECHO
%48 = or i32 %47, %46
%49 = load i32, i32* @ECHOE
%50 = or i32 %48, %49
%51 = load i32, i32* @ISIG
%52 = or i32 %50, %51
%53 = xor i32 %52, -1
%54 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
%55 = load i32, i32* %54
%56 = and i32 %55, %53
store i32 %56, i32* %54
%57 = load i32, i32* @OPOST
%58 = xor i32 %57, -1
%59 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 4
%60 = load i32, i32* %59
%61 = and i32 %60, %58
store i32 %61, i32* %59
%62 = load i32, i32* @IXON
%63 = load i32, i32* @IXOFF
%64 = or i32 %63, %62
%65 = load i32, i32* @IXANY
%66 = or i32 %64, %65
%67 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 2
%68 = load i32, i32* %67
%69 = load i32, i32* @CRTSCTS
%70 = xor i32 %69, -1
%71 = load i32, i32* %25
%72 = and i32 %71, %70
store i32 %72, i32* %25
%73 = load i32, i32* @INPCK
%74 = load i32, i32* @ISTRIP
%75 = or i32 %74, %73
%76 = or i32 %66, %75
%77 = load i32, i32* @ICRNL
%78 = or i32 %76, %77
%79 = xor i32 %78, -1
%80 = and i32 %68, %79
store i32 %80, i32* %67
%81 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 3
%82 = load i64*, i64** %81
%83 = load i64, i64* @VMIN
%84 = getelementptr inbounds i64, i64* %82, i64 %83
store i64 0, i64* %84
%85 = load i64, i64* @VTIME
%86 = getelementptr inbounds i64, i64* %82, i64 %85
store i64 0, i64* %86
%87 = load i32, i32* @TCSANOW
%88 = call i32 @tcsetattr(i32 %13, i32 %87, %struct.termios* %3)
%89 = icmp eq i32 %88, -1
br i1 %89, label %90, label %93
90: ; preds = %23
%91 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.9, i64 0, i64 0))
%92 = call i32 @close(i32 %13)
br label %123
93: ; preds = %23
%94 = getelementptr inbounds [10001 x i8], [10001 x i8]* %4, i64 0, i64 0
%95 = call i32 @usleep(i32 1000000)
%96 = call i32 @read(i32 %13, i8* %94, i32 10000)
%97 = icmp slt i32 %96, 0
br i1 %97, label %120, label %98
98: ; preds = %93, %116
%99 = phi i32 [ %118, %116 ], [ %96, %93 ]
%100 = icmp eq i32 %99, 0
br i1 %100, label %116, label %101
101: ; preds = %98
%102 = zext i32 %99 to i64
%103 = getelementptr inbounds [10001 x i8], [10001 x i8]* %4, i64 0, i64 %102
store i8 0, i8* %103
%104 = zext i32 %99 to i64
br label %105
105: ; preds = %101, %105
%106 = phi i64 [ 0, %101 ], [ %111, %105 ]
%107 = getelementptr inbounds [10001 x i8], [10001 x i8]* %4, i64 0, i64 %106
%108 = load i8, i8* %107
%109 = sext i8 %108 to i32
%110 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %109)
%111 = add nuw nsw i64 %106, 1
%112 = icmp eq i64 %111, %104
br i1 %112, label %113, label %105
113: ; preds = %105
%114 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 %99)
%115 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* %94)
br label %116
116: ; preds = %98, %113
%117 = call i32 @usleep(i32 1000000)
%118 = call i32 @read(i32 %13, i8* %94, i32 10000)
%119 = icmp slt i32 %118, 0
br i1 %119, label %120, label %98
120: ; preds = %116, %93
%121 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%122 = call i32 @close(i32 %13)
br label %123
123: ; preds = %120, %90, %20, %15
%124 = phi i32 [ -1, %15 ], [ -1, %20 ], [ -1, %90 ], [ 0, %120 ]
ret i32 %124
}