#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__ uint16_t;

/* Variables and functions */
int /*<<< orphan*/ initSerial(int volatile *, int, char *);
int /*<<< orphan*/ myReadfull(int volatile, void *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ write(int volatile, ...);
int main(int argc, char **argv) {
  volatile int fd;
  initSerial(&fd, 9600, "/dev/ttyUSB0");
  uint16_t out[6];
  out[0] = 0x0000;
  out[1] = 0x0005;
  out[2] = 0x1000 - 0x0010;
  out[3] = 0x0000;
  out[4] = 0x0080;
  out[5] = 0x1000 - 0x0010;
  uint8_t magic = 0xA3;
  write(fd, &magic, 1);
  int i = 0;
  for (i = 0; i < 6; i++) {
    write(fd, &(out[i]), 2);
  }
  i = 0;
  uint16_t nBytes = 0;
  myReadfull(fd, (void *)&nBytes, 2);
  while (nBytes > 0) {
    uint8_t returnValues[129 * 2];
    myReadfull(fd, (void *)returnValues, nBytes);
    int j = 0;
    for (j = 0; j < nBytes; j += 2) {
      double VDS = 0.0, IDS = 0.0, VGS = 0.0;
      VDS = (double)(j * out[1] >> 1) * 0.0007326007326007326;
      VGS = (double)(i * out[4]) * 0.00147168881425233645;
      IDS = (double)((returnValues[j + 1] << 8) | (returnValues[j])) *
            4.69615854231238846623e-6;
      printf("%e\t%e\t%e\n", VGS, VDS, IDS);
    }
    printf("\n\n");
    myReadfull(fd, (void *)&nBytes, 2);
    i++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x490,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
mov    $0x2580,%esi
lea    0xeaf(%rip),%rdx
call   1060 <initSerial@plt>
movq   $0x0,-0x50(%rbp)
movq   $0x5,-0x48(%rbp)
movq   $0xff0,-0x40(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x80,-0x30(%rbp)
movq   $0xff0,-0x28(%rbp)
movl   $0xa3,-0x54(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x54(%rbp),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1040 <write@plt>
movl   $0x0,-0x58(%rbp)
movl   $0x0,-0x58(%rbp)
cmpl   $0x6,-0x58(%rbp)
jge    11fc <main+0xbc>
mov    -0x14(%rbp),%edi
movslq -0x58(%rbp),%rax
lea    -0x50(%rbp),%rsi
shl    $0x3,%rax
add    %rax,%rsi
mov    $0x2,%edx
mov    $0x0,%al
call   1040 <write@plt>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    11c6 <main+0x86>
movl   $0x0,-0x58(%rbp)
movq   $0x0,-0x60(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x2,%edx
call   1030 <myReadfull@plt>
cmpq   $0x0,-0x60(%rbp)
jle    136f <main+0x22f>
mov    -0x14(%rbp),%edi
lea    -0x470(%rbp),%rsi
mov    -0x60(%rbp),%rax
mov    %eax,%edx
call   1030 <myReadfull@plt>
movl   $0x0,-0x474(%rbp)
movl   $0x0,-0x474(%rbp)
movslq -0x474(%rbp),%rax
cmp    -0x60(%rbp),%rax
jge    1342 <main+0x202>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x480(%rbp)
ff
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x488(%rbp)
ff
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x490(%rbp)
ff
movslq -0x474(%rbp),%rax
imul   -0x48(%rbp),%rax
sar    $0x1,%rax
cvtsi2sd %rax,%xmm0
movsd  0xd71(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x480(%rbp)
ff
movslq -0x58(%rbp),%rax
imul   -0x30(%rbp),%rax
cvtsi2sd %rax,%xmm0
movsd  0xd47(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x490(%rbp)
ff
mov    -0x474(%rbp),%eax
add    $0x1,%eax
cltq
mov    -0x470(%rbp,%rax,4),%eax
shl    $0x8,%eax
movslq -0x474(%rbp),%rcx
or     -0x470(%rbp,%rcx,4),%eax
cvtsi2sd %eax,%xmm0
movsd  0xd04(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x488(%rbp)
ff
movsd  -0x490(%rbp),%xmm0
ff
movsd  -0x480(%rbp),%xmm1
ff
movsd  -0x488(%rbp),%xmm2
ff
lea    0xcfe(%rip),%rdi
mov    $0x3,%al
call   1050 <printf@plt>
mov    -0x474(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x474(%rbp)
jmp    1250 <main+0x110>
lea    0xce6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x2,%edx
call   1030 <myReadfull@plt>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    121c <main+0xdc>
xor    %eax,%eax
add    $0x490,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x458,%rsp
lea    0xee0(%rip),%rdx
lea    0xc(%rsp),%rdi
mov    $0x2580,%esi
call   1070 <initSerial@plt>
lea    0x28(%rsp),%rbx
movaps 0xe7d(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
lea    0x30(%rsp),%r13
lea    0x38(%rsp),%r12
movaps 0xe77(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
lea    0x40(%rsp),%r15
lea    0x48(%rsp),%r14
movapd 0xe70(%rip),%xmm0
movapd %xmm0,0x40(%rsp)
movl   $0xa3,0x1c(%rsp)
mov    0xc(%rsp),%edi
lea    0x1c(%rsp),%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1050 <write@plt>
mov    0xc(%rsp),%edi
lea    0x20(%rsp),%rsi
mov    $0x2,%edx
xor    %eax,%eax
call   1050 <write@plt>
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    $0x2,%edx
xor    %eax,%eax
call   1050 <write@plt>
mov    0xc(%rsp),%edi
mov    %r13,%rsi
mov    $0x2,%edx
xor    %eax,%eax
call   1050 <write@plt>
mov    0xc(%rsp),%edi
mov    %r12,%rsi
mov    $0x2,%edx
xor    %eax,%eax
call   1050 <write@plt>
mov    0xc(%rsp),%edi
mov    %r15,%rsi
mov    $0x2,%edx
xor    %eax,%eax
call   1050 <write@plt>
mov    0xc(%rsp),%edi
mov    %r14,%rsi
mov    $0x2,%edx
xor    %eax,%eax
call   1050 <write@plt>
movq   $0x0,0x10(%rsp)
mov    0xc(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0x2,%edx
call   1030 <myReadfull@plt>
mov    0x10(%rsp),%rdx
test   %rdx,%rdx
jle    1365 <main+0x215>
xor    %ebx,%ebx
lea    0x50(%rsp),%r14
lea    0xdd6(%rip),%r13
lea    0xdd7(%rip),%r15
lea    0x10(%rsp),%r12
jmp    12bb <main+0x16b>
nopl   (%rax)
mov    %r15,%rdi
call   1040 <puts@plt>
mov    0xc(%rsp),%edi
mov    %r12,%rsi
mov    $0x2,%edx
call   1030 <myReadfull@plt>
add    $0x1,%rbx
mov    0x10(%rsp),%rdx
test   %rdx,%rdx
jle    1365 <main+0x215>
mov    0xc(%rsp),%edi
mov    %r14,%rsi
call   1030 <myReadfull@plt>
cmpq   $0x0,0x10(%rsp)
movsd  0xd5b(%rip),%xmm2
movsd  0xd5b(%rip),%xmm3
movsd  0xd5b(%rip),%xmm4
jle    1290 <main+0x140>
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    0x28(%rsp),%rax
imul   %rbp,%rax
sar    %rax
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
mulsd  %xmm2,%xmm1
mov    0x40(%rsp),%rax
imul   %rbx,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    0x54(%rsp,%rbp,4),%eax
shl    $0x8,%eax
or     0x50(%rsp,%rbp,4),%eax
mulsd  %xmm3,%xmm0
xorps  %xmm2,%xmm2
cvtsi2sd %eax,%xmm2
mulsd  %xmm4,%xmm2
mov    %r13,%rdi
mov    $0x3,%al
call   1060 <printf@plt>
movsd  0xcfb(%rip),%xmm4
movsd  0xceb(%rip),%xmm3
movsd  0xcdb(%rip),%xmm2
add    $0x2,%rbp
cmp    %rbp,0x10(%rsp)
jg     12f0 <main+0x1a0>
jmp    1290 <main+0x140>
xor    %eax,%eax
add    $0x458,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/ttyUSB0\00"
@.str.1 = [10 x i8] c"%e\09%e\09%e\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 [6 x i64]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64
%11 = alloca [258 x i32]
%12 = alloca i32
%13 = alloca double
%14 = alloca double
%15 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = call i32 @initSerial(i32* %6, i32 9600, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%17 = getelementptr inbounds [6 x i64], [6 x i64]* %7, i64 0, i64 0
store i64 0, i64* %17
%18 = getelementptr inbounds [6 x i64], [6 x i64]* %7, i64 0, i64 1
store i64 5, i64* %18
%19 = getelementptr inbounds [6 x i64], [6 x i64]* %7, i64 0, i64 2
store i64 4080, i64* %19
%20 = getelementptr inbounds [6 x i64], [6 x i64]* %7, i64 0, i64 3
store i64 0, i64* %20
%21 = getelementptr inbounds [6 x i64], [6 x i64]* %7, i64 0, i64 4
store i64 128, i64* %21
%22 = getelementptr inbounds [6 x i64], [6 x i64]* %7, i64 0, i64 5
store i64 4080, i64* %22
store i32 163, i32* %8
%23 = load volatile i32, i32* %6
%24 = call i32 (i32, ...) @write(i32 %23, i32* %8, i32 1)
store i32 0, i32* %9
store i32 0, i32* %9
br label %25
25: ; preds = %34, %2
%26 = load i32, i32* %9
%27 = icmp slt i32 %26, 6
br i1 %27, label %28, label %37
28: ; preds = %25
%29 = load volatile i32, i32* %6
%30 = load i32, i32* %9
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [6 x i64], [6 x i64]* %7, i64 0, i64 %31
%33 = call i32 (i32, ...) @write(i32 %29, i64* %32, i32 2)
br label %34
34: ; preds = %28
%35 = load i32, i32* %9
%36 = add nsw i32 %35, 1
store i32 %36, i32* %9
br label %25
37: ; preds = %25
store i32 0, i32* %9
store i64 0, i64* %10
%38 = load volatile i32, i32* %6
%39 = bitcast i64* %10 to i8*
%40 = call i32 @myReadfull(i32 %38, i8* %39, i32 2)
br label %41
41: ; preds = %92, %37
%42 = load i64, i64* %10
%43 = icmp sgt i64 %42, 0
br i1 %43, label %44, label %99
44: ; preds = %41
%45 = load volatile i32, i32* %6
%46 = getelementptr inbounds [258 x i32], [258 x i32]* %11, i64 0, i64 0
%47 = bitcast i32* %46 to i8*
%48 = load i64, i64* %10
%49 = trunc i64 %48 to i32
%50 = call i32 @myReadfull(i32 %45, i8* %47, i32 %49)
store i32 0, i32* %12
store i32 0, i32* %12
br label %51
51: ; preds = %89, %44
%52 = load i32, i32* %12
%53 = sext i32 %52 to i64
%54 = load i64, i64* %10
%55 = icmp slt i64 %53, %54
br i1 %55, label %56, label %92
56: ; preds = %51
store double 0.000000e+00, double* %13
store double 0.000000e+00, double* %14
store double 0.000000e+00, double* %15
%57 = load i32, i32* %12
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [6 x i64], [6 x i64]* %7, i64 0, i64 1
%60 = load i64, i64* %59
%61 = mul nsw i64 %58, %60
%62 = ashr i64 %61, 1
%63 = sitofp i64 %62 to double
%64 = fmul double %63, 0x3F48018018018018
store double %64, double* %13
%65 = load i32, i32* %9
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [6 x i64], [6 x i64]* %7, i64 0, i64 4
%68 = load i64, i64* %67
%69 = mul nsw i64 %66, %68
%70 = sitofp i64 %69 to double
%71 = fmul double %70, 0x3F581CB5D4EF4099
store double %71, double* %15
%72 = load i32, i32* %12
%73 = add nsw i32 %72, 1
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds [258 x i32], [258 x i32]* %11, i64 0, i64 %74
%76 = load i32, i32* %75
%77 = shl i32 %76, 8
%78 = load i32, i32* %12
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds [258 x i32], [258 x i32]* %11, i64 0, i64 %79
%81 = load i32, i32* %80
%82 = or i32 %77, %81
%83 = sitofp i32 %82 to double
%84 = fmul double %83, 0x3ED3B2763B14EC62
store double %84, double* %14
%85 = load double, double* %15
%86 = load double, double* %13
%87 = load double, double* %14
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double %85, double %86, double %87)
br label %89
89: ; preds = %56
%90 = load i32, i32* %12
%91 = add nsw i32 %90, 2
store i32 %91, i32* %12
br label %51
92: ; preds = %51
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%94 = load volatile i32, i32* %6
%95 = bitcast i64* %10 to i8*
%96 = call i32 @myReadfull(i32 %94, i8* %95, i32 2)
%97 = load i32, i32* %9
%98 = add nsw i32 %97, 1
store i32 %98, i32* %9
br label %41
99: ; preds = %41
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/ttyUSB0\00"
@.str.1 = [10 x i8] c"%e\09%e\09%e\0A\00"
@str = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca [6 x i64]
%5 = alloca i32
%6 = alloca i64
%7 = alloca [258 x i32]
%8 = bitcast i32* %3 to i8*
%9 = call i32 @initSerial(i32* %3, i32 9600, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%10 = bitcast [6 x i64]* %4 to i8*
%11 = getelementptr inbounds [6 x i64], [6 x i64]* %4, i64 0, i64 0
%12 = getelementptr inbounds [6 x i64], [6 x i64]* %4, i64 0, i64 1
%13 = bitcast [6 x i64]* %4 to <2 x i64>*
store <2 x i64> <i64 0, i64 5>, <2 x i64>* %13
%14 = getelementptr inbounds [6 x i64], [6 x i64]* %4, i64 0, i64 2
%15 = getelementptr inbounds [6 x i64], [6 x i64]* %4, i64 0, i64 3
%16 = bitcast i64* %14 to <2 x i64>*
store <2 x i64> <i64 4080, i64 0>, <2 x i64>* %16
%17 = getelementptr inbounds [6 x i64], [6 x i64]* %4, i64 0, i64 4
%18 = getelementptr inbounds [6 x i64], [6 x i64]* %4, i64 0, i64 5
%19 = bitcast i64* %17 to <2 x i64>*
store <2 x i64> <i64 128, i64 4080>, <2 x i64>* %19
%20 = bitcast i32* %5 to i8*
store i32 163, i32* %5
%21 = load volatile i32, i32* %3
%22 = call i32 (i32, ...) @write(i32 %21, i32* %5, i32 1)
%23 = load volatile i32, i32* %3
%24 = call i32 (i32, ...) @write(i32 %23, i64* %11, i32 2)
%25 = load volatile i32, i32* %3
%26 = call i32 (i32, ...) @write(i32 %25, i64* %12, i32 2)
%27 = load volatile i32, i32* %3
%28 = call i32 (i32, ...) @write(i32 %27, i64* %14, i32 2)
%29 = load volatile i32, i32* %3
%30 = call i32 (i32, ...) @write(i32 %29, i64* %15, i32 2)
%31 = load volatile i32, i32* %3
%32 = call i32 (i32, ...) @write(i32 %31, i64* %17, i32 2)
%33 = load volatile i32, i32* %3
%34 = call i32 (i32, ...) @write(i32 %33, i64* %18, i32 2)
%35 = bitcast i64* %6 to i8*
store i64 0, i64* %6
%36 = load volatile i32, i32* %3
%37 = call i32 @myReadfull(i32 %36, i8* %35, i32 2)
%38 = load i64, i64* %6
%39 = icmp sgt i64 %38, 0
br i1 %39, label %40, label %81
40: ; preds = %2
%41 = bitcast [258 x i32]* %7 to i8*
br label %42
42: ; preds = %40, %74
%43 = phi i64 [ 0, %40 ], [ %78, %74 ]
%44 = phi i64 [ %38, %40 ], [ %79, %74 ]
%45 = load volatile i32, i32* %3
%46 = trunc i64 %44 to i32
%47 = call i32 @myReadfull(i32 %45, i8* %41, i32 %46)
%48 = load i64, i64* %6
%49 = icmp sgt i64 %48, 0
br i1 %49, label %50, label %74
50: ; preds = %42, %50
%51 = phi i64 [ %71, %50 ], [ 0, %42 ]
%52 = load i64, i64* %12
%53 = mul nsw i64 %52, %51
%54 = ashr exact i64 %53, 1
%55 = sitofp i64 %54 to double
%56 = fmul double %55, 0x3F48018018018018
%57 = load i64, i64* %17
%58 = mul nsw i64 %57, %43
%59 = sitofp i64 %58 to double
%60 = fmul double %59, 0x3F581CB5D4EF4099
%61 = or i64 %51, 1
%62 = getelementptr inbounds [258 x i32], [258 x i32]* %7, i64 0, i64 %61
%63 = load i32, i32* %62
%64 = shl i32 %63, 8
%65 = getelementptr inbounds [258 x i32], [258 x i32]* %7, i64 0, i64 %51
%66 = load i32, i32* %65
%67 = or i32 %64, %66
%68 = sitofp i32 %67 to double
%69 = fmul double %68, 0x3ED3B2763B14EC62
%70 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double %60, double %56, double %69)
%71 = add nuw i64 %51, 2
%72 = load i64, i64* %6
%73 = icmp sgt i64 %72, %71
br i1 %73, label %50, label %74
74: ; preds = %50, %42
%75 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%76 = load volatile i32, i32* %3
%77 = call i32 @myReadfull(i32 %76, i8* %35, i32 2)
%78 = add nuw i64 %43, 1
%79 = load i64, i64* %6
%80 = icmp sgt i64 %79, 0
br i1 %80, label %42, label %81
81: ; preds = %74, %2
ret i32 0
}