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

/* Forward declarations */

/* Type definitions */
struct timeval {
  int tv_usec;
  scalar_t__ tv_sec;
};
struct timespec {
  int tv_sec;
  int tv_nsec;
};
struct termios {
  int dummy;
};
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
char EOF;
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ F_SETFL;
int /*<<< orphan*/ O_NONBLOCK;
int /*<<< orphan*/ TCSAFLUSH;
void *atoi(int /*<<< orphan*/);
int /*<<< orphan*/ cfmakeraw(struct termios *);
int /*<<< orphan*/ cfsetispeed(struct termios *, unsigned int);
int /*<<< orphan*/ cfsetospeed(struct termios *, unsigned int);
scalar_t__ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fprintf(int /*<<< orphan*/, char *, ...);
char getopt(int, char **, char *);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int /*<<< orphan*/ show_help(char *);
int /*<<< orphan*/ stderr;
char *strdup(int /*<<< orphan*/);
scalar_t__ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int main(int argc, char **argv) {
  char *sensor_id = NULL;
  char *device = NULL;
  char *aset = NULL;
  unsigned short timeout = 100;
  unsigned int baudrate = 115200;
  char c;
  while ((c = getopt(argc, argv, "hi:d:s:t:b:")) != EOF) {
    switch (c) {
    case 'h': {
      show_help(argv[0]);
      return 1;
    }
    case 'i':
      sensor_id = strdup(optarg);
      break;
    case 'd':
      device = strdup(optarg);
      break;
    case 's':
      aset = strdup(optarg);
      break;
    case 't':
      timeout = atoi(optarg);
      break;
    case 'b':
      baudrate = atoi(optarg);
      break;
    default: {
      fprintf(stderr, "ERROR: Invalid option %c!\n", c);
      show_help(argv[0]);
      return 1;
    }
    }
  }
  if (sensor_id == NULL || device == NULL) {
    fprintf(stderr,
            "ERROR: Sensor identifier and serial device path are required!\n");
    return 1;
  }
  FILE *serial = fopen(device, "r+");
  if (!serial) {
    fprintf(stderr, "ERROR: Failed to open the serial device '%s'!\n", device);
    return 2;
  }
  int serial_fd = fileno(serial);
  if (fcntl(serial_fd, F_SETFL, O_NONBLOCK) < 0) {
    fprintf(stderr, "ERROR: Failed to setup the serial device!\n");
    return 2;
  }
  struct termios tio;
  if (tcgetattr(serial_fd, &tio) < 0) {
    fprintf(stderr, "ERROR: Failed to configure the serial device!\n");
    return 2;
  }
  cfmakeraw(&tio);
  cfsetispeed(&tio, baudrate);
  cfsetospeed(&tio, baudrate);
  if (tcsetattr(serial_fd, TCSAFLUSH, &tio) < 0) {
    fprintf(stderr, "ERROR: Failed to configure the serial device!\n");
    return 2;
  }
  char buffer[1024] = {
      0,
  };
  if (aset != NULL) {
    if (fprintf(serial, "ACOM /%s %s\n", sensor_id, aset) < 0) {
      fprintf(stderr, "ERROR: Failed to send ASET %s command!\n", aset);
      fclose(serial);
      return 3;
    }
  } else {
    if (fprintf(serial, "ACOM /%s\n", sensor_id) < 0) {
      fprintf(stderr, "ERROR: Failed to send AGET command!\n");
      fclose(serial);
      return 3;
    }
  }
  struct timespec tp_start;
  if (clock_gettime(CLOCK_MONOTONIC, &tp_start) < 0) {
    fprintf(stderr, "ERROR: Failed to get monotonic clock!\n");
    return 3;
  }
  char *buffer_idx = (char *)&buffer;
  int state_end = 0;
  for (;;) {
    fd_set rfds;
    struct timeval tv;
    FD_ZERO(&rfds);
    FD_SET(serial_fd, &rfds);
    tv.tv_sec = 0;
    tv.tv_usec = 1000;
    int r = select(serial_fd + 1, &rfds, NULL, NULL, &tv);
    if (r == -1) {
      fprintf(stderr, "ERROR: Failed to receive sensor response!\n");
      fclose(serial);
      return 4;
    } else if (r) {
      char c;
      int rr = read(serial_fd, &c, sizeof(char));
      if (rr < 0) {
        fprintf(stderr, "ERROR: Failed to receive sensor response!\n");
        fclose(serial);
        return 4;
      } else if (rr == 0) {
        fprintf(stderr, "ERROR: End of file encountered!\n");
        fclose(serial);
        return 4;
      }
      if (c == 10) {
        if (state_end == 1)
          break;
        state_end++;
        continue;
      }
      if (c == 13)
        break;
      if (buffer_idx - (char *)&buffer >= sizeof(buffer))
        continue;
      *buffer_idx = c;
      buffer_idx++;
    } else {
      struct timespec tp_current;
      if (clock_gettime(CLOCK_MONOTONIC, &tp_current) < 0) {
        fprintf(stderr, "ERROR: Failed to get monotonic clock!\n");
        fclose(serial);
        return 3;
      }
      long delta = (tp_current.tv_sec * 1000 + tp_current.tv_nsec / 1000000) -
                   (tp_start.tv_sec * 1000 + tp_start.tv_nsec / 1000000);
      if (delta >= timeout) {
        fprintf(stderr, "ERROR: Timed out while parsing sensor response!\n");
        fclose(serial);
        return 4;
      }
    }
  }
  printf("%s", buffer);
  fclose(serial);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4b0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movw   $0x64,-0x2a(%rbp)
movl   $0x1c200,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xdb0(%rip),%rdx
call   1140 <getopt@plt>
mov    %al,-0x31(%rbp)
movsbl %al,%eax
mov    0x2d1a(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     13ab <main+0x15b>
movsbl -0x31(%rbp),%eax
add    $0xffffff9e,%eax
mov    %eax,%ecx
mov    %rcx,-0x4a0(%rbp)
sub    $0x12,%eax
ja     1373 <main+0x123>
mov    -0x4a0(%rbp),%rax
lea    0xd20(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10e0 <show_help@plt>
movl   $0x1,-0x4(%rbp)
jmp    1917 <main+0x6c7>
mov    0x2cf0(%rip),%rax
mov    (%rax),%edi
call   1160 <strdup@plt>
mov    %rax,-0x18(%rbp)
jmp    13a6 <main+0x156>
mov    0x2cd9(%rip),%rax
mov    (%rax),%edi
call   1160 <strdup@plt>
mov    %rax,-0x20(%rbp)
jmp    13a6 <main+0x156>
mov    0x2cc2(%rip),%rax
mov    (%rax),%edi
call   1160 <strdup@plt>
mov    %rax,-0x28(%rbp)
jmp    13a6 <main+0x156>
mov    0x2cab(%rip),%rax
mov    (%rax),%edi
call   1150 <atoi@plt>
mov    %ax,-0x2a(%rbp)
jmp    13a6 <main+0x156>
mov    0x2c94(%rip),%rax
mov    (%rax),%edi
call   1150 <atoi@plt>
mov    %eax,-0x30(%rbp)
jmp    13a6 <main+0x156>
mov    0x2c3e(%rip),%rax
mov    (%rax),%edi
movsbl -0x31(%rbp),%edx
lea    0xcd1(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10e0 <show_help@plt>
movl   $0x1,-0x4(%rbp)
jmp    1917 <main+0x6c7>
jmp    128e <main+0x3e>
cmpq   $0x0,-0x18(%rbp)
je     13c1 <main+0x171>
cmpq   $0x0,-0x20(%rbp)
jne    13e4 <main+0x194>
mov    0x2bf0(%rip),%rax
mov    (%rax),%edi
lea    0xca2(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1917 <main+0x6c7>
mov    -0x20(%rbp),%rdi
lea    0xcc3(%rip),%rsi
call   1120 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    142a <main+0x1da>
mov    0x2bae(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xc9e(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1917 <main+0x6c7>
mov    -0x40(%rbp),%rdi
call   10b0 <fileno@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%edi
mov    0x2b70(%rip),%rax
mov    (%rax),%esi
mov    0x2b8f(%rip),%rax
mov    (%rax),%edx
call   1030 <fcntl@plt>
cmp    $0x0,%rax
jge    147d <main+0x22d>
mov    0x2b57(%rip),%rax
mov    (%rax),%edi
lea    0xc7a(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1917 <main+0x6c7>
mov    -0x44(%rbp),%edi
lea    -0x48(%rbp),%rsi
call   1100 <tcgetattr@plt>
cmp    $0x0,%rax
jge    14b6 <main+0x266>
mov    0x2b1e(%rip),%rax
mov    (%rax),%edi
lea    0xc6c(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1917 <main+0x6c7>
lea    -0x48(%rbp),%rdi
call   10f0 <cfmakeraw@plt>
mov    -0x30(%rbp),%esi
lea    -0x48(%rbp),%rdi
call   1130 <cfsetispeed@plt>
mov    -0x30(%rbp),%esi
lea    -0x48(%rbp),%rdi
call   1060 <cfsetospeed@plt>
mov    -0x44(%rbp),%edi
mov    0x2aff(%rip),%rax
mov    (%rax),%esi
lea    -0x48(%rbp),%rdx
call   1110 <tcsetattr@plt>
cmp    $0x0,%rax
jge    1519 <main+0x2c9>
mov    0x2abb(%rip),%rax
mov    (%rax),%edi
lea    0xc09(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1917 <main+0x6c7>
lea    -0x450(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
cmpq   $0x0,-0x28(%rbp)
je     1592 <main+0x342>
mov    -0x40(%rbp),%rax
mov    %eax,%edi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xbf2(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
cmp    $0x0,%rax
jge    158d <main+0x33d>
mov    0x2a54(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xbda(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x40(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x3,-0x4(%rbp)
jmp    1917 <main+0x6c7>
jmp    15e5 <main+0x395>
mov    -0x40(%rbp),%rax
mov    %eax,%edi
mov    -0x18(%rbp),%rdx
lea    0xbd0(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
cmp    $0x0,%rax
jge    15e0 <main+0x390>
mov    0x29fd(%rip),%rax
mov    (%rax),%edi
lea    0xbb9(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x40(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x3,-0x4(%rbp)
jmp    1917 <main+0x6c7>
jmp    15e5 <main+0x395>
mov    0x29e4(%rip),%rax
mov    (%rax),%edi
lea    -0x458(%rbp),%rsi
call   1040 <clock_gettime@plt>
cmp    $0x0,%rax
jge    1627 <main+0x3d7>
mov    0x29ad(%rip),%rax
mov    (%rax),%edi
lea    0xb8e(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x3,-0x4(%rbp)
jmp    1917 <main+0x6c7>
lea    -0x450(%rbp),%rax
mov    %rax,-0x460(%rbp)
movl   $0x0,-0x464(%rbp)
lea    -0x468(%rbp),%rdi
call   10c0 <FD_ZERO@plt>
mov    -0x44(%rbp),%edi
lea    -0x468(%rbp),%rsi
call   1170 <FD_SET@plt>
movq   $0x0,-0x470(%rbp)
movl   $0x3e8,-0x478(%rbp)
mov    -0x44(%rbp),%edi
add    $0x1,%edi
lea    -0x468(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x478(%rbp),%r8
mov    %rcx,%rdx
call   10d0 <select@plt>
mov    %eax,-0x47c(%rbp)
cmpl   $0xffffffff,-0x47c(%rbp)
jne    16ce <main+0x47e>
mov    0x290f(%rip),%rax
mov    (%rax),%edi
lea    0xb17(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x40(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x4,-0x4(%rbp)
jmp    1917 <main+0x6c7>
cmpl   $0x0,-0x47c(%rbp)
je     17ff <main+0x5af>
mov    -0x44(%rbp),%edi
lea    -0x47d(%rbp),%rsi
mov    $0x1,%edx
call   1090 <read@plt>
mov    %eax,-0x484(%rbp)
cmpl   $0x0,-0x484(%rbp)
jge    172e <main+0x4de>
mov    0x28af(%rip),%rax
mov    (%rax),%edi
lea    0xab7(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x40(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x4,-0x4(%rbp)
jmp    1917 <main+0x6c7>
cmpl   $0x0,-0x484(%rbp)
jne    1767 <main+0x517>
mov    0x2876(%rip),%rax
mov    (%rax),%edi
lea    0xaa9(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x40(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x4,-0x4(%rbp)
jmp    1917 <main+0x6c7>
jmp    176c <main+0x51c>
movsbl -0x47d(%rbp),%eax
cmp    $0xa,%eax
jne    17a2 <main+0x552>
cmpl   $0x1,-0x464(%rbp)
jne    178e <main+0x53e>
jmp    18f4 <main+0x6a4>
mov    -0x464(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x464(%rbp)
jmp    163f <main+0x3ef>
movsbl -0x47d(%rbp),%eax
cmp    $0xd,%eax
jne    17b7 <main+0x567>
jmp    18f4 <main+0x6a4>
mov    -0x460(%rbp),%rax
lea    -0x450(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x400,%rax
jb     17d9 <main+0x589>
jmp    163f <main+0x3ef>
mov    -0x47d(%rbp),%cl
mov    -0x460(%rbp),%rax
mov    %cl,(%rax)
mov    -0x460(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x460(%rbp)
jmp    18ea <main+0x69a>
mov    0x27ca(%rip),%rax
mov    (%rax),%edi
lea    -0x490(%rbp),%rsi
call   1040 <clock_gettime@plt>
cmp    $0x0,%rax
jge    184a <main+0x5fa>
mov    0x2793(%rip),%rax
mov    (%rax),%edi
lea    0x974(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x40(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x3,-0x4(%rbp)
jmp    1917 <main+0x6c7>
imul   $0x3e8,-0x490(%rbp),%eax
mov    %eax,-0x4a8(%rbp)
mov    -0x48c(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x4a8(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x4a4(%rbp)
imul   $0x3e8,-0x458(%rbp),%ecx
mov    -0x454(%rbp),%eax
mov    $0xf4240,%esi
cltd
idiv   %esi
mov    %eax,%edx
mov    -0x4a4(%rbp),%eax
add    %edx,%ecx
sub    %ecx,%eax
cltq
mov    %rax,-0x498(%rbp)
mov    -0x498(%rbp),%rax
movzwl -0x2a(%rbp),%ecx
cmp    %rcx,%rax
jl     18e5 <main+0x695>
mov    0x26f8(%rip),%rax
mov    (%rax),%edi
lea    0x94c(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x40(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x4,-0x4(%rbp)
jmp    1917 <main+0x6c7>
jmp    18ea <main+0x69a>
jmp    18ef <main+0x69f>
jmp    163f <main+0x3ef>
lea    -0x450(%rbp),%rsi
lea    0x944(%rip),%rdi
call   1070 <printf@plt>
mov    -0x40(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x4b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x468,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xddf(%rip),%rdx
call   1140 <getopt@plt>
mov    0x2d4f(%rip),%r14
cmp    (%r14),%al
jne    12ae <main+0x5e>
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
lea    0xde5(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x468,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1c200,%ecx
mov    %rcx,0x38(%rsp)
mov    $0x64,%cx
mov    %rcx,0x28(%rsp)
xor    %ecx,%ecx
mov    %rcx,0x8(%rsp)
lea    0xd31(%rip),%r15
mov    0x2d22(%rip),%r12
lea    0xd6f(%rip),%r13
xor    %ecx,%ecx
mov    %rcx,0x10(%rsp)
xor    %ecx,%ecx
mov    %rcx,0x30(%rsp)
jmp    1312 <main+0xc2>
mov    (%r12),%edi
call   1160 <strdup@plt>
mov    %rax,0x8(%rsp)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r13,%rdx
call   1140 <getopt@plt>
cmp    (%r14),%al
je     136a <main+0x11a>
movsbl %al,%edx
lea    -0x62(%rdx),%eax
cmp    $0x12,%eax
ja     1489 <main+0x239>
movslq (%r15,%rax,4),%rax
add    %r15,%rax
jmp    *%rax
mov    (%r12),%edi
call   1150 <atoi@plt>
mov    %rax,0x38(%rsp)
jmp    1300 <main+0xb0>
mov    (%r12),%edi
call   1160 <strdup@plt>
mov    %rax,0x10(%rsp)
jmp    1300 <main+0xb0>
mov    (%r12),%edi
call   1160 <strdup@plt>
mov    %rax,0x30(%rsp)
jmp    1300 <main+0xb0>
mov    (%r12),%edi
call   1150 <atoi@plt>
mov    %rax,0x28(%rsp)
jmp    1300 <main+0xb0>
mov    0x8(%rsp),%rbp
test   %rbp,%rbp
mov    0x10(%rsp),%rbx
je     127e <main+0x2e>
test   %rbx,%rbx
je     127e <main+0x2e>
lea    0xd25(%rip),%rsi
mov    %rbx,%rdi
call   1120 <fopen@plt>
test   %rax,%rax
je     14ad <main+0x25d>
mov    %rax,%r13
mov    %rax,%rdi
call   10b0 <fileno@plt>
mov    %eax,%r15d
mov    0x2bfd(%rip),%rax
mov    (%rax),%esi
mov    0x2c1c(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
call   1030 <fcntl@plt>
test   %rax,%rax
js     14e3 <main+0x293>
lea    0x20(%rsp),%rsi
mov    %r15d,%edi
call   1100 <tcgetattr@plt>
test   %rax,%rax
js     14d1 <main+0x281>
lea    0x20(%rsp),%r14
mov    %r14,%rdi
call   10f0 <cfmakeraw@plt>
mov    %r14,%rdi
mov    0x38(%rsp),%rbx
mov    %ebx,%esi
call   1130 <cfsetispeed@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1060 <cfsetospeed@plt>
mov    0x2bce(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
mov    %r14,%rdx
call   1110 <tcsetattr@plt>
test   %rax,%rax
js     14d1 <main+0x281>
lea    0x60(%rsp),%r14
mov    $0x400,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1080 <memset@plt>
mov    0x30(%rsp),%rbx
test   %rbx,%rbx
je     1504 <main+0x2b4>
lea    0xced(%rip),%rsi
mov    %r13d,%edi
mov    %rbp,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   10a0 <fprintf@plt>
test   %rax,%rax
jns    1521 <main+0x2d1>
mov    0x2b47(%rip),%rax
mov    (%rax),%edi
lea    0xcd1(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    16b5 <main+0x465>
mov    0x2b28(%rip),%rax
mov    (%rax),%edi
lea    0xbbf(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    (%rbx),%rdi
call   10e0 <show_help@plt>
jmp    1295 <main+0x45>
mov    0x2b04(%rip),%rax
mov    (%rax),%edi
lea    0xbf8(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x2,%ebp
jmp    129a <main+0x4a>
mov    0x2ae0(%rip),%rax
mov    (%rax),%edi
lea    0xc2e(%rip),%rsi
jmp    14f3 <main+0x2a3>
mov    0x2ace(%rip),%rax
mov    (%rax),%edi
lea    0xbf1(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x2,%ebp
jmp    129a <main+0x4a>
lea    0xc68(%rip),%rsi
mov    %r13d,%edi
mov    %rbp,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
test   %rax,%rax
js     169e <main+0x44e>
mov    0x2aa8(%rip),%rax
mov    (%rax),%edi
lea    0x40(%rsp),%rsi
call   1040 <clock_gettime@plt>
test   %rax,%rax
js     167d <main+0x42d>
mov    %r15d,%ebx
add    $0x1,%ebx
movzwl 0x28(%rsp),%eax
mov    %rax,0x10(%rsp)
xor    %r12d,%r12d
lea    0x4c(%rsp),%rbp
mov    %r14,%rcx
mov    %r14,%rax
mov    %r14,0x8(%rsp)
sub    %rax,%r14
jmp    1575 <main+0x325>
cmp    $0x1,%r12d
mov    $0x1,%r12d
je     170b <main+0x4bb>
mov    %rbp,%rdi
call   10c0 <FD_ZERO@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
call   1170 <FD_SET@plt>
movq   $0x0,0x58(%rsp)
movl   $0x3e8,0x50(%rsp)
mov    %ebx,%edi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
lea    0x50(%rsp),%r8
call   10d0 <select@plt>
test   %eax,%eax
je     1601 <main+0x3b1>
cmp    $0xffffffff,%eax
je     16c7 <main+0x477>
mov    %r15d,%edi
lea    0x18(%rsp),%rsi
mov    $0x1,%edx
call   1090 <read@plt>
test   %eax,%eax
js     16d9 <main+0x489>
je     16e2 <main+0x492>
movzbl 0x18(%rsp),%eax
cmp    $0xa,%al
je     1565 <main+0x315>
cmp    $0xd,%al
je     170b <main+0x4bb>
cmp    $0x3ff,%r14
ja     1575 <main+0x325>
mov    0x8(%rsp),%r14
mov    %al,(%r14)
add    $0x1,%r14
jmp    1673 <main+0x423>
mov    0x29c8(%rip),%rax
mov    (%rax),%edi
lea    0x18(%rsp),%rsi
call   1040 <clock_gettime@plt>
test   %rax,%rax
js     172b <main+0x4db>
mov    0x18(%rsp),%eax
movslq 0x1c(%rsp),%rcx
imul   $0x431bde83,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x32,%rcx
add    %edx,%ecx
movslq 0x44(%rsp),%rdx
imul   $0xffffffffbce4217d,%rdx,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x32,%rdx
add    %esi,%edx
add    %ecx,%edx
sub    0x40(%rsp),%eax
imul   $0x3e8,%eax,%eax
add    %edx,%eax
cltq
cmp    0x10(%rsp),%rax
mov    0x8(%rsp),%r14
jge    1739 <main+0x4e9>
lea    0x60(%rsp),%rax
jmp    155b <main+0x30b>
mov    0x2934(%rip),%rax
mov    (%rax),%edi
lea    0xb15(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x3,%ebp
jmp    129a <main+0x4a>
mov    0x2913(%rip),%rax
mov    (%rax),%edi
lea    0xacf(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %r13,%rdi
call   1050 <fclose@plt>
mov    $0x3,%ebp
jmp    129a <main+0x4a>
mov    0x28ea(%rip),%rax
mov    (%rax),%edi
lea    0xaf2(%rip),%rsi
jmp    16f2 <main+0x4a2>
lea    0xae9(%rip),%rsi
jmp    16e9 <main+0x499>
lea    0xb0b(%rip),%rsi
mov    0x28c8(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %r13,%rdi
call   1050 <fclose@plt>
mov    $0x4,%ebp
jmp    129a <main+0x4a>
lea    0xb34(%rip),%rdi
lea    0x60(%rsp),%rsi
call   1070 <printf@plt>
mov    %r13,%rdi
call   1050 <fclose@plt>
xor    %ebp,%ebp
jmp    129a <main+0x4a>
mov    $0x3,%ebp
lea    0xa6b(%rip),%rsi
jmp    1745 <main+0x4f5>
mov    $0x4,%ebp
lea    0xad0(%rip),%rsi
mov    0x286c(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %r13,%rdi
call   1050 <fclose@plt>
jmp    129a <main+0x4a>

LLVM IR (-O0):
%struct.termios = type { i32 }
%struct.timespec = type { i32, i32 }
%struct.timeval = type { i32, i64 }
@.str = [12 x i8] c"hi:d:s:t:b:\00"
@EOF = global i8 0
@optarg = global i32 0
@stderr = global i32 0
@.str.1 = [27 x i8] c"ERROR: Invalid option %c!\0A\00"
@.str.2 = [63 x i8] c"ERROR: Sensor identifier and serial device path are required!\0A\00"
@.str.3 = [3 x i8] c"r+\00"
@.str.4 = [47 x i8] c"ERROR: Failed to open the serial device '%s'!\0A\00"
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.5 = [43 x i8] c"ERROR: Failed to setup the serial device!\0A\00"
@.str.6 = [47 x i8] c"ERROR: Failed to configure the serial device!\0A\00"
@TCSAFLUSH = global i32 0
@.str.7 = [13 x i8] c"ACOM /%s %s\0A\00"
@.str.8 = [40 x i8] c"ERROR: Failed to send ASET %s command!\0A\00"
@.str.9 = [10 x i8] c"ACOM /%s\0A\00"
@.str.10 = [37 x i8] c"ERROR: Failed to send AGET command!\0A\00"
@CLOCK_MONOTONIC = global i32 0
@.str.11 = [39 x i8] c"ERROR: Failed to get monotonic clock!\0A\00"
@.str.12 = [43 x i8] c"ERROR: Failed to receive sensor response!\0A\00"
@.str.13 = [33 x i8] c"ERROR: End of file encountered!\0A\00"
@.str.14 = [49 x i8] c"ERROR: Timed out while parsing sensor response!\0A\00"
@.str.15 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i16
%10 = alloca i32
%11 = alloca i8
%12 = alloca i32*
%13 = alloca i32
%14 = alloca %struct.termios
%15 = alloca [1024 x i8]
%16 = alloca %struct.timespec
%17 = alloca i8*
%18 = alloca i32
%19 = alloca i32
%20 = alloca %struct.timeval
%21 = alloca i32
%22 = alloca i8
%23 = alloca i32
%24 = alloca %struct.timespec
%25 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i8* null, i8** %7
store i8* null, i8** %8
store i16 100, i16* %9
store i32 115200, i32* %10
br label %26
26: ; preds = %68, %2
%27 = load i32, i32* %4
%28 = load i8**, i8*** %5
%29 = call signext i8 @getopt(i32 %27, i8** %28, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i8 %29, i8* %11
%30 = sext i8 %29 to i32
%31 = load i8, i8* @EOF
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %30, %32
br i1 %33, label %34, label %69
34: ; preds = %26
%35 = load i8, i8* %11
%36 = sext i8 %35 to i32
switch i32 %36, label %59 [
i32 104, label %37
i32 105, label %42
i32 100, label %45
i32 115, label %48
i32 116, label %51
i32 98, label %55
]
37: ; preds = %34
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 0
%40 = load i8*, i8** %39
%41 = call i32 @show_help(i8* %40)
store i32 1, i32* %3
br label %267
42: ; preds = %34
%43 = load i32, i32* @optarg
%44 = call i8* @strdup(i32 %43)
store i8* %44, i8** %6
br label %68
45: ; preds = %34
%46 = load i32, i32* @optarg
%47 = call i8* @strdup(i32 %46)
store i8* %47, i8** %7
br label %68
48: ; preds = %34
%49 = load i32, i32* @optarg
%50 = call i8* @strdup(i32 %49)
store i8* %50, i8** %8
br label %68
51: ; preds = %34
%52 = load i32, i32* @optarg
%53 = call i8* @atoi(i32 %52)
%54 = ptrtoint i8* %53 to i16
store i16 %54, i16* %9
br label %68
55: ; preds = %34
%56 = load i32, i32* @optarg
%57 = call i8* @atoi(i32 %56)
%58 = ptrtoint i8* %57 to i32
store i32 %58, i32* %10
br label %68
59: ; preds = %34
%60 = load i32, i32* @stderr
%61 = load i8, i8* %11
%62 = sext i8 %61 to i32
%63 = call i64 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %62)
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 0
%66 = load i8*, i8** %65
%67 = call i32 @show_help(i8* %66)
store i32 1, i32* %3
br label %267
68: ; preds = %55, %51, %48, %45, %42
br label %26
69: ; preds = %26
%70 = load i8*, i8** %6
%71 = icmp eq i8* %70, null
br i1 %71, label %75, label %72
72: ; preds = %69
%73 = load i8*, i8** %7
%74 = icmp eq i8* %73, null
br i1 %74, label %75, label %78
75: ; preds = %72, %69
%76 = load i32, i32* @stderr
%77 = call i64 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %267
78: ; preds = %72
%79 = load i8*, i8** %7
%80 = call i32* @fopen(i8* %79, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %80, i32** %12
%81 = load i32*, i32** %12
%82 = icmp ne i32* %81, null
br i1 %82, label %87, label %83
83: ; preds = %78
%84 = load i32, i32* @stderr
%85 = load i8*, i8** %7
%86 = call i64 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0), i8* %85)
store i32 2, i32* %3
br label %267
87: ; preds = %78
%88 = load i32*, i32** %12
%89 = call i32 @fileno(i32* %88)
store i32 %89, i32* %13
%90 = load i32, i32* %13
%91 = load i32, i32* @F_SETFL
%92 = load i32, i32* @O_NONBLOCK
%93 = call i64 @fcntl(i32 %90, i32 %91, i32 %92)
%94 = icmp slt i64 %93, 0
br i1 %94, label %95, label %98
95: ; preds = %87
%96 = load i32, i32* @stderr
%97 = call i64 (i32, i8*, ...) @fprintf(i32 %96, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0))
store i32 2, i32* %3
br label %267
98: ; preds = %87
%99 = load i32, i32* %13
%100 = call i64 @tcgetattr(i32 %99, %struct.termios* %14)
%101 = icmp slt i64 %100, 0
br i1 %101, label %102, label %105
102: ; preds = %98
%103 = load i32, i32* @stderr
%104 = call i64 (i32, i8*, ...) @fprintf(i32 %103, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.6, i64 0, i64 0))
store i32 2, i32* %3
br label %267
105: ; preds = %98
%106 = call i32 @cfmakeraw(%struct.termios* %14)
%107 = load i32, i32* %10
%108 = call i32 @cfsetispeed(%struct.termios* %14, i32 %107)
%109 = load i32, i32* %10
%110 = call i32 @cfsetospeed(%struct.termios* %14, i32 %109)
%111 = load i32, i32* %13
%112 = load i32, i32* @TCSAFLUSH
%113 = call i64 @tcsetattr(i32 %111, i32 %112, %struct.termios* %14)
%114 = icmp slt i64 %113, 0
br i1 %114, label %115, label %118
115: ; preds = %105
%116 = load i32, i32* @stderr
%117 = call i64 (i32, i8*, ...) @fprintf(i32 %116, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.6, i64 0, i64 0))
store i32 2, i32* %3
br label %267
118: ; preds = %105
%119 = bitcast [1024 x i8]* %15 to i8*
%120 = load i8*, i8** %8
%121 = icmp ne i8* %120, null
br i1 %121, label %122, label %136
122: ; preds = %118
%123 = load i32*, i32** %12
%124 = ptrtoint i32* %123 to i32
%125 = load i8*, i8** %6
%126 = load i8*, i8** %8
%127 = call i64 (i32, i8*, ...) @fprintf(i32 %124, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %125, i8* %126)
%128 = icmp slt i64 %127, 0
br i1 %128, label %129, label %135
129: ; preds = %122
%130 = load i32, i32* @stderr
%131 = load i8*, i8** %8
%132 = call i64 (i32, i8*, ...) @fprintf(i32 %130, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.8, i64 0, i64 0), i8* %131)
%133 = load i32*, i32** %12
%134 = call i32 @fclose(i32* %133)
store i32 3, i32* %3
br label %267
135: ; preds = %122
br label %148
136: ; preds = %118
%137 = load i32*, i32** %12
%138 = ptrtoint i32* %137 to i32
%139 = load i8*, i8** %6
%140 = call i64 (i32, i8*, ...) @fprintf(i32 %138, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i8* %139)
%141 = icmp slt i64 %140, 0
br i1 %141, label %142, label %147
142: ; preds = %136
%143 = load i32, i32* @stderr
%144 = call i64 (i32, i8*, ...) @fprintf(i32 %143, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.10, i64 0, i64 0))
%145 = load i32*, i32** %12
%146 = call i32 @fclose(i32* %145)
store i32 3, i32* %3
br label %267
147: ; preds = %136
br label %148
148: ; preds = %147, %135
%149 = load i32, i32* @CLOCK_MONOTONIC
%150 = call i64 @clock_gettime(i32 %149, %struct.timespec* %16)
%151 = icmp slt i64 %150, 0
br i1 %151, label %152, label %155
152: ; preds = %148
%153 = load i32, i32* @stderr
%154 = call i64 (i32, i8*, ...) @fprintf(i32 %153, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.11, i64 0, i64 0))
store i32 3, i32* %3
br label %267
155: ; preds = %148
%156 = bitcast [1024 x i8]* %15 to i8*
store i8* %156, i8** %17
store i32 0, i32* %18
br label %157
157: ; preds = %261, %218, %203, %155
%158 = call i32 @FD_ZERO(i32* %19)
%159 = load i32, i32* %13
%160 = call i32 @FD_SET(i32 %159, i32* %19)
%161 = getelementptr inbounds %struct.timeval, %struct.timeval* %20, i32 0, i32 1
store i64 0, i64* %161
%162 = getelementptr inbounds %struct.timeval, %struct.timeval* %20, i32 0, i32 0
store i32 1000, i32* %162
%163 = load i32, i32* %13
%164 = add nsw i32 %163, 1
%165 = call i32 @select(i32 %164, i32* %19, i32* null, i32* null, %struct.timeval* %20)
store i32 %165, i32* %21
%166 = load i32, i32* %21
%167 = icmp eq i32 %166, -1
br i1 %167, label %168, label %173
168: ; preds = %157
%169 = load i32, i32* @stderr
%170 = call i64 (i32, i8*, ...) @fprintf(i32 %169, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.12, i64 0, i64 0))
%171 = load i32*, i32** %12
%172 = call i32 @fclose(i32* %171)
store i32 4, i32* %3
br label %267
173: ; preds = %157
%174 = load i32, i32* %21
%175 = icmp ne i32 %174, 0
br i1 %175, label %176, label %224
176: ; preds = %173
%177 = load i32, i32* %13
%178 = call i32 @read(i32 %177, i8* %22, i32 1)
store i32 %178, i32* %23
%179 = load i32, i32* %23
%180 = icmp slt i32 %179, 0
br i1 %180, label %181, label %186
181: ; preds = %176
%182 = load i32, i32* @stderr
%183 = call i64 (i32, i8*, ...) @fprintf(i32 %182, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.12, i64 0, i64 0))
%184 = load i32*, i32** %12
%185 = call i32 @fclose(i32* %184)
store i32 4, i32* %3
br label %267
186: ; preds = %176
%187 = load i32, i32* %23
%188 = icmp eq i32 %187, 0
br i1 %188, label %189, label %194
189: ; preds = %186
%190 = load i32, i32* @stderr
%191 = call i64 (i32, i8*, ...) @fprintf(i32 %190, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.13, i64 0, i64 0))
%192 = load i32*, i32** %12
%193 = call i32 @fclose(i32* %192)
store i32 4, i32* %3
br label %267
194: ; preds = %186
br label %195
195: ; preds = %194
%196 = load i8, i8* %22
%197 = sext i8 %196 to i32
%198 = icmp eq i32 %197, 10
br i1 %198, label %199, label %206
199: ; preds = %195
%200 = load i32, i32* %18
%201 = icmp eq i32 %200, 1
br i1 %201, label %202, label %203
202: ; preds = %199
br label %262
203: ; preds = %199
%204 = load i32, i32* %18
%205 = add nsw i32 %204, 1
store i32 %205, i32* %18
br label %157
206: ; preds = %195
%207 = load i8, i8* %22
%208 = sext i8 %207 to i32
%209 = icmp eq i32 %208, 13
br i1 %209, label %210, label %211
210: ; preds = %206
br label %262
211: ; preds = %206
%212 = load i8*, i8** %17
%213 = bitcast [1024 x i8]* %15 to i8*
%214 = ptrtoint i8* %212 to i64
%215 = ptrtoint i8* %213 to i64
%216 = sub i64 %214, %215
%217 = icmp uge i64 %216, 1024
br i1 %217, label %218, label %219
218: ; preds = %211
br label %157
219: ; preds = %211
%220 = load i8, i8* %22
%221 = load i8*, i8** %17
store i8 %220, i8* %221
%222 = load i8*, i8** %17
%223 = getelementptr inbounds i8, i8* %222, i32 1
store i8* %223, i8** %17
br label %260
224: ; preds = %173
%225 = load i32, i32* @CLOCK_MONOTONIC
%226 = call i64 @clock_gettime(i32 %225, %struct.timespec* %24)
%227 = icmp slt i64 %226, 0
br i1 %227, label %228, label %233
228: ; preds = %224
%229 = load i32, i32* @stderr
%230 = call i64 (i32, i8*, ...) @fprintf(i32 %229, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.11, i64 0, i64 0))
%231 = load i32*, i32** %12
%232 = call i32 @fclose(i32* %231)
store i32 3, i32* %3
br label %267
233: ; preds = %224
%234 = getelementptr inbounds %struct.timespec, %struct.timespec* %24, i32 0, i32 0
%235 = load i32, i32* %234
%236 = mul nsw i32 %235, 1000
%237 = getelementptr inbounds %struct.timespec, %struct.timespec* %24, i32 0, i32 1
%238 = load i32, i32* %237
%239 = sdiv i32 %238, 1000000
%240 = add nsw i32 %236, %239
%241 = getelementptr inbounds %struct.timespec, %struct.timespec* %16, i32 0, i32 0
%242 = load i32, i32* %241
%243 = mul nsw i32 %242, 1000
%244 = getelementptr inbounds %struct.timespec, %struct.timespec* %16, i32 0, i32 1
%245 = load i32, i32* %244
%246 = sdiv i32 %245, 1000000
%247 = add nsw i32 %243, %246
%248 = sub nsw i32 %240, %247
%249 = sext i32 %248 to i64
store i64 %249, i64* %25
%250 = load i64, i64* %25
%251 = load i16, i16* %9
%252 = zext i16 %251 to i64
%253 = icmp sge i64 %250, %252
br i1 %253, label %254, label %259
254: ; preds = %233
%255 = load i32, i32* @stderr
%256 = call i64 (i32, i8*, ...) @fprintf(i32 %255, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.14, i64 0, i64 0))
%257 = load i32*, i32** %12
%258 = call i32 @fclose(i32* %257)
store i32 4, i32* %3
br label %267
259: ; preds = %233
br label %260
260: ; preds = %259, %219
br label %261
261: ; preds = %260
br label %157
262: ; preds = %210, %202
%263 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
%264 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.15, i64 0, i64 0), i8* %263)
%265 = load i32*, i32** %12
%266 = call i32 @fclose(i32* %265)
store i32 0, i32* %3
br label %267
267: ; preds = %262, %254, %228, %189, %181, %168, %152, %142, %129, %115, %102, %95, %83, %75, %59, %37
%268 = load i32, i32* %3
ret i32 %268
}

LLVM IR (-O2):
%struct.termios = type { i32 }
%struct.timespec = type { i32, i32 }
%struct.timeval = type { i32, i64 }
@.str = [12 x i8] c"hi:d:s:t:b:\00"
@EOF = global i8 0
@optarg = global i32 0
@stderr = global i32 0
@.str.1 = [27 x i8] c"ERROR: Invalid option %c!\0A\00"
@.str.2 = [63 x i8] c"ERROR: Sensor identifier and serial device path are required!\0A\00"
@.str.3 = [3 x i8] c"r+\00"
@.str.4 = [47 x i8] c"ERROR: Failed to open the serial device '%s'!\0A\00"
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.5 = [43 x i8] c"ERROR: Failed to setup the serial device!\0A\00"
@.str.6 = [47 x i8] c"ERROR: Failed to configure the serial device!\0A\00"
@TCSAFLUSH = global i32 0
@.str.7 = [13 x i8] c"ACOM /%s %s\0A\00"
@.str.8 = [40 x i8] c"ERROR: Failed to send ASET %s command!\0A\00"
@.str.9 = [10 x i8] c"ACOM /%s\0A\00"
@.str.10 = [37 x i8] c"ERROR: Failed to send AGET command!\0A\00"
@CLOCK_MONOTONIC = global i32 0
@.str.11 = [39 x i8] c"ERROR: Failed to get monotonic clock!\0A\00"
@.str.12 = [43 x i8] c"ERROR: Failed to receive sensor response!\0A\00"
@.str.13 = [33 x i8] c"ERROR: End of file encountered!\0A\00"
@.str.14 = [49 x i8] c"ERROR: Timed out while parsing sensor response!\0A\00"
@.str.15 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.termios
%4 = alloca [1024 x i8]
%5 = alloca %struct.timespec
%6 = alloca i32
%7 = alloca %struct.timeval
%8 = alloca i8
%9 = alloca %struct.timespec
%10 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%11 = load i8, i8* @EOF
%12 = icmp eq i8 %10, %11
br i1 %12, label %61, label %13
13: ; preds = %2, %48
%14 = phi i8 [ %54, %48 ], [ %10, %2 ]
%15 = phi i8* [ %53, %48 ], [ null, %2 ]
%16 = phi i8* [ %52, %48 ], [ null, %2 ]
%17 = phi i8* [ %51, %48 ], [ null, %2 ]
%18 = phi i16 [ %50, %48 ], [ 100, %2 ]
%19 = phi i32 [ %49, %48 ], [ 115200, %2 ]
%20 = sext i8 %14 to i32
switch i32 %20, label %43 [
i32 104, label %21
i32 105, label %24
i32 100, label %27
i32 115, label %30
i32 116, label %33
i32 98, label %38
]
21: ; preds = %13
%22 = load i8*, i8** %1
%23 = tail call i32 @show_help(i8* %22)
br label %207
24: ; preds = %13
%25 = load i32, i32* @optarg
%26 = tail call i8* @strdup(i32 %25)
br label %48
27: ; preds = %13
%28 = load i32, i32* @optarg
%29 = tail call i8* @strdup(i32 %28)
br label %48
30: ; preds = %13
%31 = load i32, i32* @optarg
%32 = tail call i8* @strdup(i32 %31)
br label %48
33: ; preds = %13
%34 = load i32, i32* @optarg
%35 = tail call i8* @atoi(i32 %34)
%36 = ptrtoint i8* %35 to i64
%37 = trunc i64 %36 to i16
br label %48
38: ; preds = %13
%39 = load i32, i32* @optarg
%40 = tail call i8* @atoi(i32 %39)
%41 = ptrtoint i8* %40 to i64
%42 = trunc i64 %41 to i32
br label %48
43: ; preds = %13
%44 = load i32, i32* @stderr
%45 = tail call i64 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%46 = load i8*, i8** %1
%47 = tail call i32 @show_help(i8* %46)
br label %207
48: ; preds = %38, %33, %30, %27, %24
%49 = phi i32 [ %42, %38 ], [ %19, %33 ], [ %19, %30 ], [ %19, %27 ], [ %19, %24 ]
%50 = phi i16 [ %18, %38 ], [ %37, %33 ], [ %18, %30 ], [ %18, %27 ], [ %18, %24 ]
%51 = phi i8* [ %17, %38 ], [ %17, %33 ], [ %32, %30 ], [ %17, %27 ], [ %17, %24 ]
%52 = phi i8* [ %16, %38 ], [ %16, %33 ], [ %16, %30 ], [ %29, %27 ], [ %16, %24 ]
%53 = phi i8* [ %15, %38 ], [ %15, %33 ], [ %15, %30 ], [ %15, %27 ], [ %26, %24 ]
%54 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%55 = load i8, i8* @EOF
%56 = icmp eq i8 %54, %55
br i1 %56, label %57, label %13
57: ; preds = %48
%58 = icmp eq i8* %53, null
%59 = icmp eq i8* %52, null
%60 = select i1 %58, i1 true, i1 %59
br i1 %60, label %61, label %64
61: ; preds = %2, %57
%62 = load i32, i32* @stderr
%63 = tail call i64 (i32, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.2, i64 0, i64 0))
br label %207
64: ; preds = %57
%65 = tail call i32* @fopen(i8* %52, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%66 = icmp eq i32* %65, null
br i1 %66, label %67, label %70
67: ; preds = %64
%68 = load i32, i32* @stderr
%69 = tail call i64 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0), i8* %52)
br label %207
70: ; preds = %64
%71 = tail call i32 @fileno(i32* %65)
%72 = load i32, i32* @F_SETFL
%73 = load i32, i32* @O_NONBLOCK
%74 = tail call i64 @fcntl(i32 %71, i32 %72, i32 %73)
%75 = icmp slt i64 %74, 0
br i1 %75, label %76, label %79
76: ; preds = %70
%77 = load i32, i32* @stderr
%78 = tail call i64 (i32, i8*, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0))
br label %207
79: ; preds = %70
%80 = bitcast %struct.termios* %3 to i8*
%81 = call i64 @tcgetattr(i32 %71, %struct.termios* %3)
%82 = icmp slt i64 %81, 0
br i1 %82, label %83, label %86
83: ; preds = %79
%84 = load i32, i32* @stderr
%85 = call i64 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.6, i64 0, i64 0))
br label %205
86: ; preds = %79
%87 = call i32 @cfmakeraw(%struct.termios* %3)
%88 = call i32 @cfsetispeed(%struct.termios* %3, i32 %49)
%89 = call i32 @cfsetospeed(%struct.termios* %3, i32 %49)
%90 = load i32, i32* @TCSAFLUSH
%91 = call i64 @tcsetattr(i32 %71, i32 %90, %struct.termios* %3)
%92 = icmp slt i64 %91, 0
br i1 %92, label %93, label %96
93: ; preds = %86
%94 = load i32, i32* @stderr
%95 = call i64 (i32, i8*, ...) @fprintf(i32 %94, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.6, i64 0, i64 0))
br label %205
96: ; preds = %86
%97 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%98 = icmp eq i8* %51, null
%99 = ptrtoint i32* %65 to i64
%100 = trunc i64 %99 to i32
br i1 %98, label %108, label %101
101: ; preds = %96
%102 = call i64 (i32, i8*, ...) @fprintf(i32 %100, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %53, i8* %51)
%103 = icmp slt i64 %102, 0
br i1 %103, label %104, label %115
104: ; preds = %101
%105 = load i32, i32* @stderr
%106 = call i64 (i32, i8*, ...) @fprintf(i32 %105, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.8, i64 0, i64 0), i8* %51)
%107 = call i32 @fclose(i32* %65)
br label %203
108: ; preds = %96
%109 = call i64 (i32, i8*, ...) @fprintf(i32 %100, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i8* %53)
%110 = icmp slt i64 %109, 0
br i1 %110, label %111, label %115
111: ; preds = %108
%112 = load i32, i32* @stderr
%113 = call i64 (i32, i8*, ...) @fprintf(i32 %112, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.10, i64 0, i64 0))
%114 = call i32 @fclose(i32* %65)
br label %203
115: ; preds = %108, %101
%116 = bitcast %struct.timespec* %5 to i8*
%117 = load i32, i32* @CLOCK_MONOTONIC
%118 = call i64 @clock_gettime(i32 %117, %struct.timespec* %5)
%119 = icmp slt i64 %118, 0
br i1 %119, label %133, label %120
120: ; preds = %115
%121 = bitcast i32* %6 to i8*
%122 = bitcast %struct.timeval* %7 to i8*
%123 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 1
%124 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 0
%125 = add nsw i32 %71, 1
%126 = bitcast %struct.timespec* %9 to i8*
%127 = getelementptr inbounds %struct.timespec, %struct.timespec* %9, i64 0, i32 0
%128 = getelementptr inbounds %struct.timespec, %struct.timespec* %9, i64 0, i32 1
%129 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i64 0, i32 0
%130 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i64 0, i32 1
%131 = zext i16 %50 to i64
%132 = ptrtoint [1024 x i8]* %4 to i64
br label %185
133: ; preds = %115
%134 = load i32, i32* @stderr
%135 = call i64 (i32, i8*, ...) @fprintf(i32 %134, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.11, i64 0, i64 0))
br label %201
136: ; preds = %185, %191
%137 = phi i32 [ %192, %191 ], [ %187, %185 ]
%138 = call i32 @FD_ZERO(i32* %6)
%139 = call i32 @FD_SET(i32 %71, i32* %6)
store i64 0, i64* %123
store i32 1000, i32* %124
%140 = call i32 @select(i32 %125, i32* %6, i32* null, i32* null, %struct.timeval* %7)
switch i32 %140, label %145 [
i32 -1, label %141
i32 0, label %157
]
141: ; preds = %136
%142 = load i32, i32* @stderr
%143 = call i64 (i32, i8*, ...) @fprintf(i32 %142, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.12, i64 0, i64 0))
%144 = call i32 @fclose(i32* %65)
br label %181
145: ; preds = %136
%146 = call i32 @read(i32 %71, i8* %8, i32 1)
%147 = icmp slt i32 %146, 0
br i1 %147, label %196, label %148
148: ; preds = %145
%149 = icmp eq i32 %146, 0
br i1 %149, label %196, label %150
150: ; preds = %148
%151 = load i8, i8* %8
switch i8 %151, label %154 [
i8 10, label %152
i8 13, label %193
]
152: ; preds = %150
%153 = icmp eq i32 %137, 1
br i1 %153, label %193, label %191
154: ; preds = %150
br i1 %190, label %191, label %155
155: ; preds = %154
store i8 %151, i8* %186
%156 = getelementptr inbounds i8, i8* %186, i64 1
br label %183
157: ; preds = %136
%158 = load i32, i32* @CLOCK_MONOTONIC
%159 = call i64 @clock_gettime(i32 %158, %struct.timespec* %9)
%160 = icmp slt i64 %159, 0
br i1 %160, label %174, label %161
161: ; preds = %157
%162 = load i32, i32* %127
%163 = load i32, i32* %128
%164 = sdiv i32 %163, 1000000
%165 = load i32, i32* %129
%166 = load i32, i32* %130
%167 = sdiv i32 %166, -1000000
%168 = sub i32 %162, %165
%169 = mul i32 %168, 1000
%170 = add nsw i32 %167, %164
%171 = add i32 %170, %169
%172 = sext i32 %171 to i64
%173 = icmp slt i64 %172, %131
br i1 %173, label %180, label %174
174: ; preds = %161, %157
%175 = phi i8* [ getelementptr inbounds ([39 x i8], [39 x i8]* @.str.11, i64 0, i64 0), %157 ], [ getelementptr inbounds ([49 x i8], [49 x i8]* @.str.14, i64 0, i64 0), %161 ]
%176 = phi i32 [ 3, %157 ], [ 4, %161 ]
%177 = load i32, i32* @stderr
%178 = call i64 (i32, i8*, ...) @fprintf(i32 %177, i8* %175)
%179 = call i32 @fclose(i32* %65)
br label %181
180: ; preds = %161
br label %183
181: ; preds = %141, %174
%182 = phi i32 [ %176, %174 ], [ 4, %141 ]
br label %201
183: ; preds = %180, %155
%184 = phi i8* [ %156, %155 ], [ %186, %180 ]
br label %185
185: ; preds = %183, %120
%186 = phi i8* [ %184, %183 ], [ %97, %120 ]
%187 = phi i32 [ %137, %183 ], [ 0, %120 ]
%188 = ptrtoint i8* %186 to i64
%189 = sub i64 %188, %132
%190 = icmp ugt i64 %189, 1023
br label %136
191: ; preds = %154, %152
%192 = phi i32 [ 1, %152 ], [ %137, %154 ]
br label %136
193: ; preds = %152, %150
%194 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.15, i64 0, i64 0), i8* %97)
%195 = call i32 @fclose(i32* %65)
br label %201
196: ; preds = %148, %145
%197 = phi i8* [ getelementptr inbounds ([43 x i8], [43 x i8]* @.str.12, i64 0, i64 0), %145 ], [ getelementptr inbounds ([33 x i8], [33 x i8]* @.str.13, i64 0, i64 0), %148 ]
%198 = load i32, i32* @stderr
%199 = call i64 (i32, i8*, ...) @fprintf(i32 %198, i8* %197)
%200 = call i32 @fclose(i32* %65)
br label %201
201: ; preds = %196, %181, %193, %133
%202 = phi i32 [ 3, %133 ], [ 0, %193 ], [ %182, %181 ], [ 4, %196 ]
br label %203
203: ; preds = %201, %111, %104
%204 = phi i32 [ 3, %104 ], [ %202, %201 ], [ 3, %111 ]
br label %205
205: ; preds = %203, %93, %83
%206 = phi i32 [ 2, %83 ], [ 2, %93 ], [ %204, %203 ]
br label %207
207: ; preds = %67, %205, %76, %61, %43, %21
%208 = phi i32 [ 1, %43 ], [ 1, %21 ], [ 1, %61 ], [ 2, %67 ], [ 2, %76 ], [ %206, %205 ]
ret i32 %208
}