#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 abs(double);
int /*<<< orphan*/ printf(char *, double, double);
double sin(double);
double timedelay_needed(double angle, double spacing, int antenna) {
  double deltat = 0;
  double needed = 0;
  double c = 0.299792458;
  deltat = spacing * sin(abs(angle) / 180.0 * 3.14159) / c;
  if (angle > 0)
    needed = antenna * deltat;
  if (angle < 0)
    needed = (15 - antenna) * deltat;
  if (needed < 0) {
    printf("Error in Time Needed Calc: %lf %lf\n", needed, deltat);
  }
  return needed;
}


x86 assembly (clang, -O0):
<timedelay_needed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xeb3(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1030 <abs@plt>
movsd  0xe8a(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe76(%rip),%xmm1
mulsd  %xmm1,%xmm0
call   1050 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11ca <timedelay_needed+0x9a>
cvtsi2sdl -0x14(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    11ee <timedelay_needed+0xbe>
mov    $0xf,%eax
sub    -0x14(%rbp),%eax
cvtsi2sd %eax,%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    1212 <timedelay_needed+0xe2>
movsd  -0x28(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
lea    0xe0b(%rip),%rdi
call   1040 <printf@plt>
movsd  -0x28(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timedelay_needed>:
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
movsd  %xmm1,0x18(%rsp)
movapd %xmm0,(%rsp)
call   1030 <abs@plt>
divsd  0xeb1(%rip),%xmm0
mulsd  0xeb1(%rip),%xmm0
call   1050 <sin@plt>
movapd %xmm0,%xmm1
mulsd  0x18(%rsp),%xmm1
divsd  0xea2(%rip),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
mulsd  %xmm1,%xmm0
xorpd  %xmm2,%xmm2
movapd (%rsp),%xmm4
cmpltsd %xmm4,%xmm2
andpd  %xmm0,%xmm2
mov    $0xf,%eax
sub    %ebx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
xorpd  %xmm3,%xmm3
mulsd  %xmm1,%xmm0
cmpltsd %xmm3,%xmm4
andpd  %xmm4,%xmm0
andnpd %xmm2,%xmm4
orpd   %xmm0,%xmm4
movapd %xmm4,%xmm0
ucomisd %xmm4,%xmm3
jbe    11d6 <timedelay_needed+0xa6>
lea    0xe55(%rip),%rdi
movapd %xmm0,(%rsp)
movaps (%rsp),%xmm0
call   1040 <printf@plt>
movapd (%rsp),%xmm0
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [36 x i8] c"Error in Time Needed Calc: %lf %lf\0A\00"
define double @timedelay_needed(double %0, double %1, i32 %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double
store double %0, double* %4
store double %1, double* %5
store i32 %2, i32* %6
store double 0.000000e+00, double* %7
store double 0.000000e+00, double* %8
store double 0x3FD32FCCB4ACA314, double* %9
%10 = load double, double* %5
%11 = load double, double* %4
%12 = call double @abs(double %11)
%13 = fdiv double %12, 1.800000e+02
%14 = fmul double %13, 3.141590e+00
%15 = call double @sin(double %14)
%16 = fmul double %10, %15
%17 = load double, double* %9
%18 = fdiv double %16, %17
store double %18, double* %7
%19 = load double, double* %4
%20 = fcmp ogt double %19, 0.000000e+00
br i1 %20, label %21, label %26
21: ; preds = %3
%22 = load i32, i32* %6
%23 = sitofp i32 %22 to double
%24 = load double, double* %7
%25 = fmul double %23, %24
store double %25, double* %8
br label %26
26: ; preds = %21, %3
%27 = load double, double* %4
%28 = fcmp olt double %27, 0.000000e+00
br i1 %28, label %29, label %35
29: ; preds = %26
%30 = load i32, i32* %6
%31 = sub nsw i32 15, %30
%32 = sitofp i32 %31 to double
%33 = load double, double* %7
%34 = fmul double %32, %33
store double %34, double* %8
br label %35
35: ; preds = %29, %26
%36 = load double, double* %8
%37 = fcmp olt double %36, 0.000000e+00
br i1 %37, label %38, label %42
38: ; preds = %35
%39 = load double, double* %8
%40 = load double, double* %7
%41 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), double %39, double %40)
br label %42
42: ; preds = %38, %35
%43 = load double, double* %8
ret double %43
}

LLVM IR (-O2):
@.str = [36 x i8] c"Error in Time Needed Calc: %lf %lf\0A\00"
define double @timedelay_needed(double %0, double %1, i32 %2) {
%4 = tail call double @abs(double %0)
%5 = fdiv double %4, 1.800000e+02
%6 = fmul double %5, 3.141590e+00
%7 = tail call double @sin(double %6)
%8 = fmul double %7, %1
%9 = fdiv double %8, 0x3FD32FCCB4ACA314
%10 = fcmp ogt double %0, 0.000000e+00
%11 = sitofp i32 %2 to double
%12 = fmul double %9, %11
%13 = select i1 %10, double %12, double 0.000000e+00
%14 = fcmp olt double %0, 0.000000e+00
%15 = sub nsw i32 15, %2
%16 = sitofp i32 %15 to double
%17 = fmul double %9, %16
%18 = select i1 %14, double %17, double %13
%19 = fcmp olt double %18, 0.000000e+00
br i1 %19, label %20, label %22
20: ; preds = %3
%21 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), double %18, double %9)
br label %22
22: ; preds = %20, %3
ret double %18
}