#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 fabs(double);
int sqrt(int);
int chealpix_ring_above(int nside_, double z) {
  double az = fabs(z);
  if (az <= 2. / 3.)
    return (int)(nside_ * (2 - 1.5 * z));
  int iring = (int)(nside_ * sqrt(3 * (1 - az)));
  return (z > 0) ? iring : 4 * nside_ - iring - 1;
}


x86 assembly (clang, -O0):
<chealpix_ring_above>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movaps 0xf04(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xec3(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     117a <chealpix_ring_above+0x6a>
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  0xebe(%rip),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xeba(%rip),%xmm2
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x4(%rbp)
jmp    11df <chealpix_ring_above+0xcf>
mov    -0x8(%rbp),%eax
mov    %eax,-0x20(%rbp)
movsd  0xe88(%rip),%xmm1
subsd  -0x18(%rbp),%xmm1
movsd  0xe73(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <sqrt@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x1c(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11ca <chealpix_ring_above+0xba>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    11d9 <chealpix_ring_above+0xc9>
mov    -0x8(%rbp),%eax
shl    $0x2,%eax
sub    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chealpix_ring_above>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movapd 0xee1(%rip),%xmm2
andpd  %xmm0,%xmm2
movsd  0xee5(%rip),%xmm1
ucomisd %xmm2,%xmm1
jae    1171 <chealpix_ring_above+0x61>
movsd  0xeef(%rip),%xmm1
subsd  %xmm2,%xmm1
mulsd  0xeeb(%rip),%xmm1
cvttsd2si %xmm1,%edi
movapd %xmm0,(%rsp)
call   1030 <sqrt@plt>
mov    %eax,%ecx
imul   %ebx,%ecx
xorpd  %xmm0,%xmm0
movapd (%rsp),%xmm1
ucomisd %xmm0,%xmm1
mov    %ecx,%eax
not    %eax
lea    (%rax,%rbx,4),%eax
cmova  %ecx,%eax
jmp    1190 <chealpix_ring_above+0x80>
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
mulsd  0xe98(%rip),%xmm0
addsd  0xe98(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @chealpix_ring_above(i32 %0, double %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca i32
store i32 %0, i32* %4
store double %1, double* %5
%8 = load double, double* %5
%9 = call double @llvm.fabs.f64(double %8)
store double %9, double* %6
%10 = load double, double* %6
%11 = fcmp ole double %10, 0x3FE5555555555555
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i32, i32* %4
%14 = sitofp i32 %13 to double
%15 = load double, double* %5
%16 = call double @llvm.fmuladd.f64(double -1.500000e+00, double %15, double 2.000000e+00)
%17 = fmul double %14, %16
%18 = fptosi double %17 to i32
store i32 %18, i32* %3
br label %39
19: ; preds = %2
%20 = load i32, i32* %4
%21 = load double, double* %6
%22 = fsub double 1.000000e+00, %21
%23 = fmul double 3.000000e+00, %22
%24 = fptosi double %23 to i32
%25 = call i32 @sqrt(i32 %24)
%26 = mul nsw i32 %20, %25
store i32 %26, i32* %7
%27 = load double, double* %5
%28 = fcmp ogt double %27, 0.000000e+00
br i1 %28, label %29, label %31
29: ; preds = %19
%30 = load i32, i32* %7
br label %37
31: ; preds = %19
%32 = load i32, i32* %4
%33 = mul nsw i32 4, %32
%34 = load i32, i32* %7
%35 = sub nsw i32 %33, %34
%36 = sub nsw i32 %35, 1
br label %37
37: ; preds = %31, %29
%38 = phi i32 [ %30, %29 ], [ %36, %31 ]
store i32 %38, i32* %3
br label %39
39: ; preds = %37, %12
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
define i32 @chealpix_ring_above(i32 %0, double %1) {
%3 = tail call double @llvm.fabs.f64(double %1)
%4 = fcmp ugt double %3, 0x3FE5555555555555
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = sitofp i32 %0 to double
%7 = tail call double @llvm.fmuladd.f64(double %1, double -1.500000e+00, double 2.000000e+00)
%8 = fmul double %7, %6
%9 = fptosi double %8 to i32
br label %21
10: ; preds = %2
%11 = fsub double 1.000000e+00, %3
%12 = fmul double %11, 3.000000e+00
%13 = fptosi double %12 to i32
%14 = tail call i32 @sqrt(i32 %13)
%15 = mul nsw i32 %14, %0
%16 = fcmp ogt double %1, 0.000000e+00
%17 = shl nsw i32 %0, 2
%18 = xor i32 %15, -1
%19 = add i32 %17, %18
%20 = select i1 %16, i32 %15, i32 %19
br label %21
21: ; preds = %10, %5
%22 = phi i32 [ %9, %5 ], [ %20, %10 ]
ret i32 %22
}