#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ inpbuffer;

/* Variables and functions */
long atol(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ feof(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ help();
int /*<<< orphan*/ msleep(int);
int open_port(int, char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
scalar_t__ set_opt(int, long, int, char, int);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  long boundrate = 0;
  char device[100], buffer[50], inpbuffer[50];
  int databits = 0;
  int stopbits = 0;
  char parity;
  int fd = 0;
  int nread;
  device[0] = 0;
  if (argc != 6) {
    help();
  }
  for (int i = 1; i < 6; i++) {
    if (argv[i][0] != '-') {
      if (strlen(argv[i]) >= 90) {
        printf("Too long device name\n");
        exit(0);
      } else {
        if (device[0] != 0) {
          printf("Two Path\n");
          exit(0);
        } else {
          strcpy(device, argv[i]);
        }
      }
    } else {
      if (argv[i][1] == 'b') {
        boundrate = atol(argv[i] + 2);
      }
      if (argv[i][1] == 'd') {
        databits = argv[i][2] - '0';
        if (databits != 7 && databits != 8) {
          printf("Error Databits\n");
          exit(0);
        }
      }
      if (argv[i][1] == 's') {
        stopbits = argv[i][2] - '0';
        if (stopbits != 1 && stopbits != 2) {
          printf("Error StopBits\n");
          exit(0);
        }
      }
      if (argv[i][1] == 'p') {
        parity = argv[i][2];
        if (parity != 'N' && parity != 'O' && parity != 'E' && parity != 'n' &&
            parity != 'e' && parity != 'o') {
          printf("Error Parity\n");
          exit(0);
        }
      }
    }
  }
  if ((fd = open_port(fd, device)) < 0) {
    printf("open port error\n");
    return 0;
  }
  if (set_opt(fd, boundrate, databits, parity, stopbits) < 0) {
    printf("set mode error\n");
    return -1;
  }
  while (1) {
    if (!feof(stdin)) {
      fgets(inpbuffer, sizeof(inpbuffer), stdin);
      if (strlen(inpbuffer) > 1) {
        inpbuffer[strlen(inpbuffer) - 1] = '\0';
        write(fd, inpbuffer, strlen(inpbuffer));
      }
      inpbuffer[strlen(inpbuffer) - 1] = '\0';
      write(fd, inpbuffer, strlen(inpbuffer));
    }
    nread = read(fd, buffer, 49);
    if (nread >= 49) {
      buffer[49] = '\0';
    } else {
      buffer[nread] = '\0';
    }
    if (nread == 0) {
      continue;
    }
    msleep(60);
    printf("\033[33m%s\033[34m", buffer);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x104(%rbp)
movl   $0x0,-0x108(%rbp)
movl   $0x0,-0x110(%rbp)
movb   $0x0,-0x80(%rbp)
cmpl   $0x6,-0x8(%rbp)
je     1224 <main+0x54>
mov    $0x0,%al
call   10d0 <help@plt>
movl   $0x1,-0x118(%rbp)
cmpl   $0x6,-0x118(%rbp)
jge    14a8 <main+0x2d8>
mov    -0x10(%rbp),%rax
movslq -0x118(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     12cc <main+0xfc>
mov    -0x10(%rbp),%rax
movslq -0x118(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <strlen@plt>
cmp    $0x5a,%eax
jl     1288 <main+0xb8>
lea    0xd86(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
movsbl -0x80(%rbp),%eax
cmp    $0x0,%eax
je     12aa <main+0xda>
lea    0xd7a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x118(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <strcpy@plt>
jmp    12c7 <main+0xf7>
jmp    148f <main+0x2bf>
mov    -0x10(%rbp),%rax
movslq -0x118(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl 0x1(%rax),%eax
cmp    $0x62,%eax
jne    1304 <main+0x134>
mov    -0x10(%rbp),%rax
movslq -0x118(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
add    $0x2,%rdi
call   10c0 <atol@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x118(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl 0x1(%rax),%eax
cmp    $0x64,%eax
jne    1370 <main+0x1a0>
mov    -0x10(%rbp),%rax
movslq -0x118(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl 0x2(%rax),%eax
sub    $0x30,%eax
mov    %eax,-0x104(%rbp)
cmpl   $0x7,-0x104(%rbp)
je     136b <main+0x19b>
cmpl   $0x8,-0x104(%rbp)
je     136b <main+0x19b>
lea    0xcc3(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
jmp    1370 <main+0x1a0>
mov    -0x10(%rbp),%rax
movslq -0x118(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl 0x1(%rax),%eax
cmp    $0x73,%eax
jne    13dc <main+0x20c>
mov    -0x10(%rbp),%rax
movslq -0x118(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl 0x2(%rax),%eax
sub    $0x30,%eax
mov    %eax,-0x108(%rbp)
cmpl   $0x1,-0x108(%rbp)
je     13d7 <main+0x207>
cmpl   $0x2,-0x108(%rbp)
je     13d7 <main+0x207>
lea    0xc67(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
jmp    13dc <main+0x20c>
mov    -0x10(%rbp),%rax
movslq -0x118(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl 0x1(%rax),%eax
cmp    $0x70,%eax
jne    148a <main+0x2ba>
mov    -0x10(%rbp),%rax
movslq -0x118(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    0x2(%rax),%al
mov    %al,-0x109(%rbp)
movsbl -0x109(%rbp),%eax
cmp    $0x4e,%eax
je     1485 <main+0x2b5>
movsbl -0x109(%rbp),%eax
cmp    $0x4f,%eax
je     1485 <main+0x2b5>
movsbl -0x109(%rbp),%eax
cmp    $0x45,%eax
je     1485 <main+0x2b5>
movsbl -0x109(%rbp),%eax
cmp    $0x6e,%eax
je     1485 <main+0x2b5>
movsbl -0x109(%rbp),%eax
cmp    $0x65,%eax
je     1485 <main+0x2b5>
movsbl -0x109(%rbp),%eax
cmp    $0x6f,%eax
je     1485 <main+0x2b5>
lea    0xbc9(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
jmp    148a <main+0x2ba>
jmp    148f <main+0x2bf>
jmp    1494 <main+0x2c4>
mov    -0x118(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x118(%rbp)
jmp    122e <main+0x5e>
mov    -0x110(%rbp),%edi
lea    -0x80(%rbp),%rsi
call   10f0 <open_port@plt>
mov    %eax,-0x110(%rbp)
cmp    $0x0,%eax
jge    14e0 <main+0x310>
lea    0xb81(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1695 <main+0x4c5>
mov    -0x110(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x104(%rbp),%edx
mov    -0x109(%rbp),%al
mov    -0x108(%rbp),%r8d
movsbl %al,%ecx
call   10b0 <set_opt@plt>
cmp    $0x0,%rax
jge    1529 <main+0x359>
lea    0xb49(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1695 <main+0x4c5>
jmp    152e <main+0x35e>
mov    0x2ab3(%rip),%rax
mov    (%rax),%edi
call   10a0 <feof@plt>
cmp    $0x0,%eax
jne    161a <main+0x44a>
lea    -0x100(%rbp),%rdi
mov    0x2a95(%rip),%rax
mov    (%rax),%edx
mov    $0x32,%esi
call   1090 <fgets@plt>
lea    -0x100(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x1,%eax
jle    15c7 <main+0x3f7>
lea    -0x100(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x100(%rbp,%rax,1)
mov    -0x110(%rbp),%eax
mov    %eax,-0x124(%rbp)
lea    -0x100(%rbp),%rax
mov    %rax,-0x120(%rbp)
lea    -0x100(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x124(%rbp),%edi
mov    -0x120(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
lea    -0x100(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x100(%rbp,%rax,1)
mov    -0x110(%rbp),%eax
mov    %eax,-0x134(%rbp)
lea    -0x100(%rbp),%rax
mov    %rax,-0x130(%rbp)
lea    -0x100(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x134(%rbp),%edi
mov    -0x130(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0x110(%rbp),%edi
lea    -0xc0(%rbp),%rsi
mov    $0x31,%edx
call   1080 <read@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0x31,-0x114(%rbp)
jl     1650 <main+0x480>
movb   $0x0,-0x8f(%rbp)
jmp    165f <main+0x48f>
movslq -0x114(%rbp),%rax
movb   $0x0,-0xc0(%rbp,%rax,1)
cmpl   $0x0,-0x114(%rbp)
jne    1671 <main+0x4a1>
jmp    152e <main+0x35e>
mov    $0x3c,%edi
call   1060 <msleep@plt>
lea    -0xc0(%rbp),%rsi
lea    0x9e6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    152e <main+0x35e>
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xf8,%rsp
mov    %rsi,%rbx
movb   $0x0,0x50(%rsp)
cmp    $0x6,%edi
je     1205 <main+0x25>
xor    %eax,%eax
call   10e0 <help@plt>
xor    %r14d,%r14d
mov    $0x1,%ebp
lea    0xdec(%rip),%r13
xor    %r15d,%r15d
xor    %eax,%eax
mov    %rax,0x8(%rsp)
jmp    123e <main+0x5e>
add    $0x2,%rdi
call   10d0 <atol@plt>
mov    %rax,0x8(%rsp)
xchg   %ax,%ax
add    $0x1,%rbp
cmp    $0x6,%rbp
je     12f2 <main+0x112>
mov    (%rbx,%rbp,8),%rdi
cmpb   $0x2d,(%rdi)
jne    1280 <main+0xa0>
movzbl 0x1(%rdi),%eax
add    $0x9e,%al
cmp    $0x11,%al
ja     1230 <main+0x50>
movzbl %al,%eax
movslq 0x0(%r13,%rax,4),%rax
add    %r13,%rax
jmp    *%rax
movsbl 0x2(%rdi),%r15d
lea    -0x39(%r15),%eax
cmp    $0xfffffffd,%eax
jbe    1454 <main+0x274>
add    $0xffffffd0,%r15d
jmp    1230 <main+0x50>
cs nopw 0x0(%rax,%rax,1)
call   1060 <strlen@plt>
cmp    $0x5a,%eax
jge    1438 <main+0x258>
cmpb   $0x0,0x50(%rsp)
jne    1441 <main+0x261>
mov    (%rbx,%rbp,8),%rsi
lea    0x50(%rsp),%rdi
call   1030 <strcpy@plt>
jmp    1230 <main+0x50>
movzbl 0x2(%rdi),%r12d
lea    -0x45(%r12),%eax
cmp    $0x2a,%al
ja     1466 <main+0x286>
movzbl %al,%eax
movabs $0x60100000601,%rcx
bt     %rax,%rcx
jb     1230 <main+0x50>
jmp    1466 <main+0x286>
movsbl 0x2(%rdi),%r14d
lea    -0x33(%r14),%eax
cmp    $0xfffffffd,%eax
jbe    145d <main+0x27d>
add    $0xffffffd0,%r14d
jmp    1230 <main+0x50>
xor    %ebx,%ebx
lea    0x50(%rsp),%rsi
xor    %edi,%edi
call   1100 <open_port@plt>
test   %eax,%eax
js     140a <main+0x22a>
mov    %eax,%ebp
movsbl %r12b,%ecx
mov    %eax,%edi
mov    0x8(%rsp),%rsi
mov    %r15d,%edx
mov    %r14d,%r8d
call   10c0 <set_opt@plt>
test   %rax,%rax
js     1413 <main+0x233>
mov    0x2cb8(%rip),%r12
lea    0xc0(%rsp),%rbx
lea    0x10(%rsp),%r14
lea    0xd04(%rip),%r15
jmp    136c <main+0x18c>
cs nopw 0x0(%rax,%rax,1)
movb   $0x0,0x41(%rsp)
mov    $0x3c,%edi
call   1070 <msleep@plt>
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    (%r12),%edi
call   10b0 <feof@plt>
test   %eax,%eax
jne    13dd <main+0x1fd>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x32,%esi
call   10a0 <fgets@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cmp    $0x2,%eax
jl     13ba <main+0x1da>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x31,%edx
call   1090 <read@plt>
cmp    $0x31,%eax
jge    1350 <main+0x170>
movslq %eax,%rcx
movb   $0x0,0x10(%rsp,%rcx,1)
test   %eax,%eax
jne    1355 <main+0x175>
jmp    136c <main+0x18c>
lea    0xc53(%rip),%rdi
jmp    141f <main+0x23f>
mov    $0xffffffff,%ebx
lea    0xc36(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%eax
add    $0xf8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc69(%rip),%rdi
jmp    1448 <main+0x268>
lea    0xc57(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
lea    0xc35(%rip),%rdi
jmp    1448 <main+0x268>
lea    0xc1d(%rip),%rdi
jmp    1448 <main+0x268>
lea    0xc07(%rip),%rdi
jmp    1448 <main+0x268>

LLVM IR (-O0):
@.str = [22 x i8] c"Too long device name\0A\00"
@.str.1 = [10 x i8] c"Two Path\0A\00"
@.str.2 = [16 x i8] c"Error Databits\0A\00"
@.str.3 = [16 x i8] c"Error StopBits\0A\00"
@.str.4 = [14 x i8] c"Error Parity\0A\00"
@.str.5 = [17 x i8] c"open port error\0A\00"
@.str.6 = [16 x i8] c"set mode error\0A\00"
@stdin = global i32 0
@.str.7 = [13 x i8] c"\1B[33m%s\1B[34m\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca [100 x i8]
%8 = alloca [50 x i8]
%9 = alloca [50 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %6
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %13
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
store i8 0, i8* %16
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 6
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = call i32 (...) @help()
br label %21
21: ; preds = %19, %2
store i32 1, i32* %15
br label %22
22: ; preds = %187, %21
%23 = load i32, i32* %15
%24 = icmp slt i32 %23, 6
br i1 %24, label %25, label %190
25: ; preds = %22
%26 = load i8**, i8*** %5
%27 = load i32, i32* %15
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
%30 = load i8*, i8** %29
%31 = getelementptr inbounds i8, i8* %30, i64 0
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 45
br i1 %34, label %35, label %64
35: ; preds = %25
%36 = load i8**, i8*** %5
%37 = load i32, i32* %15
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8*, i8** %36, i64 %38
%40 = load i8*, i8** %39
%41 = call i32 @strlen(i8* %40)
%42 = icmp sge i32 %41, 90
br i1 %42, label %43, label %46
43: ; preds = %35
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%45 = call i32 @exit(i32 0)
unreachable
46: ; preds = %35
%47 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %46
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%53 = call i32 @exit(i32 0)
unreachable
54: ; preds = %46
%55 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%56 = load i8**, i8*** %5
%57 = load i32, i32* %15
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8*, i8** %56, i64 %58
%60 = load i8*, i8** %59
%61 = call i32 @strcpy(i8* %55, i8* %60)
br label %62
62: ; preds = %54
br label %63
63: ; preds = %62
br label %186
64: ; preds = %25
%65 = load i8**, i8*** %5
%66 = load i32, i32* %15
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8*, i8** %65, i64 %67
%69 = load i8*, i8** %68
%70 = getelementptr inbounds i8, i8* %69, i64 1
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
%73 = icmp eq i32 %72, 98
br i1 %73, label %74, label %82
74: ; preds = %64
%75 = load i8**, i8*** %5
%76 = load i32, i32* %15
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i8*, i8** %75, i64 %77
%79 = load i8*, i8** %78
%80 = getelementptr inbounds i8, i8* %79, i64 2
%81 = call i64 @atol(i8* %80)
store i64 %81, i64* %6
br label %82
82: ; preds = %74, %64
%83 = load i8**, i8*** %5
%84 = load i32, i32* %15
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i8*, i8** %83, i64 %85
%87 = load i8*, i8** %86
%88 = getelementptr inbounds i8, i8* %87, i64 1
%89 = load i8, i8* %88
%90 = sext i8 %89 to i32
%91 = icmp eq i32 %90, 100
br i1 %91, label %92, label %111
92: ; preds = %82
%93 = load i8**, i8*** %5
%94 = load i32, i32* %15
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds i8*, i8** %93, i64 %95
%97 = load i8*, i8** %96
%98 = getelementptr inbounds i8, i8* %97, i64 2
%99 = load i8, i8* %98
%100 = sext i8 %99 to i32
%101 = sub nsw i32 %100, 48
store i32 %101, i32* %10
%102 = load i32, i32* %10
%103 = icmp ne i32 %102, 7
br i1 %103, label %104, label %110
104: ; preds = %92
%105 = load i32, i32* %10
%106 = icmp ne i32 %105, 8
br i1 %106, label %107, label %110
107: ; preds = %104
%108 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%109 = call i32 @exit(i32 0)
unreachable
110: ; preds = %104, %92
br label %111
111: ; preds = %110, %82
%112 = load i8**, i8*** %5
%113 = load i32, i32* %15
%114 = sext i32 %113 to i64
%115 = getelementptr inbounds i8*, i8** %112, i64 %114
%116 = load i8*, i8** %115
%117 = getelementptr inbounds i8, i8* %116, i64 1
%118 = load i8, i8* %117
%119 = sext i8 %118 to i32
%120 = icmp eq i32 %119, 115
br i1 %120, label %121, label %140
121: ; preds = %111
%122 = load i8**, i8*** %5
%123 = load i32, i32* %15
%124 = sext i32 %123 to i64
%125 = getelementptr inbounds i8*, i8** %122, i64 %124
%126 = load i8*, i8** %125
%127 = getelementptr inbounds i8, i8* %126, i64 2
%128 = load i8, i8* %127
%129 = sext i8 %128 to i32
%130 = sub nsw i32 %129, 48
store i32 %130, i32* %11
%131 = load i32, i32* %11
%132 = icmp ne i32 %131, 1
br i1 %132, label %133, label %139
133: ; preds = %121
%134 = load i32, i32* %11
%135 = icmp ne i32 %134, 2
br i1 %135, label %136, label %139
136: ; preds = %133
%137 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%138 = call i32 @exit(i32 0)
unreachable
139: ; preds = %133, %121
br label %140
140: ; preds = %139, %111
%141 = load i8**, i8*** %5
%142 = load i32, i32* %15
%143 = sext i32 %142 to i64
%144 = getelementptr inbounds i8*, i8** %141, i64 %143
%145 = load i8*, i8** %144
%146 = getelementptr inbounds i8, i8* %145, i64 1
%147 = load i8, i8* %146
%148 = sext i8 %147 to i32
%149 = icmp eq i32 %148, 112
br i1 %149, label %150, label %185
150: ; preds = %140
%151 = load i8**, i8*** %5
%152 = load i32, i32* %15
%153 = sext i32 %152 to i64
%154 = getelementptr inbounds i8*, i8** %151, i64 %153
%155 = load i8*, i8** %154
%156 = getelementptr inbounds i8, i8* %155, i64 2
%157 = load i8, i8* %156
store i8 %157, i8* %12
%158 = load i8, i8* %12
%159 = sext i8 %158 to i32
%160 = icmp ne i32 %159, 78
br i1 %160, label %161, label %184
161: ; preds = %150
%162 = load i8, i8* %12
%163 = sext i8 %162 to i32
%164 = icmp ne i32 %163, 79
br i1 %164, label %165, label %184
165: ; preds = %161
%166 = load i8, i8* %12
%167 = sext i8 %166 to i32
%168 = icmp ne i32 %167, 69
br i1 %168, label %169, label %184
169: ; preds = %165
%170 = load i8, i8* %12
%171 = sext i8 %170 to i32
%172 = icmp ne i32 %171, 110
br i1 %172, label %173, label %184
173: ; preds = %169
%174 = load i8, i8* %12
%175 = sext i8 %174 to i32
%176 = icmp ne i32 %175, 101
br i1 %176, label %177, label %184
177: ; preds = %173
%178 = load i8, i8* %12
%179 = sext i8 %178 to i32
%180 = icmp ne i32 %179, 111
br i1 %180, label %181, label %184
181: ; preds = %177
%182 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%183 = call i32 @exit(i32 0)
unreachable
184: ; preds = %177, %173, %169, %165, %161, %150
br label %185
185: ; preds = %184, %140
br label %186
186: ; preds = %185, %63
br label %187
187: ; preds = %186
%188 = load i32, i32* %15
%189 = add nsw i32 %188, 1
store i32 %189, i32* %15
br label %22
190: ; preds = %22
%191 = load i32, i32* %13
%192 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%193 = call i32 @open_port(i32 %191, i8* %192)
store i32 %193, i32* %13
%194 = icmp slt i32 %193, 0
br i1 %194, label %195, label %197
195: ; preds = %190
%196 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %3
br label %261
197: ; preds = %190
%198 = load i32, i32* %13
%199 = load i64, i64* %6
%200 = load i32, i32* %10
%201 = load i8, i8* %12
%202 = load i32, i32* %11
%203 = call i64 @set_opt(i32 %198, i64 %199, i32 %200, i8 signext %201, i32 %202)
%204 = icmp slt i64 %203, 0
br i1 %204, label %205, label %207
205: ; preds = %197
%206 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %3
br label %261
207: ; preds = %197
br label %208
208: ; preds = %207, %256, %257
%209 = load i32, i32* @stdin
%210 = call i32 @feof(i32 %209)
%211 = icmp ne i32 %210, 0
br i1 %211, label %241, label %212
212: ; preds = %208
%213 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%214 = load i32, i32* @stdin
%215 = call i32 @fgets(i8* %213, i32 50, i32 %214)
%216 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%217 = call i32 @strlen(i8* %216)
%218 = icmp sgt i32 %217, 1
br i1 %218, label %219, label %230
219: ; preds = %212
%220 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%221 = call i32 @strlen(i8* %220)
%222 = sub nsw i32 %221, 1
%223 = sext i32 %222 to i64
%224 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 %223
store i8 0, i8* %224
%225 = load i32, i32* %13
%226 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%227 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%228 = call i32 @strlen(i8* %227)
%229 = call i32 @write(i32 %225, i8* %226, i32 %228)
br label %230
230: ; preds = %219, %212
%231 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%232 = call i32 @strlen(i8* %231)
%233 = sub nsw i32 %232, 1
%234 = sext i32 %233 to i64
%235 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 %234
store i8 0, i8* %235
%236 = load i32, i32* %13
%237 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%238 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%239 = call i32 @strlen(i8* %238)
%240 = call i32 @write(i32 %236, i8* %237, i32 %239)
br label %241
241: ; preds = %230, %208
%242 = load i32, i32* %13
%243 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 0
%244 = call i32 @read(i32 %242, i8* %243, i32 49)
store i32 %244, i32* %14
%245 = load i32, i32* %14
%246 = icmp sge i32 %245, 49
br i1 %246, label %247, label %249
247: ; preds = %241
%248 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 49
store i8 0, i8* %248
br label %253
249: ; preds = %241
%250 = load i32, i32* %14
%251 = sext i32 %250 to i64
%252 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 %251
store i8 0, i8* %252
br label %253
253: ; preds = %249, %247
%254 = load i32, i32* %14
%255 = icmp eq i32 %254, 0
br i1 %255, label %256, label %257
256: ; preds = %253
br label %208
257: ; preds = %253
%258 = call i32 @msleep(i32 60)
%259 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 0
%260 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %259)
br label %208
261: ; preds = %205, %195
%262 = load i32, i32* %3
ret i32 %262
}

LLVM IR (-O2):
@stdin = global i32 0
@.str.7 = [13 x i8] c"\1B[33m%s\1B[34m\00"
@str = [15 x i8] c"set mode error\00"
@str.8 = [16 x i8] c"open port error\00"
@str.9 = [13 x i8] c"Error Parity\00"
@str.10 = [15 x i8] c"Error StopBits\00"
@str.11 = [15 x i8] c"Error Databits\00"
@str.12 = [9 x i8] c"Two Path\00"
@str.13 = [21 x i8] c"Too long device name\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = alloca [50 x i8]
%5 = alloca [50 x i8]
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
store i8 0, i8* %6
%9 = icmp eq i32 %0, 6
br i1 %9, label %10, label %11
10: ; preds = %11, %2
br label %16
11: ; preds = %2
%12 = tail call i32 (...) @help()
br label %10
13: ; preds = %73
%14 = call i32 @open_port(i32 0, i8* %6)
%15 = icmp slt i32 %14, 0
br i1 %15, label %120, label %80
16: ; preds = %10, %73
%17 = phi i64 [ %78, %73 ], [ 1, %10 ]
%18 = phi i8 [ %77, %73 ], [ undef, %10 ]
%19 = phi i32 [ %76, %73 ], [ 0, %10 ]
%20 = phi i32 [ %75, %73 ], [ 0, %10 ]
%21 = phi i64 [ %74, %73 ], [ 0, %10 ]
%22 = getelementptr inbounds i8*, i8** %1, i64 %17
%23 = load i8*, i8** %22
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 45
br i1 %25, label %41, label %26
26: ; preds = %16
%27 = call i32 @strlen(i8* %23)
%28 = icmp sgt i32 %27, 89
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.13, i64 0, i64 0))
%31 = call i32 @exit(i32 0)
unreachable
32: ; preds = %26
%33 = load i8, i8* %6
%34 = icmp eq i8 %33, 0
br i1 %34, label %38, label %35
35: ; preds = %32
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.12, i64 0, i64 0))
%37 = call i32 @exit(i32 0)
unreachable
38: ; preds = %32
%39 = load i8*, i8** %22
%40 = call i32 @strcpy(i8* %6, i8* %39)
br label %73
41: ; preds = %16
%42 = getelementptr inbounds i8, i8* %23, i64 1
%43 = load i8, i8* %42
switch i8 %43, label %73 [
i8 98, label %44
i8 100, label %47
i8 115, label %57
i8 112, label %67
]
44: ; preds = %41
%45 = getelementptr inbounds i8, i8* %23, i64 2
%46 = call i64 @atol(i8* %45)
br label %73
47: ; preds = %41
%48 = getelementptr inbounds i8, i8* %23, i64 2
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = add nsw i32 %50, -48
%52 = add nsw i32 %50, -57
%53 = icmp ult i32 %52, -2
br i1 %53, label %54, label %73
54: ; preds = %47
%55 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.11, i64 0, i64 0))
%56 = call i32 @exit(i32 0)
unreachable
57: ; preds = %41
%58 = getelementptr inbounds i8, i8* %23, i64 2
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = add nsw i32 %60, -48
%62 = add nsw i32 %60, -51
%63 = icmp ult i32 %62, -2
br i1 %63, label %64, label %73
64: ; preds = %57
%65 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.10, i64 0, i64 0))
%66 = call i32 @exit(i32 0)
unreachable
67: ; preds = %41
%68 = getelementptr inbounds i8, i8* %23, i64 2
%69 = load i8, i8* %68
switch i8 %69, label %70 [
i8 111, label %73
i8 110, label %73
i8 101, label %73
i8 79, label %73
i8 78, label %73
i8 69, label %73
]
70: ; preds = %67
%71 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.9, i64 0, i64 0))
%72 = call i32 @exit(i32 0)
unreachable
73: ; preds = %41, %47, %44, %57, %67, %67, %67, %67, %67, %67, %38
%74 = phi i64 [ %21, %38 ], [ %21, %67 ], [ %21, %67 ], [ %21, %67 ], [ %21, %67 ], [ %21, %67 ], [ %21, %67 ], [ %21, %57 ], [ %46, %44 ], [ %21, %47 ], [ %21, %41 ]
%75 = phi i32 [ %20, %38 ], [ %20, %67 ], [ %20, %67 ], [ %20, %67 ], [ %20, %67 ], [ %20, %67 ], [ %20, %67 ], [ %20, %57 ], [ %20, %44 ], [ %51, %47 ], [ %20, %41 ]
%76 = phi i32 [ %19, %38 ], [ %19, %67 ], [ %19, %67 ], [ %19, %67 ], [ %19, %67 ], [ %19, %67 ], [ %19, %67 ], [ %61, %57 ], [ %19, %44 ], [ %19, %47 ], [ %19, %41 ]
%77 = phi i8 [ %18, %38 ], [ %69, %67 ], [ %69, %67 ], [ %69, %67 ], [ %69, %67 ], [ %69, %67 ], [ %69, %67 ], [ %18, %57 ], [ %18, %44 ], [ %18, %47 ], [ %18, %41 ]
%78 = add nuw nsw i64 %17, 1
%79 = icmp eq i64 %78, 6
br i1 %79, label %13, label %16
80: ; preds = %13
%81 = call i64 @set_opt(i32 %14, i64 %74, i32 %75, i8 signext %77, i32 %76)
%82 = icmp slt i64 %81, 0
br i1 %82, label %120, label %83
83: ; preds = %80
%84 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 49
br label %85
85: ; preds = %119, %83
%86 = load i32, i32* @stdin
%87 = call i32 @feof(i32 %86)
%88 = icmp eq i32 %87, 0
br i1 %88, label %89, label %108
89: ; preds = %85
%90 = load i32, i32* @stdin
%91 = call i32 @fgets(i8* %8, i32 50, i32 %90)
%92 = call i32 @strlen(i8* %8)
%93 = icmp sgt i32 %92, 1
br i1 %93, label %94, label %101
94: ; preds = %89
%95 = call i32 @strlen(i8* %8)
%96 = add nsw i32 %95, -1
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 %97
store i8 0, i8* %98
%99 = call i32 @strlen(i8* %8)
%100 = call i32 @write(i32 %14, i8* %8, i32 %99)
br label %101
101: ; preds = %94, %89
%102 = call i32 @strlen(i8* %8)
%103 = add nsw i32 %102, -1
%104 = sext i32 %103 to i64
%105 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 %104
store i8 0, i8* %105
%106 = call i32 @strlen(i8* %8)
%107 = call i32 @write(i32 %14, i8* %8, i32 %106)
br label %108
108: ; preds = %101, %85
%109 = call i32 @read(i32 %14, i8* %7, i32 49)
%110 = icmp sgt i32 %109, 48
br i1 %110, label %111, label %112
111: ; preds = %108
store i8 0, i8* %84
br label %116
112: ; preds = %108
%113 = sext i32 %109 to i64
%114 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 %113
store i8 0, i8* %114
%115 = icmp eq i32 %109, 0
br i1 %115, label %119, label %116
116: ; preds = %111, %112
%117 = call i32 @msleep(i32 60)
%118 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %7)
br label %119
119: ; preds = %116, %112
br label %85
120: ; preds = %80, %13
%121 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @str.8, i64 0, i64 0), %13 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0), %80 ]
%122 = phi i32 [ 0, %13 ], [ -1, %80 ]
%123 = call i32 @puts(i8* dereferenceable(1) %121)
ret i32 %122
}