#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 scalar_t__ time_t;
typedef scalar_t__ tcflag_t;
struct termios {
  int *c_cc;
  int c_cflag;
  scalar_t__ c_lflag;
  scalar_t__ c_oflag;
  scalar_t__ c_iflag;
};

/* Variables and functions */
int CLOCAL;
int CREAD;
int CRTSCTS;
scalar_t__ EAGAIN;
scalar_t__ EINTR;
int O_NOCTTY;
int O_NONBLOCK;
int O_RDWR;
int PARENB;
int PARODD;
int /*<<< orphan*/ TCIOFLUSH;
int TCSAFLUSH;
int TCSANOW;
int USHRT_MAX;
size_t VMIN;
size_t VTIME;
int atoi(char *);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ cfmakeraw(struct termios *);
int /*<<< orphan*/ cfsetispeed(struct termios *, int);
int /*<<< orphan*/ cfsetospeed(struct termios *, int);
int /*<<< orphan*/ err(int, char *);
scalar_t__ errno;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *gpsd_hexdump(char *, int);
int /*<<< orphan*/ moto_send(int, char *, char *);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int strlen(char *);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int tcsetattr(int, int, struct termios *);
scalar_t__ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ usleep(int);
int main(int argc, char **argv) {
  int speed, l, fd, n;
  struct termios term;
  char buf[64];
  time_t s, t;
  if (argc != 5) {
    fprintf(stderr, "usage: motosend <speed> <port> msgtype moto-body-hex\n");
    return 1;
  }
  if ((l = strlen(argv[4])) > 2 * USHRT_MAX) {
    fprintf(stderr, "oversized message\n");
    return 1;
  }
  if (l % 2) {
    fprintf(stderr, "body must have an even number of hex digits\n");
    return 1;
  }
  speed = atoi(argv[1]);
  switch (speed) {
  case 230400:
  case 115200:
  case 57600:
  case 38400:
  case 28800:
  case 14400:
  case 9600:
  case 4800:
    break;
  default:
    fprintf(stderr, "invalid speed\n");
    return 1;
  }
  if ((fd = open(argv[2], O_RDWR | O_NONBLOCK | O_NOCTTY, 0644)) == -1)
    err(1, "open");
  tcgetattr(fd, &term);
  cfmakeraw(&term);
  cfsetospeed(&term, speed);
  cfsetispeed(&term, speed);
  term.c_cc[VMIN] = 8;
  term.c_cc[VTIME] = 1;
  term.c_cflag &= ~(PARENB | PARODD | CRTSCTS);
  term.c_cflag |= CREAD | CLOCAL;
  term.c_iflag = term.c_oflag = term.c_lflag = (tcflag_t)0;
  if (tcsetattr(fd, TCSANOW | TCSAFLUSH, &term) == -1)
    err(1, "tcsetattr");
  tcflush(fd, TCIOFLUSH);
  t = 0;
  n = 0;
  while (1) {
    usleep(1000);
    bzero(buf, 64);
    if ((l = read(fd, buf, 64)) == -1)
      if (!(EINTR == errno || EAGAIN == errno))
        err(1, "read");
    if (l > 0) {
      printf("%s", gpsd_hexdump(buf, l));
      fflush(stdout);
    }
    if (((s = time(NULL)) > t) && (n < 1)) {
      t = s;
      n++;
      moto_send(fd, argv[3], argv[4]);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x5,-0x8(%rbp)
je     1274 <main+0x44>
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
lea    0xd9d(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    163d <main+0x40d>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    0x2d45(%rip),%rcx
mov    (%rcx),%ecx
shl    $0x1,%ecx
cmp    %ecx,%eax
jle    12b9 <main+0x89>
mov    0x2cf1(%rip),%rax
mov    (%rax),%edi
lea    0xd8e(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    163d <main+0x40d>
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     12ee <main+0xbe>
mov    0x2cbc(%rip),%rax
mov    (%rax),%edi
lea    0xd6c(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    163d <main+0x40d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1130 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0xa4(%rbp)
sub    $0x12c0,%eax
je     13b1 <main+0x181>
jmp    1317 <main+0xe7>
mov    -0xa4(%rbp),%eax
sub    $0x2580,%eax
je     13b1 <main+0x181>
jmp    132d <main+0xfd>
mov    -0xa4(%rbp),%eax
sub    $0x3840,%eax
je     13b1 <main+0x181>
jmp    1343 <main+0x113>
mov    -0xa4(%rbp),%eax
sub    $0x7080,%eax
je     13b1 <main+0x181>
jmp    1359 <main+0x129>
mov    -0xa4(%rbp),%eax
sub    $0x9600,%eax
je     13b1 <main+0x181>
jmp    136f <main+0x13f>
mov    -0xa4(%rbp),%eax
sub    $0xe100,%eax
je     13b1 <main+0x181>
jmp    1385 <main+0x155>
mov    -0xa4(%rbp),%eax
sub    $0x1c200,%eax
je     13b1 <main+0x181>
jmp    139b <main+0x16b>
mov    -0xa4(%rbp),%eax
sub    $0x38400,%eax
jne    13b6 <main+0x186>
jmp    13b1 <main+0x181>
jmp    13d7 <main+0x1a7>
mov    0x2bd3(%rip),%rax
mov    (%rax),%edi
lea    0xcb0(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    163d <main+0x40d>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2c02(%rip),%rax
mov    (%rax),%esi
mov    0x2be9(%rip),%rax
or     (%rax),%esi
mov    0x2ba0(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   1100 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    1421 <main+0x1f1>
mov    $0x1,%edi
lea    0xc69(%rip),%rsi
call   10b0 <err@plt>
mov    -0x1c(%rbp),%edi
lea    -0x48(%rbp),%rsi
call   10e0 <tcgetattr@plt>
lea    -0x48(%rbp),%rdi
call   10d0 <cfmakeraw@plt>
mov    -0x14(%rbp),%esi
lea    -0x48(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    -0x14(%rbp),%esi
lea    -0x48(%rbp),%rdi
call   1110 <cfsetispeed@plt>
mov    -0x48(%rbp),%rax
mov    0x2b4f(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x8,(%rax,%rcx,4)
mov    -0x48(%rbp),%rax
mov    0x2afa(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2b49(%rip),%rax
mov    (%rax),%eax
mov    0x2b30(%rip),%rcx
or     (%rcx),%eax
mov    0x2ac7(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x40(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    0x2b0d(%rip),%rax
mov    (%rax),%eax
mov    0x2a9c(%rip),%rcx
or     (%rcx),%eax
or     -0x40(%rbp),%eax
mov    %eax,-0x40(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2aea(%rip),%rax
mov    (%rax),%esi
mov    0x2b01(%rip),%rax
or     (%rax),%esi
lea    -0x48(%rbp),%rdx
call   10f0 <tcsetattr@plt>
cmp    $0xffffffff,%eax
jne    1504 <main+0x2d4>
mov    $0x1,%edi
lea    0xb8b(%rip),%rsi
call   10b0 <err@plt>
mov    -0x1c(%rbp),%edi
mov    0x2a72(%rip),%rax
mov    (%rax),%esi
call   1050 <tcflush@plt>
movq   $0x0,-0xa0(%rbp)
movl   $0x0,-0x20(%rbp)
mov    $0x3e8,%edi
call   1150 <usleep@plt>
lea    -0x90(%rbp),%rdi
mov    $0x40,%esi
call   1120 <bzero@plt>
mov    -0x1c(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x40,%edx
call   1070 <read@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    15ac <main+0x37c>
mov    0x2a0f(%rip),%rax
mov    (%rax),%rax
mov    0x2a15(%rip),%rcx
cmp    (%rcx),%rax
je     15a7 <main+0x377>
mov    0x29cd(%rip),%rax
mov    (%rax),%rax
mov    0x29fb(%rip),%rcx
cmp    (%rcx),%rax
je     15a7 <main+0x377>
mov    $0x1,%edi
lea    0xaf2(%rip),%rsi
call   10b0 <err@plt>
jmp    15ac <main+0x37c>
cmpl   $0x0,-0x18(%rbp)
jle    15e2 <main+0x3b2>
lea    -0x90(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1140 <gpsd_hexdump@plt>
mov    %rax,%rsi
lea    0xaca(%rip),%rdi
call   1060 <printf@plt>
mov    0x2995(%rip),%rax
mov    (%rax),%edi
call   10c0 <fflush@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <time@plt>
mov    %rax,-0x98(%rbp)
cmp    -0xa0(%rbp),%rax
jle    1638 <main+0x408>
cmpl   $0x1,-0x20(%rbp)
jge    1638 <main+0x408>
mov    -0x98(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdx
call   10a0 <moto_send@plt>
jmp    1527 <main+0x2f7>
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
cmp    $0x5,%edi
jne    1267 <main+0x37>
mov    %rsi,%rbp
mov    0x20(%rsi),%rdi
call   1040 <strlen@plt>
mov    0x2d7a(%rip),%rcx
mov    (%rcx),%ecx
add    %ecx,%ecx
cmp    %ecx,%eax
jle    1290 <main+0x60>
lea    0xdd1(%rip),%rsi
jmp    126e <main+0x3e>
lea    0xd92(%rip),%rsi
mov    0x2d1b(%rip),%rax
mov    (%rax),%edi
call   1080 <fprintf@plt>
mov    $0x1,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
test   $0x1,%al
jne    12c7 <main+0x97>
mov    0x8(%rbp),%rdi
call   1130 <atoi@plt>
mov    %eax,%ebx
lea    0xdd0(%rip),%rsi
cmp    $0x95ff,%eax
jg     12d0 <main+0xa0>
cmp    $0x383f,%ebx
jg     12ea <main+0xba>
cmp    $0x12c0,%ebx
je     1313 <main+0xe3>
cmp    $0x2580,%ebx
je     1313 <main+0xe3>
jmp    126e <main+0x3e>
lea    0xd7b(%rip),%rsi
jmp    126e <main+0x3e>
cmp    $0x1c1ff,%ebx
jg     12ff <main+0xcf>
cmp    $0x9600,%ebx
je     1313 <main+0xe3>
cmp    $0xe100,%ebx
je     1313 <main+0xe3>
jmp    126e <main+0x3e>
cmp    $0x3840,%ebx
je     1313 <main+0xe3>
cmp    $0x7080,%ebx
je     1313 <main+0xe3>
jmp    126e <main+0x3e>
cmp    $0x38400,%ebx
je     1313 <main+0xe3>
cmp    $0x1c200,%ebx
jne    126e <main+0x3e>
mov    0x2cce(%rip),%rax
mov    0x2cb7(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x10(%rbp),%rdi
mov    0x2c68(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   1100 <open@plt>
mov    %eax,%r13d
cmp    $0xffffffff,%eax
jne    1355 <main+0x125>
lea    0xd3a(%rip),%rsi
mov    $0x1,%edi
call   10b0 <err@plt>
mov    %rbp,(%rsp)
lea    0x8(%rsp),%r15
mov    %r13d,%edi
mov    %r15,%rsi
call   10e0 <tcgetattr@plt>
mov    %r15,%rdi
call   10d0 <cfmakeraw@plt>
mov    %r15,%rdi
mov    %ebx,%esi
call   1030 <cfsetospeed@plt>
mov    %r15,%rdi
mov    %ebx,%esi
call   1110 <cfsetispeed@plt>
mov    0x8(%rsp),%rax
mov    0x2c17(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x8,(%rax,%rcx,4)
mov    0x2bc6(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2c15(%rip),%rax
mov    0x2bfe(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2b93(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    0x10(%rsp),%ecx
mov    0x2bdc(%rip),%rax
or     (%rax),%ecx
mov    0x2b6b(%rip),%rax
or     (%rax),%ecx
mov    %ecx,0x10(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x18(%rsp)
movq   $0x0,0x28(%rsp)
mov    0x2bc5(%rip),%rax
mov    0x2bde(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %r13d,%edi
mov    %r15,%rdx
call   10f0 <tcsetattr@plt>
cmp    $0xffffffff,%eax
jne    1427 <main+0x1f7>
lea    0xc6d(%rip),%rsi
mov    $0x1,%edi
call   10b0 <err@plt>
mov    0x2b52(%rip),%rax
mov    (%rax),%esi
mov    %r13d,%edi
call   1050 <tcflush@plt>
mov    $0x1,%r14b
xor    %r15d,%r15d
lea    0x30(%rsp),%rbx
lea    0xc4f(%rip),%r12
jmp    1470 <main+0x240>
nopl   0x0(%rax)
xor    %edi,%edi
call   1090 <time@plt>
mov    %rax,%rbp
cmp    %r15,%rax
setle  %al
mov    %r14d,%ecx
not    %cl
or     %al,%cl
test   $0x1,%cl
je     1510 <main+0x2e0>
mov    $0x3e8,%edi
call   1150 <usleep@plt>
mov    %rbx,%rdi
mov    $0x40,%esi
call   1120 <bzero@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x40,%edx
call   1070 <read@plt>
cmp    $0xffffffff,%eax
je     14d0 <main+0x2a0>
test   %eax,%eax
jle    1450 <main+0x220>
mov    %rbx,%rdi
mov    %eax,%esi
call   1140 <gpsd_hexdump@plt>
mov    %r12,%rdi
mov    %rax,%rsi
call   1060 <printf@plt>
mov    0x2ab4(%rip),%rax
mov    (%rax),%edi
call   10c0 <fflush@plt>
jmp    1450 <main+0x220>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x2ab1(%rip),%rax
mov    (%rax),%rax
mov    0x2a97(%rip),%rcx
cmp    %rax,(%rcx)
je     1450 <main+0x220>
mov    0x2a5f(%rip),%rcx
cmp    %rax,(%rcx)
je     1450 <main+0x220>
mov    $0x1,%edi
lea    0xb8e(%rip),%rsi
call   10b0 <err@plt>
jmp    1450 <main+0x220>
mov    (%rsp),%rax
mov    0x18(%rax),%rsi
mov    0x20(%rax),%rdx
mov    %r13d,%edi
call   10a0 <moto_send@plt>
xor    %r14d,%r14d
mov    %rbp,%r15
jmp    1470 <main+0x240>

LLVM IR (-O0):
%struct.termios = type { i32*, i32, i64, i64, i64 }
@stderr = global i32 0
@.str = [54 x i8] c"usage: motosend <speed> <port> msgtype moto-body-hex\0A\00"
@USHRT_MAX = global i32 0
@.str.1 = [19 x i8] c"oversized message\0A\00"
@.str.2 = [45 x i8] c"body must have an even number of hex digits\0A\00"
@.str.3 = [15 x i8] c"invalid speed\0A\00"
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@O_NOCTTY = global i32 0
@.str.4 = [5 x i8] c"open\00"
@VMIN = global i64 0
@VTIME = global i64 0
@PARENB = global i32 0
@PARODD = global i32 0
@CRTSCTS = global i32 0
@CREAD = global i32 0
@CLOCAL = global i32 0
@TCSANOW = global i32 0
@TCSAFLUSH = global i32 0
@.str.5 = [10 x i8] c"tcsetattr\00"
@TCIOFLUSH = global i32 0
@EINTR = global i64 0
@errno = global i64 0
@EAGAIN = global i64 0
@.str.6 = [5 x i8] c"read\00"
@.str.7 = [3 x i8] c"%s\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.termios
%11 = alloca [64 x i8]
%12 = alloca i64
%13 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 5
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %155
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 4
%22 = load i8*, i8** %21
%23 = call i32 @strlen(i8* %22)
store i32 %23, i32* %7
%24 = load i32, i32* @USHRT_MAX
%25 = mul nsw i32 2, %24
%26 = icmp sgt i32 %23, %25
br i1 %26, label %27, label %30
27: ; preds = %19
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %155
30: ; preds = %19
%31 = load i32, i32* %7
%32 = srem i32 %31, 2
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %155
37: ; preds = %30
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32 @atoi(i8* %40)
store i32 %41, i32* %6
%42 = load i32, i32* %6
switch i32 %42, label %44 [
i32 230400, label %43
i32 115200, label %43
i32 57600, label %43
i32 38400, label %43
i32 28800, label %43
i32 14400, label %43
i32 9600, label %43
i32 4800, label %43
]
43: ; preds = %37, %37, %37, %37, %37, %37, %37, %37
br label %47
44: ; preds = %37
%45 = load i32, i32* @stderr
%46 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %155
47: ; preds = %43
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 2
%50 = load i8*, i8** %49
%51 = load i32, i32* @O_RDWR
%52 = load i32, i32* @O_NONBLOCK
%53 = or i32 %51, %52
%54 = load i32, i32* @O_NOCTTY
%55 = or i32 %53, %54
%56 = call i32 @open(i8* %50, i32 %55, i32 420)
store i32 %56, i32* %8
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %60
58: ; preds = %47
%59 = call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %60
60: ; preds = %58, %47
%61 = load i32, i32* %8
%62 = call i32 @tcgetattr(i32 %61, %struct.termios* %10)
%63 = call i32 @cfmakeraw(%struct.termios* %10)
%64 = load i32, i32* %6
%65 = call i32 @cfsetospeed(%struct.termios* %10, i32 %64)
%66 = load i32, i32* %6
%67 = call i32 @cfsetispeed(%struct.termios* %10, i32 %66)
%68 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 0
%69 = load i32*, i32** %68
%70 = load i64, i64* @VMIN
%71 = getelementptr inbounds i32, i32* %69, i64 %70
store i32 8, i32* %71
%72 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 0
%73 = load i32*, i32** %72
%74 = load i64, i64* @VTIME
%75 = getelementptr inbounds i32, i32* %73, i64 %74
store i32 1, i32* %75
%76 = load i32, i32* @PARENB
%77 = load i32, i32* @PARODD
%78 = or i32 %76, %77
%79 = load i32, i32* @CRTSCTS
%80 = or i32 %78, %79
%81 = xor i32 %80, -1
%82 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 1
%83 = load i32, i32* %82
%84 = and i32 %83, %81
store i32 %84, i32* %82
%85 = load i32, i32* @CREAD
%86 = load i32, i32* @CLOCAL
%87 = or i32 %85, %86
%88 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 1
%89 = load i32, i32* %88
%90 = or i32 %89, %87
store i32 %90, i32* %88
%91 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 2
store i64 0, i64* %91
%92 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 3
store i64 0, i64* %92
%93 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 4
store i64 0, i64* %93
%94 = load i32, i32* %8
%95 = load i32, i32* @TCSANOW
%96 = load i32, i32* @TCSAFLUSH
%97 = or i32 %95, %96
%98 = call i32 @tcsetattr(i32 %94, i32 %97, %struct.termios* %10)
%99 = icmp eq i32 %98, -1
br i1 %99, label %100, label %102
100: ; preds = %60
%101 = call i32 @err(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
br label %102
102: ; preds = %100, %60
%103 = load i32, i32* %8
%104 = load i32, i32* @TCIOFLUSH
%105 = call i32 @tcflush(i32 %103, i32 %104)
store i64 0, i64* %13
store i32 0, i32* %9
br label %106
106: ; preds = %102, %154
%107 = call i32 @usleep(i32 1000)
%108 = getelementptr inbounds [64 x i8], [64 x i8]* %11, i64 0, i64 0
%109 = call i32 @bzero(i8* %108, i32 64)
%110 = load i32, i32* %8
%111 = getelementptr inbounds [64 x i8], [64 x i8]* %11, i64 0, i64 0
%112 = call i32 @read(i32 %110, i8* %111, i32 64)
store i32 %112, i32* %7
%113 = icmp eq i32 %112, -1
br i1 %113, label %114, label %125
114: ; preds = %106
%115 = load i64, i64* @EINTR
%116 = load i64, i64* @errno
%117 = icmp eq i64 %115, %116
br i1 %117, label %124, label %118
118: ; preds = %114
%119 = load i64, i64* @EAGAIN
%120 = load i64, i64* @errno
%121 = icmp eq i64 %119, %120
br i1 %121, label %124, label %122
122: ; preds = %118
%123 = call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %124
124: ; preds = %122, %118, %114
br label %125
125: ; preds = %124, %106
%126 = load i32, i32* %7
%127 = icmp sgt i32 %126, 0
br i1 %127, label %128, label %135
128: ; preds = %125
%129 = getelementptr inbounds [64 x i8], [64 x i8]* %11, i64 0, i64 0
%130 = load i32, i32* %7
%131 = call i8* @gpsd_hexdump(i8* %129, i32 %130)
%132 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %131)
%133 = load i32, i32* @stdout
%134 = call i32 @fflush(i32 %133)
br label %135
135: ; preds = %128, %125
%136 = call i64 @time(i32* null)
store i64 %136, i64* %12
%137 = load i64, i64* %13
%138 = icmp sgt i64 %136, %137
br i1 %138, label %139, label %154
139: ; preds = %135
%140 = load i32, i32* %9
%141 = icmp slt i32 %140, 1
br i1 %141, label %142, label %154
142: ; preds = %139
%143 = load i64, i64* %12
store i64 %143, i64* %13
%144 = load i32, i32* %9
%145 = add nsw i32 %144, 1
store i32 %145, i32* %9
%146 = load i32, i32* %8
%147 = load i8**, i8*** %5
%148 = getelementptr inbounds i8*, i8** %147, i64 3
%149 = load i8*, i8** %148
%150 = load i8**, i8*** %5
%151 = getelementptr inbounds i8*, i8** %150, i64 4
%152 = load i8*, i8** %151
%153 = call i32 @moto_send(i32 %146, i8* %149, i8* %152)
br label %154
154: ; preds = %142, %139, %135
br label %106
155: ; preds = %44, %34, %27, %16
%156 = load i32, i32* %3
ret i32 %156
}

LLVM IR (-O2):
%struct.termios = type { i32*, i32, i64, i64, i64 }
@stderr = global i32 0
@.str = [54 x i8] c"usage: motosend <speed> <port> msgtype moto-body-hex\0A\00"
@USHRT_MAX = global i32 0
@.str.1 = [19 x i8] c"oversized message\0A\00"
@.str.2 = [45 x i8] c"body must have an even number of hex digits\0A\00"
@.str.3 = [15 x i8] c"invalid speed\0A\00"
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@O_NOCTTY = global i32 0
@.str.4 = [5 x i8] c"open\00"
@VMIN = global i64 0
@VTIME = global i64 0
@PARENB = global i32 0
@PARODD = global i32 0
@CRTSCTS = global i32 0
@CREAD = global i32 0
@CLOCAL = global i32 0
@TCSANOW = global i32 0
@TCSAFLUSH = global i32 0
@.str.5 = [10 x i8] c"tcsetattr\00"
@TCIOFLUSH = global i32 0
@EINTR = global i64 0
@errno = global i64 0
@EAGAIN = global i64 0
@.str.6 = [5 x i8] c"read\00"
@.str.7 = [3 x i8] c"%s\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.termios
%4 = alloca [64 x i8]
%5 = bitcast %struct.termios* %3 to i8*
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 5
br i1 %7, label %8, label %103
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 4
%10 = load i8*, i8** %9
%11 = tail call i32 @strlen(i8* %10)
%12 = load i32, i32* @USHRT_MAX
%13 = shl nsw i32 %12, 1
%14 = icmp sgt i32 %11, %13
br i1 %14, label %103, label %15
15: ; preds = %8
%16 = and i32 %11, 1
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %103
18: ; preds = %15
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = tail call i32 @atoi(i8* %20)
switch i32 %21, label %103 [
i32 230400, label %22
i32 115200, label %22
i32 57600, label %22
i32 38400, label %22
i32 28800, label %22
i32 14400, label %22
i32 9600, label %22
i32 4800, label %22
]
22: ; preds = %18, %18, %18, %18, %18, %18, %18, %18
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = load i32, i32* @O_RDWR
%26 = load i32, i32* @O_NONBLOCK
%27 = or i32 %26, %25
%28 = load i32, i32* @O_NOCTTY
%29 = or i32 %27, %28
%30 = tail call i32 @open(i8* %24, i32 %29, i32 420)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %22
%33 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %34
34: ; preds = %32, %22
%35 = call i32 @tcgetattr(i32 %30, %struct.termios* %3)
%36 = call i32 @cfmakeraw(%struct.termios* %3)
%37 = call i32 @cfsetospeed(%struct.termios* %3, i32 %21)
%38 = call i32 @cfsetispeed(%struct.termios* %3, i32 %21)
%39 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%40 = load i32*, i32** %39
%41 = load i64, i64* @VMIN
%42 = getelementptr inbounds i32, i32* %40, i64 %41
store i32 8, i32* %42
%43 = load i64, i64* @VTIME
%44 = getelementptr inbounds i32, i32* %40, i64 %43
store i32 1, i32* %44
%45 = load i32, i32* @PARENB
%46 = load i32, i32* @PARODD
%47 = or i32 %46, %45
%48 = load i32, i32* @CRTSCTS
%49 = or i32 %47, %48
%50 = xor i32 %49, -1
%51 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
%52 = load i32, i32* %51
%53 = and i32 %52, %50
%54 = load i32, i32* @CREAD
%55 = load i32, i32* @CLOCAL
%56 = or i32 %54, %53
%57 = or i32 %56, %55
store i32 %57, i32* %51
%58 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 2
%59 = bitcast i64* %58 to i8*
%60 = load i32, i32* @TCSANOW
%61 = load i32, i32* @TCSAFLUSH
%62 = or i32 %61, %60
%63 = call i32 @tcsetattr(i32 %30, i32 %62, %struct.termios* %3)
%64 = icmp eq i32 %63, -1
br i1 %64, label %65, label %67
65: ; preds = %34
%66 = call i32 @err(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
br label %67
67: ; preds = %65, %34
%68 = load i32, i32* @TCIOFLUSH
%69 = call i32 @tcflush(i32 %30, i32 %68)
%70 = getelementptr inbounds i8*, i8** %1, i64 3
br label %71
71: ; preds = %99, %67
%72 = phi i1 [ false, %99 ], [ true, %67 ]
%73 = phi i64 [ %96, %99 ], [ 0, %67 ]
br label %74
74: ; preds = %71, %95
%75 = call i32 @usleep(i32 1000)
%76 = call i32 @bzero(i8* %6, i32 64)
%77 = call i32 @read(i32 %30, i8* %6, i32 64)
%78 = icmp eq i32 %77, -1
br i1 %78, label %79, label %88
79: ; preds = %74
%80 = load i64, i64* @EINTR
%81 = load i64, i64* @errno
%82 = icmp eq i64 %80, %81
%83 = load i64, i64* @EAGAIN
%84 = icmp eq i64 %83, %81
%85 = select i1 %82, i1 true, i1 %84
br i1 %85, label %95, label %86
86: ; preds = %79
%87 = call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %95
88: ; preds = %74
%89 = icmp sgt i32 %77, 0
br i1 %89, label %90, label %95
90: ; preds = %88
%91 = call i8* @gpsd_hexdump(i8* %6, i32 %77)
%92 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %91)
%93 = load i32, i32* @stdout
%94 = call i32 @fflush(i32 %93)
br label %95
95: ; preds = %86, %79, %90, %88
%96 = call i64 @time(i32* null)
%97 = icmp sgt i64 %96, %73
%98 = and i1 %97, %72
br i1 %98, label %99, label %74
99: ; preds = %95
%100 = load i8*, i8** %70
%101 = load i8*, i8** %9
%102 = call i32 @moto_send(i32 %30, i8* %100, i8* %101)
br label %71
103: ; preds = %18, %15, %8, %2
%104 = phi i8* [ getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), %8 ], [ getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), %15 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), %18 ]
%105 = load i32, i32* @stderr
%106 = tail call i32 @fprintf(i32 %105, i8* %104)
ret i32 1
}