#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);
int floor(int);
int encode_cpr_lat(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);
  return YZ & 0x1FFFF;
}


x86 assembly (clang, -O0):
<encode_cpr_lat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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  0xe9b(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
call   1030 <cprMod@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
imul   %ecx,%eax
cvtsi2sd %eax,%xmm0
divsd  -0x28(%rbp),%xmm0
movsd  0xe5c(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <floor@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
and    $0x1ffff,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encode_cpr_lat>:
push   %rbx
sub    $0x10,%rsp
test   %esi,%esi
mov    $0x20000,%eax
mov    $0x80000,%ebx
cmove  %eax,%ebx
cmp    $0x1,%edi
mov    $0x3b,%eax
adc    $0x0,%eax
cvtsi2sd %eax,%xmm2
movsd  0xeb5(%rip),%xmm1
divsd  %xmm2,%xmm1
movsd  %xmm1,0x8(%rsp)
call   1030 <cprMod@plt>
imul   %ebx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0x8(%rsp),%xmm0
addsd  0xe96(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <floor@plt>
and    $0x1ffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @encode_cpr_lat(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
store double %0, double* %5
store double %1, double* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = load i32, i32* %8
%13 = icmp ne i32 %12, 0
%14 = zext i1 %13 to i64
%15 = select i1 %13, i32 524288, i32 131072
store i32 %15, i32* %9
%16 = load i32, i32* %7
%17 = icmp ne i32 %16, 0
%18 = zext i1 %17 to i64
%19 = select i1 %17, i32 59, i32 60
%20 = sitofp i32 %19 to double
%21 = fdiv double 3.600000e+02, %20
store double %21, double* %10
%22 = load i32, i32* %9
%23 = load double, double* %5
%24 = load double, double* %10
%25 = call i32 @cprMod(double %23, double %24)
%26 = mul nsw i32 %22, %25
%27 = sitofp i32 %26 to double
%28 = load double, double* %10
%29 = fdiv double %27, %28
%30 = fadd double %29, 5.000000e-01
%31 = fptosi double %30 to i32
%32 = call i32 @floor(i32 %31)
store i32 %32, i32* %11
%33 = load i32, i32* %11
%34 = and i32 %33, 131071
ret i32 %34
}

LLVM IR (-O2):
define i32 @encode_cpr_lat(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 i32 @floor(i32 %16)
%18 = and i32 %17, 131071
ret i32 %18
}