#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 /*<<< orphan*/ int64_t;

/* Variables and functions */
int /*<<< orphan*/ ang2pix_ring_z_phi64(int /*<<< orphan*/, double, double,
                                        int /*<<< orphan*/);
int /*<<< orphan*/ atan2(double const, double const);
double fabs(double);
double sqrt(double const);
void vec2pix_ring64(int64_t nside, const double *vec, int64_t *ipix) {
  double vlen = sqrt(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]);
  double cth = vec[2] / vlen;
  double sth =
      (fabs(cth) > 0.99) ? sqrt(vec[0] * vec[0] + vec[1] * vec[1]) / vlen : -5;
  *ipix = ang2pix_ring_z_phi64(nside, cth, sth, atan2(vec[1], vec[0]));
}


x86 assembly (clang, -O0):
<vec2pix_ring64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movaps 0xe60(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xe44(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1204 <vec2pix_ring64+0xd4>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x10(%rbp),%rax
mulsd  0x8(%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1216 <vec2pix_ring64+0xe6>
movsd  0xdfc(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1216 <vec2pix_ring64+0xe6>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x4c(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
call   1030 <atan2@plt>
mov    -0x4c(%rbp),%edi
movsd  -0x48(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
mov    %eax,%esi
call   1040 <ang2pix_ring_z_phi64@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vec2pix_ring64>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
movsd  (%rsi),%xmm1
movsd  0x8(%rsi),%xmm0
mulsd  %xmm0,%xmm0
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0x10(%rsi),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1172 <vec2pix_ring64+0x42>
sqrtsd %xmm0,%xmm2
jmp    117b <vec2pix_ring64+0x4b>
call   1050 <sqrt@plt>
movapd %xmm0,%xmm2
movsd  0x10(%rbx),%xmm1
divsd  %xmm2,%xmm1
movapd 0xe74(%rip),%xmm0
andpd  %xmm1,%xmm0
ucomisd 0xe80(%rip),%xmm0
movapd %xmm1,0x10(%rsp)
jbe    11c5 <vec2pix_ring64+0x95>
movsd  (%rbx),%xmm0
movsd  0x8(%rbx),%xmm1
mulsd  %xmm1,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11cf <vec2pix_ring64+0x9f>
sqrtsd %xmm0,%xmm0
jmp    11e0 <vec2pix_ring64+0xb0>
movsd  0xe43(%rip),%xmm0
jmp    11e4 <vec2pix_ring64+0xb4>
movsd  %xmm2,0x8(%rsp)
call   1050 <sqrt@plt>
movsd  0x8(%rsp),%xmm2
divsd  %xmm2,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  (%rbx),%xmm1
movsd  0x8(%rbx),%xmm0
call   1030 <atan2@plt>
mov    %ebp,%edi
movaps 0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mov    %eax,%esi
call   1040 <ang2pix_ring_z_phi64@plt>
mov    %eax,(%r14)
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @vec2pix_ring64(i32 %0, double* %1, i32* %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca i32*
%7 = alloca double
%8 = alloca double
%9 = alloca double
store i32 %0, i32* %4
store double* %1, double** %5
store i32* %2, i32** %6
%10 = load double*, double** %5
%11 = getelementptr inbounds double, double* %10, i64 0
%12 = load double, double* %11
%13 = load double*, double** %5
%14 = getelementptr inbounds double, double* %13, i64 0
%15 = load double, double* %14
%16 = load double*, double** %5
%17 = getelementptr inbounds double, double* %16, i64 1
%18 = load double, double* %17
%19 = load double*, double** %5
%20 = getelementptr inbounds double, double* %19, i64 1
%21 = load double, double* %20
%22 = fmul double %18, %21
%23 = call double @llvm.fmuladd.f64(double %12, double %15, double %22)
%24 = load double*, double** %5
%25 = getelementptr inbounds double, double* %24, i64 2
%26 = load double, double* %25
%27 = load double*, double** %5
%28 = getelementptr inbounds double, double* %27, i64 2
%29 = load double, double* %28
%30 = call double @llvm.fmuladd.f64(double %26, double %29, double %23)
%31 = call double @sqrt(double %30)
store double %31, double* %7
%32 = load double*, double** %5
%33 = getelementptr inbounds double, double* %32, i64 2
%34 = load double, double* %33
%35 = load double, double* %7
%36 = fdiv double %34, %35
store double %36, double* %8
%37 = load double, double* %8
%38 = call double @llvm.fabs.f64(double %37)
%39 = fcmp ogt double %38, 0x3FEFAE147AE147AE
br i1 %39, label %40, label %58
40: ; preds = %3
%41 = load double*, double** %5
%42 = getelementptr inbounds double, double* %41, i64 0
%43 = load double, double* %42
%44 = load double*, double** %5
%45 = getelementptr inbounds double, double* %44, i64 0
%46 = load double, double* %45
%47 = load double*, double** %5
%48 = getelementptr inbounds double, double* %47, i64 1
%49 = load double, double* %48
%50 = load double*, double** %5
%51 = getelementptr inbounds double, double* %50, i64 1
%52 = load double, double* %51
%53 = fmul double %49, %52
%54 = call double @llvm.fmuladd.f64(double %43, double %46, double %53)
%55 = call double @sqrt(double %54)
%56 = load double, double* %7
%57 = fdiv double %55, %56
br label %59
58: ; preds = %3
br label %59
59: ; preds = %58, %40
%60 = phi double [ %57, %40 ], [ -5.000000e+00, %58 ]
store double %60, double* %9
%61 = load i32, i32* %4
%62 = load double, double* %8
%63 = load double, double* %9
%64 = load double*, double** %5
%65 = getelementptr inbounds double, double* %64, i64 1
%66 = load double, double* %65
%67 = load double*, double** %5
%68 = getelementptr inbounds double, double* %67, i64 0
%69 = load double, double* %68
%70 = call i32 @atan2(double %66, double %69)
%71 = call i32 @ang2pix_ring_z_phi64(i32 %61, double %62, double %63, i32 %70)
%72 = load i32*, i32** %6
store i32 %71, i32* %72
ret void
}

LLVM IR (-O2):
define void @vec2pix_ring64(i32 %0, double* nocapture %1, i32* nocapture writeonly %2) {
%4 = load double, double* %1
%5 = getelementptr inbounds double, double* %1, i64 1
%6 = load double, double* %5
%7 = fmul double %6, %6
%8 = tail call double @llvm.fmuladd.f64(double %4, double %4, double %7)
%9 = getelementptr inbounds double, double* %1, i64 2
%10 = load double, double* %9
%11 = tail call double @llvm.fmuladd.f64(double %10, double %10, double %8)
%12 = tail call double @sqrt(double %11)
%13 = load double, double* %9
%14 = fdiv double %13, %12
%15 = tail call double @llvm.fabs.f64(double %14)
%16 = fcmp ogt double %15, 0x3FEFAE147AE147AE
br i1 %16, label %17, label %24
17: ; preds = %3
%18 = load double, double* %1
%19 = load double, double* %5
%20 = fmul double %19, %19
%21 = tail call double @llvm.fmuladd.f64(double %18, double %18, double %20)
%22 = tail call double @sqrt(double %21)
%23 = fdiv double %22, %12
br label %24
24: ; preds = %3, %17
%25 = phi double [ %23, %17 ], [ -5.000000e+00, %3 ]
%26 = load double, double* %5
%27 = load double, double* %1
%28 = tail call i32 @atan2(double %26, double %27)
%29 = tail call i32 @ang2pix_ring_z_phi64(i32 %0, double %14, double %25, i32 %28)
store i32 %29, i32* %2
ret void
}