#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 fmod(double, double);
int /*<<< orphan*/ sphdist(double, double, double, double, double *);
void quadcube_getface(double lon, double lat, int *face) {
  int i, tmpface = 0;
  double sdist, mindist = 1000;
  double lonf;
  sphdist(lon, lat, 0.0, 1.5707963267948966, &sdist);
  if (sdist < mindist) {
    mindist = sdist;
    tmpface = 0;
  }
  sphdist(lon, lat, 0.0, -1.0 * 1.5707963267948966, &sdist);
  if (sdist < mindist) {
    mindist = sdist;
    tmpface = 5;
  }
  for (i = 1; i < 5; i++) {
    lonf = fmod(0.0 + ((i - 1) * 1.5707963267948966), 6.283185307179586);
    sphdist(lon, lat, lonf, 0.0, &sdist);
    if (sdist < mindist) {
      mindist = sdist;
      tmpface = i;
    }
  }
  *face = tmpface;
}


x86 assembly (clang, -O0):
<quadcube_getface>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movsd  0xec3(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
xorps  %xmm2,%xmm2
movsd  0xea1(%rip),%xmm3
lea    -0x28(%rbp),%rdi
call   1040 <sphdist@plt>
movsd  -0x28(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    118d <quadcube_getface+0x6d>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
xorps  %xmm2,%xmm2
movsd  0xe6e(%rip),%xmm3
lea    -0x28(%rbp),%rdi
call   1040 <sphdist@plt>
movsd  -0x28(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11d0 <quadcube_getface+0xb0>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x5,-0x20(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x5,-0x1c(%rbp)
jge    1262 <quadcube_getface+0x142>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  0xe0d(%rip),%xmm1
mulsd  %xmm1,%xmm0
xorps  %xmm1,%xmm1
addsd  %xmm1,%xmm0
movsd  0xe12(%rip),%xmm1
call   1030 <fmod@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm2
xorps  %xmm3,%xmm3
lea    -0x28(%rbp),%rdi
call   1040 <sphdist@plt>
movsd  -0x28(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    124f <quadcube_getface+0x12f>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    1254 <quadcube_getface+0x134>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11d7 <quadcube_getface+0xb7>
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quadcube_getface>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r14
movsd  %xmm1,0x20(%rsp)
movsd  %xmm0,0x18(%rsp)
movsd  0xecf(%rip),%xmm3
lea    0x10(%rsp),%r15
xorps  %xmm2,%xmm2
mov    %r15,%rdi
call   1030 <sphdist@plt>
movsd  0x10(%rsp),%xmm0
minsd  0xeb9(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xeb3(%rip),%xmm3
xorps  %xmm2,%xmm2
movsd  0x18(%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
mov    %r15,%rdi
call   1030 <sphdist@plt>
movsd  0x10(%rsp),%xmm0
xor    %eax,%eax
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
seta   %al
lea    (%rax,%rax,4),%ebp
minsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
xorps  %xmm2,%xmm2
xorps  %xmm3,%xmm3
movsd  0x18(%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
mov    %r15,%rdi
call   1030 <sphdist@plt>
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
mov    $0x1,%ebx
cmovbe %ebp,%ebx
minsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
xorps  %xmm3,%xmm3
movsd  0x18(%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
movsd  0xe17(%rip),%xmm2
mov    %r15,%rdi
call   1030 <sphdist@plt>
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
mov    $0x2,%ebp
cmovbe %ebx,%ebp
minsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xdfd(%rip),%xmm2
xorps  %xmm3,%xmm3
movsd  0x18(%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
mov    %r15,%rdi
call   1030 <sphdist@plt>
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
mov    $0x3,%ebx
cmovbe %ebp,%ebx
minsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xdc4(%rip),%xmm2
xorps  %xmm3,%xmm3
movsd  0x18(%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
mov    %r15,%rdi
call   1030 <sphdist@plt>
movsd  0x8(%rsp),%xmm0
ucomisd 0x10(%rsp),%xmm0
mov    $0x4,%eax
cmovbe %ebx,%eax
mov    %eax,(%r14)
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @quadcube_getface(double %0, double %1, i32* %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double
store double %0, double* %4
store double %1, double* %5
store i32* %2, i32** %6
store i32 0, i32* %8
store double 1.000000e+03, double* %10
%12 = load double, double* %4
%13 = load double, double* %5
%14 = call i32 @sphdist(double %12, double %13, double 0.000000e+00, double 0x3FF921FB54442D18, double* %9)
%15 = load double, double* %9
%16 = load double, double* %10
%17 = fcmp olt double %15, %16
br i1 %17, label %18, label %20
18: ; preds = %3
%19 = load double, double* %9
store double %19, double* %10
store i32 0, i32* %8
br label %20
20: ; preds = %18, %3
%21 = load double, double* %4
%22 = load double, double* %5
%23 = call i32 @sphdist(double %21, double %22, double 0.000000e+00, double 0xBFF921FB54442D18, double* %9)
%24 = load double, double* %9
%25 = load double, double* %10
%26 = fcmp olt double %24, %25
br i1 %26, label %27, label %29
27: ; preds = %20
%28 = load double, double* %9
store double %28, double* %10
store i32 5, i32* %8
br label %29
29: ; preds = %27, %20
store i32 1, i32* %7
br label %30
30: ; preds = %50, %29
%31 = load i32, i32* %7
%32 = icmp slt i32 %31, 5
br i1 %32, label %33, label %53
33: ; preds = %30
%34 = load i32, i32* %7
%35 = sub nsw i32 %34, 1
%36 = sitofp i32 %35 to double
%37 = call double @llvm.fmuladd.f64(double %36, double 0x3FF921FB54442D18, double 0.000000e+00)
%38 = call double @fmod(double %37, double 0x401921FB54442D18)
store double %38, double* %11
%39 = load double, double* %4
%40 = load double, double* %5
%41 = load double, double* %11
%42 = call i32 @sphdist(double %39, double %40, double %41, double 0.000000e+00, double* %9)
%43 = load double, double* %9
%44 = load double, double* %10
%45 = fcmp olt double %43, %44
br i1 %45, label %46, label %49
46: ; preds = %33
%47 = load double, double* %9
store double %47, double* %10
%48 = load i32, i32* %7
store i32 %48, i32* %8
br label %49
49: ; preds = %46, %33
br label %50
50: ; preds = %49
%51 = load i32, i32* %7
%52 = add nsw i32 %51, 1
store i32 %52, i32* %7
br label %30
53: ; preds = %30
%54 = load i32, i32* %8
%55 = load i32*, i32** %6
store i32 %54, i32* %55
ret void
}

LLVM IR (-O2):
define void @quadcube_getface(double %0, double %1, i32* nocapture writeonly %2) {
%4 = alloca double
%5 = bitcast double* %4 to i8*
%6 = call i32 @sphdist(double %0, double %1, double 0.000000e+00, double 0x3FF921FB54442D18, double* %4)
%7 = load double, double* %4
%8 = fcmp olt double %7, 1.000000e+03
%9 = select i1 %8, double %7, double 1.000000e+03
%10 = call i32 @sphdist(double %0, double %1, double 0.000000e+00, double 0xBFF921FB54442D18, double* %4)
%11 = load double, double* %4
%12 = fcmp olt double %11, %9
%13 = select i1 %12, i32 5, i32 0
%14 = select i1 %12, double %11, double %9
%15 = call i32 @sphdist(double %0, double %1, double 0.000000e+00, double 0.000000e+00, double* %4)
%16 = load double, double* %4
%17 = fcmp olt double %16, %14
%18 = select i1 %17, i32 1, i32 %13
%19 = select i1 %17, double %16, double %14
%20 = call i32 @sphdist(double %0, double %1, double 0x3FF921FB54442D18, double 0.000000e+00, double* %4)
%21 = load double, double* %4
%22 = fcmp olt double %21, %19
%23 = select i1 %22, i32 2, i32 %18
%24 = select i1 %22, double %21, double %19
%25 = call i32 @sphdist(double %0, double %1, double 0x400921FB54442D18, double 0.000000e+00, double* %4)
%26 = load double, double* %4
%27 = fcmp olt double %26, %24
%28 = select i1 %27, i32 3, i32 %23
%29 = select i1 %27, double %26, double %24
%30 = call i32 @sphdist(double %0, double %1, double 0x4012D97C7F3321D2, double 0.000000e+00, double* %4)
%31 = load double, double* %4
%32 = fcmp olt double %31, %29
%33 = select i1 %32, i32 4, i32 %28
store i32 %33, i32* %2
ret void
}