#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 asin(double);
double atan2(double, double);
int /*<<< orphan*/ printf(char *);
double vector_mag(double *);
int rect_to_radec(double vector[], double *ra, double *dec, double *r) {
  *r = vector_mag(vector);
  if (*r < 1e-6) {
    (void)printf("\nERROR, rect_to_radec given a zero length vector!\n");
    return (-1);
  }
  *ra = atan2(vector[1], vector[0]);
  if (*ra < 0.0)
    *ra = *ra + (2 * 3.14159265358979323846);
  *dec = asin(vector[2] / (*r));
  return (0);
}


x86 assembly (clang, -O0):
<rect_to_radec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <vector_mag@plt>
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x28(%rbp),%rax
movsd  0xe8b(%rip),%xmm0
ucomisd (%rax),%xmm0
jbe    1197 <rect_to_radec+0x57>
lea    0xe8a(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1203 <rect_to_radec+0xc3>
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
call   1030 <atan2@plt>
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
ucomisd (%rax),%xmm0
jbe    11de <rect_to_radec+0x9e>
mov    -0x18(%rbp),%rax
movsd  0xe36(%rip),%xmm0
addsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x28(%rbp),%rax
divsd  (%rax),%xmm0
call   1050 <asin@plt>
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rect_to_radec>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%rbx
call   1060 <vector_mag@plt>
movsd  %xmm0,(%r15)
movsd  0xe9a(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    117f <rect_to_radec+0x3f>
lea    0xe9d(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
jmp    11ce <rect_to_radec+0x8e>
movsd  (%rbx),%xmm1
movsd  0x8(%rbx),%xmm0
call   1040 <atan2@plt>
movsd  0xe73(%rip),%xmm1
addsd  %xmm0,%xmm1
xorpd  %xmm2,%xmm2
movapd %xmm0,%xmm3
cmpltsd %xmm2,%xmm3
andpd  %xmm3,%xmm1
andnpd %xmm0,%xmm3
orpd   %xmm1,%xmm3
movlpd %xmm3,(%r12)
movsd  0x10(%rbx),%xmm0
divsd  (%r15),%xmm0
call   1050 <asin@plt>
movsd  %xmm0,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [51 x i8] c"\0AERROR, rect_to_radec given a zero length vector!\0A\00"
define i32 @rect_to_radec(double* %0, double* %1, double* %2, double* %3) {
%5 = alloca i32
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca double*
store double* %0, double** %6
store double* %1, double** %7
store double* %2, double** %8
store double* %3, double** %9
%10 = load double*, double** %6
%11 = call double @vector_mag(double* %10)
%12 = load double*, double** %9
store double %11, double* %12
%13 = load double*, double** %9
%14 = load double, double* %13
%15 = fcmp olt double %14, 0x3EB0C6F7A0B5ED8D
br i1 %15, label %16, label %18
16: ; preds = %4
%17 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
br label %44
18: ; preds = %4
%19 = load double*, double** %6
%20 = getelementptr inbounds double, double* %19, i64 1
%21 = load double, double* %20
%22 = load double*, double** %6
%23 = getelementptr inbounds double, double* %22, i64 0
%24 = load double, double* %23
%25 = call double @atan2(double %21, double %24)
%26 = load double*, double** %7
store double %25, double* %26
%27 = load double*, double** %7
%28 = load double, double* %27
%29 = fcmp olt double %28, 0.000000e+00
br i1 %29, label %30, label %35
30: ; preds = %18
%31 = load double*, double** %7
%32 = load double, double* %31
%33 = fadd double %32, 0x401921FB54442D18
%34 = load double*, double** %7
store double %33, double* %34
br label %35
35: ; preds = %30, %18
%36 = load double*, double** %6
%37 = getelementptr inbounds double, double* %36, i64 2
%38 = load double, double* %37
%39 = load double*, double** %9
%40 = load double, double* %39
%41 = fdiv double %38, %40
%42 = call double @asin(double %41)
%43 = load double*, double** %8
store double %42, double* %43
store i32 0, i32* %5
br label %44
44: ; preds = %35, %16
%45 = load i32, i32* %5
ret i32 %45
}

LLVM IR (-O2):
@str = [50 x i8] c"\0AERROR, rect_to_radec given a zero length vector!\00"
define i32 @rect_to_radec(double* %0, double* nocapture writeonly %1, double* nocapture writeonly %2, double* nocapture %3) {
%5 = tail call double @vector_mag(double* %0)
store double %5, double* %3
%6 = fcmp olt double %5, 0x3EB0C6F7A0B5ED8D
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str, i64 0, i64 0))
br label %22
9: ; preds = %4
%10 = getelementptr inbounds double, double* %0, i64 1
%11 = load double, double* %10
%12 = load double, double* %0
%13 = tail call double @atan2(double %11, double %12)
%14 = fcmp olt double %13, 0.000000e+00
%15 = fadd double %13, 0x401921FB54442D18
%16 = select i1 %14, double %15, double %13
store double %16, double* %1
%17 = getelementptr inbounds double, double* %0, i64 2
%18 = load double, double* %17
%19 = load double, double* %3
%20 = fdiv double %18, %19
%21 = tail call double @asin(double %20)
store double %21, double* %2
br label %22
22: ; preds = %9, %7
%23 = phi i32 [ -1, %7 ], [ 0, %9 ]
ret i32 %23
}