#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 */
double cos(double);
double distance(int);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ v3_analog_inputs_enable(int);
int v3_analog_read(int);
int /*<<< orphan*/ v3_open();
int /*<<< orphan*/ v3_work();
int main() {
  v3_open();
  v3_analog_inputs_enable((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3));
  const float angle = 1.1172;
  do {
    v3_work();
    printf("D0=%f (raw v=%d)\n", distance(v3_analog_read(0)),
           v3_analog_read(0));
    printf("D1=%f (raw v=%d)\n", (distance(v3_analog_read(1)) * cos(0.460579)),
           v3_analog_read(1));
    printf("D2 (raw v=%d)\n", v3_analog_read(2));
    printf("D3 (raw v=%d)\n", v3_analog_read(3));
    usleep(500000);
  } while (1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1080 <v3_open@plt>
mov    $0xf,%edi
call   1050 <v3_analog_inputs_enable@plt>
movss  0xe58(%rip),%xmm0
movss  %xmm0,-0x8(%rbp)
mov    $0x0,%al
call   1060 <v3_work@plt>
xor    %edi,%edi
call   1040 <v3_analog_read@plt>
mov    %eax,%edi
call   1090 <distance@plt>
cvttsd2si %xmm0,%eax
mov    %eax,-0x1c(%rbp)
xor    %edi,%edi
call   1040 <v3_analog_read@plt>
mov    -0x1c(%rbp),%esi
mov    %eax,%edx
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <v3_analog_read@plt>
mov    %eax,%edi
call   1090 <distance@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  0xe07(%rip),%xmm0
call   1070 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0xc(%rbp)
mov    $0x1,%edi
call   1040 <v3_analog_read@plt>
mov    -0xc(%rbp),%esi
mov    %eax,%edx
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x2,%edi
call   1040 <v3_analog_read@plt>
mov    %eax,%esi
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x3,%edi
call   1040 <v3_analog_read@plt>
mov    %eax,%esi
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x7a120,%edi
call   10a0 <usleep@plt>
mov    $0x1,%al
test   $0x1,%al
jne    11ad <main+0x2d>
jmp    1283 <main+0x103>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %eax,%eax
call   1070 <v3_open@plt>
mov    $0xf,%edi
call   1050 <v3_analog_inputs_enable@plt>
lea    0xe78(%rip),%r14
lea    0xe83(%rip),%r15
lea    0xe8e(%rip),%r12
lea    0xe96(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1060 <v3_work@plt>
xor    %edi,%edi
call   1040 <v3_analog_read@plt>
mov    %eax,%edi
call   1080 <distance@plt>
cvttsd2si %xmm0,%ebp
xor    %edi,%edi
call   1040 <v3_analog_read@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <v3_analog_read@plt>
mov    %eax,%edi
call   1080 <distance@plt>
mulsd  0xe09(%rip),%xmm0
cvttsd2si %xmm0,%ebp
mov    $0x1,%edi
call   1040 <v3_analog_read@plt>
mov    %r15,%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x2,%edi
call   1040 <v3_analog_read@plt>
mov    %r12,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x3,%edi
call   1040 <v3_analog_read@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x7a120,%edi
call   1090 <usleep@plt>
jmp    11b0 <main+0x40>

LLVM IR (-O0):
@.str = [18 x i8] c"D0=%f (raw v=%d)\0A\00"
@.str.1 = [18 x i8] c"D1=%f (raw v=%d)\0A\00"
@.str.2 = [15 x i8] c"D2 (raw v=%d)\0A\00"
@.str.3 = [15 x i8] c"D3 (raw v=%d)\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
store i32 0, i32* %1
%3 = call i32 (...) @v3_open()
%4 = call i32 @v3_analog_inputs_enable(i32 15)
store float 0x3FF1E00D20000000, float* %2
br label %5
5: ; preds = %24, %0
%6 = call i32 (...) @v3_work()
%7 = call i32 @v3_analog_read(i32 0)
%8 = call double @distance(i32 %7)
%9 = fptosi double %8 to i32
%10 = call i32 @v3_analog_read(i32 0)
%11 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %10)
%12 = call i32 @v3_analog_read(i32 1)
%13 = call double @distance(i32 %12)
%14 = call double @cos(double 4.605790e-01)
%15 = fmul double %13, %14
%16 = fptosi double %15 to i32
%17 = call i32 @v3_analog_read(i32 1)
%18 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %17)
%19 = call i32 @v3_analog_read(i32 2)
%20 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = call i32 @v3_analog_read(i32 3)
%22 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%23 = call i32 @usleep(i32 500000)
br label %24
24: ; preds = %5
br i1 true, label %5, label %25
25: ; preds = %24
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"D0=%f (raw v=%d)\0A\00"
@.str.1 = [18 x i8] c"D1=%f (raw v=%d)\0A\00"
@.str.2 = [15 x i8] c"D2 (raw v=%d)\0A\00"
@.str.3 = [15 x i8] c"D3 (raw v=%d)\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @v3_open()
%2 = tail call i32 @v3_analog_inputs_enable(i32 15)
br label %3
3: ; preds = %3, %0
%4 = tail call i32 (...) @v3_work()
%5 = tail call i32 @v3_analog_read(i32 0)
%6 = tail call double @distance(i32 %5)
%7 = fptosi double %6 to i32
%8 = tail call i32 @v3_analog_read(i32 0)
%9 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %8)
%10 = tail call i32 @v3_analog_read(i32 1)
%11 = tail call double @distance(i32 %10)
%12 = fmul double %11, 0x3FECAA5AE86C10B2
%13 = fptosi double %12 to i32
%14 = tail call i32 @v3_analog_read(i32 1)
%15 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %14)
%16 = tail call i32 @v3_analog_read(i32 2)
%17 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = tail call i32 @v3_analog_read(i32 3)
%19 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%20 = tail call i32 @usleep(i32 500000)
br label %3
}