#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 {
  scalar_t__ *c_cc;
  int /*<<< orphan*/ c_lflag;
};
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ ICANON;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int atoi(char *);
int /*<<< orphan*/ log_date(char *);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
scalar_t__ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/,
                  int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
scalar_t__ uart_close(int, struct termios *);
int uart_open(char *, int, struct termios *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  fd_set readfds;
  int fd = -1, loop = 1, i;
  char c;
  struct termios stdinattr, stdin_bk;
  struct termios uartattr;
  char UART_DEVICE[15] = "/dev/ttyUSB10";
  printf("Petit Ichigo Term for Raspberry Pi\n");
  if (argc == 2) {
    i = atoi(argv[1]);
    if (i > 0 && i <= 64) {
      snprintf(&UART_DEVICE[5], 8, "ttyS%1d", i - 1);
      fd = uart_open(UART_DEVICE, 115200, &uartattr);
    }
  } else
    for (i = 22; i >= 0; i--) {
      if (i >= 20)
        snprintf(&UART_DEVICE[5], 8, "rfcomm%1d", i - 20);
      else if (i >= 10)
        snprintf(&UART_DEVICE[5], 8, "ttyUSB%1d", i - 10);
      else if (i == 9)
        snprintf(&UART_DEVICE[5], 8, "ttyAMA0");
      else
        snprintf(&UART_DEVICE[5], 8, "ttyS%1d", i);
      fd = uart_open(UART_DEVICE, 115200, &uartattr);
      if (fd >= 0)
        break;
    }
  if (fd < 0) {
    log_date("ERROR @ UART OPEN");
    return 1;
  } else {
    log_date(UART_DEVICE);
  }
  tcgetattr(0, &stdinattr);
  tcgetattr(0, &stdin_bk);
  stdinattr.c_lflag &= ~ICANON;
  stdinattr.c_cc[VMIN] = 0;
  stdinattr.c_cc[VTIME] = 0;
  tcsetattr(0, TCSANOW, &stdinattr);
  log_date("CONNECTED");
  log_date("Type '---' to exit.");
  c = 0x10;
  write(fd, &c, 1);
  while (loop) {
    FD_ZERO(&readfds);
    FD_SET(0, &readfds);
    FD_SET(fd, &readfds);
    if (select(fd + 1, &readfds, 0, 0, 0) != 0) {
      if (FD_ISSET(0, &readfds)) {
        if (read(0, &c, 1) == 1) {
          if (c == '\n') {
            write(fd, "\n", 1);
          } else {
            write(fd, &c, 1);
          }
          if (c == '-') {
            loop++;
            if (loop > 3) {
              loop = 0;
              write(fd, "\b\b\b", 3);
              printf("\n");
            }
          } else
            loop = 1;
        }
      }
      if (FD_ISSET(fd, &readfds)) {
        if (read(fd, &c, 1) == 1) {
          if (c == '\n') {
            write(1, "\n", 1);
          } else {
            write(1, &c, 1);
          }
        }
      }
    }
  }
  tcsetattr(0, TCSANOW, &stdin_bk);
  if (uart_close(fd, &uartattr)) {
    log_date("ERROR @ UART CLOSE");
    return 1;
  }
  log_date("CLOSED");
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    0xdf5(%rip),%rax
mov    %rax,-0x67(%rbp)
mov    0xdf3(%rip),%eax
mov    %eax,-0x5f(%rbp)
mov    0xded(%rip),%ax
mov    %ax,-0x5b(%rbp)
mov    0xde5(%rip),%al
mov    %al,-0x59(%rbp)
lea    0xddc(%rip),%rdi
call   1050 <printf@plt>
cmpl   $0x2,-0x8(%rbp)
jne    12a1 <main+0xc1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jle    129c <main+0xbc>
cmpl   $0x40,-0x20(%rbp)
jg     129c <main+0xbc>
lea    -0x67(%rbp),%rdi
add    $0x5,%rdi
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x8,%esi
lea    0xdb3(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
lea    -0x67(%rbp),%rdi
mov    $0x1c200,%esi
lea    -0x58(%rbp),%rdx
call   10e0 <uart_open@plt>
mov    %eax,-0x18(%rbp)
jmp    13a0 <main+0x1c0>
movl   $0x16,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jl     139b <main+0x1bb>
cmpl   $0x14,-0x20(%rbp)
jl     12e2 <main+0x102>
lea    -0x67(%rbp),%rdi
add    $0x5,%rdi
mov    -0x20(%rbp),%ecx
sub    $0x14,%ecx
mov    $0x8,%esi
lea    0xd65(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
jmp    1364 <main+0x184>
cmpl   $0xa,-0x20(%rbp)
jl     1312 <main+0x132>
lea    -0x67(%rbp),%rdi
add    $0x5,%rdi
mov    -0x20(%rbp),%ecx
sub    $0xa,%ecx
mov    $0x8,%esi
lea    0xd3f(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
jmp    135f <main+0x17f>
cmpl   $0x9,-0x20(%rbp)
jne    133c <main+0x15c>
lea    -0x67(%rbp),%rdi
add    $0x5,%rdi
mov    $0x8,%esi
lea    0xd1f(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
jmp    135a <main+0x17a>
lea    -0x67(%rbp),%rdi
add    $0x5,%rdi
mov    -0x20(%rbp),%ecx
mov    $0x8,%esi
lea    0xce0(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
jmp    135f <main+0x17f>
jmp    1364 <main+0x184>
lea    -0x67(%rbp),%rdi
mov    $0x1c200,%esi
lea    -0x58(%rbp),%rdx
call   10e0 <uart_open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     1388 <main+0x1a8>
jmp    139b <main+0x1bb>
jmp    138d <main+0x1ad>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    12a8 <main+0xc8>
jmp    13a0 <main+0x1c0>
cmpl   $0x0,-0x18(%rbp)
jge    13c2 <main+0x1e2>
lea    0xca6(%rip),%rdi
call   10b0 <log_date@plt>
movl   $0x1,-0x4(%rbp)
jmp    163c <main+0x45c>
lea    -0x67(%rbp),%rdi
call   10b0 <log_date@plt>
xor    %edi,%edi
lea    -0x38(%rbp),%rsi
call   10c0 <tcgetattr@plt>
xor    %edi,%edi
lea    -0x48(%rbp),%rsi
call   10c0 <tcgetattr@plt>
mov    0x2be0(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x38(%rbp),%rax
mov    0x2be2(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x38(%rbp),%rax
mov    0x2bbc(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2bc2(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x38(%rbp),%rdx
call   10d0 <tcsetattr@plt>
lea    0xc2f(%rip),%rdi
call   10b0 <log_date@plt>
lea    0xc2d(%rip),%rdi
call   10b0 <log_date@plt>
movb   $0x10,-0x21(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmpl   $0x0,-0x1c(%rbp)
je     15e7 <main+0x407>
lea    -0x14(%rbp),%rdi
call   1080 <FD_ZERO@plt>
xor    %edi,%edi
lea    -0x14(%rbp),%rsi
call   1100 <FD_SET@plt>
mov    -0x18(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1100 <FD_SET@plt>
mov    -0x18(%rbp),%edi
add    $0x1,%edi
lea    -0x14(%rbp),%rsi
xor    %r8d,%r8d
mov    %r8d,%edx
mov    %r8d,%ecx
call   1090 <select@plt>
cmp    $0x0,%rax
je     15e2 <main+0x402>
xor    %edi,%edi
lea    -0x14(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     156e <main+0x38e>
xor    %edi,%edi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   1070 <read@plt>
cmp    $0x1,%eax
jne    1569 <main+0x389>
movsbl -0x21(%rbp),%eax
cmp    $0xa,%eax
jne    1500 <main+0x320>
mov    -0x18(%rbp),%edi
lea    0xb40(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    1511 <main+0x331>
mov    -0x18(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
movsbl -0x21(%rbp),%eax
cmp    $0x2d,%eax
jne    155d <main+0x37d>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
jle    1558 <main+0x378>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
lea    0xb45(%rip),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
lea    0xade(%rip),%rdi
call   1050 <printf@plt>
jmp    1564 <main+0x384>
movl   $0x1,-0x1c(%rbp)
jmp    1569 <main+0x389>
jmp    156e <main+0x38e>
mov    -0x18(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     15dd <main+0x3fd>
mov    -0x18(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   1070 <read@plt>
cmp    $0x1,%eax
jne    15d8 <main+0x3f8>
movsbl -0x21(%rbp),%eax
cmp    $0xa,%eax
jne    15c3 <main+0x3e3>
mov    $0x1,%edx
lea    0xa7a(%rip),%rsi
mov    %edx,%edi
call   1030 <write@plt>
jmp    15d3 <main+0x3f3>
mov    $0x1,%edx
lea    -0x21(%rbp),%rsi
mov    %edx,%edi
call   1030 <write@plt>
jmp    15d8 <main+0x3f8>
jmp    15dd <main+0x3fd>
jmp    15e2 <main+0x402>
jmp    1460 <main+0x280>
mov    0x29fa(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x48(%rbp),%rdx
call   10d0 <tcsetattr@plt>
mov    -0x18(%rbp),%edi
lea    -0x58(%rbp),%rsi
call   10a0 <uart_close@plt>
cmp    $0x0,%rax
je     1629 <main+0x449>
lea    0xa73(%rip),%rdi
call   10b0 <log_date@plt>
movl   $0x1,-0x4(%rbp)
jmp    163c <main+0x45c>
lea    0xa6e(%rip),%rdi
call   10b0 <log_date@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
movabs $0x303142535579,%rax
mov    %rax,0x17(%rsp)
movabs $0x7974742f7665642f,%rax
74 74 79
mov    %rax,0x10(%rsp)
lea    0xe5b(%rip),%rdi
call   1040 <puts@plt>
cmp    $0x2,%ebp
jne    1291 <main+0xa1>
mov    0x8(%rbx),%rdi
call   1100 <atoi@plt>
add    $0xffffffff,%eax
mov    $0x1,%r14d
lea    0xde8(%rip),%rbp
cmp    $0x40,%eax
jae    1595 <main+0x3a5>
lea    0x15(%rsp),%rdi
lea    0xdaf(%rip),%rdx
mov    $0x8,%esi
mov    %eax,%ecx
xor    %eax,%eax
call   1070 <snprintf@plt>
lea    0x10(%rsp),%rdi
lea    0x28(%rsp),%rdx
mov    $0x1c200,%esi
call   10f0 <uart_open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    133a <main+0x14a>
jmp    1595 <main+0x3a5>
mov    $0xc,%ebp
lea    0x15(%rsp),%r15
lea    0xd75(%rip),%r12
lea    0x10(%rsp),%r13
lea    0x28(%rsp),%r14
nopl   0x0(%rax)
lea    0xa(%rbp),%ecx
cmp    $0x14,%ecx
jb     12d0 <main+0xe0>
lea    -0xa(%rbp),%ecx
mov    %r15,%rdi
mov    $0x8,%esi
mov    %r12,%rdx
jmp    1300 <main+0x110>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x8,%esi
cmp    $0xa,%ecx
jb     12f0 <main+0x100>
lea    0xd3d(%rip),%rdx
mov    %ebp,%ecx
jmp    1300 <main+0x110>
nopl   0x0(%rax,%rax,1)
cmp    $0xffffffff,%ebp
je     1328 <main+0x138>
lea    0xd13(%rip),%rdx
nopl   0x0(%rax)
xor    %eax,%eax
call   1070 <snprintf@plt>
mov    %r13,%rdi
mov    $0x1c200,%esi
mov    %r14,%rdx
call   10f0 <uart_open@plt>
test   %eax,%eax
jns    1338 <main+0x148>
add    $0xffffffff,%ebp
cmp    $0xfffffff5,%ebp
jne    12b0 <main+0xc0>
jmp    1588 <main+0x398>
lea    0xcfc(%rip),%rdx
xor    %eax,%eax
call   1070 <snprintf@plt>
jmp    1307 <main+0x117>
mov    %eax,%ebx
lea    0x10(%rsp),%rdi
call   10c0 <log_date@plt>
lea    0x38(%rsp),%rbp
xor    %edi,%edi
mov    %rbp,%rsi
call   10d0 <tcgetattr@plt>
lea    0x48(%rsp),%rsi
xor    %edi,%edi
call   10d0 <tcgetattr@plt>
mov    0x2c62(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x40(%rsp)
mov    0x38(%rsp),%rax
mov    0x2c66(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2c44(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2c4a(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
mov    %rbp,%rdx
call   10e0 <tcsetattr@plt>
lea    0xc94(%rip),%rdi
call   10c0 <log_date@plt>
lea    0xc92(%rip),%rdi
call   10c0 <log_date@plt>
movb   $0x10,0xb(%rsp)
lea    0xb(%rsp),%r14
mov    $0x1,%r13d
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1050 <write@plt>
lea    0x1(%rbx),%r15d
lea    0x24(%rsp),%rbp
mov    %r15d,0xc(%rsp)
jmp    140f <main+0x21f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13d,%r12d
mov    %r12d,%r13d
test   %r12d,%r12d
je     1549 <main+0x359>
mov    %rbp,%rdi
call   1090 <FD_ZERO@plt>
xor    %edi,%edi
mov    %rbp,%rsi
call   1110 <FD_SET@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   1110 <FD_SET@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10a0 <select@plt>
test   %rax,%rax
je     1400 <main+0x210>
xor    %edi,%edi
mov    %rbp,%rsi
call   1060 <FD_ISSET@plt>
test   %rax,%rax
je     14a0 <main+0x2b0>
xor    %edi,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1080 <read@plt>
cmp    $0x1,%eax
jne    14a0 <main+0x2b0>
mov    %r14,%r15
movzbl 0xb(%rsp),%r14d
mov    $0x1,%r12d
mov    %ebx,%edi
cmp    $0xa,%r14b
jne    14e3 <main+0x2f3>
lea    0xbe0(%rip),%rsi
mov    $0x1,%edx
call   1050 <write@plt>
mov    %r15,%r14
mov    0xc(%rsp),%r15d
jmp    14a3 <main+0x2b3>
nopw   0x0(%rax,%rax,1)
mov    %r13d,%r12d
mov    %ebx,%edi
mov    %rbp,%rsi
call   1060 <FD_ISSET@plt>
test   %rax,%rax
je     1403 <main+0x213>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1080 <read@plt>
cmp    $0x1,%eax
jne    1403 <main+0x213>
cmpb   $0xa,0xb(%rsp)
jne    150d <main+0x31d>
mov    $0x1,%edi
lea    0xb82(%rip),%rsi
jmp    1515 <main+0x325>
mov    %r15,%rsi
mov    $0x1,%edx
call   1050 <write@plt>
cmp    $0x2d,%r14b
mov    %r15,%r14
mov    0xc(%rsp),%r15d
jne    14a3 <main+0x2b3>
cmp    $0x3,%r13d
jge    1524 <main+0x334>
add    $0x1,%r13d
mov    %r13d,%r12d
jmp    14a3 <main+0x2b3>
mov    $0x1,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1050 <write@plt>
jmp    1403 <main+0x213>
mov    %ebx,%edi
lea    0xb38(%rip),%rsi
mov    $0x3,%edx
call   1050 <write@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %r12d,%r12d
jmp    14a3 <main+0x2b3>
mov    0x2a98(%rip),%rax
mov    (%rax),%esi
lea    0x48(%rsp),%rdx
xor    %edi,%edi
call   10e0 <tcsetattr@plt>
lea    0x28(%rsp),%rsi
mov    %ebx,%edi
call   10b0 <uart_close@plt>
xor    %r14d,%r14d
test   %rax,%rax
setne  %r14b
lea    0xb01(%rip),%rax
lea    0xae7(%rip),%rbp
cmove  %rax,%rbp
jmp    1595 <main+0x3a5>
mov    $0x1,%r14d
lea    0xa9e(%rip),%rbp
mov    %rbp,%rdi
call   10c0 <log_date@plt>
mov    %r14d,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i64*, i32 }
@__const.main.UART_DEVICE = [15 x i8] c"/dev/ttyUSB10\00\00"
@.str = [36 x i8] c"Petit Ichigo Term for Raspberry Pi\0A\00"
@.str.1 = [8 x i8] c"ttyS%1d\00"
@.str.2 = [10 x i8] c"rfcomm%1d\00"
@.str.3 = [10 x i8] c"ttyUSB%1d\00"
@.str.4 = [8 x i8] c"ttyAMA0\00"
@.str.5 = [18 x i8] c"ERROR @ UART OPEN\00"
@ICANON = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
@.str.6 = [10 x i8] c"CONNECTED\00"
@.str.7 = [20 x i8] c"Type '---' to exit.\00"
@.str.8 = [2 x i8] c"\0A\00"
@.str.9 = [4 x i8] c"\08\08\08\00"
@.str.10 = [19 x i8] c"ERROR @ UART CLOSE\00"
@.str.11 = [7 x i8] c"CLOSED\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
%11 = alloca %struct.termios
%12 = alloca %struct.termios
%13 = alloca %struct.termios
%14 = alloca [15 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %7
store i32 1, i32* %8
%15 = bitcast [15 x i8]* %14 to i8*
%16 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 2
br i1 %18, label %19, label %37
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %9
%24 = load i32, i32* %9
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %36
26: ; preds = %19
%27 = load i32, i32* %9
%28 = icmp sle i32 %27, 64
br i1 %28, label %29, label %36
29: ; preds = %26
%30 = getelementptr inbounds [15 x i8], [15 x i8]* %14, i64 0, i64 5
%31 = load i32, i32* %9
%32 = sub nsw i32 %31, 1
%33 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %30, i32 8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %32)
%34 = getelementptr inbounds [15 x i8], [15 x i8]* %14, i64 0, i64 0
%35 = call i32 @uart_open(i8* %34, i32 115200, %struct.termios* %13)
store i32 %35, i32* %7
br label %36
36: ; preds = %29, %26, %19
br label %80
37: ; preds = %2
store i32 22, i32* %9
br label %38
38: ; preds = %76, %37
%39 = load i32, i32* %9
%40 = icmp sge i32 %39, 0
br i1 %40, label %41, label %79
41: ; preds = %38
%42 = load i32, i32* %9
%43 = icmp sge i32 %42, 20
br i1 %43, label %44, label %49
44: ; preds = %41
%45 = getelementptr inbounds [15 x i8], [15 x i8]* %14, i64 0, i64 5
%46 = load i32, i32* %9
%47 = sub nsw i32 %46, 20
%48 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %45, i32 8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %47)
br label %69
49: ; preds = %41
%50 = load i32, i32* %9
%51 = icmp sge i32 %50, 10
br i1 %51, label %52, label %57
52: ; preds = %49
%53 = getelementptr inbounds [15 x i8], [15 x i8]* %14, i64 0, i64 5
%54 = load i32, i32* %9
%55 = sub nsw i32 %54, 10
%56 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %53, i32 8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %55)
br label %68
57: ; preds = %49
%58 = load i32, i32* %9
%59 = icmp eq i32 %58, 9
br i1 %59, label %60, label %63
60: ; preds = %57
%61 = getelementptr inbounds [15 x i8], [15 x i8]* %14, i64 0, i64 5
%62 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %61, i32 8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %67
63: ; preds = %57
%64 = getelementptr inbounds [15 x i8], [15 x i8]* %14, i64 0, i64 5
%65 = load i32, i32* %9
%66 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %64, i32 8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %65)
br label %67
67: ; preds = %63, %60
br label %68
68: ; preds = %67, %52
br label %69
69: ; preds = %68, %44
%70 = getelementptr inbounds [15 x i8], [15 x i8]* %14, i64 0, i64 0
%71 = call i32 @uart_open(i8* %70, i32 115200, %struct.termios* %13)
store i32 %71, i32* %7
%72 = load i32, i32* %7
%73 = icmp sge i32 %72, 0
br i1 %73, label %74, label %75
74: ; preds = %69
br label %79
75: ; preds = %69
br label %76
76: ; preds = %75
%77 = load i32, i32* %9
%78 = add nsw i32 %77, -1
store i32 %78, i32* %9
br label %38
79: ; preds = %74, %38
br label %80
80: ; preds = %79, %36
%81 = load i32, i32* %7
%82 = icmp slt i32 %81, 0
br i1 %82, label %83, label %85
83: ; preds = %80
%84 = call i32 @log_date(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %185
85: ; preds = %80
%86 = getelementptr inbounds [15 x i8], [15 x i8]* %14, i64 0, i64 0
%87 = call i32 @log_date(i8* %86)
br label %88
88: ; preds = %85
%89 = call i32 @tcgetattr(i32 0, %struct.termios* %11)
%90 = call i32 @tcgetattr(i32 0, %struct.termios* %12)
%91 = load i32, i32* @ICANON
%92 = xor i32 %91, -1
%93 = getelementptr inbounds %struct.termios, %struct.termios* %11, i32 0, i32 1
%94 = load i32, i32* %93
%95 = and i32 %94, %92
store i32 %95, i32* %93
%96 = getelementptr inbounds %struct.termios, %struct.termios* %11, i32 0, i32 0
%97 = load i64*, i64** %96
%98 = load i64, i64* @VMIN
%99 = getelementptr inbounds i64, i64* %97, i64 %98
store i64 0, i64* %99
%100 = getelementptr inbounds %struct.termios, %struct.termios* %11, i32 0, i32 0
%101 = load i64*, i64** %100
%102 = load i64, i64* @VTIME
%103 = getelementptr inbounds i64, i64* %101, i64 %102
store i64 0, i64* %103
%104 = load i32, i32* @TCSANOW
%105 = call i32 @tcsetattr(i32 0, i32 %104, %struct.termios* %11)
%106 = call i32 @log_date(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%107 = call i32 @log_date(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
store i8 16, i8* %10
%108 = load i32, i32* %7
%109 = call i32 @write(i32 %108, i8* %10, i32 1)
br label %110
110: ; preds = %174, %88
%111 = load i32, i32* %8
%112 = icmp ne i32 %111, 0
br i1 %112, label %113, label %175
113: ; preds = %110
%114 = call i32 @FD_ZERO(i32* %6)
%115 = call i32 @FD_SET(i32 0, i32* %6)
%116 = load i32, i32* %7
%117 = call i32 @FD_SET(i32 %116, i32* %6)
%118 = load i32, i32* %7
%119 = add nsw i32 %118, 1
%120 = call i64 @select(i32 %119, i32* %6, i32 0, i32 0, i32 0)
%121 = icmp ne i64 %120, 0
br i1 %121, label %122, label %174
122: ; preds = %113
%123 = call i64 @FD_ISSET(i32 0, i32* %6)
%124 = icmp ne i64 %123, 0
br i1 %124, label %125, label %155
125: ; preds = %122
%126 = call i32 @read(i32 0, i8* %10, i32 1)
%127 = icmp eq i32 %126, 1
br i1 %127, label %128, label %154
128: ; preds = %125
%129 = load i8, i8* %10
%130 = sext i8 %129 to i32
%131 = icmp eq i32 %130, 10
br i1 %131, label %132, label %135
132: ; preds = %128
%133 = load i32, i32* %7
%134 = call i32 @write(i32 %133, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i32 1)
br label %138
135: ; preds = %128
%136 = load i32, i32* %7
%137 = call i32 @write(i32 %136, i8* %10, i32 1)
br label %138
138: ; preds = %135, %132
%139 = load i8, i8* %10
%140 = sext i8 %139 to i32
%141 = icmp eq i32 %140, 45
br i1 %141, label %142, label %152
142: ; preds = %138
%143 = load i32, i32* %8
%144 = add nsw i32 %143, 1
store i32 %144, i32* %8
%145 = load i32, i32* %8
%146 = icmp sgt i32 %145, 3
br i1 %146, label %147, label %151
147: ; preds = %142
store i32 0, i32* %8
%148 = load i32, i32* %7
%149 = call i32 @write(i32 %148, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 3)
%150 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
br label %151
151: ; preds = %147, %142
br label %153
152: ; preds = %138
store i32 1, i32* %8
br label %153
153: ; preds = %152, %151
br label %154
154: ; preds = %153, %125
br label %155
155: ; preds = %154, %122
%156 = load i32, i32* %7
%157 = call i64 @FD_ISSET(i32 %156, i32* %6)
%158 = icmp ne i64 %157, 0
br i1 %158, label %159, label %173
159: ; preds = %155
%160 = load i32, i32* %7
%161 = call i32 @read(i32 %160, i8* %10, i32 1)
%162 = icmp eq i32 %161, 1
br i1 %162, label %163, label %172
163: ; preds = %159
%164 = load i8, i8* %10
%165 = sext i8 %164 to i32
%166 = icmp eq i32 %165, 10
br i1 %166, label %167, label %169
167: ; preds = %163
%168 = call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i32 1)
br label %171
169: ; preds = %163
%170 = call i32 @write(i32 1, i8* %10, i32 1)
br label %171
171: ; preds = %169, %167
br label %172
172: ; preds = %171, %159
br label %173
173: ; preds = %172, %155
br label %174
174: ; preds = %173, %113
br label %110
175: ; preds = %110
%176 = load i32, i32* @TCSANOW
%177 = call i32 @tcsetattr(i32 0, i32 %176, %struct.termios* %12)
%178 = load i32, i32* %7
%179 = call i64 @uart_close(i32 %178, %struct.termios* %13)
%180 = icmp ne i64 %179, 0
br i1 %180, label %181, label %183
181: ; preds = %175
%182 = call i32 @log_date(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0))
store i32 1, i32* %3
br label %185
183: ; preds = %175
%184 = call i32 @log_date(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0))
store i32 0, i32* %3
br label %185
185: ; preds = %183, %181, %83
%186 = load i32, i32* %3
ret i32 %186
}

LLVM IR (-O2):
%struct.termios = type { i64*, i32 }
@__const.main.UART_DEVICE = [15 x i8] c"/dev/ttyUSB10\00\00"
@.str.1 = [8 x i8] c"ttyS%1d\00"
@.str.2 = [10 x i8] c"rfcomm%1d\00"
@.str.3 = [10 x i8] c"ttyUSB%1d\00"
@.str.4 = [8 x i8] c"ttyAMA0\00"
@.str.5 = [18 x i8] c"ERROR @ UART OPEN\00"
@ICANON = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
@.str.6 = [10 x i8] c"CONNECTED\00"
@.str.7 = [20 x i8] c"Type '---' to exit.\00"
@.str.8 = [2 x i8] c"\0A\00"
@.str.9 = [4 x i8] c"\08\08\08\00"
@.str.10 = [19 x i8] c"ERROR @ UART CLOSE\00"
@.str.11 = [7 x i8] c"CLOSED\00"
@str = [35 x i8] c"Petit Ichigo Term for Raspberry Pi\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i8
%5 = alloca %struct.termios
%6 = alloca %struct.termios
%7 = alloca %struct.termios
%8 = alloca [15 x i8]
%9 = bitcast i32* %3 to i8*
%10 = bitcast %struct.termios* %5 to i8*
%11 = bitcast %struct.termios* %6 to i8*
%12 = bitcast %struct.termios* %7 to i8*
%13 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 0
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%15 = icmp eq i32 %0, 2
br i1 %15, label %18, label %16
16: ; preds = %2
%17 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 5
br label %27
18: ; preds = %2
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = tail call i32 @atoi(i8* %20)
%22 = add i32 %21, -1
%23 = icmp ult i32 %22, 64
br i1 %23, label %47, label %126
24: ; preds = %44
%25 = add nsw i32 %28, -1
%26 = icmp eq i32 %28, 0
br i1 %26, label %126, label %27
27: ; preds = %16, %24
%28 = phi i32 [ 22, %16 ], [ %25, %24 ]
%29 = icmp ugt i32 %28, 19
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = add nsw i32 %28, -20
%32 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %17, i32 8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %31)
br label %44
33: ; preds = %27
%34 = icmp ugt i32 %28, 9
br i1 %34, label %35, label %38
35: ; preds = %33
%36 = add nsw i32 %28, -10
%37 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %17, i32 8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %36)
br label %44
38: ; preds = %33
%39 = icmp eq i32 %28, 9
br i1 %39, label %40, label %42
40: ; preds = %38
%41 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %17, i32 8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %44
42: ; preds = %38
%43 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %17, i32 8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %28)
br label %44
44: ; preds = %35, %42, %40, %30
%45 = call i32 @uart_open(i8* %13, i32 115200, %struct.termios* %7)
%46 = icmp sgt i32 %45, -1
br i1 %46, label %52, label %24
47: ; preds = %18
%48 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 5
%49 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %48, i32 8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%50 = call i32 @uart_open(i8* %13, i32 115200, %struct.termios* %7)
%51 = icmp slt i32 %50, 0
br i1 %51, label %126, label %52
52: ; preds = %44, %47
%53 = phi i32 [ %50, %47 ], [ %45, %44 ]
%54 = call i32 @log_date(i8* %13)
%55 = call i32 @tcgetattr(i32 0, %struct.termios* %5)
%56 = call i32 @tcgetattr(i32 0, %struct.termios* %6)
%57 = load i32, i32* @ICANON
%58 = xor i32 %57, -1
%59 = getelementptr inbounds %struct.termios, %struct.termios* %5, i64 0, i32 1
%60 = load i32, i32* %59
%61 = and i32 %60, %58
store i32 %61, i32* %59
%62 = getelementptr inbounds %struct.termios, %struct.termios* %5, i64 0, i32 0
%63 = load i64*, i64** %62
%64 = load i64, i64* @VMIN
%65 = getelementptr inbounds i64, i64* %63, i64 %64
store i64 0, i64* %65
%66 = load i64, i64* @VTIME
%67 = getelementptr inbounds i64, i64* %63, i64 %66
store i64 0, i64* %67
%68 = load i32, i32* @TCSANOW
%69 = call i32 @tcsetattr(i32 0, i32 %68, %struct.termios* %5)
%70 = call i32 @log_date(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%71 = call i32 @log_date(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
store i8 16, i8* %4
%72 = call i32 @write(i32 %53, i8* %4, i32 1)
%73 = add nuw nsw i32 %53, 1
br label %74
74: ; preds = %52, %115
%75 = phi i32 [ 1, %52 ], [ %116, %115 ]
%76 = call i32 @FD_ZERO(i32* %3)
%77 = call i32 @FD_SET(i32 0, i32* %3)
%78 = call i32 @FD_SET(i32 %53, i32* %3)
%79 = call i64 @select(i32 %73, i32* %3, i32 0, i32 0, i32 0)
%80 = icmp eq i64 %79, 0
br i1 %80, label %115, label %81
81: ; preds = %74
%82 = call i64 @FD_ISSET(i32 0, i32* %3)
%83 = icmp eq i64 %82, 0
br i1 %83, label %101, label %84
84: ; preds = %81
%85 = call i32 @read(i32 0, i8* %4, i32 1)
%86 = icmp eq i32 %85, 1
br i1 %86, label %87, label %101
87: ; preds = %84
%88 = load i8, i8* %4
%89 = icmp eq i8 %88, 10
br i1 %89, label %90, label %92
90: ; preds = %87
%91 = call i32 @write(i32 %53, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i32 1)
br label %101
92: ; preds = %87
%93 = call i32 @write(i32 %53, i8* %4, i32 1)
%94 = icmp eq i8 %88, 45
br i1 %94, label %95, label %101
95: ; preds = %92
%96 = add nsw i32 %75, 1
%97 = icmp sgt i32 %75, 2
br i1 %97, label %98, label %101
98: ; preds = %95
%99 = call i32 @write(i32 %53, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 3)
%100 = call i32 @putchar(i32 10)
br label %101
101: ; preds = %90, %92, %84, %95, %98, %81
%102 = phi i32 [ 0, %98 ], [ %96, %95 ], [ %75, %84 ], [ %75, %81 ], [ 1, %92 ], [ 1, %90 ]
%103 = call i64 @FD_ISSET(i32 %53, i32* %3)
%104 = icmp eq i64 %103, 0
br i1 %104, label %115, label %105
105: ; preds = %101
%106 = call i32 @read(i32 %53, i8* %4, i32 1)
%107 = icmp eq i32 %106, 1
br i1 %107, label %108, label %115
108: ; preds = %105
%109 = load i8, i8* %4
%110 = icmp eq i8 %109, 10
br i1 %110, label %111, label %113
111: ; preds = %108
%112 = call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i32 1)
br label %115
113: ; preds = %108
%114 = call i32 @write(i32 1, i8* %4, i32 1)
br label %115
115: ; preds = %101, %111, %113, %105, %74
%116 = phi i32 [ %102, %111 ], [ %102, %113 ], [ %102, %105 ], [ %102, %101 ], [ %75, %74 ]
%117 = icmp eq i32 %116, 0
br i1 %117, label %118, label %74
118: ; preds = %115
%119 = load i32, i32* @TCSANOW
%120 = call i32 @tcsetattr(i32 0, i32 %119, %struct.termios* %6)
%121 = call i64 @uart_close(i32 %53, %struct.termios* %7)
%122 = icmp eq i64 %121, 0
%123 = select i1 %122, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0)
%124 = xor i1 %122, true
%125 = zext i1 %124 to i32
br label %126
126: ; preds = %24, %118, %47, %18
%127 = phi i8* [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), %18 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), %47 ], [ %123, %118 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), %24 ]
%128 = phi i32 [ 1, %18 ], [ 1, %47 ], [ %125, %118 ], [ 1, %24 ]
%129 = call i32 @log_date(i8* %127)
ret i32 %128
}