#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;
};

/* Variables and functions */
int CLOCAL;
int CREAD;
int CS8;
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int O_NOCTTY;
int O_RDWR;
int /*<<< orphan*/ TCIFLUSH;
int /*<<< orphan*/ TCOFLUSH;
int /*<<< orphan*/ TCSETS;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ cfmakeraw(struct termios *);
int /*<<< orphan*/ cfsetspeed(struct termios *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int ioctl(int, int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ memset(struct termios *, int /*<<< orphan*/, int);
int open(char const *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, unsigned char *, int);
char *strcat(char *, char const *);
scalar_t__ tcflush(int, int /*<<< orphan*/);
int write(int, unsigned char *, int);
int main(int argc, const char *argv[]) {
  struct termios theTermios;
  int fd, i = 0;
  int j = 0;
  int tioc = 0;
  unsigned char emu_cmd[] = {'B', 'E', 'R', 0x00};
  unsigned char read_cmd[] = {'B', 'R', 'R', 0x00};
  unsigned char persis_cmd[] = {'B', 'E', 'S', 0x00};
  unsigned char checksum = 0;
  unsigned char buf[257];
  int count;
  if (argc < 2) {
    printf("Usage: %s <serial port device>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  for (checksum = i = 0; i < 3; i++)
    checksum += emu_cmd[i];
  emu_cmd[3] = checksum;
  for (checksum = i = 0; i < 3; i++)
    checksum += read_cmd[i];
  read_cmd[3] = checksum;
  for (checksum = i = 0; i < 3; i++)
    checksum += persis_cmd[i];
  persis_cmd[3] = checksum;
  printf("Emulation bank command set with checksum: ");
  for (i = 0; i < 4; i++)
    printf("%02X ", emu_cmd[i]);
  printf("\n");
  printf("Read bank command set with checksum: ");
  for (i = 0; i < 4; i++)
    printf("%02X ", read_cmd[i]);
  printf("\n");
  printf("Persistent bank command set with checksum: ");
  for (i = 0; i < 4; i++)
    printf("%02X ", persis_cmd[i]);
  printf("\n");
  printf("Memset termios\n");
  memset(&theTermios, 0, sizeof(struct termios));
  printf("making raw for termios\n");
  cfmakeraw(&theTermios);
  printf("setting speed on the termios\n");
  cfsetspeed(&theTermios, 921600);
  theTermios.c_cflag |= (CREAD | CLOCAL | CS8);
  theTermios.c_cc[VMIN] = 0;
  theTermios.c_cc[VTIME] = 10;
  if (argc != 2)
    return 1;
  printf("Opening serial port\n");
  fd = open(argv[1], O_RDWR | O_NOCTTY);
  if (fd == -1) {
    printf("%s", strcat("Unable to open", argv[1]));
  }
  if (-1 == ioctl(fd, TCSETS, &theTermios))
    perror("Error with ioctl: ");
  if (0 != tcflush(fd, TCIFLUSH))
    perror("ioctl failed to flush read i/o buffer: ");
  if (0 != tcflush(fd, TCOFLUSH))
    perror("ioctl failed to flush write i/o buffer: ");
  printf("Checking read/write bank\n");
  if (4 != write(fd, read_cmd, 4))
    printf("Write failed\n");
  count = read(fd, buf, 1);
  printf("received bytes: %d\n", count);
  printf("read byte %02X - current read/write bank is: %d\n", buf[0], buf[0]);
  printf("Checking emulation bank\n");
  if (4 != write(fd, emu_cmd, 4))
    printf("Write failed\n");
  count = read(fd, buf, 1);
  printf("received bytes: %d\n", count);
  printf("read byte %02X - current emulation bank is: %d\n", buf[0], buf[0]);
  printf("Checking persistent bank\n");
  if (4 != write(fd, persis_cmd, 4))
    printf("Write failed\n");
  count = read(fd, buf, 1);
  printf("received bytes: %d\n", count);
  printf("read byte %02X - current persistent bank is: %d\n", buf[0], buf[0]);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    0xe0c(%rip),%eax
mov    %eax,-0x34(%rbp)
mov    0xe07(%rip),%eax
mov    %eax,-0x38(%rbp)
mov    0xe02(%rip),%eax
mov    %eax,-0x3c(%rbp)
movb   $0x0,-0x3d(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    123a <main+0x7a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
movl   $0x0,-0x28(%rbp)
movb   $0x0,-0x3d(%rbp)
cmpl   $0x3,-0x28(%rbp)
jge    126f <main+0xaf>
movslq -0x28(%rbp),%rax
movzbl -0x34(%rbp,%rax,1),%ecx
movzbl -0x3d(%rbp),%eax
add    %ecx,%eax
mov    %al,-0x3d(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1245 <main+0x85>
mov    -0x3d(%rbp),%al
mov    %al,-0x31(%rbp)
movl   $0x0,-0x28(%rbp)
movb   $0x0,-0x3d(%rbp)
cmpl   $0x3,-0x28(%rbp)
jge    12aa <main+0xea>
movslq -0x28(%rbp),%rax
movzbl -0x38(%rbp,%rax,1),%ecx
movzbl -0x3d(%rbp),%eax
add    %ecx,%eax
mov    %al,-0x3d(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1280 <main+0xc0>
mov    -0x3d(%rbp),%al
mov    %al,-0x35(%rbp)
movl   $0x0,-0x28(%rbp)
movb   $0x0,-0x3d(%rbp)
cmpl   $0x3,-0x28(%rbp)
jge    12e5 <main+0x125>
movslq -0x28(%rbp),%rax
movzbl -0x3c(%rbp,%rax,1),%ecx
movzbl -0x3d(%rbp),%eax
add    %ecx,%eax
mov    %al,-0x3d(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    12bb <main+0xfb>
mov    -0x3d(%rbp),%al
mov    %al,-0x39(%rbp)
lea    0xd3a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x28(%rbp)
cmpl   $0x4,-0x28(%rbp)
jge    132f <main+0x16f>
movslq -0x28(%rbp),%rax
movzbl -0x34(%rbp,%rax,1),%esi
lea    0xd3d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1300 <main+0x140>
lea    0xcf4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd19(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x28(%rbp)
cmpl   $0x4,-0x28(%rbp)
jge    1381 <main+0x1c1>
movslq -0x28(%rbp),%rax
movzbl -0x38(%rbp,%rax,1),%esi
lea    0xceb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1352 <main+0x192>
lea    0xca2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xced(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x28(%rbp)
cmpl   $0x4,-0x28(%rbp)
jge    13d3 <main+0x213>
movslq -0x28(%rbp),%rax
movzbl -0x3c(%rbp,%rax,1),%esi
lea    0xc99(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    13a4 <main+0x1e4>
lea    0xc50(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xcc7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
lea    0xcb9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x20(%rbp),%rdi
call   10a0 <cfmakeraw@plt>
lea    0xcba(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x20(%rbp),%rdi
mov    $0xe1000,%esi
call   1070 <cfsetspeed@plt>
mov    0x2b9f(%rip),%rax
mov    (%rax),%eax
mov    0x2b3e(%rip),%rcx
or     (%rcx),%eax
mov    0x2b85(%rip),%rcx
or     (%rcx),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2b6a(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
mov    0x2b1d(%rip),%rcx
mov    (%rcx),%rcx
movl   $0xa,(%rax,%rcx,4)
cmpl   $0x2,-0x8(%rbp)
je     1493 <main+0x2d3>
movl   $0x1,-0x4(%rbp)
jmp    1716 <main+0x556>
lea    0xc5b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2b30(%rip),%rax
mov    (%rax),%esi
mov    0x2af7(%rip),%rax
or     (%rax),%esi
call   10b0 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    14f2 <main+0x332>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xc31(%rip),%rdi
call   10d0 <strcat@plt>
mov    %rax,%rsi
lea    0xc1f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%edi
mov    0x2aa4(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1080 <ioctl@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1522 <main+0x362>
lea    0xbff(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x24(%rbp),%edi
mov    0x2a8c(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     154d <main+0x38d>
lea    0xbe7(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x24(%rbp),%edi
mov    0x2a99(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1578 <main+0x3b8>
lea    0xbe4(%rip),%rdi
call   10c0 <perror@plt>
lea    0xc01(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,%ecx
mov    $0x4,%eax
cmp    %ecx,%eax
je     15b4 <main+0x3f4>
lea    0xbed(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%edi
lea    -0x140(%rbp),%rsi
mov    $0x1,%edx
call   1090 <read@plt>
mov    %eax,-0x144(%rbp)
mov    -0x144(%rbp),%esi
lea    0xbcd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movzbl -0x140(%rbp),%esi
movzbl -0x140(%rbp),%edx
lea    0xbc5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xbe8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%edi
lea    -0x34(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,%ecx
mov    $0x4,%eax
cmp    %ecx,%eax
je     163a <main+0x47a>
lea    0xb67(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%edi
lea    -0x140(%rbp),%rsi
mov    $0x1,%edx
call   1090 <read@plt>
mov    %eax,-0x144(%rbp)
mov    -0x144(%rbp),%esi
lea    0xb47(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movzbl -0x140(%rbp),%esi
movzbl -0x140(%rbp),%edx
lea    0xb89(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xbab(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%edi
lea    -0x3c(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,%ecx
mov    $0x4,%eax
cmp    %ecx,%eax
je     16c0 <main+0x500>
lea    0xae1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%edi
lea    -0x140(%rbp),%rsi
mov    $0x1,%edx
call   1090 <read@plt>
mov    %eax,-0x144(%rbp)
mov    -0x144(%rbp),%esi
lea    0xac1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movzbl -0x140(%rbp),%esi
movzbl -0x140(%rbp),%edx
lea    0xb4d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2887(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x130,%rsp
mov    %rsi,%r14
movl   $0xd9524542,0xc(%rsp)
d9
movl   $0xe6525242,0x8(%rsp)
e6
movl   $0xda534542,0x4(%rsp)
da
cmp    $0x2,%edi
jl     15cb <main+0x3eb>
mov    %edi,%ebp
lea    0xe08(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe25(%rip),%rbx
mov    %rbx,%rdi
mov    $0x42,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    $0x45,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    $0x52,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    $0xd9,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xdde(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    $0x42,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    $0x52,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    $0x52,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    $0xe6,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xdb0(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    $0x42,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    $0x45,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    $0x53,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    $0xda,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xea4(%rip),%rdi
call   1040 <puts@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
lea    0xe93(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   10c0 <cfmakeraw@plt>
lea    0xe96(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    $0xe1000,%esi
call   1090 <cfsetspeed@plt>
mov    0x2c70(%rip),%rax
mov    0x2c11(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2c56(%rip),%rax
or     (%rax),%ecx
or     %ecx,0x10(%rsp)
mov    0x18(%rsp),%rax
mov    0x2c3c(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2bf3(%rip),%rcx
mov    (%rcx),%rcx
movl   $0xa,(%rax,%rcx,4)
mov    $0x1,%eax
cmp    $0x2,%ebp
jne    158c <main+0x3ac>
lea    0xe46(%rip),%rdi
call   1040 <puts@plt>
mov    0x8(%r14),%rdi
mov    0x2c14(%rip),%rax
mov    0x2bdd(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   10d0 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    1407 <main+0x227>
mov    0x8(%r14),%rsi
lea    0xcb8(%rip),%rbp
mov    %rbp,%rdi
call   10f0 <strcat@plt>
lea    0xca6(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2b92(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
mov    %ebx,%edi
call   10a0 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1598 <main+0x3b8>
mov    0x2b8c(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1060 <tcflush@plt>
test   %rax,%rax
jne    15a9 <main+0x3c9>
mov    0x2bab(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1060 <tcflush@plt>
test   %rax,%rax
jne    15ba <main+0x3da>
lea    0xdb8(%rip),%rdi
call   1040 <puts@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1050 <write@plt>
cmp    $0x4,%eax
je     1485 <main+0x2a5>
lea    0xde0(%rip),%rdi
call   1040 <puts@plt>
lea    0x20(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   10b0 <read@plt>
lea    0xc7c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
movzbl 0x20(%rsp),%edx
lea    0xc7b(%rip),%rdi
mov    %edx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xd6d(%rip),%rdi
call   1040 <puts@plt>
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1050 <write@plt>
cmp    $0x4,%eax
je     14e9 <main+0x309>
lea    0xd7c(%rip),%rdi
call   1040 <puts@plt>
lea    0x20(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   10b0 <read@plt>
lea    0xc18(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
movzbl 0x20(%rsp),%edx
lea    0xc48(%rip),%rdi
mov    %edx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xd21(%rip),%rdi
call   1040 <puts@plt>
lea    0x4(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1050 <write@plt>
cmp    $0x4,%eax
je     154d <main+0x36d>
lea    0xd18(%rip),%rdi
call   1040 <puts@plt>
lea    0x20(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   10b0 <read@plt>
lea    0xbb4(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
movzbl 0x20(%rsp),%edx
lea    0xc14(%rip),%rdi
mov    %edx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2a0e(%rip),%rax
mov    (%rax),%eax
add    $0x130,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xb16(%rip),%rdi
call   10e0 <perror@plt>
jmp    1425 <main+0x245>
lea    0xb18(%rip),%rdi
call   10e0 <perror@plt>
jmp    143e <main+0x25e>
lea    0xb2f(%rip),%rdi
call   10e0 <perror@plt>
jmp    1457 <main+0x277>
mov    (%r14),%rsi
lea    0xa2b(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x29c5(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32, i32* }
@__const.main.emu_cmd = [4 x i8] c"BER\00"
@__const.main.read_cmd = [4 x i8] c"BRR\00"
@__const.main.persis_cmd = [4 x i8] c"BES\00"
@.str = [32 x i8] c"Usage: %s <serial port device>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [43 x i8] c"Emulation bank command set with checksum: \00"
@.str.2 = [6 x i8] c"%02X \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [38 x i8] c"Read bank command set with checksum: \00"
@.str.5 = [44 x i8] c"Persistent bank command set with checksum: \00"
@.str.6 = [16 x i8] c"Memset termios\0A\00"
@.str.7 = [24 x i8] c"making raw for termios\0A\00"
@.str.8 = [30 x i8] c"setting speed on the termios\0A\00"
@CREAD = global i32 0
@CLOCAL = global i32 0
@CS8 = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@.str.9 = [21 x i8] c"Opening serial port\0A\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@.str.10 = [3 x i8] c"%s\00"
@.str.11 = [15 x i8] c"Unable to open\00"
@TCSETS = global i32 0
@.str.12 = [19 x i8] c"Error with ioctl: \00"
@TCIFLUSH = global i32 0
@.str.13 = [40 x i8] c"ioctl failed to flush read i/o buffer: \00"
@TCOFLUSH = global i32 0
@.str.14 = [41 x i8] c"ioctl failed to flush write i/o buffer: \00"
@.str.15 = [26 x i8] c"Checking read/write bank\0A\00"
@.str.16 = [14 x i8] c"Write failed\0A\00"
@.str.17 = [20 x i8] c"received bytes: %d\0A\00"
@.str.18 = [49 x i8] c"read byte %02X - current read/write bank is: %d\0A\00"
@.str.19 = [25 x i8] c"Checking emulation bank\0A\00"
@.str.20 = [48 x i8] c"read byte %02X - current emulation bank is: %d\0A\00"
@.str.21 = [26 x i8] c"Checking persistent bank\0A\00"
@.str.22 = [49 x i8] c"read byte %02X - current persistent bank is: %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.termios
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [4 x i8]
%12 = alloca [4 x i8]
%13 = alloca [4 x i8]
%14 = alloca i8
%15 = alloca [257 x i8]
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
%17 = bitcast [4 x i8]* %11 to i8*
%18 = bitcast [4 x i8]* %12 to i8*
%19 = bitcast [4 x i8]* %13 to i8*
store i8 0, i8* %14
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 2
br i1 %21, label %22, label %29
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %25)
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %2
store i32 0, i32* %8
store i8 0, i8* %14
br label %30
30: ; preds = %43, %29
%31 = load i32, i32* %8
%32 = icmp slt i32 %31, 3
br i1 %32, label %33, label %46
33: ; preds = %30
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 %35
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = load i8, i8* %14
%40 = zext i8 %39 to i32
%41 = add nsw i32 %40, %38
%42 = trunc i32 %41 to i8
store i8 %42, i8* %14
br label %43
43: ; preds = %33
%44 = load i32, i32* %8
%45 = add nsw i32 %44, 1
store i32 %45, i32* %8
br label %30
46: ; preds = %30
%47 = load i8, i8* %14
%48 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 3
store i8 %47, i8* %48
store i32 0, i32* %8
store i8 0, i8* %14
br label %49
49: ; preds = %62, %46
%50 = load i32, i32* %8
%51 = icmp slt i32 %50, 3
br i1 %51, label %52, label %65
52: ; preds = %49
%53 = load i32, i32* %8
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [4 x i8], [4 x i8]* %12, i64 0, i64 %54
%56 = load i8, i8* %55
%57 = zext i8 %56 to i32
%58 = load i8, i8* %14
%59 = zext i8 %58 to i32
%60 = add nsw i32 %59, %57
%61 = trunc i32 %60 to i8
store i8 %61, i8* %14
br label %62
62: ; preds = %52
%63 = load i32, i32* %8
%64 = add nsw i32 %63, 1
store i32 %64, i32* %8
br label %49
65: ; preds = %49
%66 = load i8, i8* %14
%67 = getelementptr inbounds [4 x i8], [4 x i8]* %12, i64 0, i64 3
store i8 %66, i8* %67
store i32 0, i32* %8
store i8 0, i8* %14
br label %68
68: ; preds = %81, %65
%69 = load i32, i32* %8
%70 = icmp slt i32 %69, 3
br i1 %70, label %71, label %84
71: ; preds = %68
%72 = load i32, i32* %8
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 %73
%75 = load i8, i8* %74
%76 = zext i8 %75 to i32
%77 = load i8, i8* %14
%78 = zext i8 %77 to i32
%79 = add nsw i32 %78, %76
%80 = trunc i32 %79 to i8
store i8 %80, i8* %14
br label %81
81: ; preds = %71
%82 = load i32, i32* %8
%83 = add nsw i32 %82, 1
store i32 %83, i32* %8
br label %68
84: ; preds = %68
%85 = load i8, i8* %14
%86 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 3
store i8 %85, i8* %86
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %8
br label %88
88: ; preds = %98, %84
%89 = load i32, i32* %8
%90 = icmp slt i32 %89, 4
br i1 %90, label %91, label %101
91: ; preds = %88
%92 = load i32, i32* %8
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 %93
%95 = load i8, i8* %94
%96 = zext i8 %95 to i32
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %96)
br label %98
98: ; preds = %91
%99 = load i32, i32* %8
%100 = add nsw i32 %99, 1
store i32 %100, i32* %8
br label %88
101: ; preds = %88
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %8
br label %104
104: ; preds = %114, %101
%105 = load i32, i32* %8
%106 = icmp slt i32 %105, 4
br i1 %106, label %107, label %117
107: ; preds = %104
%108 = load i32, i32* %8
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds [4 x i8], [4 x i8]* %12, i64 0, i64 %109
%111 = load i8, i8* %110
%112 = zext i8 %111 to i32
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %112)
br label %114
114: ; preds = %107
%115 = load i32, i32* %8
%116 = add nsw i32 %115, 1
store i32 %116, i32* %8
br label %104
117: ; preds = %104
%118 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%119 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %8
br label %120
120: ; preds = %130, %117
%121 = load i32, i32* %8
%122 = icmp slt i32 %121, 4
br i1 %122, label %123, label %133
123: ; preds = %120
%124 = load i32, i32* %8
%125 = sext i32 %124 to i64
%126 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 %125
%127 = load i8, i8* %126
%128 = zext i8 %127 to i32
%129 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %128)
br label %130
130: ; preds = %123
%131 = load i32, i32* %8
%132 = add nsw i32 %131, 1
store i32 %132, i32* %8
br label %120
133: ; preds = %120
%134 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%135 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%136 = call i32 @memset(%struct.termios* %6, i32 0, i32 16)
%137 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0))
%138 = call i32 @cfmakeraw(%struct.termios* %6)
%139 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0))
%140 = call i32 @cfsetspeed(%struct.termios* %6, i32 921600)
%141 = load i32, i32* @CREAD
%142 = load i32, i32* @CLOCAL
%143 = or i32 %141, %142
%144 = load i32, i32* @CS8
%145 = or i32 %143, %144
%146 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%147 = load i32, i32* %146
%148 = or i32 %147, %145
store i32 %148, i32* %146
%149 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%150 = load i32*, i32** %149
%151 = load i64, i64* @VMIN
%152 = getelementptr inbounds i32, i32* %150, i64 %151
store i32 0, i32* %152
%153 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%154 = load i32*, i32** %153
%155 = load i64, i64* @VTIME
%156 = getelementptr inbounds i32, i32* %154, i64 %155
store i32 10, i32* %156
%157 = load i32, i32* %4
%158 = icmp ne i32 %157, 2
br i1 %158, label %159, label %160
159: ; preds = %133
store i32 1, i32* %3
br label %260
160: ; preds = %133
%161 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0))
%162 = load i8**, i8*** %5
%163 = getelementptr inbounds i8*, i8** %162, i64 1
%164 = load i8*, i8** %163
%165 = load i32, i32* @O_RDWR
%166 = load i32, i32* @O_NOCTTY
%167 = or i32 %165, %166
%168 = call i32 @open(i8* %164, i32 %167)
store i32 %168, i32* %7
%169 = load i32, i32* %7
%170 = icmp eq i32 %169, -1
br i1 %170, label %171, label %177
171: ; preds = %160
%172 = load i8**, i8*** %5
%173 = getelementptr inbounds i8*, i8** %172, i64 1
%174 = load i8*, i8** %173
%175 = call i8* @strcat(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0), i8* %174)
%176 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i8* %175)
br label %177
177: ; preds = %171, %160
%178 = load i32, i32* %7
%179 = load i32, i32* @TCSETS
%180 = call i32 @ioctl(i32 %178, i32 %179, %struct.termios* %6)
%181 = icmp eq i32 -1, %180
br i1 %181, label %182, label %184
182: ; preds = %177
%183 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.12, i64 0, i64 0))
br label %184
184: ; preds = %182, %177
%185 = load i32, i32* %7
%186 = load i32, i32* @TCIFLUSH
%187 = call i64 @tcflush(i32 %185, i32 %186)
%188 = icmp ne i64 0, %187
br i1 %188, label %189, label %191
189: ; preds = %184
%190 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.13, i64 0, i64 0))
br label %191
191: ; preds = %189, %184
%192 = load i32, i32* %7
%193 = load i32, i32* @TCOFLUSH
%194 = call i64 @tcflush(i32 %192, i32 %193)
%195 = icmp ne i64 0, %194
br i1 %195, label %196, label %198
196: ; preds = %191
%197 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.14, i64 0, i64 0))
br label %198
198: ; preds = %196, %191
%199 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.15, i64 0, i64 0))
%200 = load i32, i32* %7
%201 = getelementptr inbounds [4 x i8], [4 x i8]* %12, i64 0, i64 0
%202 = call i32 @write(i32 %200, i8* %201, i32 4)
%203 = icmp ne i32 4, %202
br i1 %203, label %204, label %206
204: ; preds = %198
%205 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.16, i64 0, i64 0))
br label %206
206: ; preds = %204, %198
%207 = load i32, i32* %7
%208 = getelementptr inbounds [257 x i8], [257 x i8]* %15, i64 0, i64 0
%209 = call i32 @read(i32 %207, i8* %208, i32 1)
store i32 %209, i32* %16
%210 = load i32, i32* %16
%211 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.17, i64 0, i64 0), i32 %210)
%212 = getelementptr inbounds [257 x i8], [257 x i8]* %15, i64 0, i64 0
%213 = load i8, i8* %212
%214 = zext i8 %213 to i32
%215 = getelementptr inbounds [257 x i8], [257 x i8]* %15, i64 0, i64 0
%216 = load i8, i8* %215
%217 = zext i8 %216 to i32
%218 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.18, i64 0, i64 0), i32 %214, i32 %217)
%219 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.19, i64 0, i64 0))
%220 = load i32, i32* %7
%221 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 0
%222 = call i32 @write(i32 %220, i8* %221, i32 4)
%223 = icmp ne i32 4, %222
br i1 %223, label %224, label %226
224: ; preds = %206
%225 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.16, i64 0, i64 0))
br label %226
226: ; preds = %224, %206
%227 = load i32, i32* %7
%228 = getelementptr inbounds [257 x i8], [257 x i8]* %15, i64 0, i64 0
%229 = call i32 @read(i32 %227, i8* %228, i32 1)
store i32 %229, i32* %16
%230 = load i32, i32* %16
%231 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.17, i64 0, i64 0), i32 %230)
%232 = getelementptr inbounds [257 x i8], [257 x i8]* %15, i64 0, i64 0
%233 = load i8, i8* %232
%234 = zext i8 %233 to i32
%235 = getelementptr inbounds [257 x i8], [257 x i8]* %15, i64 0, i64 0
%236 = load i8, i8* %235
%237 = zext i8 %236 to i32
%238 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.20, i64 0, i64 0), i32 %234, i32 %237)
%239 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.21, i64 0, i64 0))
%240 = load i32, i32* %7
%241 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 0
%242 = call i32 @write(i32 %240, i8* %241, i32 4)
%243 = icmp ne i32 4, %242
br i1 %243, label %244, label %246
244: ; preds = %226
%245 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.16, i64 0, i64 0))
br label %246
246: ; preds = %244, %226
%247 = load i32, i32* %7
%248 = getelementptr inbounds [257 x i8], [257 x i8]* %15, i64 0, i64 0
%249 = call i32 @read(i32 %247, i8* %248, i32 1)
store i32 %249, i32* %16
%250 = load i32, i32* %16
%251 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.17, i64 0, i64 0), i32 %250)
%252 = getelementptr inbounds [257 x i8], [257 x i8]* %15, i64 0, i64 0
%253 = load i8, i8* %252
%254 = zext i8 %253 to i32
%255 = getelementptr inbounds [257 x i8], [257 x i8]* %15, i64 0, i64 0
%256 = load i8, i8* %255
%257 = zext i8 %256 to i32
%258 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.22, i64 0, i64 0), i32 %254, i32 %257)
%259 = load i32, i32* @EXIT_SUCCESS
store i32 %259, i32* %3
br label %260
260: ; preds = %246, %159
%261 = load i32, i32* %3
ret i32 %261
}

LLVM IR (-O2):
%struct.termios = type { i32, i32* }
@.str = [32 x i8] c"Usage: %s <serial port device>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [43 x i8] c"Emulation bank command set with checksum: \00"
@.str.2 = [6 x i8] c"%02X \00"
@.str.4 = [38 x i8] c"Read bank command set with checksum: \00"
@.str.5 = [44 x i8] c"Persistent bank command set with checksum: \00"
@CREAD = global i32 0
@CLOCAL = global i32 0
@CS8 = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@.str.10 = [3 x i8] c"%s\00"
@.str.11 = [15 x i8] c"Unable to open\00"
@TCSETS = global i32 0
@.str.12 = [19 x i8] c"Error with ioctl: \00"
@TCIFLUSH = global i32 0
@.str.13 = [40 x i8] c"ioctl failed to flush read i/o buffer: \00"
@TCOFLUSH = global i32 0
@.str.14 = [41 x i8] c"ioctl failed to flush write i/o buffer: \00"
@.str.17 = [20 x i8] c"received bytes: %d\0A\00"
@.str.18 = [49 x i8] c"read byte %02X - current read/write bank is: %d\0A\00"
@.str.20 = [48 x i8] c"read byte %02X - current emulation bank is: %d\0A\00"
@.str.22 = [49 x i8] c"read byte %02X - current persistent bank is: %d\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [15 x i8] c"Memset termios\00"
@str.23 = [23 x i8] c"making raw for termios\00"
@str.24 = [29 x i8] c"setting speed on the termios\00"
@str.25 = [20 x i8] c"Opening serial port\00"
@str.26 = [25 x i8] c"Checking read/write bank\00"
@str.27 = [24 x i8] c"Checking emulation bank\00"
@str.28 = [25 x i8] c"Checking persistent bank\00"
@str.31 = [13 x i8] c"Write failed\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.termios
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [257 x i8]
%8 = bitcast %struct.termios* %3 to i8*
%9 = bitcast i32* %4 to i8*
store i32 -648919742, i32* %4
%10 = bitcast i32* %5 to i8*
store i32 -430812606, i32* %5
%11 = bitcast i32* %6 to i8*
store i32 -632076990, i32* %6
%12 = getelementptr inbounds [257 x i8], [257 x i8]* %7, i64 0, i64 0
%13 = icmp slt i32 %0, 2
br i1 %13, label %54, label %14
14: ; preds = %2
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 66)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 69)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 82)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 217)
%20 = tail call i32 @putchar(i32 10)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0))
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 66)
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 82)
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 82)
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 230)
%26 = tail call i32 @putchar(i32 10)
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0))
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 66)
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 69)
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 83)
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 218)
%32 = tail call i32 @putchar(i32 10)
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%34 = call i32 @memset(%struct.termios* %3, i32 0, i32 16)
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.23, i64 0, i64 0))
%36 = call i32 @cfmakeraw(%struct.termios* %3)
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.24, i64 0, i64 0))
%38 = call i32 @cfsetspeed(%struct.termios* %3, i32 921600)
%39 = load i32, i32* @CREAD
%40 = load i32, i32* @CLOCAL
%41 = or i32 %40, %39
%42 = load i32, i32* @CS8
%43 = or i32 %41, %42
%44 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%45 = load i32, i32* %44
%46 = or i32 %43, %45
store i32 %46, i32* %44
%47 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
%48 = load i32*, i32** %47
%49 = load i64, i64* @VMIN
%50 = getelementptr inbounds i32, i32* %48, i64 %49
store i32 0, i32* %50
%51 = load i64, i64* @VTIME
%52 = getelementptr inbounds i32, i32* %48, i64 %51
store i32 10, i32* %52
%53 = icmp eq i32 %0, 2
br i1 %53, label %59, label %125
54: ; preds = %2
%55 = load i8*, i8** %1
%56 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %55)
%57 = load i32, i32* @EXIT_FAILURE
%58 = tail call i32 @exit(i32 %57)
unreachable
59: ; preds = %14
%60 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.25, i64 0, i64 0))
%61 = getelementptr inbounds i8*, i8** %1, i64 1
%62 = load i8*, i8** %61
%63 = load i32, i32* @O_RDWR
%64 = load i32, i32* @O_NOCTTY
%65 = or i32 %64, %63
%66 = call i32 @open(i8* %62, i32 %65)
%67 = icmp eq i32 %66, -1
br i1 %67, label %68, label %72
68: ; preds = %59
%69 = load i8*, i8** %61
%70 = call i8* @strcat(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0), i8* dereferenceable(1) %69)
%71 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0))
br label %72
72: ; preds = %68, %59
%73 = load i32, i32* @TCSETS
%74 = call i32 @ioctl(i32 %66, i32 %73, %struct.termios* %3)
%75 = icmp eq i32 %74, -1
br i1 %75, label %76, label %78
76: ; preds = %72
%77 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.12, i64 0, i64 0))
br label %78
78: ; preds = %76, %72
%79 = load i32, i32* @TCIFLUSH
%80 = call i64 @tcflush(i32 %66, i32 %79)
%81 = icmp eq i64 %80, 0
br i1 %81, label %84, label %82
82: ; preds = %78
%83 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.13, i64 0, i64 0))
br label %84
84: ; preds = %82, %78
%85 = load i32, i32* @TCOFLUSH
%86 = call i64 @tcflush(i32 %66, i32 %85)
%87 = icmp eq i64 %86, 0
br i1 %87, label %90, label %88
88: ; preds = %84
%89 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.14, i64 0, i64 0))
br label %90
90: ; preds = %88, %84
%91 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.26, i64 0, i64 0))
%92 = call i32 @write(i32 %66, i8* %10, i32 4)
%93 = icmp eq i32 %92, 4
br i1 %93, label %96, label %94
94: ; preds = %90
%95 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.31, i64 0, i64 0))
br label %96
96: ; preds = %94, %90
%97 = call i32 @read(i32 %66, i8* %12, i32 1)
%98 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.17, i64 0, i64 0), i32 %97)
%99 = load i8, i8* %12
%100 = zext i8 %99 to i32
%101 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.18, i64 0, i64 0), i32 %100, i32 %100)
%102 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.27, i64 0, i64 0))
%103 = call i32 @write(i32 %66, i8* %9, i32 4)
%104 = icmp eq i32 %103, 4
br i1 %104, label %107, label %105
105: ; preds = %96
%106 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.31, i64 0, i64 0))
br label %107
107: ; preds = %105, %96
%108 = call i32 @read(i32 %66, i8* %12, i32 1)
%109 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.17, i64 0, i64 0), i32 %108)
%110 = load i8, i8* %12
%111 = zext i8 %110 to i32
%112 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.20, i64 0, i64 0), i32 %111, i32 %111)
%113 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.28, i64 0, i64 0))
%114 = call i32 @write(i32 %66, i8* %11, i32 4)
%115 = icmp eq i32 %114, 4
br i1 %115, label %118, label %116
116: ; preds = %107
%117 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.31, i64 0, i64 0))
br label %118
118: ; preds = %116, %107
%119 = call i32 @read(i32 %66, i8* %12, i32 1)
%120 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.17, i64 0, i64 0), i32 %119)
%121 = load i8, i8* %12
%122 = zext i8 %121 to i32
%123 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.22, i64 0, i64 0), i32 %122, i32 %122)
%124 = load i32, i32* @EXIT_SUCCESS
br label %125
125: ; preds = %14, %118
%126 = phi i32 [ %124, %118 ], [ 1, %14 ]
ret i32 %126
}