#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 */
int cprMod(double, double);
double cprN(double, int);
double floor(int);
int encode_cpr_lon(double lat, double lon, int odd, int surface) {
  int NbPow = (surface ? 1 << 19 : 1 << 17);
  double Dlat = 360.0 / (odd ? 59 : 60);
  int YZ = floor(NbPow * cprMod(lat, Dlat) / Dlat + 0.5);
  double Rlat = Dlat * (1.0 * YZ / NbPow + floor(lat / Dlat));
  double Dlon = (360.0 / cprN(Rlat, odd));
  int XZ = floor(NbPow * cprMod(lon, Dlon) / Dlon + 0.5);
  return XZ & 0x1FFFF;
}


x86 assembly (clang, -O0):
<encode_cpr_lon>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
mov    %esi,-0x18(%rbp)
mov    -0x18(%rbp),%edx
mov    $0x20000,%eax
mov    $0x80000,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edx
mov    $0x3c,%eax
mov    $0x3b,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
cvtsi2sd %eax,%xmm1
movsd  0xe8b(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x5c(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
call   1030 <cprMod@plt>
mov    %eax,%ecx
mov    -0x5c(%rbp),%eax
imul   %ecx,%eax
cvtsi2sd %eax,%xmm0
divsd  -0x28(%rbp),%xmm0
movsd  0xe4c(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1050 <floor@plt>
cvttsd2si %xmm0,%eax
mov    %eax,-0x2c(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
cvtsi2sdl -0x2c(%rbp),%xmm1
movsd  0xe31(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x8(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <floor@plt>
movsd  -0x58(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x50(%rbp),%xmm0
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
mov    -0x14(%rbp),%edi
call   1040 <cprN@plt>
movaps %xmm0,%xmm1
movsd  0xdd2(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x48(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
call   1030 <cprMod@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%eax
imul   %ecx,%eax
cvtsi2sd %eax,%xmm0
divsd  -0x40(%rbp),%xmm0
movsd  0xd93(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1050 <floor@plt>
cvttsd2si %xmm0,%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
and    $0x1ffff,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encode_cpr_lon>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
mov    %edi,%ebx
movsd  %xmm1,0x18(%rsp)
movsd  %xmm0,0x10(%rsp)
test   %esi,%esi
mov    $0x20000,%eax
mov    $0x80000,%ebp
cmove  %eax,%ebp
cmp    $0x1,%edi
mov    $0x3b,%eax
adc    $0x0,%eax
cvtsi2sd %eax,%xmm2
movsd  0xe96(%rip),%xmm1
divsd  %xmm2,%xmm1
movsd  %xmm1,0x8(%rsp)
call   1030 <cprMod@plt>
imul   %ebp,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0x8(%rsp),%xmm0
addsd  0xe77(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <floor@plt>
cvttpd2dq %xmm0,%xmm0
cvtdq2pd %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
divsd  %xmm0,%xmm1
movapd %xmm1,0x20(%rsp)
movsd  0x10(%rsp),%xmm0
divsd  0x8(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <floor@plt>
addsd  0x20(%rsp),%xmm0
mulsd  0x8(%rsp),%xmm0
mov    %ebx,%edi
call   1040 <cprN@plt>
movsd  0xe1d(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x18(%rsp),%xmm0
call   1030 <cprMod@plt>
imul   %ebp,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0x8(%rsp),%xmm0
addsd  0xdf8(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <floor@plt>
cvttsd2si %xmm0,%eax
and    $0x1ffff,%eax
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @encode_cpr_lon(double %0, double %1, i32 %2, i32 %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
%11 = alloca i32
%12 = alloca double
%13 = alloca double
%14 = alloca i32
store double %0, double* %5
store double %1, double* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%15 = load i32, i32* %8
%16 = icmp ne i32 %15, 0
%17 = zext i1 %16 to i64
%18 = select i1 %16, i32 524288, i32 131072
store i32 %18, i32* %9
%19 = load i32, i32* %7
%20 = icmp ne i32 %19, 0
%21 = zext i1 %20 to i64
%22 = select i1 %20, i32 59, i32 60
%23 = sitofp i32 %22 to double
%24 = fdiv double 3.600000e+02, %23
store double %24, double* %10
%25 = load i32, i32* %9
%26 = load double, double* %5
%27 = load double, double* %10
%28 = call i32 @cprMod(double %26, double %27)
%29 = mul nsw i32 %25, %28
%30 = sitofp i32 %29 to double
%31 = load double, double* %10
%32 = fdiv double %30, %31
%33 = fadd double %32, 5.000000e-01
%34 = fptosi double %33 to i32
%35 = call double @floor(i32 %34)
%36 = fptosi double %35 to i32
store i32 %36, i32* %11
%37 = load double, double* %10
%38 = load i32, i32* %11
%39 = sitofp i32 %38 to double
%40 = fmul double 1.000000e+00, %39
%41 = load i32, i32* %9
%42 = sitofp i32 %41 to double
%43 = fdiv double %40, %42
%44 = load double, double* %5
%45 = load double, double* %10
%46 = fdiv double %44, %45
%47 = fptosi double %46 to i32
%48 = call double @floor(i32 %47)
%49 = fadd double %43, %48
%50 = fmul double %37, %49
store double %50, double* %12
%51 = load double, double* %12
%52 = load i32, i32* %7
%53 = call double @cprN(double %51, i32 %52)
%54 = fdiv double 3.600000e+02, %53
store double %54, double* %13
%55 = load i32, i32* %9
%56 = load double, double* %6
%57 = load double, double* %13
%58 = call i32 @cprMod(double %56, double %57)
%59 = mul nsw i32 %55, %58
%60 = sitofp i32 %59 to double
%61 = load double, double* %13
%62 = fdiv double %60, %61
%63 = fadd double %62, 5.000000e-01
%64 = fptosi double %63 to i32
%65 = call double @floor(i32 %64)
%66 = fptosi double %65 to i32
store i32 %66, i32* %14
%67 = load i32, i32* %14
%68 = and i32 %67, 131071
ret i32 %68
}

LLVM IR (-O2):
define i32 @encode_cpr_lon(double %0, double %1, i32 %2, i32 %3) {
%5 = icmp eq i32 %3, 0
%6 = select i1 %5, i32 131072, i32 524288
%7 = icmp eq i32 %2, 0
%8 = select i1 %7, i32 60, i32 59
%9 = sitofp i32 %8 to double
%10 = fdiv double 3.600000e+02, %9
%11 = tail call i32 @cprMod(double %0, double %10)
%12 = mul nsw i32 %11, %6
%13 = sitofp i32 %12 to double
%14 = fdiv double %13, %10
%15 = fadd double %14, 5.000000e-01
%16 = fptosi double %15 to i32
%17 = tail call double @floor(i32 %16)
%18 = fptosi double %17 to i32
%19 = sitofp i32 %18 to double
%20 = sitofp i32 %6 to double
%21 = fdiv double %19, %20
%22 = fdiv double %0, %10
%23 = fptosi double %22 to i32
%24 = tail call double @floor(i32 %23)
%25 = fadd double %24, %21
%26 = fmul double %10, %25
%27 = tail call double @cprN(double %26, i32 %2)
%28 = fdiv double 3.600000e+02, %27
%29 = tail call i32 @cprMod(double %1, double %28)
%30 = mul nsw i32 %29, %6
%31 = sitofp i32 %30 to double
%32 = fdiv double %31, %28
%33 = fadd double %32, 5.000000e-01
%34 = fptosi double %33 to i32
%35 = tail call double @floor(i32 %34)
%36 = fptosi double %35 to i32
%37 = and i32 %36, 131071
ret i32 %37
}