#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 */

/* Variables and functions */
int adc1_read(short *, int);
int adc2_read(short *, int);
int /*<<< orphan*/ adc_open(int);
float calc_sd(short *, int);
int /*<<< orphan*/ gdb_stdio_printf(char *, ...);
int main(void) {
  short buf[(320 * 4)];
  float sd1, sd2;
  adc_open(2 * (320 * 4));
  gdb_stdio_printf("Starting!\n");
  while (1) {
    while (adc1_read(buf, (320 * 4)) == -1)
      ;
    sd1 = calc_sd(buf, (320 * 4));
    while (adc2_read(buf, (320 * 4)) == -1)
      ;
    sd2 = calc_sd(buf, (320 * 4));
    gdb_stdio_printf("adc1: %5.1f adc2: %5.1f\n", (double)sd1, (double)sd2);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0xa00,%edi
call   1050 <adc_open@plt>
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <gdb_stdio_printf@plt>
jmp    117f <main+0x2f>
lea    -0xa10(%rbp),%rdi
mov    $0x500,%esi
call   1040 <adc1_read@plt>
cmp    $0xffffffff,%eax
jne    119e <main+0x4e>
jmp    117f <main+0x2f>
lea    -0xa10(%rbp),%rdi
mov    $0x500,%esi
call   1070 <calc_sd@plt>
movss  %xmm0,-0xa14(%rbp)
ff
lea    -0xa10(%rbp),%rdi
mov    $0x500,%esi
call   1060 <adc2_read@plt>
cmp    $0xffffffff,%eax
jne    11d6 <main+0x86>
jmp    11b7 <main+0x67>
lea    -0xa10(%rbp),%rdi
mov    $0x500,%esi
call   1070 <calc_sd@plt>
movss  %xmm0,-0xa18(%rbp)
ff
movss  -0xa14(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm0
movss  -0xa18(%rbp),%xmm1
ff
cvtss2sd %xmm1,%xmm1
lea    0xdfd(%rip),%rdi
mov    $0x2,%al
call   1030 <gdb_stdio_printf@plt>
jmp    117a <main+0x2a>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0xa18,%rsp
mov    $0xa00,%edi
call   1050 <adc_open@plt>
lea    0xe95(%rip),%rdi
xor    %eax,%eax
call   1030 <gdb_stdio_printf@plt>
lea    0x10(%rsp),%rbx
lea    0xe8d(%rip),%r14
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0x500,%esi
call   1040 <adc1_read@plt>
cmp    $0xffffffff,%eax
je     1180 <main+0x30>
mov    %rbx,%rdi
mov    $0x500,%esi
call   1070 <calc_sd@plt>
movss  %xmm0,0xc(%rsp)
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    $0x500,%esi
call   1060 <adc2_read@plt>
cmp    $0xffffffff,%eax
je     11b0 <main+0x60>
mov    %rbx,%rdi
mov    $0x500,%esi
call   1070 <calc_sd@plt>
movss  0xc(%rsp),%xmm1
xorps  %xmm2,%xmm2
cvtss2sd %xmm1,%xmm2
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
mov    %r14,%rdi
movaps %xmm2,%xmm0
mov    $0x2,%al
call   1030 <gdb_stdio_printf@plt>
jmp    1180 <main+0x30>

LLVM IR (-O0):
@.str = [11 x i8] c"Starting!\0A\00"
@.str.1 = [25 x i8] c"adc1: %5.1f adc2: %5.1f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1280 x i16]
%3 = alloca float
%4 = alloca float
store i32 0, i32* %1
%5 = call i32 @adc_open(i32 2560)
%6 = call i32 (i8*, ...) @gdb_stdio_printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %0, %21
br label %8
8: ; preds = %12, %7
%9 = getelementptr inbounds [1280 x i16], [1280 x i16]* %2, i64 0, i64 0
%10 = call i32 @adc1_read(i16* %9, i32 1280)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %13
12: ; preds = %8
br label %8
13: ; preds = %8
%14 = getelementptr inbounds [1280 x i16], [1280 x i16]* %2, i64 0, i64 0
%15 = call float @calc_sd(i16* %14, i32 1280)
store float %15, float* %3
br label %16
16: ; preds = %20, %13
%17 = getelementptr inbounds [1280 x i16], [1280 x i16]* %2, i64 0, i64 0
%18 = call i32 @adc2_read(i16* %17, i32 1280)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %21
20: ; preds = %16
br label %16
21: ; preds = %16
%22 = getelementptr inbounds [1280 x i16], [1280 x i16]* %2, i64 0, i64 0
%23 = call float @calc_sd(i16* %22, i32 1280)
store float %23, float* %4
%24 = load float, float* %3
%25 = fpext float %24 to double
%26 = load float, float* %4
%27 = fpext float %26 to double
%28 = call i32 (i8*, ...) @gdb_stdio_printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), double %25, double %27)
br label %7
}

LLVM IR (-O2):
@.str = [11 x i8] c"Starting!\0A\00"
@.str.1 = [25 x i8] c"adc1: %5.1f adc2: %5.1f\0A\00"
define i32 @main() {
%1 = alloca [1280 x i16]
%2 = bitcast [1280 x i16]* %1 to i8*
%3 = tail call i32 @adc_open(i32 2560)
%4 = tail call i32 (i8*, ...) @gdb_stdio_printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [1280 x i16], [1280 x i16]* %1, i64 0, i64 0
br label %6
6: ; preds = %9, %0
%7 = call i32 @adc1_read(i16* %5, i32 1280)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %10
9: ; preds = %6, %15
br label %6
10: ; preds = %6
%11 = call float @calc_sd(i16* %5, i32 1280)
br label %12
12: ; preds = %12, %10
%13 = call i32 @adc2_read(i16* %5, i32 1280)
%14 = icmp eq i32 %13, -1
br i1 %14, label %12, label %15
15: ; preds = %12
%16 = call float @calc_sd(i16* %5, i32 1280)
%17 = fpext float %11 to double
%18 = fpext float %16 to double
%19 = call i32 (i8*, ...) @gdb_stdio_printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), double %17, double %18)
br label %9
}