#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_cc;
  int /*<<< orphan*/ c_cflag;
};
typedef int /*<<< orphan*/ str;

/* Variables and functions */
int /*<<< orphan*/ B115200;
int /*<<< orphan*/ CLOCAL;
int /*<<< orphan*/ CRTSCTS;
int /*<<< orphan*/ CS8;
int /*<<< orphan*/ CSIZE;
int /*<<< orphan*/ CSTOPB;
int /*<<< orphan*/ F_GETFL;
int /*<<< orphan*/ F_SETFL;
int O_NOCTTY;
int O_NONBLOCK;
int O_RDWR;
int /*<<< orphan*/ PARENB;
int /*<<< orphan*/ PARODD;
int /*<<< orphan*/ TCIOFLUSH;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ cfmakeraw(struct termios *);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fcntl(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getopt(int, char **, char *);
int open(char *, int);
size_t optind;
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(int);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
scalar_t__ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ usage(int /*<<< orphan*/, int);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  struct termios ti;
  int fd, ret, c, mode = -1;
  char str[8];
  while ((c = getopt(argc, argv, "v?hbu")) > 0) {
    switch (c) {
    case 'v':
      printf("%s: version %s\n", argv[0], "0.1");
      exit(0);
    case 'h':
      mode = 4;
      break;
    case 'b':
      mode = 1;
      break;
    case 'u':
      mode = 3;
      break;
    case '?':
      usage(stdout, 0);
      break;
    default:
      fprintf(stderr, "ERROR: unkown option '%c'\n", c);
      usage(stderr, 1);
      break;
    }
  }
  if (mode < 0)
    mode = 1;
  sprintf(str, "boot %i\n", mode);
  sleep(1);
  fd = open(argv[optind], O_RDWR | O_NOCTTY);
  if (fd < 0) {
    fprintf(stderr, "Can't open serial port: %s (%d)\n", strerror(errno),
            errno);
    return -1;
  }
  tcflush(fd, TCIOFLUSH);
  if (tcgetattr(fd, &ti) < 0) {
    fprintf(stderr, "Can't get port settings: %s (%d)\n", strerror(errno),
            errno);
    close(fd);
    return -1;
  }
  cfmakeraw(&ti);
  ti.c_cflag |= CLOCAL;
  ti.c_cflag &= ~CRTSCTS;
  ti.c_cflag &= ~PARENB;
  ti.c_cflag &= ~PARODD;
  ti.c_cflag &= ~CSIZE;
  ti.c_cflag |= CS8;
  ti.c_cflag &= ~CSTOPB;
  ti.c_cc[VMIN] = 1;
  ti.c_cc[VTIME] = 0;
  cfsetospeed(&ti, B115200);
  if (tcsetattr(fd, TCSANOW, &ti) < 0) {
    fprintf(stderr, "Can't change port settings: %s (%d)\n", strerror(errno),
            errno);
    close(fd);
    return -1;
  }
  tcflush(fd, TCIOFLUSH);
  if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK) < 0) {
    fprintf(stderr, "Can't set non blocking mode: %s (%d)\n", strerror(errno),
            errno);
    close(fd);
    return -1;
  }
  ret = write(fd, str, sizeof(str));
  if (ret < 0)
    fprintf(stderr, "UART write error\n");
  else
    ret = 0;
  tcflush(fd, TCIOFLUSH);
  close(fd);
  sleep(1);
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xdc5(%rip),%rdx
call   10f0 <getopt@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jle    1330 <main+0x120>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
sub    $0x3f,%eax
je     12e9 <main+0xd9>
jmp    1260 <main+0x50>
mov    -0x3c(%rbp),%eax
sub    $0x62,%eax
je     12d1 <main+0xc1>
jmp    1271 <main+0x61>
mov    -0x3c(%rbp),%eax
sub    $0x68,%eax
je     12c5 <main+0xb5>
jmp    1282 <main+0x72>
mov    -0x3c(%rbp),%eax
sub    $0x75,%eax
je     12dd <main+0xcd>
jmp    1293 <main+0x83>
mov    -0x3c(%rbp),%eax
sub    $0x76,%eax
jne    12fe <main+0xee>
jmp    12a4 <main+0x94>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd54(%rip),%rdi
lea    0xd5d(%rip),%rdx
call   1070 <printf@plt>
xor    %edi,%edi
call   1110 <exit@plt>
movl   $0x4,-0x30(%rbp)
jmp    132b <main+0x11b>
movl   $0x1,-0x30(%rbp)
jmp    132b <main+0x11b>
movl   $0x3,-0x30(%rbp)
jmp    132b <main+0x11b>
mov    0x2c78(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   10b0 <usage@plt>
jmp    132b <main+0x11b>
mov    0x2c8b(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%edx
lea    0xd09(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2c71(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
call   10b0 <usage@plt>
jmp    122d <main+0x1d>
cmpl   $0x0,-0x30(%rbp)
jge    1341 <main+0x131>
movl   $0x1,-0x30(%rbp)
lea    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%edx
lea    0xce6(%rip),%rsi
call   1100 <sprintf@plt>
mov    $0x1,%edi
call   1130 <sleep@plt>
mov    -0x10(%rbp),%rax
mov    0x2c57(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2c71(%rip),%rax
mov    (%rax),%esi
mov    0x2c18(%rip),%rax
or     (%rax),%esi
call   10e0 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    13d7 <main+0x1c7>
mov    0x2bf5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2bd9(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0x40(%rbp),%edi
mov    %rax,%rdx
mov    0x2bc5(%rip),%rax
mov    (%rax),%ecx
lea    0xc7a(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    167a <main+0x46a>
mov    -0x24(%rbp),%edi
mov    0x2b8f(%rip),%rax
mov    (%rax),%esi
call   1060 <tcflush@plt>
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   10c0 <tcgetattr@plt>
cmp    $0x0,%rax
jge    1449 <main+0x239>
mov    0x2b8b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2b6f(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    %rax,%rdx
mov    0x2b5b(%rip),%rax
mov    (%rax),%ecx
lea    0xc31(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    167a <main+0x46a>
lea    -0x20(%rbp),%rdi
call   10a0 <cfmakeraw@plt>
mov    0x2adf(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2ae0(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2b5e(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2b3c(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2b0a(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2b08(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2a81(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2adb(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
mov    0x2a6e(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2a65(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   1050 <cfsetospeed@plt>
mov    -0x24(%rbp),%edi
mov    0x2ac0(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   10d0 <tcsetattr@plt>
cmp    $0x0,%rax
jge    1570 <main+0x360>
mov    0x2a64(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2a48(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0x48(%rbp),%edi
mov    %rax,%rdx
mov    0x2a34(%rip),%rax
mov    (%rax),%ecx
lea    0xb2c(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    167a <main+0x46a>
mov    -0x24(%rbp),%edi
mov    0x29f6(%rip),%rax
mov    (%rax),%esi
call   1060 <tcflush@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    0x29fa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x24(%rbp),%edi
mov    0x29db(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    -0x50(%rbp),%edi
mov    -0x4c(%rbp),%esi
mov    %eax,%edx
mov    0x2a2b(%rip),%rax
or     (%rax),%edx
call   1030 <fcntl@plt>
cmp    $0x0,%eax
jge    1610 <main+0x400>
mov    0x29c4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    0x29a8(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0x54(%rbp),%edi
mov    %rax,%rdx
mov    0x2994(%rip),%rax
mov    (%rax),%ecx
lea    0xab1(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    167a <main+0x46a>
mov    -0x24(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0x8,%edx
call   1040 <write@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    164a <main+0x43a>
mov    0x295b(%rip),%rax
mov    (%rax),%edi
lea    0xa8e(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    1651 <main+0x441>
movl   $0x0,-0x28(%rbp)
mov    -0x24(%rbp),%edi
mov    0x2915(%rip),%rax
mov    (%rax),%esi
call   1060 <tcflush@plt>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
mov    $0x1,%edi
call   1130 <sleep@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r12
mov    %edi,%ebp
lea    0xe2a(%rip),%rdx
call   10f0 <getopt@plt>
test   %eax,%eax
jle    12e1 <main+0xd1>
mov    $0xffffffff,%ebx
lea    0xe11(%rip),%r14
lea    0xdb6(%rip),%r15
jmp    1266 <main+0x56>
nopl   0x0(%rax)
mov    $0x3,%ebx
mov    %ebp,%edi
mov    %r12,%rsi
mov    %r14,%rdx
call   10f0 <getopt@plt>
test   %eax,%eax
jle    12dd <main+0xcd>
mov    %ebx,%r13d
lea    -0x62(%rax),%ecx
cmp    $0x14,%ecx
ja     1290 <main+0x80>
mov    $0x4,%ebx
movslq (%r15,%rcx,4),%rcx
add    %r15,%rcx
jmp    *%rcx
mov    $0x1,%ebx
jmp    1255 <main+0x45>
cs nopw 0x0(%rax,%rax,1)
cmp    $0x3f,%eax
jne    12b0 <main+0xa0>
mov    0x2ccc(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
jmp    12d0 <main+0xc0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x2cd9(%rip),%rbx
mov    (%rbx),%edi
lea    0xdae(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    (%rbx),%edi
mov    $0x1,%esi
call   10b0 <usage@plt>
mov    %r13d,%ebx
jmp    1255 <main+0x45>
test   %ebx,%ebx
jns    12e6 <main+0xd6>
mov    $0x1,%ebx
lea    0xd9c(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    %ebx,%edx
call   1100 <sprintf@plt>
mov    $0x1,%edi
call   1130 <sleep@plt>
mov    0x2cb6(%rip),%rax
mov    (%rax),%rax
mov    (%r12,%rax,8),%rdi
mov    0x2cd0(%rip),%rax
mov    0x2c79(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   10e0 <open@plt>
test   %eax,%eax
js     149a <main+0x28a>
mov    %eax,%ebx
mov    0x2c37(%rip),%r15
mov    (%r15),%esi
mov    %eax,%edi
call   1060 <tcflush@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
call   10c0 <tcgetattr@plt>
test   %rax,%rax
js     14ca <main+0x2ba>
mov    %rsp,%rbp
mov    %rbp,%rdi
call   10a0 <cfmakeraw@plt>
mov    0x2bd0(%rip),%rax
mov    0x8(%rsp),%ecx
or     (%rax),%ecx
mov    0x2bd3(%rip),%rax
mov    (%rax),%eax
mov    0x2c5a(%rip),%rdx
or     (%rdx),%eax
mov    0x2c41(%rip),%rdx
or     (%rdx),%eax
mov    0x2c18(%rip),%rdx
or     (%rdx),%eax
not    %eax
and    %ecx,%eax
mov    0x2c1b(%rip),%rcx
or     (%rcx),%eax
mov    0x2b9a(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %eax,%ecx
mov    %ecx,0x8(%rsp)
mov    (%rsp),%rax
mov    0x2bf5(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2b8c(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2b83(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1050 <cfsetospeed@plt>
mov    0x2be2(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %rbp,%rdx
call   10d0 <tcsetattr@plt>
test   %rax,%rax
js     14ee <main+0x2de>
mov    (%r15),%esi
mov    %ebx,%edi
call   1060 <tcflush@plt>
mov    0x2b74(%rip),%rax
mov    (%rax),%r14d
mov    0x2b5a(%rip),%rax
mov    (%rax),%esi
xor    %ebp,%ebp
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    0x2bae(%rip),%rcx
or     (%rcx),%eax
mov    %ebx,%edi
mov    %r14d,%esi
mov    %eax,%edx
call   1030 <fcntl@plt>
test   %eax,%eax
js     1512 <main+0x302>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1040 <write@plt>
test   %eax,%eax
jns    147a <main+0x26a>
mov    %eax,%r14d
mov    0x2b29(%rip),%rax
mov    (%rax),%edi
lea    0xcb0(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r14d,%ebp
mov    (%r15),%esi
mov    %ebx,%edi
call   1060 <tcflush@plt>
mov    %ebx,%edi
call   1080 <close@plt>
mov    $0x1,%edi
call   1130 <sleep@plt>
jmp    154c <main+0x33c>
mov    0x2aef(%rip),%rax
mov    (%rax),%ebx
mov    0x2ad6(%rip),%rbp
mov    0x0(%rbp),%edi
call   1120 <strerror@plt>
mov    0x0(%rbp),%ecx
lea    0xbd6(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    1547 <main+0x337>
mov    0x2abf(%rip),%rax
mov    (%rax),%ebp
mov    0x2aa6(%rip),%r14
mov    (%r14),%edi
call   1120 <strerror@plt>
mov    (%r14),%ecx
lea    0xbc7(%rip),%rsi
jmp    1534 <main+0x324>
mov    0x2a9b(%rip),%rax
mov    (%rax),%ebp
mov    0x2a82(%rip),%r14
mov    (%r14),%edi
call   1120 <strerror@plt>
mov    (%r14),%ecx
lea    0xbc5(%rip),%rsi
jmp    1534 <main+0x324>
mov    0x2a77(%rip),%rax
mov    (%rax),%ebp
mov    0x2a5e(%rip),%r14
mov    (%r14),%edi
call   1120 <strerror@plt>
mov    (%r14),%ecx
lea    0xbc6(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %ebx,%edi
call   1080 <close@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r12),%rsi
lea    0xaf2(%rip),%rdi
lea    0xafb(%rip),%rdx
call   1070 <printf@plt>
xor    %edi,%edi
call   1110 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32*, i32 }
@.str = [6 x i8] c"v?hbu\00"
@.str.1 = [16 x i8] c"%s: version %s\0A\00"
@.str.2 = [4 x i8] c"0.1\00"
@stdout = global i32 0
@stderr = global i32 0
@.str.3 = [27 x i8] c"ERROR: unkown option '%c'\0A\00"
@.str.4 = [9 x i8] c"boot %i\0A\00"
@optind = global i64 0
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@.str.5 = [33 x i8] c"Can't open serial port: %s (%d)\0A\00"
@errno = global i32 0
@TCIOFLUSH = global i32 0
@.str.6 = [34 x i8] c"Can't get port settings: %s (%d)\0A\00"
@CLOCAL = global i32 0
@CRTSCTS = global i32 0
@PARENB = global i32 0
@PARODD = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@CSTOPB = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@B115200 = global i32 0
@TCSANOW = global i32 0
@.str.7 = [37 x i8] c"Can't change port settings: %s (%d)\0A\00"
@F_SETFL = global i32 0
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.8 = [38 x i8] c"Can't set non blocking mode: %s (%d)\0A\00"
@.str.9 = [18 x i8] c"UART write error\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.termios
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [8 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %10
br label %12
12: ; preds = %37, %2
%13 = load i32, i32* %4
%14 = load i8**, i8*** %5
%15 = call i32 @getopt(i32 %13, i8** %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 %15, i32* %9
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %38
17: ; preds = %12
%18 = load i32, i32* %9
switch i32 %18, label %31 [
i32 118, label %19
i32 104, label %25
i32 98, label %26
i32 117, label %27
i32 63, label %28
]
19: ; preds = %17
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 @exit(i32 0)
unreachable
25: ; preds = %17
store i32 4, i32* %10
br label %37
26: ; preds = %17
store i32 1, i32* %10
br label %37
27: ; preds = %17
store i32 3, i32* %10
br label %37
28: ; preds = %17
%29 = load i32, i32* @stdout
%30 = call i32 @usage(i32 %29, i32 0)
br label %37
31: ; preds = %17
%32 = load i32, i32* @stderr
%33 = load i32, i32* %9
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %33)
%35 = load i32, i32* @stderr
%36 = call i32 @usage(i32 %35, i32 1)
br label %37
37: ; preds = %31, %28, %27, %26, %25
br label %12
38: ; preds = %12
%39 = load i32, i32* %10
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %38
store i32 1, i32* %10
br label %42
42: ; preds = %41, %38
%43 = getelementptr inbounds [8 x i8], [8 x i8]* %11, i64 0, i64 0
%44 = load i32, i32* %10
%45 = call i32 @sprintf(i8* %43, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %44)
%46 = call i32 @sleep(i32 1)
%47 = load i8**, i8*** %5
%48 = load i64, i64* @optind
%49 = getelementptr inbounds i8*, i8** %47, i64 %48
%50 = load i8*, i8** %49
%51 = load i32, i32* @O_RDWR
%52 = load i32, i32* @O_NOCTTY
%53 = or i32 %51, %52
%54 = call i32 @open(i8* %50, i32 %53)
store i32 %54, i32* %7
%55 = load i32, i32* %7
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %63
57: ; preds = %42
%58 = load i32, i32* @stderr
%59 = load i32, i32* @errno
%60 = call i8* @strerror(i32 %59)
%61 = load i32, i32* @errno
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* %60, i32 %61)
store i32 -1, i32* %3
br label %174
63: ; preds = %42
%64 = load i32, i32* %7
%65 = load i32, i32* @TCIOFLUSH
%66 = call i32 @tcflush(i32 %64, i32 %65)
%67 = load i32, i32* %7
%68 = call i64 @tcgetattr(i32 %67, %struct.termios* %6)
%69 = icmp slt i64 %68, 0
br i1 %69, label %70, label %78
70: ; preds = %63
%71 = load i32, i32* @stderr
%72 = load i32, i32* @errno
%73 = call i8* @strerror(i32 %72)
%74 = load i32, i32* @errno
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i8* %73, i32 %74)
%76 = load i32, i32* %7
%77 = call i32 @close(i32 %76)
store i32 -1, i32* %3
br label %174
78: ; preds = %63
%79 = call i32 @cfmakeraw(%struct.termios* %6)
%80 = load i32, i32* @CLOCAL
%81 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%82 = load i32, i32* %81
%83 = or i32 %82, %80
store i32 %83, i32* %81
%84 = load i32, i32* @CRTSCTS
%85 = xor i32 %84, -1
%86 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%87 = load i32, i32* %86
%88 = and i32 %87, %85
store i32 %88, i32* %86
%89 = load i32, i32* @PARENB
%90 = xor i32 %89, -1
%91 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%92 = load i32, i32* %91
%93 = and i32 %92, %90
store i32 %93, i32* %91
%94 = load i32, i32* @PARODD
%95 = xor i32 %94, -1
%96 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%97 = load i32, i32* %96
%98 = and i32 %97, %95
store i32 %98, i32* %96
%99 = load i32, i32* @CSIZE
%100 = xor i32 %99, -1
%101 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%102 = load i32, i32* %101
%103 = and i32 %102, %100
store i32 %103, i32* %101
%104 = load i32, i32* @CS8
%105 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%106 = load i32, i32* %105
%107 = or i32 %106, %104
store i32 %107, i32* %105
%108 = load i32, i32* @CSTOPB
%109 = xor i32 %108, -1
%110 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%111 = load i32, i32* %110
%112 = and i32 %111, %109
store i32 %112, i32* %110
%113 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%114 = load i32*, i32** %113
%115 = load i64, i64* @VMIN
%116 = getelementptr inbounds i32, i32* %114, i64 %115
store i32 1, i32* %116
%117 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%118 = load i32*, i32** %117
%119 = load i64, i64* @VTIME
%120 = getelementptr inbounds i32, i32* %118, i64 %119
store i32 0, i32* %120
%121 = load i32, i32* @B115200
%122 = call i32 @cfsetospeed(%struct.termios* %6, i32 %121)
%123 = load i32, i32* %7
%124 = load i32, i32* @TCSANOW
%125 = call i64 @tcsetattr(i32 %123, i32 %124, %struct.termios* %6)
%126 = icmp slt i64 %125, 0
br i1 %126, label %127, label %135
127: ; preds = %78
%128 = load i32, i32* @stderr
%129 = load i32, i32* @errno
%130 = call i8* @strerror(i32 %129)
%131 = load i32, i32* @errno
%132 = call i32 (i32, i8*, ...) @fprintf(i32 %128, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), i8* %130, i32 %131)
%133 = load i32, i32* %7
%134 = call i32 @close(i32 %133)
store i32 -1, i32* %3
br label %174
135: ; preds = %78
%136 = load i32, i32* %7
%137 = load i32, i32* @TCIOFLUSH
%138 = call i32 @tcflush(i32 %136, i32 %137)
%139 = load i32, i32* %7
%140 = load i32, i32* @F_SETFL
%141 = load i32, i32* %7
%142 = load i32, i32* @F_GETFL
%143 = call i32 @fcntl(i32 %141, i32 %142, i32 0)
%144 = load i32, i32* @O_NONBLOCK
%145 = or i32 %143, %144
%146 = call i32 @fcntl(i32 %139, i32 %140, i32 %145)
%147 = icmp slt i32 %146, 0
br i1 %147, label %148, label %156
148: ; preds = %135
%149 = load i32, i32* @stderr
%150 = load i32, i32* @errno
%151 = call i8* @strerror(i32 %150)
%152 = load i32, i32* @errno
%153 = call i32 (i32, i8*, ...) @fprintf(i32 %149, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0), i8* %151, i32 %152)
%154 = load i32, i32* %7
%155 = call i32 @close(i32 %154)
store i32 -1, i32* %3
br label %174
156: ; preds = %135
%157 = load i32, i32* %7
%158 = getelementptr inbounds [8 x i8], [8 x i8]* %11, i64 0, i64 0
%159 = call i32 @write(i32 %157, i8* %158, i32 8)
store i32 %159, i32* %8
%160 = load i32, i32* %8
%161 = icmp slt i32 %160, 0
br i1 %161, label %162, label %165
162: ; preds = %156
%163 = load i32, i32* @stderr
%164 = call i32 (i32, i8*, ...) @fprintf(i32 %163, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0))
br label %166
165: ; preds = %156
store i32 0, i32* %8
br label %166
166: ; preds = %165, %162
%167 = load i32, i32* %7
%168 = load i32, i32* @TCIOFLUSH
%169 = call i32 @tcflush(i32 %167, i32 %168)
%170 = load i32, i32* %7
%171 = call i32 @close(i32 %170)
%172 = call i32 @sleep(i32 1)
%173 = load i32, i32* %8
store i32 %173, i32* %3
br label %174
174: ; preds = %166, %148, %127, %70, %57
%175 = load i32, i32* %3
ret i32 %175
}

LLVM IR (-O2):
%struct.termios = type { i32*, i32 }
@.str = [6 x i8] c"v?hbu\00"
@.str.1 = [16 x i8] c"%s: version %s\0A\00"
@.str.2 = [4 x i8] c"0.1\00"
@stdout = global i32 0
@stderr = global i32 0
@.str.3 = [27 x i8] c"ERROR: unkown option '%c'\0A\00"
@.str.4 = [9 x i8] c"boot %i\0A\00"
@optind = global i64 0
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@.str.5 = [33 x i8] c"Can't open serial port: %s (%d)\0A\00"
@errno = global i32 0
@TCIOFLUSH = global i32 0
@.str.6 = [34 x i8] c"Can't get port settings: %s (%d)\0A\00"
@CLOCAL = global i32 0
@CRTSCTS = global i32 0
@PARENB = global i32 0
@PARODD = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@CSTOPB = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@B115200 = global i32 0
@TCSANOW = global i32 0
@.str.7 = [37 x i8] c"Can't change port settings: %s (%d)\0A\00"
@F_SETFL = global i32 0
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.8 = [38 x i8] c"Can't set non blocking mode: %s (%d)\0A\00"
@.str.9 = [18 x i8] c"UART write error\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.termios
%4 = alloca [8 x i8]
%5 = bitcast %struct.termios* %3 to i8*
%6 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%7 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %32
9: ; preds = %2, %26
%10 = phi i32 [ %28, %26 ], [ %7, %2 ]
%11 = phi i32 [ %27, %26 ], [ -1, %2 ]
switch i32 %10, label %21 [
i32 118, label %12
i32 104, label %26
i32 98, label %16
i32 117, label %17
i32 63, label %18
]
12: ; preds = %9
%13 = load i8*, i8** %1
%14 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i32 @exit(i32 0)
unreachable
16: ; preds = %9
br label %26
17: ; preds = %9
br label %26
18: ; preds = %9
%19 = load i32, i32* @stdout
%20 = tail call i32 @usage(i32 %19, i32 0)
br label %26
21: ; preds = %9
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %10)
%24 = load i32, i32* @stderr
%25 = tail call i32 @usage(i32 %24, i32 1)
br label %26
26: ; preds = %9, %21, %18, %17, %16
%27 = phi i32 [ %11, %21 ], [ %11, %18 ], [ 3, %17 ], [ 1, %16 ], [ 4, %9 ]
%28 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%29 = icmp sgt i32 %28, 0
br i1 %29, label %9, label %30
30: ; preds = %26
%31 = icmp slt i32 %27, 0
br i1 %31, label %32, label %33
32: ; preds = %2, %30
br label %33
33: ; preds = %30, %32
%34 = phi i32 [ 1, %32 ], [ %27, %30 ]
%35 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %34)
%36 = tail call i32 @sleep(i32 1)
%37 = load i64, i64* @optind
%38 = getelementptr inbounds i8*, i8** %1, i64 %37
%39 = load i8*, i8** %38
%40 = load i32, i32* @O_RDWR
%41 = load i32, i32* @O_NOCTTY
%42 = or i32 %41, %40
%43 = tail call i32 @open(i8* %39, i32 %42)
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %51
45: ; preds = %33
%46 = load i32, i32* @stderr
%47 = load i32, i32* @errno
%48 = tail call i8* @strerror(i32 %47)
%49 = load i32, i32* @errno
%50 = tail call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* %48, i32 %49)
br label %130
51: ; preds = %33
%52 = load i32, i32* @TCIOFLUSH
%53 = tail call i32 @tcflush(i32 %43, i32 %52)
%54 = call i64 @tcgetattr(i32 %43, %struct.termios* %3)
%55 = icmp slt i64 %54, 0
br i1 %55, label %56, label %63
56: ; preds = %51
%57 = load i32, i32* @stderr
%58 = load i32, i32* @errno
%59 = call i8* @strerror(i32 %58)
%60 = load i32, i32* @errno
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i8* %59, i32 %60)
%62 = call i32 @close(i32 %43)
br label %130
63: ; preds = %51
%64 = call i32 @cfmakeraw(%struct.termios* %3)
%65 = load i32, i32* @CLOCAL
%66 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
%67 = load i32, i32* %66
%68 = or i32 %67, %65
%69 = load i32, i32* @CRTSCTS
%70 = load i32, i32* @PARENB
%71 = or i32 %69, %70
%72 = load i32, i32* @PARODD
%73 = or i32 %71, %72
%74 = load i32, i32* @CSIZE
%75 = or i32 %73, %74
%76 = xor i32 %75, -1
%77 = and i32 %68, %76
%78 = load i32, i32* @CS8
%79 = or i32 %78, %77
%80 = load i32, i32* @CSTOPB
%81 = xor i32 %80, -1
%82 = and i32 %79, %81
store i32 %82, i32* %66
%83 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%84 = load i32*, i32** %83
%85 = load i64, i64* @VMIN
%86 = getelementptr inbounds i32, i32* %84, i64 %85
store i32 1, i32* %86
%87 = load i64, i64* @VTIME
%88 = getelementptr inbounds i32, i32* %84, i64 %87
store i32 0, i32* %88
%89 = load i32, i32* @B115200
%90 = call i32 @cfsetospeed(%struct.termios* %3, i32 %89)
%91 = load i32, i32* @TCSANOW
%92 = call i64 @tcsetattr(i32 %43, i32 %91, %struct.termios* %3)
%93 = icmp slt i64 %92, 0
br i1 %93, label %94, label %101
94: ; preds = %63
%95 = load i32, i32* @stderr
%96 = load i32, i32* @errno
%97 = call i8* @strerror(i32 %96)
%98 = load i32, i32* @errno
%99 = call i32 (i32, i8*, ...) @fprintf(i32 %95, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), i8* %97, i32 %98)
%100 = call i32 @close(i32 %43)
br label %130
101: ; preds = %63
%102 = load i32, i32* @TCIOFLUSH
%103 = call i32 @tcflush(i32 %43, i32 %102)
%104 = load i32, i32* @F_SETFL
%105 = load i32, i32* @F_GETFL
%106 = call i32 @fcntl(i32 %43, i32 %105, i32 0)
%107 = load i32, i32* @O_NONBLOCK
%108 = or i32 %107, %106
%109 = call i32 @fcntl(i32 %43, i32 %104, i32 %108)
%110 = icmp slt i32 %109, 0
br i1 %110, label %111, label %118
111: ; preds = %101
%112 = load i32, i32* @stderr
%113 = load i32, i32* @errno
%114 = call i8* @strerror(i32 %113)
%115 = load i32, i32* @errno
%116 = call i32 (i32, i8*, ...) @fprintf(i32 %112, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0), i8* %114, i32 %115)
%117 = call i32 @close(i32 %43)
br label %130
118: ; preds = %101
%119 = call i32 @write(i32 %43, i8* %6, i32 8)
%120 = icmp slt i32 %119, 0
br i1 %120, label %121, label %124
121: ; preds = %118
%122 = load i32, i32* @stderr
%123 = call i32 (i32, i8*, ...) @fprintf(i32 %122, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0))
br label %124
124: ; preds = %118, %121
%125 = phi i32 [ %119, %121 ], [ 0, %118 ]
%126 = load i32, i32* @TCIOFLUSH
%127 = call i32 @tcflush(i32 %43, i32 %126)
%128 = call i32 @close(i32 %43)
%129 = call i32 @sleep(i32 1)
br label %130
130: ; preds = %124, %111, %94, %56, %45
%131 = phi i32 [ -1, %45 ], [ -1, %56 ], [ -1, %94 ], [ -1, %111 ], [ %125, %124 ]
ret i32 %131
}