#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 int32_t;

/* Variables and functions */
double fabs(double);
int /*<<< orphan*/ printf(char *, double, double);
double sin(double);
double timedelay_needed(double angle, double spacing, int32_t card) {
  double deltat = 0;
  double needed = 0;
  double c = 0.299792458;
  int32_t antenna = -1;
  double radians = 0.0;
  if (card > 15)
    antenna = card - 10;
  else
    antenna = card;
  deltat = (spacing / c) * sin((fabs(angle) * 3.14159) / 180.0);
  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    $0x50,%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)
movl   $0xffffffff,-0x34(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
cmpl   $0xf,-0x14(%rbp)
jle    1179 <timedelay_needed+0x59>
mov    -0x14(%rbp),%eax
sub    $0xa,%eax
mov    %eax,-0x34(%rbp)
jmp    117f <timedelay_needed+0x5f>
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
movsd  -0x10(%rbp),%xmm0
divsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x8(%rbp),%xmm0
movaps 0xe86(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xe6a(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe56(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11ed <timedelay_needed+0xcd>
cvtsi2sdl -0x34(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1211 <timedelay_needed+0xf1>
mov    $0xf,%eax
sub    -0x34(%rbp),%eax
cvtsi2sd %eax,%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    1235 <timedelay_needed+0x115>
movsd  -0x28(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
lea    0xe00(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x28(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timedelay_needed>:
push   %rbx
sub    $0x20,%rsp
movapd %xmm0,%xmm2
movapd %xmm0,(%rsp)
lea    -0xa(%rdi),%ebx
cmp    $0x10,%edi
cmovl  %edi,%ebx
divsd  0xec1(%rip),%xmm1
movsd  %xmm1,0x18(%rsp)
movapd 0xed3(%rip),%xmm0
andpd  %xmm2,%xmm0
mulsd  0xeaf(%rip),%xmm0
divsd  0xeaf(%rip),%xmm0
call   1040 <sin@plt>
movapd %xmm0,%xmm1
mulsd  0x18(%rsp),%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    11d8 <timedelay_needed+0xb8>
lea    0xe6b(%rip),%rdi
movapd %xmm0,(%rsp)
movaps (%rsp),%xmm0
call   1030 <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
%10 = alloca i32
%11 = 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
store i32 -1, i32* %10
store double 0.000000e+00, double* %11
%12 = load i32, i32* %6
%13 = icmp sgt i32 %12, 15
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = load i32, i32* %6
%16 = sub nsw i32 %15, 10
store i32 %16, i32* %10
br label %19
17: ; preds = %3
%18 = load i32, i32* %6
store i32 %18, i32* %10
br label %19
19: ; preds = %17, %14
%20 = load double, double* %5
%21 = load double, double* %9
%22 = fdiv double %20, %21
%23 = load double, double* %4
%24 = call double @llvm.fabs.f64(double %23)
%25 = fmul double %24, 3.141590e+00
%26 = fdiv double %25, 1.800000e+02
%27 = call double @sin(double %26)
%28 = fmul double %22, %27
store double %28, double* %7
%29 = load double, double* %4
%30 = fcmp ogt double %29, 0.000000e+00
br i1 %30, label %31, label %36
31: ; preds = %19
%32 = load i32, i32* %10
%33 = sitofp i32 %32 to double
%34 = load double, double* %7
%35 = fmul double %33, %34
store double %35, double* %8
br label %36
36: ; preds = %31, %19
%37 = load double, double* %4
%38 = fcmp olt double %37, 0.000000e+00
br i1 %38, label %39, label %45
39: ; preds = %36
%40 = load i32, i32* %10
%41 = sub nsw i32 15, %40
%42 = sitofp i32 %41 to double
%43 = load double, double* %7
%44 = fmul double %42, %43
store double %44, double* %8
br label %45
45: ; preds = %39, %36
%46 = load double, double* %8
%47 = fcmp olt double %46, 0.000000e+00
br i1 %47, label %48, label %52
48: ; preds = %45
%49 = load double, double* %8
%50 = load double, double* %7
%51 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), double %49, double %50)
br label %52
52: ; preds = %48, %45
%53 = load double, double* %8
ret double %53
}

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 = icmp sgt i32 %2, 15
%5 = add nsw i32 %2, -10
%6 = select i1 %4, i32 %5, i32 %2
%7 = fdiv double %1, 0x3FD32FCCB4ACA314
%8 = tail call double @llvm.fabs.f64(double %0)
%9 = fmul double %8, 3.141590e+00
%10 = fdiv double %9, 1.800000e+02
%11 = tail call double @sin(double %10)
%12 = fmul double %7, %11
%13 = fcmp ogt double %0, 0.000000e+00
%14 = sitofp i32 %6 to double
%15 = fmul double %12, %14
%16 = select i1 %13, double %15, double 0.000000e+00
%17 = fcmp olt double %0, 0.000000e+00
%18 = sub nsw i32 15, %6
%19 = sitofp i32 %18 to double
%20 = fmul double %12, %19
%21 = select i1 %17, double %20, double %16
%22 = fcmp olt double %21, 0.000000e+00
br i1 %22, label %23, label %25
23: ; preds = %3
%24 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), double %21, double %12)
br label %25
25: ; preds = %23, %3
ret double %21
}