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

/* Forward declarations */

/* Type definitions */
typedef int uint8_t;
typedef scalar_t__ uint32_t;
typedef int int16_t;

/* Variables and functions */
int /*<<< orphan*/ initSerial(int volatile *, int, char *);
int /*<<< orphan*/ myReadfull(int volatile, void *, scalar_t__);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ write(int volatile, int *, int);
int main(int argc, char **argv) {
  volatile int fd;
  initSerial(&fd, 115200, "/dev/ttyUSB0");
  uint8_t magic = 0xA3;
  write(fd, &magic, 1);
  uint32_t nBytes = 0;
  myReadfull(fd, (void *)&nBytes, 4);
  if (nBytes > 0) {
    int16_t returnValues[nBytes / 2];
    myReadfull(fd, (void *)returnValues, nBytes);
    int j = 0;
    for (j = 0; j < nBytes / 2; j++) {
      printf("%d\n", returnValues[j]);
    }
    printf("\n\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
mov    $0x1c200,%esi
lea    0xe9a(%rip),%rdx
call   1060 <initSerial@plt>
movl   $0xa3,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1030 <myReadfull@plt>
cmpq   $0x0,-0x20(%rbp)
jle    1258 <main+0x118>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
add    %rcx,%rax
sar    %rax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x40(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rdx
call   1030 <myReadfull@plt>
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x34(%rbp)
movslq -0x34(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
cmp    %rcx,%rax
jge    1243 <main+0x103>
mov    -0x40(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11f6 <main+0xb6>
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
lea    0xe9a(%rip),%rdx
lea    -0x24(%rbp),%rdi
mov    $0x1c200,%esi
call   1070 <initSerial@plt>
movl   $0xa3,-0x34(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x34(%rbp),%rsi
mov    $0x1,%edx
call   1050 <write@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x4,%edx
call   1030 <myReadfull@plt>
mov    -0x30(%rbp),%rax
test   %rax,%rax
jle    1227 <main+0xd7>
mov    %rsp,%r15
and    $0xfffffffffffffffe,%rax
mov    %rsp,%r12
add    %rax,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    -0x24(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %r12,%rsi
call   1030 <myReadfull@plt>
cmpq   $0x2,-0x30(%rbp)
jl     1218 <main+0xc8>
lea    0xe27(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    (%r12,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
add    %rax,%rcx
sar    %rcx
cmp    %rbx,%rcx
jg     11f0 <main+0xa0>
lea    0xdf0(%rip),%rdi
call   1040 <puts@plt>
mov    %r15,%rsp
xor    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/ttyUSB0\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [3 x i8] c"\0A\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 i64
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32 @initSerial(i32* %6, i32 115200, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 163, i32* %7
%13 = load volatile i32, i32* %6
%14 = call i32 @write(i32 %13, i32* %7, i32 1)
store i64 0, i64* %8
%15 = load volatile i32, i32* %6
%16 = bitcast i64* %8 to i8*
%17 = call i32 @myReadfull(i32 %15, i8* %16, i64 4)
%18 = load i64, i64* %8
%19 = icmp sgt i64 %18, 0
br i1 %19, label %20, label %47
20: ; preds = %2
%21 = load i64, i64* %8
%22 = sdiv i64 %21, 2
%23 = call i8* @llvm.stacksave()
store i8* %23, i8** %9
%24 = alloca i32, i64 %22
store i64 %22, i64* %10
%25 = load volatile i32, i32* %6
%26 = bitcast i32* %24 to i8*
%27 = load i64, i64* %8
%28 = call i32 @myReadfull(i32 %25, i8* %26, i64 %27)
store i32 0, i32* %11
store i32 0, i32* %11
br label %29
29: ; preds = %41, %20
%30 = load i32, i32* %11
%31 = sext i32 %30 to i64
%32 = load i64, i64* %8
%33 = sdiv i64 %32, 2
%34 = icmp slt i64 %31, %33
br i1 %34, label %35, label %44
35: ; preds = %29
%36 = load i32, i32* %11
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %24, i64 %37
%39 = load i32, i32* %38
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %35
%42 = load i32, i32* %11
%43 = add nsw i32 %42, 1
store i32 %43, i32* %11
br label %29
44: ; preds = %29
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%46 = load i8*, i8** %9
br label %47
47: ; preds = %44, %2
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/ttyUSB0\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@str = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = bitcast i32* %3 to i8*
%7 = call i32 @initSerial(i32* %3, i32 115200, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%8 = bitcast i32* %4 to i8*
store i32 163, i32* %4
%9 = load volatile i32, i32* %3
%10 = call i32 @write(i32 %9, i32* %4, i32 1)
%11 = bitcast i64* %5 to i8*
store i64 0, i64* %5
%12 = load volatile i32, i32* %3
%13 = call i32 @myReadfull(i32 %12, i8* %11, i64 4)
%14 = load i64, i64* %5
%15 = icmp sgt i64 %14, 0
br i1 %15, label %16, label %37
16: ; preds = %2
%17 = lshr i64 %14, 1
%18 = call i8* @llvm.stacksave()
%19 = alloca i32, i64 %17
%20 = load volatile i32, i32* %3
%21 = bitcast i32* %19 to i8*
%22 = load i64, i64* %5
%23 = call i32 @myReadfull(i32 %20, i8* %21, i64 %22)
%24 = load i64, i64* %5
%25 = icmp sgt i64 %24, 1
br i1 %25, label %26, label %35
26: ; preds = %16, %26
%27 = phi i64 [ %31, %26 ], [ 0, %16 ]
%28 = getelementptr inbounds i32, i32* %19, i64 %27
%29 = load i32, i32* %28
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %29)
%31 = add nuw nsw i64 %27, 1
%32 = load i64, i64* %5
%33 = sdiv i64 %32, 2
%34 = icmp sgt i64 %33, %31
br i1 %34, label %26, label %35
35: ; preds = %26, %16
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
br label %37
37: ; preds = %35, %2
ret i32 0
}