#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 M_PI;
double cos(double);
int floor(double);
double log(scalar_t__);
double pow(double, int);
scalar_t__ tan(double);
int lat2tile(double lat, int z) {
  int y = floor(
      (1.0 -
       log(tan(lat * M_PI / 180.0) + 1.0 / cos(lat * M_PI / 180.0)) / M_PI) /
      2.0 * pow(2.0, z));
  return y < 0 ? 0 : y;
}


x86 assembly (clang, -O0):
<lat2tile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    0x2e7c(%rip),%rax
mulsd  (%rax),%xmm0
movsd  0xe98(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1030 <tan@plt>
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    0x2e51(%rip),%rax
mulsd  (%rax),%xmm0
movsd  0xe6d(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <cos@plt>
movaps %xmm0,%xmm2
movsd  -0x20(%rbp),%xmm0
movsd  0xe4c(%rip),%xmm1
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rdi
call   1050 <log@plt>
movaps %xmm0,%xmm1
mov    0x2e10(%rip),%rax
divsd  (%rax),%xmm1
movsd  0xe24(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  0xe10(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0xc(%rbp),%edi
movsd  0xdfc(%rip),%xmm0
call   1060 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
mulsd  %xmm1,%xmm0
call   1070 <floor@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1231 <lat2tile+0xe1>
xor    %eax,%eax
mov    %eax,-0x24(%rbp)
jmp    1237 <lat2tile+0xe7>
mov    -0x10(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lat2tile>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebp
movapd %xmm0,%xmm1
movsd  %xmm0,0x10(%rsp)
mov    0x2e7f(%rip),%rbx
movsd  (%rbx),%xmm0
mulsd  %xmm1,%xmm0
divsd  0xe87(%rip),%xmm0
call   1030 <tan@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
mulsd  (%rbx),%xmm0
divsd  0xe62(%rip),%xmm0
call   1040 <cos@plt>
movsd  0xe5d(%rip),%xmm1
divsd  %xmm0,%xmm1
addsd  0x8(%rsp),%xmm1
cvttsd2si %xmm1,%rdi
call   1050 <log@plt>
divsd  (%rbx),%xmm0
movsd  0xe3d(%rip),%xmm1
subsd  %xmm0,%xmm1
mulsd  0xe39(%rip),%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0xe33(%rip),%xmm0
mov    %ebp,%edi
call   1060 <pow@plt>
mulsd  0x8(%rsp),%xmm0
call   1070 <floor@plt>
xor    %ecx,%ecx
test   %eax,%eax
cmovs  %ecx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@M_PI = global double 0.000000e+00
define i32 @lat2tile(double %0, i32 %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca i32
store double %0, double* %3
store i32 %1, i32* %4
%6 = load double, double* %3
%7 = load double, double* @M_PI
%8 = fmul double %6, %7
%9 = fdiv double %8, 1.800000e+02
%10 = call i64 @tan(double %9)
%11 = sitofp i64 %10 to double
%12 = load double, double* %3
%13 = load double, double* @M_PI
%14 = fmul double %12, %13
%15 = fdiv double %14, 1.800000e+02
%16 = call double @cos(double %15)
%17 = fdiv double 1.000000e+00, %16
%18 = fadd double %11, %17
%19 = fptosi double %18 to i64
%20 = call double @log(i64 %19)
%21 = load double, double* @M_PI
%22 = fdiv double %20, %21
%23 = fsub double 1.000000e+00, %22
%24 = fdiv double %23, 2.000000e+00
%25 = load i32, i32* %4
%26 = call double @pow(double 2.000000e+00, i32 %25)
%27 = fmul double %24, %26
%28 = call i32 @floor(double %27)
store i32 %28, i32* %5
%29 = load i32, i32* %5
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %2
br label %34
32: ; preds = %2
%33 = load i32, i32* %5
br label %34
34: ; preds = %32, %31
%35 = phi i32 [ 0, %31 ], [ %33, %32 ]
ret i32 %35
}

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
define i32 @lat2tile(double %0, i32 %1) {
%3 = load double, double* @M_PI
%4 = fmul double %3, %0
%5 = fdiv double %4, 1.800000e+02
%6 = tail call i64 @tan(double %5)
%7 = sitofp i64 %6 to double
%8 = load double, double* @M_PI
%9 = fmul double %8, %0
%10 = fdiv double %9, 1.800000e+02
%11 = tail call double @cos(double %10)
%12 = fdiv double 1.000000e+00, %11
%13 = fadd double %12, %7
%14 = fptosi double %13 to i64
%15 = tail call double @log(i64 %14)
%16 = load double, double* @M_PI
%17 = fdiv double %15, %16
%18 = fsub double 1.000000e+00, %17
%19 = fmul double %18, 5.000000e-01
%20 = tail call double @pow(double 2.000000e+00, i32 %1)
%21 = fmul double %20, %19
%22 = tail call i32 @floor(double %21)
%23 = icmp sgt i32 %22, 0
%24 = select i1 %23, i32 %22, i32 0
ret i32 %24
}