#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 reduce(double, double, double);
int /*<<< orphan*/ sprintf(char *, char *, char, char, int, int,
                           int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ tolower(char);
void latlon_to_maidenhead(double mLtd, double mLng, char *mStr) {
  int i, j, k, l, m, n;
  mLng = -mLng;
  mLng = reduce(180.0 - mLng, 0.0, 360.0);
  mLtd = reduce(90.0 + mLtd, 0.0, 360.0);
  i = (int)(mLng / 20.0);
  j = (int)(mLtd / 10.0);
  mLng -= (double)i * 20.0;
  mLtd -= (double)j * 10.0;
  k = (int)(mLng / 2.0);
  l = (int)(mLtd / 1.0);
  mLng -= (double)k * 2.0;
  mLtd -= (double)l * 1.0;
  m = (int)(mLng * 12.0);
  n = (int)(mLtd * 24.0);
  sprintf(mStr, "%c%c%d%d%c%c", 'A' + (char)i, 'A' + (char)j, k, l,
          tolower('A' + (char)m), tolower('A' + (char)n));
}


x86 assembly (clang, -O0):
<latlon_to_maidenhead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xed1(%rip),%xmm0
subsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
movsd  0xeb1(%rip),%xmm2
call   1030 <reduce@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  0xea7(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
movsd  0xe8f(%rip),%xmm2
call   1030 <reduce@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe70(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x1c(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe50(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x20(%rbp)
cvtsi2sdl -0x1c(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xe24(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
cvtsi2sdl -0x20(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xde6(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xdc4(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x24(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xda4(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x28(%rbp)
cvtsi2sdl -0x24(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
cvtsi2sdl -0x28(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  0xd31(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x2c(%rbp)
movsd  0xd15(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x1c(%rbp),%eax
movsbl %al,%eax
add    $0x41,%eax
mov    %al,-0x3e(%rbp)
mov    -0x20(%rbp),%eax
movsbl %al,%eax
add    $0x41,%eax
mov    %al,-0x3d(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x2c(%rbp),%eax
movsbl %al,%eax
add    $0x41,%eax
movsbl %al,%edi
call   1040 <tolower@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%eax
movsbl %al,%eax
add    $0x41,%eax
movsbl %al,%edi
call   1040 <tolower@plt>
mov    -0x48(%rbp),%rdi
mov    -0x3e(%rbp),%dl
mov    -0x3d(%rbp),%cl
mov    -0x3c(%rbp),%r8d
mov    -0x38(%rbp),%r9d
mov    -0x34(%rbp),%r10d
lea    0xce3(%rip),%rsi
movsbl %dl,%edx
movsbl %cl,%ecx
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   1050 <sprintf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<latlon_to_maidenhead>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,0x10(%rsp)
movapd %xmm1,%xmm3
movsd  %xmm0,0x8(%rsp)
addsd  0xeab(%rip),%xmm3
movsd  0xeab(%rip),%xmm2
xorpd  %xmm1,%xmm1
movapd %xmm3,%xmm0
call   1030 <reduce@plt>
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
addsd  0xe93(%rip),%xmm0
xorpd  %xmm1,%xmm1
movsd  0xe7f(%rip),%xmm2
call   1030 <reduce@plt>
movsd  0xe82(%rip),%xmm1
movsd  (%rsp),%xmm5
movapd %xmm5,%xmm2
divsd  %xmm1,%xmm2
cvttsd2si %xmm2,%ebp
movsd  0xe71(%rip),%xmm3
movapd %xmm0,%xmm4
divsd  %xmm3,%xmm4
cvttsd2si %xmm4,%ebx
cvttpd2dq %xmm2,%xmm2
cvtdq2pd %xmm2,%xmm2
mulsd  %xmm1,%xmm2
subsd  %xmm2,%xmm5
cvttpd2dq %xmm4,%xmm1
cvtdq2pd %xmm1,%xmm1
mulsd  %xmm3,%xmm1
subsd  %xmm1,%xmm0
movsd  0xe45(%rip),%xmm1
movapd %xmm5,%xmm3
mulsd  %xmm5,%xmm1
cvttsd2si %xmm1,%r12d
cvttsd2si %xmm0,%r15d
cvttpd2dq %xmm1,%xmm1
cvtdq2pd %xmm1,%xmm1
addsd  %xmm1,%xmm1
cvttpd2dq %xmm0,%xmm2
subsd  %xmm1,%xmm3
cvtdq2pd %xmm2,%xmm1
subsd  %xmm1,%xmm0
mulsd  0xe17(%rip),%xmm3
cvttsd2si %xmm3,%eax
mulsd  0xe13(%rip),%xmm0
cvttsd2si %xmm0,%r14d
add    $0x41,%bpl
add    $0x41,%bl
add    $0x41,%al
movsbl %al,%edi
call   1040 <tolower@plt>
mov    %eax,%r13d
add    $0x41,%r14b
movsbl %r14b,%edi
call   1040 <tolower@plt>
movsbl %bpl,%edx
movsbl %bl,%ecx
lea    0xde7(%rip),%rsi
mov    0x10(%rsp),%rdi
mov    %r12d,%r8d
mov    %r15d,%r9d
push   %rax
push   %r13
call   1050 <sprintf@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"%c%c%d%d%c%c\00"
define void @latlon_to_maidenhead(double %0, double %1, i8* %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store double %0, double* %4
store double %1, double* %5
store i8* %2, i8** %6
%13 = load double, double* %5
%14 = fneg double %13
store double %14, double* %5
%15 = load double, double* %5
%16 = fsub double 1.800000e+02, %15
%17 = call double @reduce(double %16, double 0.000000e+00, double 3.600000e+02)
store double %17, double* %5
%18 = load double, double* %4
%19 = fadd double 9.000000e+01, %18
%20 = call double @reduce(double %19, double 0.000000e+00, double 3.600000e+02)
store double %20, double* %4
%21 = load double, double* %5
%22 = fdiv double %21, 2.000000e+01
%23 = fptosi double %22 to i32
store i32 %23, i32* %7
%24 = load double, double* %4
%25 = fdiv double %24, 1.000000e+01
%26 = fptosi double %25 to i32
store i32 %26, i32* %8
%27 = load i32, i32* %7
%28 = sitofp i32 %27 to double
%29 = load double, double* %5
%30 = fneg double %28
%31 = call double @llvm.fmuladd.f64(double %30, double 2.000000e+01, double %29)
store double %31, double* %5
%32 = load i32, i32* %8
%33 = sitofp i32 %32 to double
%34 = load double, double* %4
%35 = fneg double %33
%36 = call double @llvm.fmuladd.f64(double %35, double 1.000000e+01, double %34)
store double %36, double* %4
%37 = load double, double* %5
%38 = fdiv double %37, 2.000000e+00
%39 = fptosi double %38 to i32
store i32 %39, i32* %9
%40 = load double, double* %4
%41 = fdiv double %40, 1.000000e+00
%42 = fptosi double %41 to i32
store i32 %42, i32* %10
%43 = load i32, i32* %9
%44 = sitofp i32 %43 to double
%45 = load double, double* %5
%46 = fneg double %44
%47 = call double @llvm.fmuladd.f64(double %46, double 2.000000e+00, double %45)
store double %47, double* %5
%48 = load i32, i32* %10
%49 = sitofp i32 %48 to double
%50 = load double, double* %4
%51 = fneg double %49
%52 = call double @llvm.fmuladd.f64(double %51, double 1.000000e+00, double %50)
store double %52, double* %4
%53 = load double, double* %5
%54 = fmul double %53, 1.200000e+01
%55 = fptosi double %54 to i32
store i32 %55, i32* %11
%56 = load double, double* %4
%57 = fmul double %56, 2.400000e+01
%58 = fptosi double %57 to i32
store i32 %58, i32* %12
%59 = load i8*, i8** %6
%60 = load i32, i32* %7
%61 = trunc i32 %60 to i8
%62 = sext i8 %61 to i32
%63 = add nsw i32 65, %62
%64 = trunc i32 %63 to i8
%65 = load i32, i32* %8
%66 = trunc i32 %65 to i8
%67 = sext i8 %66 to i32
%68 = add nsw i32 65, %67
%69 = trunc i32 %68 to i8
%70 = load i32, i32* %9
%71 = load i32, i32* %10
%72 = load i32, i32* %11
%73 = trunc i32 %72 to i8
%74 = sext i8 %73 to i32
%75 = add nsw i32 65, %74
%76 = trunc i32 %75 to i8
%77 = call i32 @tolower(i8 signext %76)
%78 = load i32, i32* %12
%79 = trunc i32 %78 to i8
%80 = sext i8 %79 to i32
%81 = add nsw i32 65, %80
%82 = trunc i32 %81 to i8
%83 = call i32 @tolower(i8 signext %82)
%84 = call i32 @sprintf(i8* %59, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8 signext %64, i8 signext %69, i32 %70, i32 %71, i32 %77, i32 %83)
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"%c%c%d%d%c%c\00"
define void @latlon_to_maidenhead(double %0, double %1, i8* nocapture writeonly %2) {
%4 = fadd double %1, 1.800000e+02
%5 = tail call double @reduce(double %4, double 0.000000e+00, double 3.600000e+02)
%6 = fadd double %0, 9.000000e+01
%7 = tail call double @reduce(double %6, double 0.000000e+00, double 3.600000e+02)
%8 = fdiv double %5, 2.000000e+01
%9 = fptosi double %8 to i32
%10 = fdiv double %7, 1.000000e+01
%11 = fptosi double %10 to i32
%12 = sitofp i32 %9 to double
%13 = fneg double %12
%14 = tail call double @llvm.fmuladd.f64(double %13, double 2.000000e+01, double %5)
%15 = sitofp i32 %11 to double
%16 = fneg double %15
%17 = tail call double @llvm.fmuladd.f64(double %16, double 1.000000e+01, double %7)
%18 = fmul double %14, 5.000000e-01
%19 = fptosi double %18 to i32
%20 = fptosi double %17 to i32
%21 = sitofp i32 %19 to double
%22 = fneg double %21
%23 = tail call double @llvm.fmuladd.f64(double %22, double 2.000000e+00, double %14)
%24 = sitofp i32 %20 to double
%25 = fsub double %17, %24
%26 = fmul double %23, 1.200000e+01
%27 = fptosi double %26 to i32
%28 = fmul double %25, 2.400000e+01
%29 = fptosi double %28 to i32
%30 = trunc i32 %9 to i8
%31 = add i8 %30, 65
%32 = trunc i32 %11 to i8
%33 = add i8 %32, 65
%34 = trunc i32 %27 to i8
%35 = add i8 %34, 65
%36 = tail call i32 @tolower(i8 signext %35)
%37 = trunc i32 %29 to i8
%38 = add i8 %37, 65
%39 = tail call i32 @tolower(i8 signext %38)
%40 = tail call i32 @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8 signext %31, i8 signext %33, i32 %19, i32 %20, i32 %36, i32 %39)
ret void
}