#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_cflag;
  int c_lflag;
};
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ B2400;
int CLOCAL;
int CREAD;
int CS8;
int CSIZE;
int CSTOPB;
int ECHO;
int ECHOE;
int /*<<< orphan*/ FNDELAY;
int /*<<< orphan*/ F_SETFL;
int ICANON;
int ISIG;
int O_NDELAY;
int O_NOCTTY;
int O_RDWR;
int PARENB;
int /*<<< orphan*/ TCSANOW;
int atoi(char *);
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, unsigned char **, int);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ usleep(int);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int driveID = 12;
  int commandID = 0;
  char *serialPort = "/dev/ttyUSB1";
  char serialPort2[] = "/dev/ttyUSB1";
  int serialWait = 60;
  int fd;
  int x;
  int bytes;
  char c;
  unsigned char buffer[12];
  if (argc > 1) {
    driveID = atoi(argv[1]);
  }
  if (argc > 2) {
    if (strcmp(argv[2], "stop") == 0)
      commandID = 0;
    if (strcmp(argv[2], "up") == 0)
      commandID = 1;
    if (strcmp(argv[2], "hoch") == 0)
      commandID = 1;
    if (strcmp(argv[2], "down") == 0)
      commandID = 2;
    if (strcmp(argv[2], "runter") == 0)
      commandID = 2;
    if (strcmp(argv[2], "pos1") == 0)
      commandID = 3;
    if (strcmp(argv[2], "pos2") == 0)
      commandID = 4;
  }
  if (argc > 3) {
    serialPort = argv[3];
  } else {
    serialPort = serialPort2;
  }
  if (argc > 4) {
    serialWait = atoi(argv[4]);
  } else {
    serialWait = 40;
  }
  fd = open(serialPort, O_RDWR | O_NOCTTY | O_NDELAY);
  if (fd == -1) {
    perror("open_port: Unable to open serialPort ");
  } else {
    fcntl(fd, F_SETFL, 0);
  }
  struct termios options;
  tcgetattr(fd, &options);
  cfsetispeed(&options, B2400);
  cfsetospeed(&options, B2400);
  options.c_cflag |= (CLOCAL | CREAD);
  options.c_cflag &= ~CSIZE;
  options.c_cflag |= CS8;
  options.c_cflag &= ~PARENB;
  options.c_cflag &= ~CSTOPB;
  options.c_cflag &= ~CSIZE;
  options.c_cflag |= CS8;
  options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
  tcsetattr(fd, TCSANOW, &options);
  int n;
  char tmpBytes[4];
  tmpBytes[0] = 0x50 + driveID;
  tmpBytes[1] = commandID;
  tmpBytes[2] = tmpBytes[0] + tmpBytes[1];
  tmpBytes[2] = ~(tmpBytes[0] + tmpBytes[1]) + 1;
  n = write(fd, tmpBytes, 3);
  if (n < 0)
    fputs("write() of smi command failed!\n", stderr);
  printf("%02X %02X %02X: ", tmpBytes[0], tmpBytes[1], tmpBytes[2]);
  usleep(serialWait * 1000);
  fcntl(fd, F_SETFL, FNDELAY);
  bytes = read(fd, &buffer, sizeof(buffer));
  for (x = 3; x < bytes; x++) {
    c = buffer[x];
    printf("%02X ", c);
  }
  printf("\n");
  close(fd);
  if (buffer[bytes - 1] == 0xff) {
    return (0);
  } else {
    return (-1);
  }
}


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   $0xc,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xde5(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xdda(%rip),%rax
mov    %rax,-0x2d(%rbp)
mov    0xdd8(%rip),%eax
mov    %eax,-0x25(%rbp)
mov    0xdd3(%rip),%al
mov    %al,-0x21(%rbp)
movl   $0x3c,-0x34(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    125d <main+0x6d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1100 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    136f <main+0x17f>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd97(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    128c <main+0x9c>
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd77(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    12b1 <main+0xc1>
movl   $0x1,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd55(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    12d6 <main+0xe6>
movl   $0x1,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd35(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    12fb <main+0x10b>
movl   $0x2,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd15(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    1320 <main+0x130>
movl   $0x2,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xcf7(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    1345 <main+0x155>
movl   $0x3,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xcd7(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    136a <main+0x17a>
movl   $0x4,-0x18(%rbp)
jmp    136f <main+0x17f>
cmpl   $0x3,-0x8(%rbp)
jle    138a <main+0x19a>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1392 <main+0x1a2>
lea    -0x2d(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x4,-0x8(%rbp)
jle    13b1 <main+0x1c1>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1100 <atoi@plt>
mov    %eax,-0x34(%rbp)
jmp    13b8 <main+0x1c8>
movl   $0x28,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2c25(%rip),%rax
mov    (%rax),%esi
mov    0x2bcc(%rip),%rax
or     (%rax),%esi
mov    0x2ba3(%rip),%rax
or     (%rax),%esi
call   10d0 <open@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0xffffffff,-0x38(%rbp)
jne    13fa <main+0x20a>
lea    0xc40(%rip),%rdi
call   10f0 <perror@plt>
jmp    140d <main+0x21d>
mov    -0x38(%rbp),%edi
mov    0x2b7c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    -0x38(%rbp),%edi
lea    -0x58(%rbp),%rsi
call   10b0 <tcgetattr@plt>
mov    0x2b68(%rip),%rax
mov    (%rax),%esi
lea    -0x58(%rbp),%rdi
call   10e0 <cfsetispeed@plt>
mov    0x2b56(%rip),%rax
mov    (%rax),%esi
lea    -0x58(%rbp),%rdi
call   1050 <cfsetospeed@plt>
mov    0x2b0c(%rip),%rax
mov    (%rax),%eax
mov    0x2b6b(%rip),%rcx
or     (%rcx),%eax
or     -0x58(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    0x2b4c(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x58(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    0x2b42(%rip),%rax
mov    (%rax),%eax
or     -0x58(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    0x2b63(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x58(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    0x2ac9(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x58(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    0x2b07(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x58(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    0x2afd(%rip),%rax
mov    (%rax),%eax
or     -0x58(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    0x2aa6(%rip),%rax
mov    (%rax),%eax
mov    0x2b05(%rip),%rcx
or     (%rcx),%eax
mov    0x2af4(%rip),%rcx
or     (%rcx),%eax
mov    0x2ae3(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x54(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x38(%rbp),%edi
mov    0x2ae6(%rip),%rax
mov    (%rax),%esi
lea    -0x58(%rbp),%rdx
call   10c0 <tcsetattr@plt>
mov    -0x14(%rbp),%eax
add    $0x50,%eax
mov    %al,-0x60(%rbp)
mov    -0x18(%rbp),%eax
mov    %al,-0x5f(%rbp)
movsbl -0x60(%rbp),%eax
movsbl -0x5f(%rbp),%ecx
add    %ecx,%eax
mov    %al,-0x5e(%rbp)
movsbl -0x60(%rbp),%eax
movsbl -0x5f(%rbp),%ecx
add    %ecx,%eax
xor    $0xffffffff,%eax
add    $0x1,%eax
mov    %al,-0x5e(%rbp)
mov    -0x38(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x3,%edx
call   1040 <write@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jge    155f <main+0x36f>
mov    0x2a3f(%rip),%rax
mov    (%rax),%esi
lea    0xafc(%rip),%rdi
call   1070 <fputs@plt>
movsbl -0x60(%rbp),%esi
movsbl -0x5f(%rbp),%edx
movsbl -0x5e(%rbp),%ecx
lea    0xb04(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
imul   $0x3e8,-0x34(%rbp),%edi
call   1110 <usleep@plt>
mov    -0x38(%rbp),%edi
mov    0x29f1(%rip),%rax
mov    (%rax),%esi
mov    0x29d8(%rip),%rax
mov    (%rax),%edx
call   1030 <fcntl@plt>
mov    -0x38(%rbp),%edi
lea    -0x4d(%rbp),%rsi
mov    $0xc,%edx
call   1090 <read@plt>
mov    %eax,-0x40(%rbp)
movl   $0x3,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x40(%rbp),%eax
jge    15f1 <main+0x401>
movslq -0x3c(%rbp),%rax
mov    -0x4d(%rbp,%rax,1),%al
mov    %al,-0x41(%rbp)
movsbl -0x41(%rbp),%esi
lea    0xaab(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    15ba <main+0x3ca>
lea    0xa7c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x38(%rbp),%edi
call   1080 <close@plt>
mov    -0x40(%rbp),%eax
sub    $0x1,%eax
cltq
movzbl -0x4d(%rbp,%rax,1),%eax
cmp    $0xff,%eax
jne    162b <main+0x43b>
movl   $0x0,-0x4(%rbp)
jmp    1632 <main+0x442>
movl   $0xffffffff,-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    $0x38,%rsp
lea    0x18(%rsp),%rbx
movabs $0x31425355797474,%rax
mov    %rax,0x1d(%rsp)
movabs $0x7974742f7665642f,%rax
74 74 79
mov    %rax,0x18(%rsp)
mov    $0x9c40,%r14d
cmp    $0x2,%edi
jl     1260 <main+0x60>
mov    %rsi,%rbp
mov    %edi,%r15d
mov    0x8(%rsi),%rdi
call   1110 <atoi@plt>
mov    %eax,%r12d
add    $0x50,%r12b
cmp    $0x2,%r15d
jne    126b <main+0x6b>
xor    %r13d,%r13d
jmp    134d <main+0x14d>
mov    $0x5c,%r12b
xor    %r13d,%r13d
jmp    134d <main+0x14d>
mov    0x10(%rbp),%rdi
lea    0xd97(%rip),%rsi
call   10b0 <strcmp@plt>
mov    0x10(%rbp),%rdi
lea    0xd8c(%rip),%rsi
call   10b0 <strcmp@plt>
test   %rax,%rax
sete   %r13b
mov    0x10(%rbp),%rdi
lea    0xd78(%rip),%rsi
call   10b0 <strcmp@plt>
test   %rax,%rax
sete   %r14b
or     %r13b,%r14b
mov    0x10(%rbp),%rdi
lea    0xd63(%rip),%rsi
call   10b0 <strcmp@plt>
mov    %rax,%r13
mov    0x10(%rbp),%rdi
lea    0xd55(%rip),%rsi
call   10b0 <strcmp@plt>
test   %r13,%r13
movzbl %r14b,%ebx
mov    $0x2,%ecx
cmove  %ecx,%ebx
test   %rax,%rax
cmove  %ecx,%ebx
mov    0x10(%rbp),%rdi
lea    0xd37(%rip),%rsi
call   10b0 <strcmp@plt>
test   %rax,%rax
mov    $0x3,%r14d
cmovne %ebx,%r14d
mov    0x10(%rbp),%rdi
lea    0xd1f(%rip),%rsi
call   10b0 <strcmp@plt>
test   %rax,%rax
mov    $0x4,%r13d
cmovne %r14d,%r13d
cmp    $0x4,%r15d
jb     1342 <main+0x142>
mov    0x18(%rbp),%rbx
mov    $0x9c40,%r14d
je     134d <main+0x14d>
mov    0x20(%rbp),%rdi
call   1110 <atoi@plt>
imul   $0x3e8,%eax,%r14d
jmp    134d <main+0x14d>
mov    $0x9c40,%r14d
lea    0x18(%rsp),%rbx
mov    0x2c94(%rip),%rax
mov    0x2c3d(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2c12(%rip),%rax
or     (%rax),%esi
mov    %rbx,%rdi
call   10e0 <open@plt>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
je     1539 <main+0x339>
mov    0x2bfd(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
xor    %edx,%edx
call   1040 <fcntl@plt>
lea    0x10(%rsp),%rbx
mov    %r15d,%edi
mov    %rbx,%rsi
call   10c0 <tcgetattr@plt>
mov    0x2be2(%rip),%rbp
mov    0x0(%rbp),%esi
mov    %rbx,%rdi
call   10f0 <cfsetispeed@plt>
mov    0x0(%rbp),%esi
mov    %rbx,%rdi
call   1060 <cfsetospeed@plt>
mov    0x2b8d(%rip),%rax
mov    0x2bee(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     0x10(%rsp),%ecx
mov    0x2bcf(%rip),%rax
mov    0x2bd0(%rip),%rdx
mov    0x2b71(%rip),%rsi
mov    (%rsi),%esi
or     (%rax),%esi
mov    0x2bee(%rip),%rax
or     (%rax),%esi
not    %esi
and    %ecx,%esi
or     (%rdx),%esi
mov    0x2b67(%rip),%rax
mov    0x2bc8(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2bb5(%rip),%rax
or     (%rax),%ecx
mov    %esi,0x10(%rsp)
mov    0x2ba0(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x14(%rsp)
mov    0x2ba9(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
mov    %rbx,%rdx
call   10d0 <tcsetattr@plt>
mov    %r12b,0xc(%rsp)
mov    %r13b,0xd(%rsp)
lea    (%r12,%r13,1),%ebx
neg    %bl
mov    %bl,0xe(%rsp)
lea    0xc(%rsp),%rsi
mov    %r15d,%edi
mov    $0x3,%edx
call   1050 <write@plt>
test   %eax,%eax
jns    147b <main+0x27b>
mov    0x2b23(%rip),%rax
mov    (%rax),%esi
lea    0xbe0(%rip),%rdi
call   1080 <fputs@plt>
movsbl %r12b,%esi
movzbl %r13b,%edx
movsbl %bl,%ecx
lea    0xbe9(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r14d,%edi
call   1120 <usleep@plt>
mov    0x2add(%rip),%rax
mov    (%rax),%esi
mov    0x2ac4(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
call   1040 <fcntl@plt>
lea    0x2c(%rsp),%r14
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   10a0 <read@plt>
mov    %eax,%r12d
cmp    $0x4,%eax
jl     1508 <main+0x308>
mov    %r12d,%ebx
mov    $0x3,%ebp
lea    0xba5(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl 0x2c(%rsp,%rbp,1),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    14f0 <main+0x2f0>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15d,%edi
call   1090 <close@plt>
movslq %r12d,%rcx
xor    %eax,%eax
cmpb   $0xff,-0x1(%rcx,%r14,1)
setne  %al
neg    %eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xaf0(%rip),%rdi
call   1100 <perror@plt>
jmp    138f <main+0x18f>

LLVM IR (-O0):
%struct.termios = type { i32, i32 }
@.str = [13 x i8] c"/dev/ttyUSB1\00"
@__const.main.serialPort2 = [13 x i8] c"/dev/ttyUSB1\00"
@.str.1 = [5 x i8] c"stop\00"
@.str.2 = [3 x i8] c"up\00"
@.str.3 = [5 x i8] c"hoch\00"
@.str.4 = [5 x i8] c"down\00"
@.str.5 = [7 x i8] c"runter\00"
@.str.6 = [5 x i8] c"pos1\00"
@.str.7 = [5 x i8] c"pos2\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@.str.8 = [38 x i8] c"open_port: Unable to open serialPort \00"
@F_SETFL = global i32 0
@B2400 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@TCSANOW = global i32 0
@.str.9 = [32 x i8] c"write() of smi command failed!\0A\00"
@stderr = global i32 0
@.str.10 = [17 x i8] c"%02X %02X %02X: \00"
@FNDELAY = global i32 0
@.str.11 = [6 x i8] c"%02X \00"
@.str.12 = [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 i32
%8 = alloca i8*
%9 = alloca [13 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8
%15 = alloca [12 x i8]
%16 = alloca %struct.termios
%17 = alloca i32
%18 = alloca [4 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 12, i32* %6
store i32 0, i32* %7
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8** %8
%19 = bitcast [13 x i8]* %9 to i8*
store i32 60, i32* %10
%20 = load i32, i32* %4
%21 = icmp sgt i32 %20, 1
br i1 %21, label %22, label %27
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %6
br label %27
27: ; preds = %22, %2
%28 = load i32, i32* %4
%29 = icmp sgt i32 %28, 2
br i1 %29, label %30, label %80
30: ; preds = %27
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %30
store i32 0, i32* %7
br label %37
37: ; preds = %36, %30
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i64 @strcmp(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %37
store i32 1, i32* %7
br label %44
44: ; preds = %43, %37
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 2
%47 = load i8*, i8** %46
%48 = call i64 @strcmp(i8* %47, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %44
store i32 1, i32* %7
br label %51
51: ; preds = %50, %44
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 2
%54 = load i8*, i8** %53
%55 = call i64 @strcmp(i8* %54, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %58
57: ; preds = %51
store i32 2, i32* %7
br label %58
58: ; preds = %57, %51
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 2
%61 = load i8*, i8** %60
%62 = call i64 @strcmp(i8* %61, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%63 = icmp eq i64 %62, 0
br i1 %63, label %64, label %65
64: ; preds = %58
store i32 2, i32* %7
br label %65
65: ; preds = %64, %58
%66 = load i8**, i8*** %5
%67 = getelementptr inbounds i8*, i8** %66, i64 2
%68 = load i8*, i8** %67
%69 = call i64 @strcmp(i8* %68, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%70 = icmp eq i64 %69, 0
br i1 %70, label %71, label %72
71: ; preds = %65
store i32 3, i32* %7
br label %72
72: ; preds = %71, %65
%73 = load i8**, i8*** %5
%74 = getelementptr inbounds i8*, i8** %73, i64 2
%75 = load i8*, i8** %74
%76 = call i64 @strcmp(i8* %75, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%77 = icmp eq i64 %76, 0
br i1 %77, label %78, label %79
78: ; preds = %72
store i32 4, i32* %7
br label %79
79: ; preds = %78, %72
br label %80
80: ; preds = %79, %27
%81 = load i32, i32* %4
%82 = icmp sgt i32 %81, 3
br i1 %82, label %83, label %87
83: ; preds = %80
%84 = load i8**, i8*** %5
%85 = getelementptr inbounds i8*, i8** %84, i64 3
%86 = load i8*, i8** %85
store i8* %86, i8** %8
br label %89
87: ; preds = %80
%88 = getelementptr inbounds [13 x i8], [13 x i8]* %9, i64 0, i64 0
store i8* %88, i8** %8
br label %89
89: ; preds = %87, %83
%90 = load i32, i32* %4
%91 = icmp sgt i32 %90, 4
br i1 %91, label %92, label %97
92: ; preds = %89
%93 = load i8**, i8*** %5
%94 = getelementptr inbounds i8*, i8** %93, i64 4
%95 = load i8*, i8** %94
%96 = call i32 @atoi(i8* %95)
store i32 %96, i32* %10
br label %98
97: ; preds = %89
store i32 40, i32* %10
br label %98
98: ; preds = %97, %92
%99 = load i8*, i8** %8
%100 = load i32, i32* @O_RDWR
%101 = load i32, i32* @O_NOCTTY
%102 = or i32 %100, %101
%103 = load i32, i32* @O_NDELAY
%104 = or i32 %102, %103
%105 = call i32 @open(i8* %99, i32 %104)
store i32 %105, i32* %11
%106 = load i32, i32* %11
%107 = icmp eq i32 %106, -1
br i1 %107, label %108, label %110
108: ; preds = %98
%109 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0))
br label %114
110: ; preds = %98
%111 = load i32, i32* %11
%112 = load i32, i32* @F_SETFL
%113 = call i32 @fcntl(i32 %111, i32 %112, i32 0)
br label %114
114: ; preds = %110, %108
%115 = load i32, i32* %11
%116 = call i32 @tcgetattr(i32 %115, %struct.termios* %16)
%117 = load i32, i32* @B2400
%118 = call i32 @cfsetispeed(%struct.termios* %16, i32 %117)
%119 = load i32, i32* @B2400
%120 = call i32 @cfsetospeed(%struct.termios* %16, i32 %119)
%121 = load i32, i32* @CLOCAL
%122 = load i32, i32* @CREAD
%123 = or i32 %121, %122
%124 = getelementptr inbounds %struct.termios, %struct.termios* %16, i32 0, i32 0
%125 = load i32, i32* %124
%126 = or i32 %125, %123
store i32 %126, i32* %124
%127 = load i32, i32* @CSIZE
%128 = xor i32 %127, -1
%129 = getelementptr inbounds %struct.termios, %struct.termios* %16, i32 0, i32 0
%130 = load i32, i32* %129
%131 = and i32 %130, %128
store i32 %131, i32* %129
%132 = load i32, i32* @CS8
%133 = getelementptr inbounds %struct.termios, %struct.termios* %16, i32 0, i32 0
%134 = load i32, i32* %133
%135 = or i32 %134, %132
store i32 %135, i32* %133
%136 = load i32, i32* @PARENB
%137 = xor i32 %136, -1
%138 = getelementptr inbounds %struct.termios, %struct.termios* %16, i32 0, i32 0
%139 = load i32, i32* %138
%140 = and i32 %139, %137
store i32 %140, i32* %138
%141 = load i32, i32* @CSTOPB
%142 = xor i32 %141, -1
%143 = getelementptr inbounds %struct.termios, %struct.termios* %16, i32 0, i32 0
%144 = load i32, i32* %143
%145 = and i32 %144, %142
store i32 %145, i32* %143
%146 = load i32, i32* @CSIZE
%147 = xor i32 %146, -1
%148 = getelementptr inbounds %struct.termios, %struct.termios* %16, i32 0, i32 0
%149 = load i32, i32* %148
%150 = and i32 %149, %147
store i32 %150, i32* %148
%151 = load i32, i32* @CS8
%152 = getelementptr inbounds %struct.termios, %struct.termios* %16, i32 0, i32 0
%153 = load i32, i32* %152
%154 = or i32 %153, %151
store i32 %154, i32* %152
%155 = load i32, i32* @ICANON
%156 = load i32, i32* @ECHO
%157 = or i32 %155, %156
%158 = load i32, i32* @ECHOE
%159 = or i32 %157, %158
%160 = load i32, i32* @ISIG
%161 = or i32 %159, %160
%162 = xor i32 %161, -1
%163 = getelementptr inbounds %struct.termios, %struct.termios* %16, i32 0, i32 1
%164 = load i32, i32* %163
%165 = and i32 %164, %162
store i32 %165, i32* %163
%166 = load i32, i32* %11
%167 = load i32, i32* @TCSANOW
%168 = call i32 @tcsetattr(i32 %166, i32 %167, %struct.termios* %16)
%169 = load i32, i32* %6
%170 = add nsw i32 80, %169
%171 = trunc i32 %170 to i8
%172 = getelementptr inbounds [4 x i8], [4 x i8]* %18, i64 0, i64 0
store i8 %171, i8* %172
%173 = load i32, i32* %7
%174 = trunc i32 %173 to i8
%175 = getelementptr inbounds [4 x i8], [4 x i8]* %18, i64 0, i64 1
store i8 %174, i8* %175
%176 = getelementptr inbounds [4 x i8], [4 x i8]* %18, i64 0, i64 0
%177 = load i8, i8* %176
%178 = sext i8 %177 to i32
%179 = getelementptr inbounds [4 x i8], [4 x i8]* %18, i64 0, i64 1
%180 = load i8, i8* %179
%181 = sext i8 %180 to i32
%182 = add nsw i32 %178, %181
%183 = trunc i32 %182 to i8
%184 = getelementptr inbounds [4 x i8], [4 x i8]* %18, i64 0, i64 2
store i8 %183, i8* %184
%185 = getelementptr inbounds [4 x i8], [4 x i8]* %18, i64 0, i64 0
%186 = load i8, i8* %185
%187 = sext i8 %186 to i32
%188 = getelementptr inbounds [4 x i8], [4 x i8]* %18, i64 0, i64 1
%189 = load i8, i8* %188
%190 = sext i8 %189 to i32
%191 = add nsw i32 %187, %190
%192 = xor i32 %191, -1
%193 = add nsw i32 %192, 1
%194 = trunc i32 %193 to i8
%195 = getelementptr inbounds [4 x i8], [4 x i8]* %18, i64 0, i64 2
store i8 %194, i8* %195
%196 = load i32, i32* %11
%197 = getelementptr inbounds [4 x i8], [4 x i8]* %18, i64 0, i64 0
%198 = call i32 @write(i32 %196, i8* %197, i32 3)
store i32 %198, i32* %17
%199 = load i32, i32* %17
%200 = icmp slt i32 %199, 0
br i1 %200, label %201, label %204
201: ; preds = %114
%202 = load i32, i32* @stderr
%203 = call i32 @fputs(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0), i32 %202)
br label %204
204: ; preds = %201, %114
%205 = getelementptr inbounds [4 x i8], [4 x i8]* %18, i64 0, i64 0
%206 = load i8, i8* %205
%207 = sext i8 %206 to i32
%208 = getelementptr inbounds [4 x i8], [4 x i8]* %18, i64 0, i64 1
%209 = load i8, i8* %208
%210 = sext i8 %209 to i32
%211 = getelementptr inbounds [4 x i8], [4 x i8]* %18, i64 0, i64 2
%212 = load i8, i8* %211
%213 = sext i8 %212 to i32
%214 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0), i32 %207, i32 %210, i32 %213)
%215 = load i32, i32* %10
%216 = mul nsw i32 %215, 1000
%217 = call i32 @usleep(i32 %216)
%218 = load i32, i32* %11
%219 = load i32, i32* @F_SETFL
%220 = load i32, i32* @FNDELAY
%221 = call i32 @fcntl(i32 %218, i32 %219, i32 %220)
%222 = load i32, i32* %11
%223 = bitcast [12 x i8]* %15 to i8**
%224 = call i32 @read(i32 %222, i8** %223, i32 12)
store i32 %224, i32* %13
store i32 3, i32* %12
br label %225
225: ; preds = %237, %204
%226 = load i32, i32* %12
%227 = load i32, i32* %13
%228 = icmp slt i32 %226, %227
br i1 %228, label %229, label %240
229: ; preds = %225
%230 = load i32, i32* %12
%231 = sext i32 %230 to i64
%232 = getelementptr inbounds [12 x i8], [12 x i8]* %15, i64 0, i64 %231
%233 = load i8, i8* %232
store i8 %233, i8* %14
%234 = load i8, i8* %14
%235 = sext i8 %234 to i32
%236 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), i32 %235)
br label %237
237: ; preds = %229
%238 = load i32, i32* %12
%239 = add nsw i32 %238, 1
store i32 %239, i32* %12
br label %225
240: ; preds = %225
%241 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0))
%242 = load i32, i32* %11
%243 = call i32 @close(i32 %242)
%244 = load i32, i32* %13
%245 = sub nsw i32 %244, 1
%246 = sext i32 %245 to i64
%247 = getelementptr inbounds [12 x i8], [12 x i8]* %15, i64 0, i64 %246
%248 = load i8, i8* %247
%249 = zext i8 %248 to i32
%250 = icmp eq i32 %249, 255
br i1 %250, label %251, label %252
251: ; preds = %240
store i32 0, i32* %3
br label %253
252: ; preds = %240
store i32 -1, i32* %3
br label %253
253: ; preds = %252, %251
%254 = load i32, i32* %3
ret i32 %254
}

LLVM IR (-O2):
%struct.termios = type { i32, i32 }
@__const.main.serialPort2 = [13 x i8] c"/dev/ttyUSB1\00"
@.str.1 = [5 x i8] c"stop\00"
@.str.2 = [3 x i8] c"up\00"
@.str.3 = [5 x i8] c"hoch\00"
@.str.4 = [5 x i8] c"down\00"
@.str.5 = [7 x i8] c"runter\00"
@.str.6 = [5 x i8] c"pos1\00"
@.str.7 = [5 x i8] c"pos2\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@.str.8 = [38 x i8] c"open_port: Unable to open serialPort \00"
@F_SETFL = global i32 0
@B2400 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@TCSANOW = global i32 0
@.str.9 = [32 x i8] c"write() of smi command failed!\0A\00"
@stderr = global i32 0
@.str.10 = [17 x i8] c"%02X %02X %02X: \00"
@FNDELAY = global i32 0
@.str.11 = [6 x i8] c"%02X \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [13 x i8]
%4 = alloca [12 x i8]
%5 = alloca %struct.termios
%6 = alloca [4 x i8]
%7 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [12 x i8], [12 x i8]* %4, i64 0, i64 0
%9 = icmp sgt i32 %0, 1
br i1 %9, label %10, label %55
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
%14 = trunc i32 %13 to i8
%15 = add i8 %14, 80
%16 = icmp eq i32 %0, 2
br i1 %16, label %55, label %17
17: ; preds = %10
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = tail call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%21 = load i8*, i8** %18
%22 = tail call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
%24 = load i8*, i8** %18
%25 = tail call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
%27 = select i1 %26, i1 true, i1 %23
%28 = zext i1 %27 to i8
%29 = load i8*, i8** %18
%30 = tail call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
%32 = load i8*, i8** %18
%33 = tail call i64 @strcmp(i8* %32, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
%35 = select i1 %34, i1 true, i1 %31
%36 = select i1 %35, i8 2, i8 %28
%37 = load i8*, i8** %18
%38 = tail call i64 @strcmp(i8* %37, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
%40 = select i1 %39, i8 3, i8 %36
%41 = load i8*, i8** %18
%42 = tail call i64 @strcmp(i8* %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%43 = icmp eq i64 %42, 0
%44 = select i1 %43, i8 4, i8 %40
%45 = icmp ugt i32 %0, 3
br i1 %45, label %46, label %55
46: ; preds = %17
%47 = getelementptr inbounds i8*, i8** %1, i64 3
%48 = load i8*, i8** %47
%49 = icmp eq i32 %0, 4
br i1 %49, label %55, label %50
50: ; preds = %46
%51 = getelementptr inbounds i8*, i8** %1, i64 4
%52 = load i8*, i8** %51
%53 = tail call i32 @atoi(i8* %52)
%54 = mul i32 %53, 1000
br label %55
55: ; preds = %2, %10, %17, %46, %50
%56 = phi i8* [ %48, %50 ], [ %48, %46 ], [ %7, %17 ], [ %7, %10 ], [ %7, %2 ]
%57 = phi i8 [ %15, %50 ], [ %15, %46 ], [ %15, %17 ], [ %15, %10 ], [ 92, %2 ]
%58 = phi i8 [ %44, %50 ], [ %44, %46 ], [ %44, %17 ], [ 0, %10 ], [ 0, %2 ]
%59 = phi i32 [ %54, %50 ], [ 40000, %46 ], [ 40000, %17 ], [ 40000, %10 ], [ 40000, %2 ]
%60 = load i32, i32* @O_RDWR
%61 = load i32, i32* @O_NOCTTY
%62 = or i32 %61, %60
%63 = load i32, i32* @O_NDELAY
%64 = or i32 %62, %63
%65 = call i32 @open(i8* %56, i32 %64)
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %69
67: ; preds = %55
%68 = tail call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0))
br label %72
69: ; preds = %55
%70 = load i32, i32* @F_SETFL
%71 = tail call i32 @fcntl(i32 %65, i32 %70, i32 0)
br label %72
72: ; preds = %69, %67
%73 = bitcast %struct.termios* %5 to i8*
%74 = call i32 @tcgetattr(i32 %65, %struct.termios* %5)
%75 = load i32, i32* @B2400
%76 = call i32 @cfsetispeed(%struct.termios* %5, i32 %75)
%77 = load i32, i32* @B2400
%78 = call i32 @cfsetospeed(%struct.termios* %5, i32 %77)
%79 = load i32, i32* @CLOCAL
%80 = load i32, i32* @CREAD
%81 = or i32 %80, %79
%82 = getelementptr inbounds %struct.termios, %struct.termios* %5, i64 0, i32 0
%83 = load i32, i32* %82
%84 = or i32 %81, %83
%85 = load i32, i32* @CSIZE
%86 = load i32, i32* @CS8
%87 = load i32, i32* @PARENB
%88 = load i32, i32* @CSTOPB
%89 = or i32 %88, %85
%90 = or i32 %87, %89
%91 = xor i32 %90, -1
%92 = and i32 %84, %91
%93 = or i32 %86, %92
store i32 %93, i32* %82
%94 = load i32, i32* @ICANON
%95 = load i32, i32* @ECHO
%96 = or i32 %95, %94
%97 = load i32, i32* @ECHOE
%98 = or i32 %96, %97
%99 = load i32, i32* @ISIG
%100 = or i32 %98, %99
%101 = xor i32 %100, -1
%102 = getelementptr inbounds %struct.termios, %struct.termios* %5, i64 0, i32 1
%103 = load i32, i32* %102
%104 = and i32 %103, %101
store i32 %104, i32* %102
%105 = load i32, i32* @TCSANOW
%106 = call i32 @tcsetattr(i32 %65, i32 %105, %struct.termios* %5)
%107 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
store i8 %57, i8* %107
%108 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 1
store i8 %58, i8* %108
%109 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 2
%110 = add i8 %57, %58
%111 = sub i8 0, %110
store i8 %111, i8* %109
%112 = call i32 @write(i32 %65, i8* %107, i32 3)
%113 = icmp slt i32 %112, 0
br i1 %113, label %114, label %117
114: ; preds = %72
%115 = load i32, i32* @stderr
%116 = call i32 @fputs(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0), i32 %115)
br label %117
117: ; preds = %114, %72
%118 = sext i8 %57 to i32
%119 = zext i8 %58 to i32
%120 = sext i8 %111 to i32
%121 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0), i32 %118, i32 %119, i32 %120)
%122 = call i32 @usleep(i32 %59)
%123 = load i32, i32* @F_SETFL
%124 = load i32, i32* @FNDELAY
%125 = call i32 @fcntl(i32 %65, i32 %123, i32 %124)
%126 = bitcast [12 x i8]* %4 to i8**
%127 = call i32 @read(i32 %65, i8** %126, i32 12)
%128 = icmp sgt i32 %127, 3
br i1 %128, label %129, label %139
129: ; preds = %117
%130 = zext i32 %127 to i64
br label %131
131: ; preds = %129, %131
%132 = phi i64 [ 3, %129 ], [ %137, %131 ]
%133 = getelementptr inbounds [12 x i8], [12 x i8]* %4, i64 0, i64 %132
%134 = load i8, i8* %133
%135 = sext i8 %134 to i32
%136 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), i32 %135)
%137 = add nuw nsw i64 %132, 1
%138 = icmp eq i64 %137, %130
br i1 %138, label %139, label %131
139: ; preds = %131, %117
%140 = call i32 @putchar(i32 10)
%141 = call i32 @close(i32 %65)
%142 = add nsw i32 %127, -1
%143 = sext i32 %142 to i64
%144 = getelementptr inbounds [12 x i8], [12 x i8]* %4, i64 0, i64 %143
%145 = load i8, i8* %144
%146 = icmp ne i8 %145, -1
%147 = sext i1 %146 to i32
ret i32 %147
}