#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;
int cos(double);
double log(scalar_t__);
scalar_t__ tan(double);
void latlon2tile(double lat, double lon, int zoom, unsigned int *x,
                 unsigned int *y) {
  double lat_rad = lat * M_PI / 180;
  unsigned long long n = 1LL << zoom;
  *x = n * ((lon + 180) / 360);
  *y = n * (1 - (log(tan(lat_rad) + 1 / cos(lat_rad)) / M_PI)) / 2;
}


x86 assembly (clang, -O0):
<latlon2tile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    0x2e8f(%rip),%rax
mov    %rax,-0x48(%rbp)
movsd  (%rax),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe93(%rip),%xmm4
divsd  %xmm4,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x14(%rbp),%cl
mov    $0x1,%eax
shl    %cl,%rax
mov    %rax,-0x38(%rbp)
movq   -0x38(%rbp),%xmm0
movaps 0xe8f(%rip),%xmm2
punpckldq %xmm2,%xmm0
movapd 0xe93(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm3
unpckhpd %xmm0,%xmm0
addsd  %xmm3,%xmm0
movsd  -0x10(%rbp),%xmm3
addsd  %xmm4,%xmm3
movsd  0xe4b(%rip),%xmm4
divsd  %xmm4,%xmm3
mulsd  %xmm3,%xmm0
cvttsd2si %xmm0,%rax
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movq   -0x38(%rbp),%xmm0
punpckldq %xmm2,%xmm0
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1030 <tan@plt>
mov    %rax,-0x50(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1040 <cos@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%ecx
xor    %edx,%edx
mov    $0x1,%eax
idiv   %ecx
cltq
add    %rax,%rdi
call   1050 <log@plt>
mov    -0x48(%rbp),%rax
movaps %xmm0,%xmm2
movsd  -0x40(%rbp),%xmm0
movsd  (%rax),%xmm1
divsd  %xmm1,%xmm2
movsd  0xdd4(%rip),%xmm1
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdcc(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<latlon2tile>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%r14
mov    %edi,%ecx
mov    0x2ea3(%rip),%r15
mulsd  (%r15),%xmm0
movapd %xmm0,%xmm3
mov    $0x1,%eax
shl    %cl,%rax
movsd  0xea2(%rip),%xmm4
movq   %rax,%xmm2
punpckldq 0xeb5(%rip),%xmm2
divsd  %xmm4,%xmm3
movapd %xmm3,%xmm0
movsd  %xmm3,0x8(%rsp)
subpd  0xeaf(%rip),%xmm2
movapd %xmm2,%xmm3
unpckhpd %xmm2,%xmm3
addsd  %xmm2,%xmm3
movapd %xmm3,0x10(%rsp)
addsd  %xmm4,%xmm1
divsd  0xe69(%rip),%xmm1
mulsd  %xmm3,%xmm1
cvttsd2si %xmm1,%rax
mov    %eax,(%rsi)
call   1030 <tan@plt>
mov    %rax,%rbx
movsd  0x8(%rsp),%xmm0
call   1040 <cos@plt>
lea    0x1(%rax),%ecx
xor    %edx,%edx
cmp    $0x3,%ecx
cmovb  %eax,%edx
movslq %edx,%rdi
add    %rbx,%rdi
call   1050 <log@plt>
divsd  (%r15),%xmm0
movsd  0xe30(%rip),%xmm1
subsd  %xmm0,%xmm1
mulsd  0x10(%rsp),%xmm1
mulsd  0xe26(%rip),%xmm1
cvttsd2si %xmm1,%rax
mov    %eax,(%r14)
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@M_PI = global double 0.000000e+00
define void @latlon2tile(double %0, double %1, i32 %2, i32* %3, i32* %4) {
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca double
%12 = alloca i64
store double %0, double* %6
store double %1, double* %7
store i32 %2, i32* %8
store i32* %3, i32** %9
store i32* %4, i32** %10
%13 = load double, double* %6
%14 = load double, double* @M_PI
%15 = fmul double %13, %14
%16 = fdiv double %15, 1.800000e+02
store double %16, double* %11
%17 = load i32, i32* %8
%18 = zext i32 %17 to i64
%19 = shl i64 1, %18
store i64 %19, i64* %12
%20 = load i64, i64* %12
%21 = uitofp i64 %20 to double
%22 = load double, double* %7
%23 = fadd double %22, 1.800000e+02
%24 = fdiv double %23, 3.600000e+02
%25 = fmul double %21, %24
%26 = fptoui double %25 to i32
%27 = load i32*, i32** %9
store i32 %26, i32* %27
%28 = load i64, i64* %12
%29 = uitofp i64 %28 to double
%30 = load double, double* %11
%31 = call i64 @tan(double %30)
%32 = load double, double* %11
%33 = call i32 @cos(double %32)
%34 = sdiv i32 1, %33
%35 = sext i32 %34 to i64
%36 = add nsw i64 %31, %35
%37 = call double @log(i64 %36)
%38 = load double, double* @M_PI
%39 = fdiv double %37, %38
%40 = fsub double 1.000000e+00, %39
%41 = fmul double %29, %40
%42 = fdiv double %41, 2.000000e+00
%43 = fptoui double %42 to i32
%44 = load i32*, i32** %10
store i32 %43, i32* %44
ret void
}

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
define void @latlon2tile(double %0, double %1, i32 %2, i32* nocapture writeonly %3, i32* nocapture writeonly %4) {
%6 = load double, double* @M_PI
%7 = fmul double %6, %0
%8 = fdiv double %7, 1.800000e+02
%9 = zext i32 %2 to i64
%10 = shl nuw i64 1, %9
%11 = uitofp i64 %10 to double
%12 = fadd double %1, 1.800000e+02
%13 = fdiv double %12, 3.600000e+02
%14 = fmul double %13, %11
%15 = fptoui double %14 to i32
store i32 %15, i32* %3
%16 = tail call i64 @tan(double %8)
%17 = tail call i32 @cos(double %8)
%18 = add i32 %17, 1
%19 = icmp ult i32 %18, 3
%20 = select i1 %19, i32 %17, i32 0
%21 = sext i32 %20 to i64
%22 = add nsw i64 %16, %21
%23 = tail call double @log(i64 %22)
%24 = load double, double* @M_PI
%25 = fdiv double %23, %24
%26 = fsub double 1.000000e+00, %25
%27 = fmul double %26, %11
%28 = fmul double %27, 5.000000e-01
%29 = fptoui double %28 to i32
store i32 %29, i32* %4
ret void
}