#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;
  int bsize = (0x40 * 256);
  unsigned char read_cmd[] = {'Z', 'R', bsize / 256, 0x00, 0x00, 0x00};
  unsigned char checksum = 0;
  unsigned char buf[65537];
  int count;
  if (argc < 2) {
    printf("Usage: %s <serial port device>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  for (checksum = i = 0; i < 5; i++)
    checksum += read_cmd[i];
  read_cmd[5] = checksum;
  printf("Read block command set with checksum: ");
  for (i = 0; i < 6; i++)
    printf("%02X ", read_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] = 1;
  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("sending read block command\n");
  if (6 != write(fd, read_cmd, 6))
    printf("Write failed\n");
  j = count = read(fd, buf, bsize + 1);
  while (j < bsize + 1) {
    printf("received bytes: %d requested read of size: %d total read: %d\n",
           count, bsize + 1, j);
    count = read(fd, buf, bsize + 1);
    j += count;
  }
  printf("final received bytes: %d requested read of size: %d total read: %d\n",
         count, bsize + 1, j);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10050,%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)
movl   $0x4000,-0x34(%rbp)
movb   $0x5a,-0x3a(%rbp)
movb   $0x52,-0x39(%rbp)
mov    -0x34(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %al,-0x38(%rbp)
movb   $0x0,-0x37(%rbp)
movb   $0x0,-0x36(%rbp)
movb   $0x0,-0x35(%rbp)
movb   $0x0,-0x3b(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1248 <main+0x88>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
movl   $0x0,-0x28(%rbp)
movb   $0x0,-0x3b(%rbp)
cmpl   $0x5,-0x28(%rbp)
jge    127d <main+0xbd>
movslq -0x28(%rbp),%rax
movzbl -0x3a(%rbp,%rax,1),%ecx
movzbl -0x3b(%rbp),%eax
add    %ecx,%eax
mov    %al,-0x3b(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1253 <main+0x93>
mov    -0x3b(%rbp),%al
mov    %al,-0x35(%rbp)
lea    0xd96(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x28(%rbp)
cmpl   $0x6,-0x28(%rbp)
jge    12c7 <main+0x107>
movslq -0x28(%rbp),%rax
movzbl -0x3a(%rbp,%rax,1),%esi
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1298 <main+0xd8>
lea    0xd50(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd71(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
lea    0xd63(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x20(%rbp),%rdi
call   10a0 <cfmakeraw@plt>
lea    0xd64(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x20(%rbp),%rdi
mov    $0xe1000,%esi
call   1070 <cfsetspeed@plt>
mov    0x2cab(%rip),%rax
mov    (%rax),%eax
mov    0x2c4a(%rip),%rcx
or     (%rcx),%eax
mov    0x2c91(%rip),%rcx
or     (%rcx),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2c76(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
mov    0x2c29(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
cmpl   $0x2,-0x8(%rbp)
je     1387 <main+0x1c7>
movl   $0x1,-0x4(%rbp)
jmp    1549 <main+0x389>
lea    0xd05(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2c3c(%rip),%rax
mov    (%rax),%esi
mov    0x2c03(%rip),%rax
or     (%rax),%esi
call   10b0 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    13e6 <main+0x226>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xcdb(%rip),%rdi
call   10d0 <strcat@plt>
mov    %rax,%rsi
lea    0xcc9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%edi
mov    0x2bb0(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1080 <ioctl@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1416 <main+0x256>
lea    0xca9(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x24(%rbp),%edi
mov    0x2b98(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1441 <main+0x281>
lea    0xc91(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x24(%rbp),%edi
mov    0x2ba5(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     146c <main+0x2ac>
lea    0xc8e(%rip),%rdi
call   10c0 <perror@plt>
lea    0xcab(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%edi
lea    -0x3a(%rbp),%rsi
mov    $0x6,%edx
call   1030 <write@plt>
mov    %eax,%ecx
mov    $0x6,%eax
cmp    %ecx,%eax
je     14a8 <main+0x2e8>
lea    0xc99(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%edi
lea    -0x10040(%rbp),%rsi
mov    -0x34(%rbp),%edx
add    $0x1,%edx
call   1090 <read@plt>
mov    %eax,-0x10044(%rbp)
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    1520 <main+0x360>
mov    -0x10044(%rbp),%esi
mov    -0x34(%rbp),%edx
add    $0x1,%edx
mov    -0x2c(%rbp),%ecx
lea    0xc61(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%edi
lea    -0x10040(%rbp),%rsi
mov    -0x34(%rbp),%edx
add    $0x1,%edx
call   1090 <read@plt>
mov    %eax,-0x10044(%rbp)
mov    -0x10044(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    14c6 <main+0x306>
mov    -0x10044(%rbp),%esi
mov    -0x34(%rbp),%edx
add    $0x1,%edx
mov    -0x2c(%rbp),%ecx
lea    0xc12(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2a54(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x10028,%rsp
mov    %rsi,%r14
movl   $0x40525a,0xa(%rsp)
movb   $0x0,0xe(%rsp)
cmp    $0x2,%edi
jl     14b2 <main+0x2d2>
mov    %edi,%ebx
movb   $0xec,0xf(%rsp)
lea    0xe0c(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe25(%rip),%rbp
mov    %rbp,%rdi
mov    $0x5a,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbp,%rdi
mov    $0x52,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbp,%rdi
mov    $0x40,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbp,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbp,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbp,%rdi
mov    $0xec,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe80(%rip),%rdi
call   1040 <puts@plt>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
lea    0xe6f(%rip),%rdi
call   1040 <puts@plt>
mov    %rbp,%rdi
call   10c0 <cfmakeraw@plt>
lea    0xe72(%rip),%rdi
call   1040 <puts@plt>
mov    %rbp,%rdi
mov    $0xe1000,%esi
call   1090 <cfsetspeed@plt>
mov    0x2d04(%rip),%rax
mov    0x2ca5(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2cea(%rip),%rax
or     (%rax),%ecx
or     %ecx,0x10(%rsp)
mov    0x18(%rsp),%rax
mov    0x2cd0(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2c87(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    $0x1,%eax
cmp    $0x2,%ebx
jne    1471 <main+0x291>
lea    0xe22(%rip),%rdi
call   1040 <puts@plt>
mov    0x8(%r14),%rdi
mov    0x2ca8(%rip),%rax
mov    0x2c71(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   10d0 <open@plt>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
jne    1374 <main+0x194>
mov    0x8(%r14),%rsi
lea    0xcf5(%rip),%rbx
mov    %rbx,%rdi
call   10f0 <strcat@plt>
lea    0xce3(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2c25(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
mov    %r15d,%edi
call   10a0 <ioctl@plt>
cmp    $0xffffffff,%eax
je     147f <main+0x29f>
mov    0x2c1e(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
call   1060 <tcflush@plt>
test   %rax,%rax
jne    1490 <main+0x2b0>
mov    0x2c3c(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
call   1060 <tcflush@plt>
test   %rax,%rax
jne    14a1 <main+0x2c1>
lea    0xd90(%rip),%rdi
call   1040 <puts@plt>
lea    0xa(%rsp),%rsi
mov    %r15d,%edi
mov    $0x6,%edx
call   1050 <write@plt>
cmp    $0x6,%eax
je     13f6 <main+0x216>
lea    0xd88(%rip),%rdi
call   1040 <puts@plt>
lea    0x20(%rsp),%rsi
mov    %r15d,%edi
mov    $0x4001,%edx
call   10b0 <read@plt>
cmp    $0x4000,%eax
jg     144f <main+0x26f>
lea    0xcb3(%rip),%r14
lea    0x20(%rsp),%rbx
mov    %eax,%ebp
nopl   (%rax)
mov    %r14,%rdi
mov    %eax,%esi
mov    $0x4001,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x4001,%edx
call   10b0 <read@plt>
add    %eax,%ebp
cmp    $0x4001,%ebp
jl     1420 <main+0x240>
jmp    1451 <main+0x271>
mov    %eax,%ebp
lea    0xc6b(%rip),%rdi
mov    %eax,%esi
mov    $0x4001,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2b29(%rip),%rax
mov    (%rax),%eax
add    $0x10028,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xbd9(%rip),%rdi
call   10e0 <perror@plt>
jmp    1393 <main+0x1b3>
lea    0xbdb(%rip),%rdi
call   10e0 <perror@plt>
jmp    13ad <main+0x1cd>
lea    0xbf2(%rip),%rdi
call   10e0 <perror@plt>
jmp    13c7 <main+0x1e7>
mov    (%r14),%rsi
lea    0xb44(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2ade(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32, i32* }
@.str = [32 x i8] c"Usage: %s <serial port device>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [39 x i8] c"Read block command set with checksum: \00"
@.str.2 = [6 x i8] c"%02X \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [16 x i8] c"Memset termios\0A\00"
@.str.5 = [24 x i8] c"making raw for termios\0A\00"
@.str.6 = [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.7 = [21 x i8] c"Opening serial port\0A\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@.str.8 = [3 x i8] c"%s\00"
@.str.9 = [15 x i8] c"Unable to open\00"
@TCSETS = global i32 0
@.str.10 = [19 x i8] c"Error with ioctl: \00"
@TCIFLUSH = global i32 0
@.str.11 = [40 x i8] c"ioctl failed to flush read i/o buffer: \00"
@TCOFLUSH = global i32 0
@.str.12 = [41 x i8] c"ioctl failed to flush write i/o buffer: \00"
@.str.13 = [28 x i8] c"sending read block command\0A\00"
@.str.14 = [14 x i8] c"Write failed\0A\00"
@.str.15 = [62 x i8] c"received bytes: %d requested read of size: %d total read: %d\0A\00"
@.str.16 = [68 x i8] c"final received bytes: %d requested read of size: %d total read: %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 i32
%12 = alloca [6 x i8]
%13 = alloca i8
%14 = alloca [65537 x i8]
%15 = 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
store i32 16384, i32* %11
%16 = getelementptr inbounds [6 x i8], [6 x i8]* %12, i64 0, i64 0
store i8 90, i8* %16
%17 = getelementptr inbounds i8, i8* %16, i64 1
store i8 82, i8* %17
%18 = getelementptr inbounds i8, i8* %17, i64 1
%19 = load i32, i32* %11
%20 = sdiv i32 %19, 256
%21 = trunc i32 %20 to i8
store i8 %21, i8* %18
%22 = getelementptr inbounds i8, i8* %18, i64 1
store i8 0, i8* %22
%23 = getelementptr inbounds i8, i8* %22, i64 1
store i8 0, i8* %23
%24 = getelementptr inbounds i8, i8* %23, i64 1
store i8 0, i8* %24
store i8 0, i8* %13
%25 = load i32, i32* %4
%26 = icmp slt i32 %25, 2
br i1 %26, label %27, label %34
27: ; preds = %2
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 0
%30 = load i8*, i8** %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %30)
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %2
store i32 0, i32* %8
store i8 0, i8* %13
br label %35
35: ; preds = %48, %34
%36 = load i32, i32* %8
%37 = icmp slt i32 %36, 5
br i1 %37, label %38, label %51
38: ; preds = %35
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [6 x i8], [6 x i8]* %12, i64 0, i64 %40
%42 = load i8, i8* %41
%43 = zext i8 %42 to i32
%44 = load i8, i8* %13
%45 = zext i8 %44 to i32
%46 = add nsw i32 %45, %43
%47 = trunc i32 %46 to i8
store i8 %47, i8* %13
br label %48
48: ; preds = %38
%49 = load i32, i32* %8
%50 = add nsw i32 %49, 1
store i32 %50, i32* %8
br label %35
51: ; preds = %35
%52 = load i8, i8* %13
%53 = getelementptr inbounds [6 x i8], [6 x i8]* %12, i64 0, i64 5
store i8 %52, i8* %53
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %8
br label %55
55: ; preds = %65, %51
%56 = load i32, i32* %8
%57 = icmp slt i32 %56, 6
br i1 %57, label %58, label %68
58: ; preds = %55
%59 = load i32, i32* %8
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [6 x i8], [6 x i8]* %12, i64 0, i64 %60
%62 = load i8, i8* %61
%63 = zext i8 %62 to i32
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %63)
br label %65
65: ; preds = %58
%66 = load i32, i32* %8
%67 = add nsw i32 %66, 1
store i32 %67, i32* %8
br label %55
68: ; preds = %55
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%71 = call i32 @memset(%struct.termios* %6, i32 0, i32 16)
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%73 = call i32 @cfmakeraw(%struct.termios* %6)
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
%75 = call i32 @cfsetspeed(%struct.termios* %6, i32 921600)
%76 = load i32, i32* @CREAD
%77 = load i32, i32* @CLOCAL
%78 = or i32 %76, %77
%79 = load i32, i32* @CS8
%80 = or i32 %78, %79
%81 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%82 = load i32, i32* %81
%83 = or i32 %82, %80
store i32 %83, i32* %81
%84 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%85 = load i32*, i32** %84
%86 = load i64, i64* @VMIN
%87 = getelementptr inbounds i32, i32* %85, i64 %86
store i32 0, i32* %87
%88 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%89 = load i32*, i32** %88
%90 = load i64, i64* @VTIME
%91 = getelementptr inbounds i32, i32* %89, i64 %90
store i32 1, i32* %91
%92 = load i32, i32* %4
%93 = icmp ne i32 %92, 2
br i1 %93, label %94, label %95
94: ; preds = %68
store i32 1, i32* %3
br label %173
95: ; preds = %68
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0))
%97 = load i8**, i8*** %5
%98 = getelementptr inbounds i8*, i8** %97, i64 1
%99 = load i8*, i8** %98
%100 = load i32, i32* @O_RDWR
%101 = load i32, i32* @O_NOCTTY
%102 = or i32 %100, %101
%103 = call i32 @open(i8* %99, i32 %102)
store i32 %103, i32* %7
%104 = load i32, i32* %7
%105 = icmp eq i32 %104, -1
br i1 %105, label %106, label %112
106: ; preds = %95
%107 = load i8**, i8*** %5
%108 = getelementptr inbounds i8*, i8** %107, i64 1
%109 = load i8*, i8** %108
%110 = call i8* @strcat(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), i8* %109)
%111 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* %110)
br label %112
112: ; preds = %106, %95
%113 = load i32, i32* %7
%114 = load i32, i32* @TCSETS
%115 = call i32 @ioctl(i32 %113, i32 %114, %struct.termios* %6)
%116 = icmp eq i32 -1, %115
br i1 %116, label %117, label %119
117: ; preds = %112
%118 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0))
br label %119
119: ; preds = %117, %112
%120 = load i32, i32* %7
%121 = load i32, i32* @TCIFLUSH
%122 = call i64 @tcflush(i32 %120, i32 %121)
%123 = icmp ne i64 0, %122
br i1 %123, label %124, label %126
124: ; preds = %119
%125 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.11, i64 0, i64 0))
br label %126
126: ; preds = %124, %119
%127 = load i32, i32* %7
%128 = load i32, i32* @TCOFLUSH
%129 = call i64 @tcflush(i32 %127, i32 %128)
%130 = icmp ne i64 0, %129
br i1 %130, label %131, label %133
131: ; preds = %126
%132 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.12, i64 0, i64 0))
br label %133
133: ; preds = %131, %126
%134 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.13, i64 0, i64 0))
%135 = load i32, i32* %7
%136 = getelementptr inbounds [6 x i8], [6 x i8]* %12, i64 0, i64 0
%137 = call i32 @write(i32 %135, i8* %136, i32 6)
%138 = icmp ne i32 6, %137
br i1 %138, label %139, label %141
139: ; preds = %133
%140 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.14, i64 0, i64 0))
br label %141
141: ; preds = %139, %133
%142 = load i32, i32* %7
%143 = getelementptr inbounds [65537 x i8], [65537 x i8]* %14, i64 0, i64 0
%144 = load i32, i32* %11
%145 = add nsw i32 %144, 1
%146 = call i32 @read(i32 %142, i8* %143, i32 %145)
store i32 %146, i32* %15
store i32 %146, i32* %9
br label %147
147: ; preds = %152, %141
%148 = load i32, i32* %9
%149 = load i32, i32* %11
%150 = add nsw i32 %149, 1
%151 = icmp slt i32 %148, %150
br i1 %151, label %152, label %166
152: ; preds = %147
%153 = load i32, i32* %15
%154 = load i32, i32* %11
%155 = add nsw i32 %154, 1
%156 = load i32, i32* %9
%157 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.15, i64 0, i64 0), i32 %153, i32 %155, i32 %156)
%158 = load i32, i32* %7
%159 = getelementptr inbounds [65537 x i8], [65537 x i8]* %14, i64 0, i64 0
%160 = load i32, i32* %11
%161 = add nsw i32 %160, 1
%162 = call i32 @read(i32 %158, i8* %159, i32 %161)
store i32 %162, i32* %15
%163 = load i32, i32* %15
%164 = load i32, i32* %9
%165 = add nsw i32 %164, %163
store i32 %165, i32* %9
br label %147
166: ; preds = %147
%167 = load i32, i32* %15
%168 = load i32, i32* %11
%169 = add nsw i32 %168, 1
%170 = load i32, i32* %9
%171 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.16, i64 0, i64 0), i32 %167, i32 %169, i32 %170)
%172 = load i32, i32* @EXIT_SUCCESS
store i32 %172, i32* %3
br label %173
173: ; preds = %166, %94
%174 = load i32, i32* %3
ret i32 %174
}

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 = [39 x i8] c"Read block command set with checksum: \00"
@.str.2 = [6 x i8] c"%02X \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.8 = [3 x i8] c"%s\00"
@.str.9 = [15 x i8] c"Unable to open\00"
@TCSETS = global i32 0
@.str.10 = [19 x i8] c"Error with ioctl: \00"
@TCIFLUSH = global i32 0
@.str.11 = [40 x i8] c"ioctl failed to flush read i/o buffer: \00"
@TCOFLUSH = global i32 0
@.str.12 = [41 x i8] c"ioctl failed to flush write i/o buffer: \00"
@.str.15 = [62 x i8] c"received bytes: %d requested read of size: %d total read: %d\0A\00"
@.str.16 = [68 x i8] c"final received bytes: %d requested read of size: %d total read: %d\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [15 x i8] c"Memset termios\00"
@str.17 = [23 x i8] c"making raw for termios\00"
@str.18 = [29 x i8] c"setting speed on the termios\00"
@str.19 = [20 x i8] c"Opening serial port\00"
@str.20 = [27 x i8] c"sending read block command\00"
@str.21 = [13 x i8] c"Write failed\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.termios
%4 = alloca [6 x i8]
%5 = alloca [65537 x i8]
%6 = bitcast %struct.termios* %3 to i8*
%7 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
store i8 90, i8* %7
%8 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 1
store i8 82, i8* %8
%9 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 2
store i8 64, i8* %9
%10 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 3
store i8 0, i8* %10
%11 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 4
store i8 0, i8* %11
%12 = getelementptr inbounds [65537 x i8], [65537 x i8]* %5, i64 0, i64 0
%13 = icmp slt i32 %0, 2
br i1 %13, label %45, label %14
14: ; preds = %2
%15 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 5
store i8 -20, i8* %15
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 90)
%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 64)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 0)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 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 236)
%23 = tail call i32 @putchar(i32 10)
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%25 = call i32 @memset(%struct.termios* %3, i32 0, i32 16)
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.17, i64 0, i64 0))
%27 = call i32 @cfmakeraw(%struct.termios* %3)
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.18, i64 0, i64 0))
%29 = call i32 @cfsetspeed(%struct.termios* %3, i32 921600)
%30 = load i32, i32* @CREAD
%31 = load i32, i32* @CLOCAL
%32 = or i32 %31, %30
%33 = load i32, i32* @CS8
%34 = or i32 %32, %33
%35 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%36 = load i32, i32* %35
%37 = or i32 %34, %36
store i32 %37, i32* %35
%38 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
%39 = load i32*, i32** %38
%40 = load i64, i64* @VMIN
%41 = getelementptr inbounds i32, i32* %39, i64 %40
store i32 0, i32* %41
%42 = load i64, i64* @VTIME
%43 = getelementptr inbounds i32, i32* %39, i64 %42
store i32 1, i32* %43
%44 = icmp eq i32 %0, 2
br i1 %44, label %50, label %102
45: ; preds = %2
%46 = load i8*, i8** %1
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %46)
%48 = load i32, i32* @EXIT_FAILURE
%49 = tail call i32 @exit(i32 %48)
unreachable
50: ; preds = %14
%51 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.19, i64 0, i64 0))
%52 = getelementptr inbounds i8*, i8** %1, i64 1
%53 = load i8*, i8** %52
%54 = load i32, i32* @O_RDWR
%55 = load i32, i32* @O_NOCTTY
%56 = or i32 %55, %54
%57 = call i32 @open(i8* %53, i32 %56)
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %63
59: ; preds = %50
%60 = load i8*, i8** %52
%61 = call i8* @strcat(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), i8* dereferenceable(1) %60)
%62 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
br label %63
63: ; preds = %59, %50
%64 = load i32, i32* @TCSETS
%65 = call i32 @ioctl(i32 %57, i32 %64, %struct.termios* %3)
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %69
67: ; preds = %63
%68 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0))
br label %69
69: ; preds = %67, %63
%70 = load i32, i32* @TCIFLUSH
%71 = call i64 @tcflush(i32 %57, i32 %70)
%72 = icmp eq i64 %71, 0
br i1 %72, label %75, label %73
73: ; preds = %69
%74 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.11, i64 0, i64 0))
br label %75
75: ; preds = %73, %69
%76 = load i32, i32* @TCOFLUSH
%77 = call i64 @tcflush(i32 %57, i32 %76)
%78 = icmp eq i64 %77, 0
br i1 %78, label %81, label %79
79: ; preds = %75
%80 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.12, i64 0, i64 0))
br label %81
81: ; preds = %79, %75
%82 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.20, i64 0, i64 0))
%83 = call i32 @write(i32 %57, i8* %7, i32 6)
%84 = icmp eq i32 %83, 6
br i1 %84, label %87, label %85
85: ; preds = %81
%86 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.21, i64 0, i64 0))
br label %87
87: ; preds = %85, %81
%88 = call i32 @read(i32 %57, i8* %12, i32 16385)
%89 = icmp slt i32 %88, 16385
br i1 %89, label %90, label %97
90: ; preds = %87, %90
%91 = phi i32 [ %94, %90 ], [ %88, %87 ]
%92 = phi i32 [ %95, %90 ], [ %88, %87 ]
%93 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @.str.15, i64 0, i64 0), i32 %91, i32 16385, i32 %92)
%94 = call i32 @read(i32 %57, i8* %12, i32 16385)
%95 = add nsw i32 %94, %92
%96 = icmp slt i32 %95, 16385
br i1 %96, label %90, label %97
97: ; preds = %90, %87
%98 = phi i32 [ %88, %87 ], [ %95, %90 ]
%99 = phi i32 [ %88, %87 ], [ %94, %90 ]
%100 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([68 x i8], [68 x i8]* @.str.16, i64 0, i64 0), i32 %99, i32 16385, i32 %98)
%101 = load i32, i32* @EXIT_SUCCESS
br label %102
102: ; preds = %14, %97
%103 = phi i32 [ %101, %97 ], [ 1, %14 ]
ret i32 %103
}