#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_cc;
};
typedef int /*<<< orphan*/ speed_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ B115200;
int CLOCAL;
int CREAD;
int CRTSCTS;
int CS8;
int CSIZE;
int CSTOPB;
int O_NOCTTY;
int O_RDWR;
int PARENB;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ TCIFLUSH;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ cfmakeraw(struct termios *);
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fread(unsigned char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
unsigned char *malloc(size_t);
int /*<<< orphan*/ memcmp(unsigned char *, char *, int);
int /*<<< orphan*/ memset(struct termios *, int /*<<< orphan*/, int);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
scalar_t__ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ write(int, unsigned char *, int);
int main(int argc, char *argv[]) {
  int fd, res;
  char buf[255];
  struct termios tty;
  struct termios tty_old;
  memset(&tty, 0, sizeof tty);
  fd = open(argv[1], O_RDWR | O_NOCTTY);
  if (fd < 0) {
    perror("/dev/ttyUSB0");
    exit(-1);
  }
  if (tcgetattr(fd, &tty) != 0) {
    fprintf(stderr, "error %d from tcgetattr\n", errno);
  }
  tty_old = tty;
  cfsetospeed(&tty, (speed_t)B115200);
  cfsetispeed(&tty, (speed_t)B115200);
  tty.c_cflag &= ~PARENB;
  tty.c_cflag &= ~CSTOPB;
  tty.c_cflag &= ~CSIZE;
  tty.c_cflag |= CS8;
  tty.c_cflag &= ~CRTSCTS;
  tty.c_cc[VMIN] = 1;
  tty.c_cc[VTIME] = 5;
  tty.c_cflag |= CREAD | CLOCAL;
  cfmakeraw(&tty);
  tcflush(fd, TCIFLUSH);
  if (tcsetattr(fd, TCSANOW, &tty) != 0) {
    fprintf(stderr, "error %d from tcsetattr\n", errno);
  }
  FILE *inf = fopen(argv[2], "rb");
  if (inf) {
    unsigned char *buf;
    fseek(inf, 0, SEEK_END);
    size_t len = ftell(inf);
    fseek(inf, 0, SEEK_SET);
    buf = malloc(len);
    fread(buf, 1, len, inf);
    if (!memcmp(buf, "YM3!", 4)) {
      int offset = (len - 4) / 14;
      printf("%d samples\n", offset);
      int n;
      for (n = 0; n < offset; n++) {
        int i;
        for (i = 0; i < 14; i++) {
          write(fd, &buf[4 + offset * i + n], 1);
        }
        write(fd, buf, 2);
        usleep(20 * 1000);
      }
    } else {
      fprintf(stderr, "Unsupported format!\n");
    }
    fclose(inf);
  } else {
    fprintf(stderr, "Can't open file!\n");
  }
  tcsetattr(fd, TCSANOW, &tty_old);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x130(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1090 <memset@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2d5d(%rip),%rax
mov    (%rax),%esi
mov    0x2d04(%rip),%rax
or     (%rax),%esi
call   1120 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12be <main+0x6e>
lea    0xd51(%rip),%rdi
call   1150 <perror@plt>
mov    $0xffffffff,%edi
call   1160 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x130(%rbp),%rsi
call   1100 <tcgetattr@plt>
cmp    $0x0,%rax
je     12f7 <main+0xa7>
mov    0x2cb2(%rip),%rax
mov    (%rax),%edi
mov    0x2ca1(%rip),%rax
mov    (%rax),%edx
lea    0xd1d(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x130(%rbp),%rax
mov    %rax,-0x140(%rbp)
mov    -0x128(%rbp),%rax
mov    %rax,-0x138(%rbp)
mov    0x2c5e(%rip),%rax
mov    (%rax),%rax
mov    %eax,%esi
lea    -0x130(%rbp),%rdi
call   1060 <cfsetospeed@plt>
mov    0x2c46(%rip),%rax
mov    (%rax),%rax
mov    %eax,%esi
lea    -0x130(%rbp),%rdi
call   1140 <cfsetispeed@plt>
mov    0x2c8e(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x130(%rbp),%eax
mov    %eax,-0x130(%rbp)
mov    0x2bf6(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x130(%rbp),%eax
mov    %eax,-0x130(%rbp)
mov    0x2c36(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x130(%rbp),%eax
mov    %eax,-0x130(%rbp)
mov    0x2c2e(%rip),%rax
mov    (%rax),%eax
or     -0x130(%rbp),%eax
mov    %eax,-0x130(%rbp)
mov    0x2bb9(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x130(%rbp),%eax
mov    %eax,-0x130(%rbp)
mov    -0x128(%rbp),%rax
mov    0x2bf2(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x128(%rbp),%rax
mov    0x2b92(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x5,(%rax,%rcx,4)
mov    0x2bd9(%rip),%rax
mov    (%rax),%eax
mov    0x2b58(%rip),%rcx
or     (%rcx),%eax
or     -0x130(%rbp),%eax
mov    %eax,-0x130(%rbp)
lea    -0x130(%rbp),%rdi
call   10f0 <cfmakeraw@plt>
mov    -0x14(%rbp),%edi
mov    0x2b84(%rip),%rax
mov    (%rax),%esi
call   1070 <tcflush@plt>
mov    -0x14(%rbp),%edi
mov    0x2ba3(%rip),%rax
mov    (%rax),%esi
lea    -0x130(%rbp),%rdx
call   1110 <tcsetattr@plt>
cmp    $0x0,%rax
je     1465 <main+0x215>
mov    0x2b44(%rip),%rax
mov    (%rax),%edi
mov    0x2b33(%rip),%rax
mov    (%rax),%edx
lea    0xbc8(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xbcb(%rip),%rsi
call   1130 <fopen@plt>
mov    %rax,-0x148(%rbp)
cmpq   $0x0,-0x148(%rbp)
je     1624 <main+0x3d4>
mov    -0x148(%rbp),%rdi
mov    0x2b44(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10e0 <fseek@plt>
mov    -0x148(%rbp),%rdi
call   10c0 <ftell@plt>
mov    %rax,-0x158(%rbp)
mov    -0x148(%rbp),%rdi
mov    0x2aba(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10e0 <fseek@plt>
mov    -0x158(%rbp),%rdi
call   10d0 <malloc@plt>
mov    %rax,-0x150(%rbp)
mov    -0x150(%rbp),%rdi
mov    -0x158(%rbp),%rdx
mov    -0x148(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x150(%rbp),%rdi
lea    0xb33(%rip),%rsi
mov    $0x4,%edx
call   10a0 <memcmp@plt>
cmp    $0x0,%eax
jne    15fc <main+0x3ac>
mov    -0x158(%rbp),%rax
sub    $0x4,%rax
mov    $0xe,%ecx
xor    %edx,%edx
div    %rcx
mov    %eax,-0x15c(%rbp)
mov    -0x15c(%rbp),%esi
lea    0xafd(%rip),%rdi
call   1080 <printf@plt>
movl   $0x0,-0x160(%rbp)
mov    -0x160(%rbp),%eax
cmp    -0x15c(%rbp),%eax
jge    15f7 <main+0x3a7>
movl   $0x0,-0x164(%rbp)
cmpl   $0xe,-0x164(%rbp)
jge    15c5 <main+0x375>
mov    -0x14(%rbp),%edi
mov    -0x150(%rbp),%rsi
mov    -0x15c(%rbp),%eax
imul   -0x164(%rbp),%eax
add    $0x4,%eax
add    -0x160(%rbp),%eax
cltq
add    %rax,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    -0x164(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x164(%rbp)
jmp    1575 <main+0x325>
mov    -0x14(%rbp),%edi
mov    -0x150(%rbp),%rsi
mov    $0x2,%edx
call   1040 <write@plt>
mov    $0x4e20,%edi
call   1170 <usleep@plt>
mov    -0x160(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x160(%rbp)
jmp    1559 <main+0x309>
jmp    1613 <main+0x3c3>
mov    0x298d(%rip),%rax
mov    (%rax),%edi
lea    0xa47(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x148(%rbp),%rdi
call   1050 <fclose@plt>
jmp    163b <main+0x3eb>
mov    0x2965(%rip),%rax
mov    (%rax),%edi
lea    0xa34(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x14(%rbp),%edi
mov    0x298b(%rip),%rax
mov    (%rax),%esi
lea    -0x140(%rbp),%rdx
call   1110 <tcsetattr@plt>
xor    %eax,%eax
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rsi,%r14
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1090 <memset@plt>
mov    0x8(%r14),%rdi
mov    0x2d6a(%rip),%rax
mov    0x2d13(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1120 <open@plt>
test   %eax,%eax
js     1718 <main+0x4c8>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
call   1100 <tcgetattr@plt>
test   %rax,%rax
je     12c7 <main+0x77>
mov    0x2ce2(%rip),%rax
mov    (%rax),%edi
mov    0x2cd1(%rip),%rax
mov    (%rax),%edx
lea    0xd4d(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
movups (%rsp),%xmm0
movaps %xmm0,0x70(%rsp)
mov    0x2ca1(%rip),%rbx
mov    (%rbx),%esi
mov    %rsp,%r15
mov    %r15,%rdi
call   1060 <cfsetospeed@plt>
mov    (%rbx),%esi
mov    %r15,%rdi
call   1140 <cfsetispeed@plt>
mov    0x2ce3(%rip),%rax
mov    (%rax),%eax
mov    0x2c5a(%rip),%rcx
or     (%rcx),%eax
mov    0x2ca9(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    (%rsp),%eax
mov    0x2cab(%rip),%rcx
or     (%rcx),%eax
mov    0x2c42(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %eax,%ecx
mov    %ecx,(%rsp)
mov    0x8(%rsp),%rax
mov    0x2c85(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2c2c(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x5,(%rax,%rcx,4)
mov    0x2c73(%rip),%rax
mov    0x2bf4(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     %ecx,(%rsp)
mov    %r15,%rdi
call   10f0 <cfmakeraw@plt>
mov    0x2c2e(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1070 <tcflush@plt>
mov    0x2c4e(%rip),%rbx
mov    (%rbx),%esi
mov    %ebp,%edi
mov    %r15,%rdx
call   1110 <tcsetattr@plt>
test   %rax,%rax
je     13b3 <main+0x163>
mov    0x2bf6(%rip),%rax
mov    (%rax),%edi
mov    0x2be5(%rip),%rax
mov    (%rax),%edx
lea    0xc7a(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    0x10(%r14),%rdi
lea    0xc81(%rip),%rsi
call   1130 <fopen@plt>
test   %rax,%rax
je     1457 <main+0x207>
mov    %rax,%r14
mov    0x2c0a(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   10e0 <fseek@plt>
mov    %r14,%rdi
call   10c0 <ftell@plt>
mov    %rax,%r15
mov    0x2b8c(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   10e0 <fseek@plt>
mov    %r15,%rdi
call   10d0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %r14,0x10(%rsp)
mov    %r14,%rcx
call   1030 <fread@plt>
lea    0xc18(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   10a0 <memcmp@plt>
test   %eax,%eax
je     1473 <main+0x223>
mov    0x2b4e(%rip),%rax
mov    (%rax),%edi
lea    0xc08(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
jmp    16e5 <main+0x495>
mov    0x2b32(%rip),%rax
mov    (%rax),%edi
lea    0xc01(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
jmp    16f6 <main+0x4a6>
add    $0xfffffffffffffffc,%r15
shr    %r15
movabs $0x4924924924924925,%rcx
92 24 49
mov    %r15,%rax
mul    %rcx
mov    %rdx,%r15
shr    %r15
lea    0xbb0(%rip),%rdi
mov    %r15d,%esi
call   1080 <printf@plt>
test   %r15d,%r15d
jle    16e5 <main+0x495>
mov    %r15d,%eax
mov    %rax,0x68(%rsp)
lea    (%r15,%r15,2),%eax
lea    (%r15,%r15,4),%ecx
lea    0x0(,%r15,8),%edx
sub    %r15d,%edx
lea    0x4(%r15),%esi
mov    %rsi,0x58(%rsp)
lea    (%r15,%r15,1),%esi
add    $0x4,%esi
mov    %rsi,0x50(%rsp)
lea    0x4(%r15,%r15,2),%esi
mov    %rsi,0x48(%rsp)
lea    0x4(,%r15,4),%esi
mov    %rsi,0x40(%rsp)
lea    0x4(%r15,%r15,4),%esi
mov    %rsi,0x38(%rsp)
lea    (%rax,%rax,1),%esi
add    $0x4,%esi
mov    %rsi,0x30(%rsp)
add    $0x4,%edx
mov    %rdx,0x60(%rsp)
mov    %r15d,%edx
and    $0x1fffffff,%edx
lea    0x4(,%rdx,8),%rdx
mov    %rdx,0x28(%rsp)
lea    (%r15,%r15,8),%edx
add    $0x4,%edx
mov    %rdx,0x20(%rsp)
lea    0x4(%rcx,%rcx,1),%edx
mov    %rdx,0x18(%rsp)
lea    (%r15,%rcx,2),%r13d
add    $0x4,%r13d
lea    0x4(,%rax,4),%r14d
lea    (%r15,%rax,4),%r15d
add    $0x4,%r15d
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x4(%r12),%eax
movslq %eax,%rsi
add    %rbx,%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1040 <write@plt>
mov    0x58(%rsp),%rax
add    %r12d,%eax
movslq %eax,%rsi
add    %rbx,%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1040 <write@plt>
mov    0x50(%rsp),%rax
add    %r12d,%eax
movslq %eax,%rsi
add    %rbx,%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1040 <write@plt>
mov    0x48(%rsp),%rax
add    %r12d,%eax
movslq %eax,%rsi
add    %rbx,%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1040 <write@plt>
mov    0x40(%rsp),%rax
add    %r12d,%eax
movslq %eax,%rsi
add    %rbx,%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1040 <write@plt>
mov    0x38(%rsp),%rax
add    %r12d,%eax
movslq %eax,%rsi
add    %rbx,%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1040 <write@plt>
mov    0x30(%rsp),%rax
add    %r12d,%eax
movslq %eax,%rsi
add    %rbx,%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1040 <write@plt>
mov    0x60(%rsp),%rax
add    %r12d,%eax
movslq %eax,%rsi
add    %rbx,%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1040 <write@plt>
mov    0x28(%rsp),%rax
add    %r12d,%eax
movslq %eax,%rsi
add    %rbx,%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1040 <write@plt>
mov    0x20(%rsp),%rax
add    %r12d,%eax
movslq %eax,%rsi
add    %rbx,%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1040 <write@plt>
mov    0x18(%rsp),%rax
add    %r12d,%eax
movslq %eax,%rsi
add    %rbx,%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1040 <write@plt>
lea    (%r12,%r13,1),%eax
movslq %eax,%rsi
add    %rbx,%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1040 <write@plt>
lea    (%r14,%r12,1),%eax
movslq %eax,%rsi
add    %rbx,%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1040 <write@plt>
lea    (%r15,%r12,1),%eax
movslq %eax,%rsi
add    %rbx,%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1040 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1040 <write@plt>
mov    $0x4e20,%edi
call   1170 <usleep@plt>
add    $0x1,%r12
cmp    %r12,0x68(%rsp)
jne    1560 <main+0x310>
mov    0x10(%rsp),%rdi
call   1050 <fclose@plt>
mov    0x28da(%rip),%rbx
mov    (%rbx),%esi
lea    0x70(%rsp),%rdx
mov    %ebp,%edi
call   1110 <tcsetattr@plt>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x8e1(%rip),%rdi
call   1150 <perror@plt>
mov    $0xffffffff,%edi
call   1160 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32, i32* }
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@.str = [13 x i8] c"/dev/ttyUSB0\00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"error %d from tcgetattr\0A\00"
@errno = global i32 0
@B115200 = global i64 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@CRTSCTS = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@CREAD = global i32 0
@CLOCAL = global i32 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
@.str.2 = [25 x i8] c"error %d from tcsetattr\0A\00"
@.str.3 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.4 = [5 x i8] c"YM3!\00"
@.str.5 = [12 x i8] c"%d samples\0A\00"
@.str.6 = [21 x i8] c"Unsupported format!\0A\00"
@.str.7 = [18 x i8] c"Can't open file!\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 [255 x i8]
%9 = alloca %struct.termios
%10 = alloca %struct.termios
%11 = alloca i32*
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = call i32 @memset(%struct.termios* %9, i32 0, i32 16)
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = load i32, i32* @O_RDWR
%22 = load i32, i32* @O_NOCTTY
%23 = or i32 %21, %22
%24 = call i32 @open(i8* %20, i32 %23)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %2
%28 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%29 = call i32 @exit(i32 -1)
unreachable
30: ; preds = %2
%31 = load i32, i32* %6
%32 = call i64 @tcgetattr(i32 %31, %struct.termios* %9)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %30
%35 = load i32, i32* @stderr
%36 = load i32, i32* @errno
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %36)
br label %38
38: ; preds = %34, %30
%39 = bitcast %struct.termios* %10 to i8*
%40 = bitcast %struct.termios* %9 to i8*
%41 = load i64, i64* @B115200
%42 = trunc i64 %41 to i32
%43 = call i32 @cfsetospeed(%struct.termios* %9, i32 %42)
%44 = load i64, i64* @B115200
%45 = trunc i64 %44 to i32
%46 = call i32 @cfsetispeed(%struct.termios* %9, i32 %45)
%47 = load i32, i32* @PARENB
%48 = xor i32 %47, -1
%49 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 0
%50 = load i32, i32* %49
%51 = and i32 %50, %48
store i32 %51, i32* %49
%52 = load i32, i32* @CSTOPB
%53 = xor i32 %52, -1
%54 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 0
%55 = load i32, i32* %54
%56 = and i32 %55, %53
store i32 %56, i32* %54
%57 = load i32, i32* @CSIZE
%58 = xor i32 %57, -1
%59 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 0
%60 = load i32, i32* %59
%61 = and i32 %60, %58
store i32 %61, i32* %59
%62 = load i32, i32* @CS8
%63 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 0
%64 = load i32, i32* %63
%65 = or i32 %64, %62
store i32 %65, i32* %63
%66 = load i32, i32* @CRTSCTS
%67 = xor i32 %66, -1
%68 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 0
%69 = load i32, i32* %68
%70 = and i32 %69, %67
store i32 %70, i32* %68
%71 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 1
%72 = load i32*, i32** %71
%73 = load i64, i64* @VMIN
%74 = getelementptr inbounds i32, i32* %72, i64 %73
store i32 1, i32* %74
%75 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 1
%76 = load i32*, i32** %75
%77 = load i64, i64* @VTIME
%78 = getelementptr inbounds i32, i32* %76, i64 %77
store i32 5, i32* %78
%79 = load i32, i32* @CREAD
%80 = load i32, i32* @CLOCAL
%81 = or i32 %79, %80
%82 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 0
%83 = load i32, i32* %82
%84 = or i32 %83, %81
store i32 %84, i32* %82
%85 = call i32 @cfmakeraw(%struct.termios* %9)
%86 = load i32, i32* %6
%87 = load i32, i32* @TCIFLUSH
%88 = call i32 @tcflush(i32 %86, i32 %87)
%89 = load i32, i32* %6
%90 = load i32, i32* @TCSANOW
%91 = call i64 @tcsetattr(i32 %89, i32 %90, %struct.termios* %9)
%92 = icmp ne i64 %91, 0
br i1 %92, label %93, label %97
93: ; preds = %38
%94 = load i32, i32* @stderr
%95 = load i32, i32* @errno
%96 = call i32 (i32, i8*, ...) @fprintf(i32 %94, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %95)
br label %97
97: ; preds = %93, %38
%98 = load i8**, i8*** %5
%99 = getelementptr inbounds i8*, i8** %98, i64 2
%100 = load i8*, i8** %99
%101 = call i32* @fopen(i8* %100, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %101, i32** %11
%102 = load i32*, i32** %11
%103 = icmp ne i32* %102, null
br i1 %103, label %104, label %167
104: ; preds = %97
%105 = load i32*, i32** %11
%106 = load i32, i32* @SEEK_END
%107 = call i32 @fseek(i32* %105, i32 0, i32 %106)
%108 = load i32*, i32** %11
%109 = call i64 @ftell(i32* %108)
store i64 %109, i64* %13
%110 = load i32*, i32** %11
%111 = load i32, i32* @SEEK_SET
%112 = call i32 @fseek(i32* %110, i32 0, i32 %111)
%113 = load i64, i64* %13
%114 = call i8* @malloc(i64 %113)
store i8* %114, i8** %12
%115 = load i8*, i8** %12
%116 = load i64, i64* %13
%117 = load i32*, i32** %11
%118 = call i32 @fread(i8* %115, i32 1, i64 %116, i32* %117)
%119 = load i8*, i8** %12
%120 = call i32 @memcmp(i8* %119, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%121 = icmp ne i32 %120, 0
br i1 %121, label %161, label %122
122: ; preds = %104
%123 = load i64, i64* %13
%124 = sub i64 %123, 4
%125 = udiv i64 %124, 14
%126 = trunc i64 %125 to i32
store i32 %126, i32* %14
%127 = load i32, i32* %14
%128 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %127)
store i32 0, i32* %15
br label %129
129: ; preds = %157, %122
%130 = load i32, i32* %15
%131 = load i32, i32* %14
%132 = icmp slt i32 %130, %131
br i1 %132, label %133, label %160
133: ; preds = %129
store i32 0, i32* %16
br label %134
134: ; preds = %149, %133
%135 = load i32, i32* %16
%136 = icmp slt i32 %135, 14
br i1 %136, label %137, label %152
137: ; preds = %134
%138 = load i32, i32* %6
%139 = load i8*, i8** %12
%140 = load i32, i32* %14
%141 = load i32, i32* %16
%142 = mul nsw i32 %140, %141
%143 = add nsw i32 4, %142
%144 = load i32, i32* %15
%145 = add nsw i32 %143, %144
%146 = sext i32 %145 to i64
%147 = getelementptr inbounds i8, i8* %139, i64 %146
%148 = call i32 @write(i32 %138, i8* %147, i32 1)
br label %149
149: ; preds = %137
%150 = load i32, i32* %16
%151 = add nsw i32 %150, 1
store i32 %151, i32* %16
br label %134
152: ; preds = %134
%153 = load i32, i32* %6
%154 = load i8*, i8** %12
%155 = call i32 @write(i32 %153, i8* %154, i32 2)
%156 = call i32 @usleep(i32 20000)
br label %157
157: ; preds = %152
%158 = load i32, i32* %15
%159 = add nsw i32 %158, 1
store i32 %159, i32* %15
br label %129
160: ; preds = %129
br label %164
161: ; preds = %104
%162 = load i32, i32* @stderr
%163 = call i32 (i32, i8*, ...) @fprintf(i32 %162, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
br label %164
164: ; preds = %161, %160
%165 = load i32*, i32** %11
%166 = call i32 @fclose(i32* %165)
br label %170
167: ; preds = %97
%168 = load i32, i32* @stderr
%169 = call i32 (i32, i8*, ...) @fprintf(i32 %168, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
br label %170
170: ; preds = %167, %164
%171 = load i32, i32* %6
%172 = load i32, i32* @TCSANOW
%173 = call i64 @tcsetattr(i32 %171, i32 %172, %struct.termios* %10)
ret i32 0
}

LLVM IR (-O2):
%struct.termios = type { i32, i32* }
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@.str = [13 x i8] c"/dev/ttyUSB0\00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"error %d from tcgetattr\0A\00"
@errno = global i32 0
@B115200 = global i64 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@CRTSCTS = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@CREAD = global i32 0
@CLOCAL = global i32 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
@.str.2 = [25 x i8] c"error %d from tcsetattr\0A\00"
@.str.3 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.4 = [5 x i8] c"YM3!\00"
@.str.5 = [12 x i8] c"%d samples\0A\00"
@.str.6 = [21 x i8] c"Unsupported format!\0A\00"
@.str.7 = [18 x i8] c"Can't open file!\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.termios
%4 = alloca %struct.termios
%5 = bitcast %struct.termios* %3 to i8*
%6 = bitcast %struct.termios* %4 to i8*
%7 = call i32 @memset(%struct.termios* %3, i32 0, i32 16)
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = load i32, i32* @O_RDWR
%11 = load i32, i32* @O_NOCTTY
%12 = or i32 %11, %10
%13 = call i32 @open(i8* %9, i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %2
%19 = call i64 @tcgetattr(i32 %13, %struct.termios* %3)
%20 = icmp eq i64 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = load i32, i32* @errno
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %21, %18
%26 = load i64, i64* @B115200
%27 = trunc i64 %26 to i32
%28 = call i32 @cfsetospeed(%struct.termios* %3, i32 %27)
%29 = load i64, i64* @B115200
%30 = trunc i64 %29 to i32
%31 = call i32 @cfsetispeed(%struct.termios* %3, i32 %30)
%32 = load i32, i32* @PARENB
%33 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%34 = load i32, i32* %33
%35 = load i32, i32* @CSTOPB
%36 = or i32 %32, %35
%37 = load i32, i32* @CSIZE
%38 = or i32 %36, %37
%39 = xor i32 %38, -1
%40 = and i32 %34, %39
%41 = load i32, i32* @CS8
%42 = or i32 %41, %40
%43 = load i32, i32* @CRTSCTS
%44 = xor i32 %43, -1
%45 = and i32 %42, %44
store i32 %45, i32* %33
%46 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
%47 = load i32*, i32** %46
%48 = load i64, i64* @VMIN
%49 = getelementptr inbounds i32, i32* %47, i64 %48
store i32 1, i32* %49
%50 = load i64, i64* @VTIME
%51 = getelementptr inbounds i32, i32* %47, i64 %50
store i32 5, i32* %51
%52 = load i32, i32* @CREAD
%53 = load i32, i32* @CLOCAL
%54 = or i32 %53, %52
%55 = load i32, i32* %33
%56 = or i32 %54, %55
store i32 %56, i32* %33
%57 = call i32 @cfmakeraw(%struct.termios* %3)
%58 = load i32, i32* @TCIFLUSH
%59 = call i32 @tcflush(i32 %13, i32 %58)
%60 = load i32, i32* @TCSANOW
%61 = call i64 @tcsetattr(i32 %13, i32 %60, %struct.termios* %3)
%62 = icmp eq i64 %61, 0
br i1 %62, label %67, label %63
63: ; preds = %25
%64 = load i32, i32* @stderr
%65 = load i32, i32* @errno
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %65)
br label %67
67: ; preds = %63, %25
%68 = getelementptr inbounds i8*, i8** %1, i64 2
%69 = load i8*, i8** %68
%70 = call i32* @fopen(i8* %69, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%71 = icmp eq i32* %70, null
br i1 %71, label %182, label %72
72: ; preds = %67
%73 = load i32, i32* @SEEK_END
%74 = call i32 @fseek(i32* %70, i32 0, i32 %73)
%75 = call i64 @ftell(i32* %70)
%76 = load i32, i32* @SEEK_SET
%77 = call i32 @fseek(i32* %70, i32 0, i32 %76)
%78 = call i8* @malloc(i64 %75)
%79 = call i32 @fread(i8* %78, i32 1, i64 %75, i32* %70)
%80 = call i32 @memcmp(i8* %78, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%81 = icmp eq i32 %80, 0
br i1 %81, label %82, label %177
82: ; preds = %72
%83 = add i64 %75, -4
%84 = udiv i64 %83, 14
%85 = trunc i64 %84 to i32
%86 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %85)
%87 = icmp sgt i32 %85, 0
br i1 %87, label %88, label %180
88: ; preds = %82
%89 = and i64 %84, 4294967295
%90 = trunc i64 %84 to i32
%91 = shl i32 %90, 1
%92 = trunc i64 %84 to i32
%93 = mul i32 %92, 3
%94 = trunc i64 %84 to i32
%95 = shl i32 %94, 2
%96 = trunc i64 %84 to i32
%97 = mul i32 %96, 5
%98 = trunc i64 %84 to i32
%99 = mul i32 %98, 6
%100 = trunc i64 %84 to i32
%101 = mul i32 %100, 7
%102 = trunc i64 %84 to i32
%103 = shl i32 %102, 3
%104 = trunc i64 %84 to i32
%105 = mul i32 %104, 9
%106 = trunc i64 %84 to i32
%107 = mul i32 %106, 10
%108 = trunc i64 %84 to i32
%109 = mul i32 %108, 11
%110 = trunc i64 %84 to i32
%111 = mul i32 %110, 12
%112 = trunc i64 %84 to i32
%113 = mul i32 %112, 13
br label %114
114: ; preds = %88, %114
%115 = phi i64 [ 0, %88 ], [ %175, %114 ]
%116 = trunc i64 %115 to i32
%117 = add i32 %116, 4
%118 = sext i32 %117 to i64
%119 = getelementptr inbounds i8, i8* %78, i64 %118
%120 = call i32 @write(i32 %13, i8* %119, i32 1)
%121 = add i32 %117, %85
%122 = sext i32 %121 to i64
%123 = getelementptr inbounds i8, i8* %78, i64 %122
%124 = call i32 @write(i32 %13, i8* %123, i32 1)
%125 = add i32 %117, %91
%126 = sext i32 %125 to i64
%127 = getelementptr inbounds i8, i8* %78, i64 %126
%128 = call i32 @write(i32 %13, i8* %127, i32 1)
%129 = add i32 %117, %93
%130 = sext i32 %129 to i64
%131 = getelementptr inbounds i8, i8* %78, i64 %130
%132 = call i32 @write(i32 %13, i8* %131, i32 1)
%133 = add i32 %117, %95
%134 = sext i32 %133 to i64
%135 = getelementptr inbounds i8, i8* %78, i64 %134
%136 = call i32 @write(i32 %13, i8* %135, i32 1)
%137 = add i32 %117, %97
%138 = sext i32 %137 to i64
%139 = getelementptr inbounds i8, i8* %78, i64 %138
%140 = call i32 @write(i32 %13, i8* %139, i32 1)
%141 = add i32 %117, %99
%142 = sext i32 %141 to i64
%143 = getelementptr inbounds i8, i8* %78, i64 %142
%144 = call i32 @write(i32 %13, i8* %143, i32 1)
%145 = add i32 %117, %101
%146 = sext i32 %145 to i64
%147 = getelementptr inbounds i8, i8* %78, i64 %146
%148 = call i32 @write(i32 %13, i8* %147, i32 1)
%149 = add i32 %117, %103
%150 = sext i32 %149 to i64
%151 = getelementptr inbounds i8, i8* %78, i64 %150
%152 = call i32 @write(i32 %13, i8* %151, i32 1)
%153 = add i32 %117, %105
%154 = sext i32 %153 to i64
%155 = getelementptr inbounds i8, i8* %78, i64 %154
%156 = call i32 @write(i32 %13, i8* %155, i32 1)
%157 = add i32 %117, %107
%158 = sext i32 %157 to i64
%159 = getelementptr inbounds i8, i8* %78, i64 %158
%160 = call i32 @write(i32 %13, i8* %159, i32 1)
%161 = add i32 %117, %109
%162 = sext i32 %161 to i64
%163 = getelementptr inbounds i8, i8* %78, i64 %162
%164 = call i32 @write(i32 %13, i8* %163, i32 1)
%165 = add i32 %117, %111
%166 = sext i32 %165 to i64
%167 = getelementptr inbounds i8, i8* %78, i64 %166
%168 = call i32 @write(i32 %13, i8* %167, i32 1)
%169 = add i32 %117, %113
%170 = sext i32 %169 to i64
%171 = getelementptr inbounds i8, i8* %78, i64 %170
%172 = call i32 @write(i32 %13, i8* %171, i32 1)
%173 = call i32 @write(i32 %13, i8* %78, i32 2)
%174 = call i32 @usleep(i32 20000)
%175 = add nuw nsw i64 %115, 1
%176 = icmp eq i64 %175, %89
br i1 %176, label %180, label %114
177: ; preds = %72
%178 = load i32, i32* @stderr
%179 = call i32 (i32, i8*, ...) @fprintf(i32 %178, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
br label %180
180: ; preds = %114, %82, %177
%181 = call i32 @fclose(i32* %70)
br label %185
182: ; preds = %67
%183 = load i32, i32* @stderr
%184 = call i32 (i32, i8*, ...) @fprintf(i32 %183, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
br label %185
185: ; preds = %182, %180
%186 = load i32, i32* @TCSANOW
%187 = call i64 @tcsetattr(i32 %13, i32 %186, %struct.termios* %4)
ret i32 0
}