#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 /*<<< orphan*/ sprintf(char *, char *, int);
char *latlon_to_MMM(char *target, double lat, double lon) {
  int col, row, ori = 0;
  if (lon < 0.0)
    col = (int)(-lat * 0.1) + 1;
  else
    col = 36 - (int)(lat * 0.1);
  if (lat >= 80.0)
    row = 25;
  else if (lat >= 0.0)
    row = (int)(lat * 0.1);
  else {
    ori = 299;
    row = (int)(-lat * 0.1);
  }
  sprintf(target, "%03d", col + ori + row * 36);
  return target;
}


x86 assembly (clang, -O0):
<latlon_to_MMM>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1172 <latlon_to_MMM+0x62>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xea1(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118d <latlon_to_MMM+0x7d>
movsd  0xe86(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
cvttsd2si %xmm0,%ecx
mov    $0x24,%eax
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe6e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11b0 <latlon_to_MMM+0xa0>
movl   $0x19,-0x20(%rbp)
jmp    1216 <latlon_to_MMM+0x106>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11db <latlon_to_MMM+0xcb>
movsd  0xe36(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x20(%rbp)
jmp    1211 <latlon_to_MMM+0x101>
movl   $0x12b,-0x24(%rbp)
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xdfa(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x20(%rbp)
jmp    1216 <latlon_to_MMM+0x106>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%edx
add    -0x24(%rbp),%edx
imul   $0x24,-0x20(%rbp),%eax
add    %eax,%edx
lea    0xde3(%rip),%rsi
call   1030 <sprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<latlon_to_MMM>:
push   %rbx
mov    %rdi,%rbx
xorpd  %xmm2,%xmm2
ucomisd %xmm1,%xmm2
jbe    1133 <latlon_to_MMM+0x23>
movsd  0xee2(%rip),%xmm1
mulsd  %xmm0,%xmm1
cvttsd2si %xmm1,%eax
add    $0x1,%eax
jmp    114a <latlon_to_MMM+0x3a>
movsd  0xec5(%rip),%xmm1
mulsd  %xmm0,%xmm1
cvttsd2si %xmm1,%ecx
mov    $0x24,%eax
sub    %ecx,%eax
xor    %ecx,%ecx
mov    $0x19,%edx
ucomisd 0xeb7(%rip),%xmm0
jae    1184 <latlon_to_MMM+0x74>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jae    1178 <latlon_to_MMM+0x68>
mulsd  0xe9b(%rip),%xmm0
cvttsd2si %xmm0,%edx
mov    $0x12b,%ecx
jmp    1184 <latlon_to_MMM+0x74>
mulsd  0xe80(%rip),%xmm0
cvttsd2si %xmm0,%edx
add    %eax,%ecx
lea    (%rdx,%rdx,8),%eax
lea    (%rcx,%rax,4),%edx
lea    0xe85(%rip),%rsi
mov    %rbx,%rdi
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%03d\00"
define i8* @latlon_to_MMM(i8* %0, double %1, double %2) {
%4 = alloca i8*
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store double %1, double* %5
store double %2, double* %6
store i32 0, i32* %9
%10 = load double, double* %6
%11 = fcmp olt double %10, 0.000000e+00
br i1 %11, label %12, label %18
12: ; preds = %3
%13 = load double, double* %5
%14 = fneg double %13
%15 = fmul double %14, 1.000000e-01
%16 = fptosi double %15 to i32
%17 = add nsw i32 %16, 1
store i32 %17, i32* %7
br label %23
18: ; preds = %3
%19 = load double, double* %5
%20 = fmul double %19, 1.000000e-01
%21 = fptosi double %20 to i32
%22 = sub nsw i32 36, %21
store i32 %22, i32* %7
br label %23
23: ; preds = %18, %12
%24 = load double, double* %5
%25 = fcmp oge double %24, 8.000000e+01
br i1 %25, label %26, label %27
26: ; preds = %23
store i32 25, i32* %8
br label %40
27: ; preds = %23
%28 = load double, double* %5
%29 = fcmp oge double %28, 0.000000e+00
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = load double, double* %5
%32 = fmul double %31, 1.000000e-01
%33 = fptosi double %32 to i32
store i32 %33, i32* %8
br label %39
34: ; preds = %27
store i32 299, i32* %9
%35 = load double, double* %5
%36 = fneg double %35
%37 = fmul double %36, 1.000000e-01
%38 = fptosi double %37 to i32
store i32 %38, i32* %8
br label %39
39: ; preds = %34, %30
br label %40
40: ; preds = %39, %26
%41 = load i8*, i8** %4
%42 = load i32, i32* %7
%43 = load i32, i32* %9
%44 = add nsw i32 %42, %43
%45 = load i32, i32* %8
%46 = mul nsw i32 %45, 36
%47 = add nsw i32 %44, %46
%48 = call i32 @sprintf(i8* %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %47)
%49 = load i8*, i8** %4
ret i8* %49
}

LLVM IR (-O2):
@.str = [5 x i8] c"%03d\00"
define i8* @latlon_to_MMM(i8* returned writeonly %0, double %1, double %2) {
%4 = fcmp olt double %2, 0.000000e+00
br i1 %4, label %5, label %9
5: ; preds = %3
%6 = fmul double %1, -1.000000e-01
%7 = fptosi double %6 to i32
%8 = add nsw i32 %7, 1
br label %13
9: ; preds = %3
%10 = fmul double %1, 1.000000e-01
%11 = fptosi double %10 to i32
%12 = sub nsw i32 36, %11
br label %13
13: ; preds = %9, %5
%14 = phi i32 [ %8, %5 ], [ %12, %9 ]
%15 = fcmp ult double %1, 8.000000e+01
br i1 %15, label %16, label %24
16: ; preds = %13
%17 = fcmp ult double %1, 0.000000e+00
br i1 %17, label %21, label %18
18: ; preds = %16
%19 = fmul double %1, 1.000000e-01
%20 = fptosi double %19 to i32
br label %24
21: ; preds = %16
%22 = fmul double %1, -1.000000e-01
%23 = fptosi double %22 to i32
br label %24
24: ; preds = %13, %18, %21
%25 = phi i32 [ %20, %18 ], [ %23, %21 ], [ 25, %13 ]
%26 = phi i32 [ 0, %18 ], [ 299, %21 ], [ 0, %13 ]
%27 = add nsw i32 %26, %14
%28 = mul nsw i32 %25, 36
%29 = add nsw i32 %27, %28
%30 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %29)
ret i8* %0
}