#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 timeval {
  int tv_sec;
  scalar_t__ tv_usec;
};
struct termios {
  int /*<<< orphan*/ c_cflag;
};
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int /*<<< orphan*/ CLOCAL;
int /*<<< orphan*/ CRTSCTS;
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int O_NOCTTY;
int O_RDWR;
int /*<<< orphan*/ TCIFLUSH;
int /*<<< orphan*/ TCSANOW;
int atoi(int /*<<< orphan*/);
int /*<<< orphan*/ cfmakeraw(struct termios *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int getopt(int, char **, char *);
int open(char *, int);
int /*<<< orphan*/ optarg;
int optind;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_usage(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char **, int);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
scalar_t__ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int write(int, char *, int);
int main(int argc, char **argv) {
  fd_set readfs;
  struct timeval Timeout;
  struct termios term;
  int fd, ret;
  char *tty;
  char j[2];
  char *btr = NULL;
  int opt, count = 26;
  char i;
  while ((opt = getopt(argc, argv, "c:?")) != -1) {
    switch (opt) {
    case 'c':
      count = atoi(optarg);
      break;
    case '?':
    default:
      print_usage(argv[0]);
      break;
    }
  }
  if (argc - optind != 1)
    print_usage(argv[0]);
  tty = argv[optind];
  printf("count=%d\n", count);
  if ((fd = open(tty, O_RDWR | O_NOCTTY)) < 0) {
    perror(tty);
    exit(1);
  }
  printf("uart port used: %s\n", tty);
  tcflush(fd, TCIFLUSH);
  if (tcgetattr(fd, &term) < 0) {
    perror("can't get port settings");
    return -1;
  }
  cfmakeraw(&term);
  term.c_cflag |= CLOCAL;
  term.c_cflag &= ~CRTSCTS;
  if (tcsetattr(fd, TCSANOW, &term) < 0) {
    perror("can't set port settings");
    return -1;
  }
  for (i = 65; i < count + 65; i++) {
    ret = write(fd, &i, 1);
    if (ret != 1) {
      printf("write error!\n");
      exit(1);
    }
    FD_SET(fd, &readfs);
    Timeout.tv_usec = 0;
    Timeout.tv_sec = 10;
    ret = select(fd + 1, &readfs, NULL, NULL, &Timeout);
    if (ret == 0) {
      printf("read timeout error!\n");
      exit(1);
    } else
      ret = read(fd, &j, 1);
    if (ret != 1) {
      printf("read error!\n");
      exit(1);
    }
    if (i != j[0]) {
      printf("read data error: wrote 0x%x read 0x%x\n", i, j[0]);
      exit(1);
    }
    printf("%c", j[0]);
  }
  printf("\n");
  close(fd);
  return 0;
}


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)
movq   $0x0,-0x50(%rbp)
movl   $0x1a,-0x58(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xdcd(%rip),%rdx
call   10e0 <getopt@plt>
mov    %eax,-0x54(%rbp)
cmp    $0xffffffff,%eax
je     1295 <main+0x95>
mov    -0x54(%rbp),%eax
mov    %eax,-0x60(%rbp)
sub    $0x3f,%eax
je     127f <main+0x7f>
jmp    1258 <main+0x58>
mov    -0x60(%rbp),%eax
sub    $0x63,%eax
jne    1284 <main+0x84>
jmp    1269 <main+0x69>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
call   10f0 <atoi@plt>
mov    %eax,-0x58(%rbp)
jmp    1290 <main+0x90>
jmp    1284 <main+0x84>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1110 <print_usage@plt>
jmp    1225 <main+0x25>
mov    -0x8(%rbp),%eax
mov    0x2d31(%rip),%rcx
sub    (%rcx),%eax
cmp    $0x1,%eax
je     12b6 <main+0xb6>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1110 <print_usage@plt>
mov    -0x10(%rbp),%rax
mov    0x2d0f(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x40(%rbp)
mov    -0x58(%rbp),%esi
lea    0xd2e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x40(%rbp),%rdi
mov    0x2cf8(%rip),%rax
mov    (%rax),%esi
mov    0x2cc7(%rip),%rax
or     (%rax),%esi
call   10c0 <open@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    1317 <main+0x117>
mov    -0x40(%rbp),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x40(%rbp),%rsi
lea    0xcec(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x34(%rbp),%edi
mov    0x2c8d(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
mov    -0x34(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   10a0 <tcgetattr@plt>
cmp    $0x0,%rax
jge    1368 <main+0x168>
lea    0xccb(%rip),%rdi
call   10d0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1511 <main+0x311>
lea    -0x30(%rbp),%rdi
call   1090 <cfmakeraw@plt>
mov    0x2c28(%rip),%rax
mov    (%rax),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2c21(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x34(%rbp),%edi
mov    0x2c3c(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   10b0 <tcsetattr@plt>
cmp    $0x0,%rax
jge    13c9 <main+0x1c9>
lea    0xc82(%rip),%rdi
call   10d0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1511 <main+0x311>
movb   $0x41,-0x59(%rbp)
movsbl -0x59(%rbp),%eax
mov    -0x58(%rbp),%ecx
add    $0x41,%ecx
cmp    %ecx,%eax
jge    14f4 <main+0x2f4>
mov    -0x34(%rbp),%edi
lea    -0x59(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x1,-0x38(%rbp)
je     1415 <main+0x215>
lea    0xc4e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x34(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1120 <FD_SET@plt>
movq   $0x0,-0x20(%rbp)
movl   $0xa,-0x28(%rbp)
mov    -0x34(%rbp),%edi
add    $0x1,%edi
lea    -0x14(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x28(%rbp),%r8
mov    %rcx,%rdx
call   1080 <select@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jne    146f <main+0x26f>
lea    0xc02(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x34(%rbp),%edi
lea    -0x42(%rbp),%rsi
mov    $0x1,%edx
call   1070 <read@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x1,-0x38(%rbp)
je     14a5 <main+0x2a5>
lea    0xbe1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
movsbl -0x59(%rbp),%eax
movsbl -0x42(%rbp),%ecx
cmp    %ecx,%eax
je     14d5 <main+0x2d5>
movsbl -0x59(%rbp),%esi
movsbl -0x42(%rbp),%edx
lea    0xbbe(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
movsbl -0x42(%rbp),%esi
lea    0xbc9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x59(%rbp),%al
add    $0x1,%al
mov    %al,-0x59(%rbp)
jmp    13cd <main+0x1cd>
lea    0xb85(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x34(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-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    $0x28,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
movl   $0x1a,0x4(%rsp)
lea    0xdbe(%rip),%r14
mov    0x2daf(%rip),%r15
jmp    1258 <main+0x38>
nopl   0x0(%rax,%rax,1)
mov    (%rbx),%rdi
call   1130 <print_usage@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1100 <getopt@plt>
cmp    $0xffffffff,%eax
je     127d <main+0x5d>
cmp    $0x63,%eax
jne    1250 <main+0x30>
mov    (%r15),%edi
call   1110 <atoi@plt>
mov    %eax,0x4(%rsp)
jmp    1258 <main+0x38>
mov    0x2d4c(%rip),%r14
mov    (%r14),%eax
sub    %eax,%ebp
cmp    $0x1,%ebp
je     1299 <main+0x79>
mov    (%rbx),%rdi
call   1130 <print_usage@plt>
mov    (%r14),%eax
cltq
mov    (%rbx,%rax,8),%rbx
lea    0xd5e(%rip),%rdi
mov    0x4(%rsp),%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2d28(%rip),%rax
mov    0x2cf9(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
call   10e0 <open@plt>
test   %eax,%eax
js     148f <main+0x26f>
mov    %eax,%ebp
lea    0xd32(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2cd3(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1060 <tcflush@plt>
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
call   10c0 <tcgetattr@plt>
test   %rax,%rax
js     1431 <main+0x211>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   10b0 <cfmakeraw@plt>
mov    0x2c81(%rip),%rax
mov    0x8(%rsp),%ecx
or     (%rax),%ecx
mov    0x2c7c(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %ecx,%eax
mov    %eax,0x8(%rsp)
mov    0x2c9b(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %rbx,%rdx
call   10d0 <tcsetattr@plt>
test   %rax,%rax
js     143a <main+0x21a>
movb   $0x41,0x3(%rsp)
cmpl   $0x0,0x4(%rsp)
jle    140f <main+0x1ef>
addl   $0x41,0x4(%rsp)
mov    %ebp,%r15d
add    $0x1,%r15d
mov    $0x41,%ebx
lea    0x14(%rsp),%r13
lea    0x18(%rsp),%r12
lea    0x12(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%edi
lea    0x3(%rsp),%rsi
mov    $0x1,%edx
call   1050 <write@plt>
cmp    $0x1,%eax
jne    144d <main+0x22d>
mov    %ebp,%edi
mov    %r13,%rsi
call   1140 <FD_SET@plt>
movq   $0x0,0x20(%rsp)
movl   $0xa,0x18(%rsp)
mov    %r15d,%edi
mov    %r13,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r12,%r8
call   10a0 <select@plt>
test   %eax,%eax
je     1456 <main+0x236>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1090 <read@plt>
cmp    $0x1,%eax
jne    145f <main+0x23f>
movsbl 0x12(%rsp),%edx
cmp    %bl,%dl
jne    1475 <main+0x255>
mov    %ebx,%edi
call   1030 <putchar@plt>
lea    0x1(%rbx),%eax
mov    %al,0x3(%rsp)
movsbl %al,%ebx
cmp    %ebx,0x4(%rsp)
jg     1390 <main+0x170>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %ebp,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xbea(%rip),%rdi
jmp    1441 <main+0x221>
lea    0xbf9(%rip),%rdi
call   10f0 <perror@plt>
mov    $0xffffffff,%eax
jmp    1422 <main+0x202>
lea    0xc45(%rip),%rdi
jmp    1466 <main+0x246>
lea    0xc28(%rip),%rdi
jmp    1466 <main+0x246>
lea    0xc13(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
lea    0xbd6(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    %rbx,%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
%struct.termios = type { i32 }
@.str = [4 x i8] c"c:?\00"
@optarg = global i32 0
@optind = global i32 0
@.str.1 = [10 x i8] c"count=%d\0A\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@.str.2 = [20 x i8] c"uart port used: %s\0A\00"
@TCIFLUSH = global i32 0
@.str.3 = [24 x i8] c"can't get port settings\00"
@CLOCAL = global i32 0
@CRTSCTS = global i32 0
@TCSANOW = global i32 0
@.str.4 = [24 x i8] c"can't set port settings\00"
@.str.5 = [14 x i8] c"write error!\0A\00"
@.str.6 = [21 x i8] c"read timeout error!\0A\00"
@.str.7 = [13 x i8] c"read error!\0A\00"
@.str.8 = [39 x i8] c"read data error: wrote 0x%x read 0x%x\0A\00"
@.str.9 = [3 x i8] c"%c\00"
@.str.10 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.timeval
%8 = alloca %struct.termios
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca [2 x i8]
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %13
store i32 26, i32* %15
br label %17
17: ; preds = %33, %2
%18 = load i32, i32* %4
%19 = load i8**, i8*** %5
%20 = call i32 @getopt(i32 %18, i8** %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 %20, i32* %14
%21 = icmp ne i32 %20, -1
br i1 %21, label %22, label %34
22: ; preds = %17
%23 = load i32, i32* %14
switch i32 %23, label %28 [
i32 99, label %24
i32 63, label %27
]
24: ; preds = %22
%25 = load i32, i32* @optarg
%26 = call i32 @atoi(i32 %25)
store i32 %26, i32* %15
br label %33
27: ; preds = %22
br label %28
28: ; preds = %22, %27
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 0
%31 = load i8*, i8** %30
%32 = call i32 @print_usage(i8* %31)
br label %33
33: ; preds = %28, %24
br label %17
34: ; preds = %17
%35 = load i32, i32* %4
%36 = load i32, i32* @optind
%37 = sub nsw i32 %35, %36
%38 = icmp ne i32 %37, 1
br i1 %38, label %39, label %44
39: ; preds = %34
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 0
%42 = load i8*, i8** %41
%43 = call i32 @print_usage(i8* %42)
br label %44
44: ; preds = %39, %34
%45 = load i8**, i8*** %5
%46 = load i32, i32* @optind
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %45, i64 %47
%49 = load i8*, i8** %48
store i8* %49, i8** %11
%50 = load i32, i32* %15
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %50)
%52 = load i8*, i8** %11
%53 = load i32, i32* @O_RDWR
%54 = load i32, i32* @O_NOCTTY
%55 = or i32 %53, %54
%56 = call i32 @open(i8* %52, i32 %55)
store i32 %56, i32* %9
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %62
58: ; preds = %44
%59 = load i8*, i8** %11
%60 = call i32 @perror(i8* %59)
%61 = call i32 @exit(i32 1)
unreachable
62: ; preds = %44
%63 = load i8*, i8** %11
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %63)
%65 = load i32, i32* %9
%66 = load i32, i32* @TCIFLUSH
%67 = call i32 @tcflush(i32 %65, i32 %66)
%68 = load i32, i32* %9
%69 = call i64 @tcgetattr(i32 %68, %struct.termios* %8)
%70 = icmp slt i64 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %62
%72 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %155
73: ; preds = %62
%74 = call i32 @cfmakeraw(%struct.termios* %8)
%75 = load i32, i32* @CLOCAL
%76 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%77 = load i32, i32* %76
%78 = or i32 %77, %75
store i32 %78, i32* %76
%79 = load i32, i32* @CRTSCTS
%80 = xor i32 %79, -1
%81 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%82 = load i32, i32* %81
%83 = and i32 %82, %80
store i32 %83, i32* %81
%84 = load i32, i32* %9
%85 = load i32, i32* @TCSANOW
%86 = call i64 @tcsetattr(i32 %84, i32 %85, %struct.termios* %8)
%87 = icmp slt i64 %86, 0
br i1 %87, label %88, label %90
88: ; preds = %73
%89 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %3
br label %155
90: ; preds = %73
store i8 65, i8* %16
br label %91
91: ; preds = %148, %90
%92 = load i8, i8* %16
%93 = sext i8 %92 to i32
%94 = load i32, i32* %15
%95 = add nsw i32 %94, 65
%96 = icmp slt i32 %93, %95
br i1 %96, label %97, label %151
97: ; preds = %91
%98 = load i32, i32* %9
%99 = call i32 @write(i32 %98, i8* %16, i32 1)
store i32 %99, i32* %10
%100 = load i32, i32* %10
%101 = icmp ne i32 %100, 1
br i1 %101, label %102, label %105
102: ; preds = %97
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%104 = call i32 @exit(i32 1)
unreachable
105: ; preds = %97
%106 = load i32, i32* %9
%107 = call i32 @FD_SET(i32 %106, i32* %6)
%108 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
store i64 0, i64* %108
%109 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
store i32 10, i32* %109
%110 = load i32, i32* %9
%111 = add nsw i32 %110, 1
%112 = call i32 @select(i32 %111, i32* %6, i32* null, i32* null, %struct.timeval* %7)
store i32 %112, i32* %10
%113 = load i32, i32* %10
%114 = icmp eq i32 %113, 0
br i1 %114, label %115, label %118
115: ; preds = %105
%116 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%117 = call i32 @exit(i32 1)
unreachable
118: ; preds = %105
%119 = load i32, i32* %9
%120 = bitcast [2 x i8]* %12 to i8**
%121 = call i32 @read(i32 %119, i8** %120, i32 1)
store i32 %121, i32* %10
br label %122
122: ; preds = %118
%123 = load i32, i32* %10
%124 = icmp ne i32 %123, 1
br i1 %124, label %125, label %128
125: ; preds = %122
%126 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
%127 = call i32 @exit(i32 1)
unreachable
128: ; preds = %122
%129 = load i8, i8* %16
%130 = sext i8 %129 to i32
%131 = getelementptr inbounds [2 x i8], [2 x i8]* %12, i64 0, i64 0
%132 = load i8, i8* %131
%133 = sext i8 %132 to i32
%134 = icmp ne i32 %130, %133
br i1 %134, label %135, label %143
135: ; preds = %128
%136 = load i8, i8* %16
%137 = sext i8 %136 to i32
%138 = getelementptr inbounds [2 x i8], [2 x i8]* %12, i64 0, i64 0
%139 = load i8, i8* %138
%140 = sext i8 %139 to i32
%141 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.8, i64 0, i64 0), i32 %137, i32 %140)
%142 = call i32 @exit(i32 1)
unreachable
143: ; preds = %128
%144 = getelementptr inbounds [2 x i8], [2 x i8]* %12, i64 0, i64 0
%145 = load i8, i8* %144
%146 = sext i8 %145 to i32
%147 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32 %146)
br label %148
148: ; preds = %143
%149 = load i8, i8* %16
%150 = add i8 %149, 1
store i8 %150, i8* %16
br label %91
151: ; preds = %91
%152 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%153 = load i32, i32* %9
%154 = call i32 @close(i32 %153)
store i32 0, i32* %3
br label %155
155: ; preds = %151, %88, %71
%156 = load i32, i32* %3
ret i32 %156
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
%struct.termios = type { i32 }
@.str = [4 x i8] c"c:?\00"
@optarg = global i32 0
@optind = global i32 0
@.str.1 = [10 x i8] c"count=%d\0A\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@.str.2 = [20 x i8] c"uart port used: %s\0A\00"
@TCIFLUSH = global i32 0
@.str.3 = [24 x i8] c"can't get port settings\00"
@CLOCAL = global i32 0
@CRTSCTS = global i32 0
@TCSANOW = global i32 0
@.str.4 = [24 x i8] c"can't set port settings\00"
@.str.8 = [39 x i8] c"read data error: wrote 0x%x read 0x%x\0A\00"
@str = [12 x i8] c"read error!\00"
@str.11 = [20 x i8] c"read timeout error!\00"
@str.12 = [13 x i8] c"write error!\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca %struct.timeval
%5 = alloca %struct.termios
%6 = alloca [2 x i8]
%7 = alloca i8
%8 = bitcast i32* %3 to i8*
%9 = bitcast %struct.timeval* %4 to i8*
%10 = bitcast %struct.termios* %5 to i8*
%11 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
br label %12
12: ; preds = %16, %2
%13 = phi i32 [ %18, %16 ], [ 26, %2 ]
br label %14
14: ; preds = %12, %19
%15 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
switch i32 %15, label %19 [
i32 -1, label %22
i32 99, label %16
]
16: ; preds = %14
%17 = load i32, i32* @optarg
%18 = tail call i32 @atoi(i32 %17)
br label %12
19: ; preds = %14
%20 = load i8*, i8** %1
%21 = tail call i32 @print_usage(i8* %20)
br label %14
22: ; preds = %14
%23 = load i32, i32* @optind
%24 = sub nsw i32 %0, %23
%25 = icmp eq i32 %24, 1
br i1 %25, label %30, label %26
26: ; preds = %22
%27 = load i8*, i8** %1
%28 = tail call i32 @print_usage(i8* %27)
%29 = load i32, i32* @optind
br label %30
30: ; preds = %26, %22
%31 = phi i32 [ %29, %26 ], [ %23, %22 ]
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %1, i64 %32
%34 = load i8*, i8** %33
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%36 = load i32, i32* @O_RDWR
%37 = load i32, i32* @O_NOCTTY
%38 = or i32 %37, %36
%39 = tail call i32 @open(i8* %34, i32 %38)
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %30
%42 = tail call i32 @perror(i8* %34)
%43 = tail call i32 @exit(i32 1)
unreachable
44: ; preds = %30
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %34)
%46 = load i32, i32* @TCIFLUSH
%47 = tail call i32 @tcflush(i32 %39, i32 %46)
%48 = call i64 @tcgetattr(i32 %39, %struct.termios* %5)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %44
%51 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %110
52: ; preds = %44
%53 = call i32 @cfmakeraw(%struct.termios* %5)
%54 = load i32, i32* @CLOCAL
%55 = getelementptr inbounds %struct.termios, %struct.termios* %5, i64 0, i32 0
%56 = load i32, i32* %55
%57 = or i32 %56, %54
%58 = load i32, i32* @CRTSCTS
%59 = xor i32 %58, -1
%60 = and i32 %57, %59
store i32 %60, i32* %55
%61 = load i32, i32* @TCSANOW
%62 = call i64 @tcsetattr(i32 %39, i32 %61, %struct.termios* %5)
%63 = icmp slt i64 %62, 0
br i1 %63, label %72, label %64
64: ; preds = %52
%65 = add nsw i32 %13, 65
store i8 65, i8* %7
%66 = icmp sgt i32 %13, 0
br i1 %66, label %67, label %107
67: ; preds = %64
%68 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%69 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%70 = add nuw nsw i32 %39, 1
%71 = bitcast [2 x i8]* %6 to i8**
br label %74
72: ; preds = %52
%73 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %110
74: ; preds = %67, %102
%75 = phi i32 [ 65, %67 ], [ %105, %102 ]
%76 = trunc i32 %75 to i8
%77 = call i32 @write(i32 %39, i8* %7, i32 1)
%78 = icmp eq i32 %77, 1
br i1 %78, label %82, label %79
79: ; preds = %74
%80 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.12, i64 0, i64 0))
%81 = call i32 @exit(i32 1)
unreachable
82: ; preds = %74
%83 = call i32 @FD_SET(i32 %39, i32* %3)
store i64 0, i64* %68
store i32 10, i32* %69
%84 = call i32 @select(i32 %70, i32* %3, i32* null, i32* null, %struct.timeval* %4)
%85 = icmp eq i32 %84, 0
br i1 %85, label %86, label %89
86: ; preds = %82
%87 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.11, i64 0, i64 0))
%88 = call i32 @exit(i32 1)
unreachable
89: ; preds = %82
%90 = call i32 @read(i32 %39, i8** %71, i32 1)
%91 = icmp eq i32 %90, 1
br i1 %91, label %95, label %92
92: ; preds = %89
%93 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%94 = call i32 @exit(i32 1)
unreachable
95: ; preds = %89
%96 = load i8, i8* %11
%97 = icmp eq i8 %96, %76
br i1 %97, label %102, label %98
98: ; preds = %95
%99 = sext i8 %96 to i32
%100 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.8, i64 0, i64 0), i32 %75, i32 %99)
%101 = call i32 @exit(i32 1)
unreachable
102: ; preds = %95
%103 = call i32 @putchar(i32 %75)
%104 = add i8 %76, 1
store i8 %104, i8* %7
%105 = sext i8 %104 to i32
%106 = icmp sgt i32 %65, %105
br i1 %106, label %74, label %107
107: ; preds = %102, %64
%108 = call i32 @putchar(i32 10)
%109 = call i32 @close(i32 %39)
br label %110
110: ; preds = %107, %72, %50
%111 = phi i32 [ -1, %50 ], [ -1, %72 ], [ 0, %107 ]
ret i32 %111
}