#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 */
char MapsWithMe_Base64Char(int const);
int MapsWithMe_LatToInt(double, int);
int MapsWithMe_LonToInt(double, int);
void MapsWithMe_LatLonToString(double lat, double lon, char *s, int nBytes) {
  if (nBytes > 10)
    nBytes = 10;
  int const latI = MapsWithMe_LatToInt(lat, (1 << (10 * 3)) - 1);
  int const lonI = MapsWithMe_LonToInt(lon, (1 << (10 * 3)) - 1);
  int i, shift;
  for (i = 0, shift = (10 * 3) - 3; i < nBytes; ++i, shift -= 3) {
    int const latBits = latI >> shift & 7;
    int const lonBits = lonI >> shift & 7;
    int const nextByte = (latBits >> 2 & 1) << 5 | (lonBits >> 2 & 1) << 4 |
                         (latBits >> 1 & 1) << 3 | (lonBits >> 1 & 1) << 2 |
                         (latBits & 1) << 1 | (lonBits & 1);
    s[i] = MapsWithMe_Base64Char(nextByte);
  }
}


x86 assembly (clang, -O0):
<MapsWithMe_LatLonToString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jle    115a <MapsWithMe_LatLonToString+0x2a>
movl   $0xa,-0x1c(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    $0x3fffffff,%edi
call   1050 <MapsWithMe_LatToInt@plt>
mov    %eax,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
mov    $0x3fffffff,%edi
call   1030 <MapsWithMe_LonToInt@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x1b,-0x2c(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    122c <MapsWithMe_LatLonToString+0xfc>
mov    -0x20(%rbp),%eax
mov    -0x2c(%rbp),%ecx
sar    %cl,%eax
and    $0x7,%eax
mov    %eax,-0x30(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x2c(%rbp),%ecx
sar    %cl,%eax
and    $0x7,%eax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%eax
sar    $0x2,%eax
and    $0x1,%eax
shl    $0x5,%eax
mov    -0x34(%rbp),%ecx
sar    $0x2,%ecx
and    $0x1,%ecx
shl    $0x4,%ecx
or     %ecx,%eax
mov    -0x30(%rbp),%ecx
sar    $0x1,%ecx
and    $0x1,%ecx
shl    $0x3,%ecx
or     %ecx,%eax
mov    -0x34(%rbp),%ecx
sar    $0x1,%ecx
and    $0x1,%ecx
shl    $0x2,%ecx
or     %ecx,%eax
mov    -0x30(%rbp),%ecx
and    $0x1,%ecx
shl    $0x1,%ecx
or     %ecx,%eax
mov    -0x34(%rbp),%ecx
and    $0x1,%ecx
or     %ecx,%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%edi
call   1040 <MapsWithMe_Base64Char@plt>
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
sub    $0x3,%eax
mov    %eax,-0x2c(%rbp)
jmp    118c <MapsWithMe_LatLonToString+0x5c>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MapsWithMe_LatLonToString>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%r14
movsd  %xmm1,(%rsp)
mov    $0x3fffffff,%edi
call   1050 <MapsWithMe_LatToInt@plt>
mov    %eax,%r15d
movsd  (%rsp),%xmm0
mov    $0x3fffffff,%edi
call   1030 <MapsWithMe_LonToInt@plt>
test   %ebp,%ebp
jle    11cd <MapsWithMe_LatLonToString+0x9d>
mov    %eax,%r12d
cmp    $0xa,%ebp
mov    $0xa,%r13d
cmovb  %ebp,%r13d
mov    $0x1b,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %r15d,%eax
mov    %ebp,%ecx
sar    %cl,%eax
mov    %r12d,%edx
sar    %cl,%edx
mov    %eax,%ecx
and    $0x4,%ecx
mov    %edx,%esi
and    $0x4,%esi
mov    %eax,%edi
and    $0x2,%edi
mov    %edx,%r8d
and    $0x2,%r8d
and    $0x1,%eax
and    $0x1,%edx
lea    (%rdx,%rsi,4),%edx
lea    (%rdx,%rcx,8),%ecx
lea    (%rcx,%rdi,4),%ecx
lea    (%rcx,%r8,2),%ecx
lea    (%rcx,%rax,2),%edi
call   1040 <MapsWithMe_Base64Char@plt>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
add    $0xfffffffd,%ebp
cmp    %rbx,%r13
jne    1180 <MapsWithMe_LatLonToString+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @MapsWithMe_LatLonToString(double %0, double %1, i8* %2, i32 %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store double %0, double* %5
store double %1, double* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%16 = load i32, i32* %8
%17 = icmp sgt i32 %16, 10
br i1 %17, label %18, label %19
18: ; preds = %4
store i32 10, i32* %8
br label %19
19: ; preds = %18, %4
%20 = load double, double* %5
%21 = call i32 @MapsWithMe_LatToInt(double %20, i32 1073741823)
store i32 %21, i32* %9
%22 = load double, double* %6
%23 = call i32 @MapsWithMe_LonToInt(double %22, i32 1073741823)
store i32 %23, i32* %10
store i32 0, i32* %11
store i32 27, i32* %12
br label %24
24: ; preds = %69, %19
%25 = load i32, i32* %11
%26 = load i32, i32* %8
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %74
28: ; preds = %24
%29 = load i32, i32* %9
%30 = load i32, i32* %12
%31 = ashr i32 %29, %30
%32 = and i32 %31, 7
store i32 %32, i32* %13
%33 = load i32, i32* %10
%34 = load i32, i32* %12
%35 = ashr i32 %33, %34
%36 = and i32 %35, 7
store i32 %36, i32* %14
%37 = load i32, i32* %13
%38 = ashr i32 %37, 2
%39 = and i32 %38, 1
%40 = shl i32 %39, 5
%41 = load i32, i32* %14
%42 = ashr i32 %41, 2
%43 = and i32 %42, 1
%44 = shl i32 %43, 4
%45 = or i32 %40, %44
%46 = load i32, i32* %13
%47 = ashr i32 %46, 1
%48 = and i32 %47, 1
%49 = shl i32 %48, 3
%50 = or i32 %45, %49
%51 = load i32, i32* %14
%52 = ashr i32 %51, 1
%53 = and i32 %52, 1
%54 = shl i32 %53, 2
%55 = or i32 %50, %54
%56 = load i32, i32* %13
%57 = and i32 %56, 1
%58 = shl i32 %57, 1
%59 = or i32 %55, %58
%60 = load i32, i32* %14
%61 = and i32 %60, 1
%62 = or i32 %59, %61
store i32 %62, i32* %15
%63 = load i32, i32* %15
%64 = call signext i8 @MapsWithMe_Base64Char(i32 %63)
%65 = load i8*, i8** %7
%66 = load i32, i32* %11
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %65, i64 %67
store i8 %64, i8* %68
br label %69
69: ; preds = %28
%70 = load i32, i32* %11
%71 = add nsw i32 %70, 1
store i32 %71, i32* %11
%72 = load i32, i32* %12
%73 = sub nsw i32 %72, 3
store i32 %73, i32* %12
br label %24
74: ; preds = %24
ret void
}

LLVM IR (-O2):
define void @MapsWithMe_LatLonToString(double %0, double %1, i8* nocapture writeonly %2, i32 %3) {
%5 = tail call i32 @MapsWithMe_LatToInt(double %0, i32 1073741823)
%6 = tail call i32 @MapsWithMe_LonToInt(double %1, i32 1073741823)
%7 = icmp sgt i32 %3, 0
br i1 %7, label %8, label %38
8: ; preds = %4
%9 = icmp ult i32 %3, 10
%10 = select i1 %9, i32 %3, i32 10
%11 = zext i32 %10 to i64
br label %12
12: ; preds = %8, %12
%13 = phi i64 [ 0, %8 ], [ %35, %12 ]
%14 = phi i32 [ 27, %8 ], [ %36, %12 ]
%15 = ashr i32 %5, %14
%16 = ashr i32 %6, %14
%17 = shl i32 %15, 3
%18 = and i32 %17, 32
%19 = shl i32 %16, 2
%20 = and i32 %19, 16
%21 = shl i32 %15, 2
%22 = and i32 %21, 8
%23 = shl i32 %16, 1
%24 = and i32 %23, 4
%25 = shl i32 %15, 1
%26 = and i32 %25, 2
%27 = and i32 %16, 1
%28 = or i32 %20, %27
%29 = or i32 %28, %18
%30 = or i32 %29, %22
%31 = or i32 %30, %24
%32 = or i32 %31, %26
%33 = tail call signext i8 @MapsWithMe_Base64Char(i32 %32)
%34 = getelementptr inbounds i8, i8* %2, i64 %13
store i8 %33, i8* %34
%35 = add nuw nsw i64 %13, 1
%36 = add nsw i32 %14, -3
%37 = icmp eq i64 %35, %11
br i1 %37, label %38, label %12
38: ; preds = %12, %4
ret void
}