#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 */

/* Variables and functions */
int Open_Port(char *);
scalar_t__ Set_Opt(int, int, int, char, int);
int /*<<< orphan*/ TCIOFLUSH;
int atoi(char *);
int /*<<< orphan*/ close(int);
int getopt(int, char **, char *);
int /*<<< orphan*/ memcpy(char *, char *, int /*<<< orphan*/);
char *optarg;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
size_t strlen(char *);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  char *comport = "/dev/ttyUSB2";
  int speed = 115200;
  char snd_buf[128] = "";
  char recv_buf[512] = "";
  int fd = -1;
  int length = 0;
  int type = 0;
  int result = 0;
  while ((result = getopt(argc, argv, "rw:a:v:t:s:")) != -1) {
    switch (result) {
    case 'r':
      type = 0;
      break;
    case 'w':
      type = 1;
      memcpy(snd_buf, optarg, strlen(optarg) + 1);
      snd_buf[strlen(optarg)] = '\r';
      break;
    case 'a':
      type = 2;
      memcpy(snd_buf, optarg, strlen(optarg) + 1);
      snd_buf[strlen(optarg)] = '\r';
      break;
    case 'v':
      type = 3;
      memcpy(snd_buf, optarg, strlen(optarg) + 1);
      snd_buf[strlen(optarg)] = '\r';
      break;
    case 't':
      comport = optarg;
      break;
    case 's':
      speed = atoi(optarg);
      break;
    default:
      printf("Usage: %s [rwavts] r read w write a readwrite v writeread t "
             "device s speed\n",
             argv[0]);
      break;
    }
  }
  if ((fd = Open_Port(comport)) < 0) {
    printf("Open uart err \n");
    return -1;
  }
  if ((Set_Opt(fd, speed, 8, 'N', 1)) < 0) {
    perror("Set_Opt RS485 error");
    return -2;
  }
  tcflush(fd, TCIOFLUSH);
  switch (type) {
  case 0:
    while ((length = read(fd, recv_buf, 512)) > 0) {
      tcflush(fd, TCIOFLUSH);
      printf("%s\n", recv_buf);
    }
    break;
  case 1:
    printf("%s\n", snd_buf);
    length = write(fd, snd_buf, 128);
    break;
  case 2:
    printf("%s\n", snd_buf);
    while ((length = read(fd, recv_buf, 512)) > 0) {
      tcflush(fd, TCIOFLUSH);
      printf("%s\n", recv_buf);
    }
    tcflush(fd, TCIOFLUSH);
    length = write(fd, snd_buf, 128);
    break;
  case 3:
    printf("%s\n", snd_buf);
    length = write(fd, snd_buf, 128);
    while ((length = read(fd, recv_buf, 512)) > 0) {
      tcflush(fd, TCIOFLUSH);
      printf("%s\n", recv_buf);
    }
    break;
  default:
    break;
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2f0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe7c(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x1c200,-0x1c(%rbp)
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1070 <memset@plt>
lea    -0x2a0(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1070 <memset@plt>
movl   $0xffffffff,-0x2a4(%rbp)
ff ff ff
movl   $0x0,-0x2a8(%rbp)
movl   $0x0,-0x2ac(%rbp)
movl   $0x0,-0x2b0(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe22(%rip),%rdx
call   10c0 <getopt@plt>
mov    %eax,-0x2b0(%rbp)
cmp    $0xffffffff,%eax
je     1437 <main+0x267>
mov    -0x2b0(%rbp),%eax
add    $0xffffff9f,%eax
mov    %eax,%ecx
mov    %rcx,-0x2b8(%rbp)
sub    $0x16,%eax
ja     141d <main+0x24d>
mov    -0x2b8(%rbp),%rax
lea    0xd7c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x0,-0x2ac(%rbp)
jmp    1432 <main+0x262>
movl   $0x1,-0x2ac(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0x2c8(%rbp)
mov    0x2d2d(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x2c0(%rbp)
mov    0x2d1c(%rip),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    -0x2c8(%rbp),%rdi
mov    -0x2c0(%rbp),%rsi
add    $0x1,%rax
mov    %eax,%edx
call   10a0 <memcpy@plt>
mov    0x2cf4(%rip),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
movb   $0xd,-0xa0(%rbp,%rax,1)
0d
jmp    1432 <main+0x262>
movl   $0x2,-0x2ac(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0x2d8(%rbp)
mov    0x2cc0(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x2d0(%rbp)
mov    0x2caf(%rip),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    -0x2d8(%rbp),%rdi
mov    -0x2d0(%rbp),%rsi
add    $0x1,%rax
mov    %eax,%edx
call   10a0 <memcpy@plt>
mov    0x2c87(%rip),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
movb   $0xd,-0xa0(%rbp,%rax,1)
0d
jmp    1432 <main+0x262>
movl   $0x3,-0x2ac(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0x2e8(%rbp)
mov    0x2c53(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x2e0(%rbp)
mov    0x2c42(%rip),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    -0x2e8(%rbp),%rdi
mov    -0x2e0(%rbp),%rsi
add    $0x1,%rax
mov    %eax,%edx
call   10a0 <memcpy@plt>
mov    0x2c1a(%rip),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
movb   $0xd,-0xa0(%rbp,%rax,1)
0d
jmp    1432 <main+0x262>
mov    0x2bfe(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1432 <main+0x262>
mov    0x2beb(%rip),%rax
mov    (%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    1432 <main+0x262>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xc5a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1249 <main+0x79>
mov    -0x18(%rbp),%rdi
call   10e0 <Open_Port@plt>
mov    %eax,-0x2a4(%rbp)
cmp    $0x0,%eax
jge    1469 <main+0x299>
lea    0xc7b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    16c1 <main+0x4f1>
mov    -0x2a4(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    $0x8,%edx
mov    $0x4e,%ecx
mov    $0x1,%r8d
call   10f0 <Set_Opt@plt>
cmp    $0x0,%rax
jge    14a9 <main+0x2d9>
lea    0xc49(%rip),%rdi
call   10b0 <perror@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    16c1 <main+0x4f1>
mov    -0x2a4(%rbp),%edi
mov    0x2b22(%rip),%rax
mov    (%rax),%esi
call   1050 <tcflush@plt>
mov    -0x2ac(%rbp),%eax
mov    %rax,-0x2f0(%rbp)
sub    $0x3,%rax
ja     16aa <main+0x4da>
mov    -0x2f0(%rbp),%rax
lea    0xb1e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
jmp    14f0 <main+0x320>
mov    -0x2a4(%rbp),%edi
lea    -0x2a0(%rbp),%rsi
mov    $0x200,%edx
call   1090 <read@plt>
mov    %eax,-0x2a8(%rbp)
cmp    $0x0,%eax
jle    1544 <main+0x374>
mov    -0x2a4(%rbp),%edi
mov    0x2ab5(%rip),%rax
mov    (%rax),%esi
call   1050 <tcflush@plt>
lea    -0x2a0(%rbp),%rsi
lea    0xbbd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    14f0 <main+0x320>
jmp    16af <main+0x4df>
lea    -0xa0(%rbp),%rsi
lea    0xb9e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x2a4(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x80,%edx
call   1030 <write@plt>
mov    %eax,-0x2a8(%rbp)
jmp    16af <main+0x4df>
lea    -0xa0(%rbp),%rsi
lea    0xb67(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x2a4(%rbp),%edi
lea    -0x2a0(%rbp),%rsi
mov    $0x200,%edx
call   1090 <read@plt>
mov    %eax,-0x2a8(%rbp)
cmp    $0x0,%eax
jle    15e9 <main+0x419>
mov    -0x2a4(%rbp),%edi
mov    0x2a10(%rip),%rax
mov    (%rax),%esi
call   1050 <tcflush@plt>
lea    -0x2a0(%rbp),%rsi
lea    0xb18(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1595 <main+0x3c5>
mov    -0x2a4(%rbp),%edi
mov    0x29e2(%rip),%rax
mov    (%rax),%esi
call   1050 <tcflush@plt>
mov    -0x2a4(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x80,%edx
call   1030 <write@plt>
mov    %eax,-0x2a8(%rbp)
jmp    16af <main+0x4df>
lea    -0xa0(%rbp),%rsi
lea    0xac8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x2a4(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x80,%edx
call   1030 <write@plt>
mov    %eax,-0x2a8(%rbp)
mov    -0x2a4(%rbp),%edi
lea    -0x2a0(%rbp),%rsi
mov    $0x200,%edx
call   1090 <read@plt>
mov    %eax,-0x2a8(%rbp)
cmp    $0x0,%eax
jle    16a5 <main+0x4d5>
mov    -0x2a4(%rbp),%edi
mov    0x2954(%rip),%rax
mov    (%rax),%esi
call   1050 <tcflush@plt>
lea    -0x2a0(%rbp),%rsi
lea    0xa5c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1651 <main+0x481>
jmp    16af <main+0x4df>
jmp    16af <main+0x4df>
mov    -0x2a4(%rbp),%edi
call   1080 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x298,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
xorps  %xmm0,%xmm0
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
lea    0x90(%rsp),%rdi
mov    $0x200,%edx
xor    %esi,%esi
call   1080 <memset@plt>
movl   $0x1c200,0x4(%rsp)
lea    0xe25(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0xe26(%rip),%r12
lea    0xe2b(%rip),%r13
lea    0xd9f(%rip),%r15
xor    %r14d,%r14d
jmp    1286 <main+0xa6>
cs nopw 0x0(%rax,%rax,1)
cmp    $0xffffffff,%eax
je     138d <main+0x1ad>
mov    (%rbx),%rsi
mov    %r13,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   10d0 <getopt@plt>
lea    -0x61(%rax),%ecx
cmp    $0x16,%ecx
ja     1270 <main+0x90>
movslq (%r15,%rcx,4),%rax
add    %r15,%rax
jmp    *%rax
mov    0x2d4d(%rip),%rax
mov    (%rax),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edx
lea    0x10(%rsp),%rdi
mov    %r14,%rsi
call   10b0 <memcpy@plt>
mov    0x2d2b(%rip),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
movb   $0xd,0x10(%rsp,%rax,1)
mov    $0x2,%r14d
jmp    1286 <main+0xa6>
mov    0x2d0f(%rip),%rax
mov    (%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,0x4(%rsp)
jmp    1286 <main+0xa6>
mov    0x2cfa(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x8(%rsp)
jmp    1286 <main+0xa6>
mov    0x2ce6(%rip),%rax
mov    (%rax),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edx
lea    0x10(%rsp),%rdi
mov    %r14,%rsi
call   10b0 <memcpy@plt>
mov    0x2cc4(%rip),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
movb   $0xd,0x10(%rsp,%rax,1)
mov    $0x3,%r14d
jmp    1286 <main+0xa6>
mov    0x2ca5(%rip),%rax
mov    (%rax),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edx
lea    0x10(%rsp),%rdi
mov    %r14,%rsi
call   10b0 <memcpy@plt>
mov    0x2c83(%rip),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
movb   $0xd,0x10(%rsp,%rax,1)
mov    $0x1,%r14d
jmp    1286 <main+0xa6>
mov    0x8(%rsp),%rdi
call   10f0 <Open_Port@plt>
test   %eax,%eax
js     143a <main+0x25a>
mov    %eax,%ebx
mov    %eax,%edi
mov    0x4(%rsp),%esi
mov    $0x8,%edx
mov    $0x4e,%ecx
mov    $0x1,%r8d
call   1100 <Set_Opt@plt>
test   %rax,%rax
js     1550 <main+0x370>
mov    0x2c0c(%rip),%r15
mov    (%r15),%esi
mov    %ebx,%edi
call   1060 <tcflush@plt>
mov    %r14d,%eax
lea    0xc7c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0x90(%rsp),%rsi
mov    %ebx,%edi
mov    $0x200,%edx
call   10a0 <read@plt>
test   %eax,%eax
jle    1535 <main+0x355>
lea    0x90(%rsp),%rbp
nopl   (%rax)
mov    (%r15),%esi
mov    %ebx,%edi
call   1060 <tcflush@plt>
mov    %rbp,%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x200,%edx
call   10a0 <read@plt>
test   %eax,%eax
jg     1410 <main+0x230>
jmp    1535 <main+0x355>
lea    0xca4(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
jmp    153e <main+0x35e>
lea    0x10(%rsp),%rdi
call   1030 <puts@plt>
jmp    14bf <main+0x2df>
lea    0x10(%rsp),%rdi
call   1030 <puts@plt>
lea    0x90(%rsp),%rsi
mov    %ebx,%edi
mov    $0x200,%edx
call   10a0 <read@plt>
test   %eax,%eax
jle    14b5 <main+0x2d5>
lea    0x90(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
mov    (%r15),%esi
mov    %ebx,%edi
call   1060 <tcflush@plt>
mov    %rbp,%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x200,%edx
call   10a0 <read@plt>
test   %eax,%eax
jg     1490 <main+0x2b0>
mov    (%r15),%esi
mov    %ebx,%edi
call   1060 <tcflush@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x80,%edx
call   1040 <write@plt>
jmp    1535 <main+0x355>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x80,%edx
call   1040 <write@plt>
lea    0x90(%rsp),%rsi
mov    %ebx,%edi
mov    $0x200,%edx
call   10a0 <read@plt>
test   %eax,%eax
jle    1535 <main+0x355>
lea    0x90(%rsp),%rbp
xchg   %ax,%ax
mov    (%r15),%esi
mov    %ebx,%edi
call   1060 <tcflush@plt>
mov    %rbp,%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x200,%edx
call   10a0 <read@plt>
test   %eax,%eax
jg     1510 <main+0x330>
mov    %ebx,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x298,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb7a(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xfffffffe,%eax
jmp    153e <main+0x35e>

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/ttyUSB2\00"
@.str.1 = [12 x i8] c"rw:a:v:t:s:\00"
@optarg = global i8* null
@.str.2 = [76 x i8] c"Usage: %s [rwavts] r read w write a readwrite v writeread t device s speed\0A\00"
@.str.3 = [16 x i8] c"Open uart err \0A\00"
@.str.4 = [20 x i8] c"Set_Opt RS485 error\00"
@TCIOFLUSH = global i32 0
@.str.5 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [128 x i8]
%9 = alloca [512 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8** %6
store i32 115200, i32* %7
%14 = bitcast [128 x i8]* %8 to i8*
%15 = bitcast [512 x i8]* %9 to i8*
store i32 -1, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
br label %16
16: ; preds = %67, %2
%17 = load i32, i32* %4
%18 = load i8**, i8*** %5
%19 = call i32 @getopt(i32 %17, i8** %18, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i32 %19, i32* %13
%20 = icmp ne i32 %19, -1
br i1 %20, label %21, label %68
21: ; preds = %16
%22 = load i32, i32* %13
switch i32 %22, label %62 [
i32 114, label %23
i32 119, label %24
i32 97, label %35
i32 118, label %46
i32 116, label %57
i32 115, label %59
]
23: ; preds = %21
store i32 0, i32* %12
br label %67
24: ; preds = %21
store i32 1, i32* %12
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%26 = load i8*, i8** @optarg
%27 = load i8*, i8** @optarg
%28 = call i64 @strlen(i8* %27)
%29 = add i64 %28, 1
%30 = trunc i64 %29 to i32
%31 = call i32 @memcpy(i8* %25, i8* %26, i32 %30)
%32 = load i8*, i8** @optarg
%33 = call i64 @strlen(i8* %32)
%34 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 %33
store i8 13, i8* %34
br label %67
35: ; preds = %21
store i32 2, i32* %12
%36 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%37 = load i8*, i8** @optarg
%38 = load i8*, i8** @optarg
%39 = call i64 @strlen(i8* %38)
%40 = add i64 %39, 1
%41 = trunc i64 %40 to i32
%42 = call i32 @memcpy(i8* %36, i8* %37, i32 %41)
%43 = load i8*, i8** @optarg
%44 = call i64 @strlen(i8* %43)
%45 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 %44
store i8 13, i8* %45
br label %67
46: ; preds = %21
store i32 3, i32* %12
%47 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%48 = load i8*, i8** @optarg
%49 = load i8*, i8** @optarg
%50 = call i64 @strlen(i8* %49)
%51 = add i64 %50, 1
%52 = trunc i64 %51 to i32
%53 = call i32 @memcpy(i8* %47, i8* %48, i32 %52)
%54 = load i8*, i8** @optarg
%55 = call i64 @strlen(i8* %54)
%56 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 %55
store i8 13, i8* %56
br label %67
57: ; preds = %21
%58 = load i8*, i8** @optarg
store i8* %58, i8** %6
br label %67
59: ; preds = %21
%60 = load i8*, i8** @optarg
%61 = call i32 @atoi(i8* %60)
store i32 %61, i32* %7
br label %67
62: ; preds = %21
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 0
%65 = load i8*, i8** %64
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.2, i64 0, i64 0), i8* %65)
br label %67
67: ; preds = %62, %59, %57, %46, %35, %24, %23
br label %16
68: ; preds = %16
%69 = load i8*, i8** %6
%70 = call i32 @Open_Port(i8* %69)
store i32 %70, i32* %10
%71 = icmp slt i32 %70, 0
br i1 %71, label %72, label %74
72: ; preds = %68
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %148
74: ; preds = %68
%75 = load i32, i32* %10
%76 = load i32, i32* %7
%77 = call i64 @Set_Opt(i32 %75, i32 %76, i32 8, i8 signext 78, i32 1)
%78 = icmp slt i64 %77, 0
br i1 %78, label %79, label %81
79: ; preds = %74
%80 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
store i32 -2, i32* %3
br label %148
81: ; preds = %74
%82 = load i32, i32* %10
%83 = load i32, i32* @TCIOFLUSH
%84 = call i32 @tcflush(i32 %82, i32 %83)
%85 = load i32, i32* %12
switch i32 %85, label %144 [
i32 0, label %86
i32 1, label %99
i32 2, label %105
i32 3, label %126
]
86: ; preds = %81
br label %87
87: ; preds = %92, %86
%88 = load i32, i32* %10
%89 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%90 = call i32 @read(i32 %88, i8* %89, i32 512)
store i32 %90, i32* %11
%91 = icmp sgt i32 %90, 0
br i1 %91, label %92, label %98
92: ; preds = %87
%93 = load i32, i32* %10
%94 = load i32, i32* @TCIOFLUSH
%95 = call i32 @tcflush(i32 %93, i32 %94)
%96 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %96)
br label %87
98: ; preds = %87
br label %145
99: ; preds = %81
%100 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %100)
%102 = load i32, i32* %10
%103 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%104 = call i32 @write(i32 %102, i8* %103, i32 128)
store i32 %104, i32* %11
br label %145
105: ; preds = %81
%106 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %106)
br label %108
108: ; preds = %113, %105
%109 = load i32, i32* %10
%110 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%111 = call i32 @read(i32 %109, i8* %110, i32 512)
store i32 %111, i32* %11
%112 = icmp sgt i32 %111, 0
br i1 %112, label %113, label %119
113: ; preds = %108
%114 = load i32, i32* %10
%115 = load i32, i32* @TCIOFLUSH
%116 = call i32 @tcflush(i32 %114, i32 %115)
%117 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%118 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %117)
br label %108
119: ; preds = %108
%120 = load i32, i32* %10
%121 = load i32, i32* @TCIOFLUSH
%122 = call i32 @tcflush(i32 %120, i32 %121)
%123 = load i32, i32* %10
%124 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%125 = call i32 @write(i32 %123, i8* %124, i32 128)
store i32 %125, i32* %11
br label %145
126: ; preds = %81
%127 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%128 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %127)
%129 = load i32, i32* %10
%130 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%131 = call i32 @write(i32 %129, i8* %130, i32 128)
store i32 %131, i32* %11
br label %132
132: ; preds = %137, %126
%133 = load i32, i32* %10
%134 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%135 = call i32 @read(i32 %133, i8* %134, i32 512)
store i32 %135, i32* %11
%136 = icmp sgt i32 %135, 0
br i1 %136, label %137, label %143
137: ; preds = %132
%138 = load i32, i32* %10
%139 = load i32, i32* @TCIOFLUSH
%140 = call i32 @tcflush(i32 %138, i32 %139)
%141 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%142 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %141)
br label %132
143: ; preds = %132
br label %145
144: ; preds = %81
br label %145
145: ; preds = %144, %143, %119, %99, %98
%146 = load i32, i32* %10
%147 = call i32 @close(i32 %146)
store i32 0, i32* %3
br label %148
148: ; preds = %145, %79, %72
%149 = load i32, i32* %3
ret i32 %149
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/ttyUSB2\00"
@.str.1 = [12 x i8] c"rw:a:v:t:s:\00"
@optarg = global i8* null
@.str.2 = [76 x i8] c"Usage: %s [rwavts] r read w write a readwrite v writeread t device s speed\0A\00"
@.str.4 = [20 x i8] c"Set_Opt RS485 error\00"
@TCIOFLUSH = global i32 0
@str = [15 x i8] c"Open uart err \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [128 x i8]
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
br label %7
7: ; preds = %47, %2
%8 = phi i8* [ %48, %47 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), %2 ]
%9 = phi i32 [ %12, %47 ], [ 115200, %2 ]
%10 = phi i32 [ %15, %47 ], [ 0, %2 ]
br label %11
11: ; preds = %7, %49
%12 = phi i32 [ %9, %7 ], [ %51, %49 ]
%13 = phi i32 [ %10, %7 ], [ %15, %49 ]
br label %14
14: ; preds = %45, %11
%15 = phi i32 [ %13, %11 ], [ %46, %45 ]
br label %16
16: ; preds = %14, %52
%17 = call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
switch i32 %17, label %52 [
i32 -1, label %55
i32 114, label %45
i32 119, label %18
i32 97, label %27
i32 118, label %36
i32 116, label %47
i32 115, label %49
]
18: ; preds = %16
%19 = load i8*, i8** @optarg
%20 = call i64 @strlen(i8* dereferenceable(1) %19)
%21 = trunc i64 %20 to i32
%22 = add i32 %21, 1
%23 = call i32 @memcpy(i8* %5, i8* %19, i32 %22)
%24 = load i8*, i8** @optarg
%25 = call i64 @strlen(i8* dereferenceable(1) %24)
%26 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %25
store i8 13, i8* %26
br label %45
27: ; preds = %16
%28 = load i8*, i8** @optarg
%29 = call i64 @strlen(i8* dereferenceable(1) %28)
%30 = trunc i64 %29 to i32
%31 = add i32 %30, 1
%32 = call i32 @memcpy(i8* %5, i8* %28, i32 %31)
%33 = load i8*, i8** @optarg
%34 = call i64 @strlen(i8* dereferenceable(1) %33)
%35 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %34
store i8 13, i8* %35
br label %45
36: ; preds = %16
%37 = load i8*, i8** @optarg
%38 = call i64 @strlen(i8* dereferenceable(1) %37)
%39 = trunc i64 %38 to i32
%40 = add i32 %39, 1
%41 = call i32 @memcpy(i8* %5, i8* %37, i32 %40)
%42 = load i8*, i8** @optarg
%43 = call i64 @strlen(i8* dereferenceable(1) %42)
%44 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %43
store i8 13, i8* %44
br label %45
45: ; preds = %16, %36, %27, %18
%46 = phi i32 [ 1, %18 ], [ 2, %27 ], [ 3, %36 ], [ 0, %16 ]
br label %14
47: ; preds = %16
%48 = load i8*, i8** @optarg
br label %7
49: ; preds = %16
%50 = load i8*, i8** @optarg
%51 = call i32 @atoi(i8* %50)
br label %11
52: ; preds = %16
%53 = load i8*, i8** %1
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([76 x i8], [76 x i8]* @.str.2, i64 0, i64 0), i8* %53)
br label %16
55: ; preds = %16
%56 = call i32 @Open_Port(i8* %8)
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %55
%59 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %108
60: ; preds = %55
%61 = call i64 @Set_Opt(i32 %56, i32 %12, i32 8, i8 signext 78, i32 1)
%62 = icmp slt i64 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %60
%64 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %108
65: ; preds = %60
%66 = load i32, i32* @TCIOFLUSH
%67 = call i32 @tcflush(i32 %56, i32 %66)
switch i32 %15, label %105 [
i32 0, label %68
i32 1, label %77
i32 2, label %79
i32 3, label %92
]
68: ; preds = %65
%69 = call i32 @read(i32 %56, i8* %6, i32 512)
%70 = icmp sgt i32 %69, 0
br i1 %70, label %71, label %106
71: ; preds = %68, %71
%72 = load i32, i32* @TCIOFLUSH
%73 = call i32 @tcflush(i32 %56, i32 %72)
%74 = call i32 @puts(i8* %6)
%75 = call i32 @read(i32 %56, i8* %6, i32 512)
%76 = icmp sgt i32 %75, 0
br i1 %76, label %71, label %106
77: ; preds = %65
%78 = call i32 @puts(i8* %5)
br label %103
79: ; preds = %65
%80 = call i32 @puts(i8* %5)
%81 = call i32 @read(i32 %56, i8* %6, i32 512)
%82 = icmp sgt i32 %81, 0
br i1 %82, label %83, label %89
83: ; preds = %79, %83
%84 = load i32, i32* @TCIOFLUSH
%85 = call i32 @tcflush(i32 %56, i32 %84)
%86 = call i32 @puts(i8* %6)
%87 = call i32 @read(i32 %56, i8* %6, i32 512)
%88 = icmp sgt i32 %87, 0
br i1 %88, label %83, label %89
89: ; preds = %83, %79
%90 = load i32, i32* @TCIOFLUSH
%91 = call i32 @tcflush(i32 %56, i32 %90)
br label %103
92: ; preds = %65
%93 = call i32 @puts(i8* %5)
%94 = call i32 @write(i32 %56, i8* %5, i32 128)
%95 = call i32 @read(i32 %56, i8* %6, i32 512)
%96 = icmp sgt i32 %95, 0
br i1 %96, label %97, label %106
97: ; preds = %92, %97
%98 = load i32, i32* @TCIOFLUSH
%99 = call i32 @tcflush(i32 %56, i32 %98)
%100 = call i32 @puts(i8* %6)
%101 = call i32 @read(i32 %56, i8* %6, i32 512)
%102 = icmp sgt i32 %101, 0
br i1 %102, label %97, label %106
103: ; preds = %77, %89
%104 = call i32 @write(i32 %56, i8* %5, i32 128)
br label %106
105: ; preds = %65
unreachable
106: ; preds = %97, %71, %103, %92, %68
%107 = call i32 @close(i32 %56)
br label %108
108: ; preds = %106, %63, %58
%109 = phi i32 [ -1, %58 ], [ -2, %63 ], [ 0, %106 ]
ret i32 %109
}