#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 abs(double);
int fabs(double);
scalar_t__ round(int);
int snprintf(char *, int, char *, int, double, ...);
int coord_str(double c, int lat_lon, char *buf, int len) {
  if (buf == NULL)
    return -1;
  switch (lat_lon) {
  case 0:
    return snprintf(buf, len, "%02d %c %.1f'", abs(c), c < 0 ? 'S' : 'N',
                    (double)((int)round(fabs(c) * (60 * 100)) % (60 * 100)) /
                        100);
  case 1:
    return snprintf(buf, len, "%03d %c %.1f'", abs(c), c < 0 ? 'W' : 'E',
                    (double)((int)round(fabs(c) * (60 * 100)) % (60 * 100)) /
                        100);
  case 2:
    return snprintf(buf, len, "%02d° %.1f'", abs(c),
                    (double)((int)round(fabs(c) * (60 * 100)) % (60 * 100)) /
                        100);
  case 3:
    return snprintf(buf, len, "%03d° %.1f'", abs(c),
                    (double)((int)round(fabs(c) * (60 * 100)) % (60 * 100)) /
                        100);
  }
  return -1;
}


x86 assembly (clang, -O0):
<coord_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %edx,-0x24(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1171 <coord_str+0x31>
movl   $0xffffffff,-0x4(%rbp)
jmp    1393 <coord_str+0x253>
mov    -0x14(%rbp),%eax
mov    %rax,-0x30(%rbp)
sub    $0x3,%rax
ja     138c <coord_str+0x24c>
mov    -0x30(%rbp),%rax
lea    0xe7b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x40(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <abs@plt>
mov    %eax,-0x3c(%rbp)
movsd  -0x10(%rbp),%xmm1
xorps  %xmm0,%xmm0
mov    $0x4e,%eax
mov    $0x53,%ecx
ucomisd %xmm1,%xmm0
cmova  %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <fabs@plt>
imul   $0x1770,%eax,%edi
call   1060 <round@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%esi
mov    -0x3c(%rbp),%ecx
movsd  -0x38(%rbp),%xmm0
mov    $0x1770,%r8d
cltd
idiv   %r8d
cvtsi2sd %edx,%xmm1
movsd  0xdf3(%rip),%xmm2
divsd  %xmm2,%xmm1
lea    0xe00(%rip),%rdx
mov    $0x2,%al
call   1040 <snprintf@plt>
mov    %eax,-0x4(%rbp)
jmp    1393 <coord_str+0x253>
mov    -0x20(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x58(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <abs@plt>
mov    %eax,-0x54(%rbp)
movsd  -0x10(%rbp),%xmm1
xorps  %xmm0,%xmm0
mov    $0x45,%eax
mov    $0x57,%ecx
ucomisd %xmm1,%xmm0
cmova  %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <fabs@plt>
imul   $0x1770,%eax,%edi
call   1060 <round@plt>
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%esi
mov    -0x54(%rbp),%ecx
movsd  -0x50(%rbp),%xmm0
mov    $0x1770,%r8d
cltd
idiv   %r8d
cvtsi2sd %edx,%xmm1
movsd  0xd62(%rip),%xmm2
divsd  %xmm2,%xmm1
lea    0xd7d(%rip),%rdx
mov    $0x2,%al
call   1040 <snprintf@plt>
mov    %eax,-0x4(%rbp)
jmp    1393 <coord_str+0x253>
mov    -0x20(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x68(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <abs@plt>
mov    %eax,-0x64(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <fabs@plt>
imul   $0x1770,%eax,%edi
call   1060 <round@plt>
mov    -0x70(%rbp),%rdi
mov    -0x68(%rbp),%esi
mov    -0x64(%rbp),%ecx
mov    $0x1770,%r8d
cltd
idiv   %r8d
cvtsi2sd %edx,%xmm0
movsd  0xcf8(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xd21(%rip),%rdx
mov    $0x1,%al
call   1040 <snprintf@plt>
mov    %eax,-0x4(%rbp)
jmp    1393 <coord_str+0x253>
mov    -0x20(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x78(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <abs@plt>
mov    %eax,-0x74(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <fabs@plt>
imul   $0x1770,%eax,%edi
call   1060 <round@plt>
mov    -0x80(%rbp),%rdi
mov    -0x78(%rbp),%esi
mov    -0x74(%rbp),%ecx
mov    $0x1770,%r8d
cltd
idiv   %r8d
cvtsi2sd %edx,%xmm0
movsd  0xc8e(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xcc4(%rip),%rdx
mov    $0x1,%al
call   1040 <snprintf@plt>
mov    %eax,-0x4(%rbp)
jmp    1393 <coord_str+0x253>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<coord_str>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
test   %rsi,%rsi
je     11f1 <coord_str+0xb1>
cmp    $0x3,%edi
ja     11f1 <coord_str+0xb1>
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %edi,%eax
lea    0xebd(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
movsd  %xmm0,0x8(%rsp)
jmp    *%rax
xorpd  %xmm1,%xmm1
xor    %ebp,%ebp
ucomisd %xmm0,%xmm1
seta   %bpl
call   1030 <abs@plt>
mov    %eax,%r14d
lea    0xe81(%rip),%rax
movsd  (%rax,%rbp,8),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1050 <fabs@plt>
imul   $0x1770,%eax,%edi
call   1060 <round@plt>
cltq
imul   $0x57619f1,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x27,%rcx
add    %edx,%ecx
imul   $0x1770,%ecx,%ecx
sub    %ecx,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
divsd  0xe1b(%rip),%xmm1
lea    0xe4c(%rip),%rdx
jmp    1273 <coord_str+0x133>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xorpd  %xmm1,%xmm1
xor    %ebp,%ebp
ucomisd %xmm0,%xmm1
seta   %bpl
call   1030 <abs@plt>
mov    %eax,%r14d
lea    0xdea(%rip),%rax
movsd  (%rax,%rbp,8),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1050 <fabs@plt>
imul   $0x1770,%eax,%edi
call   1060 <round@plt>
cltq
imul   $0x57619f1,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x27,%rcx
add    %edx,%ecx
imul   $0x1770,%ecx,%ecx
sub    %ecx,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
divsd  0xd94(%rip),%xmm1
lea    0xdd3(%rip),%rdx
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r14d,%ecx
movsd  0x10(%rsp),%xmm0
mov    $0x2,%al
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <snprintf@plt>
call   1030 <abs@plt>
mov    %eax,%r14d
movsd  0x8(%rsp),%xmm0
call   1050 <fabs@plt>
imul   $0x1770,%eax,%edi
call   1060 <round@plt>
cltq
imul   $0x57619f1,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x27,%rcx
add    %edx,%ecx
imul   $0x1770,%ecx,%ecx
sub    %ecx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0xd22(%rip),%xmm0
lea    0xd6f(%rip),%rdx
jmp    1339 <coord_str+0x1f9>
call   1030 <abs@plt>
mov    %eax,%r14d
movsd  0x8(%rsp),%xmm0
call   1050 <fabs@plt>
imul   $0x1770,%eax,%edi
call   1060 <round@plt>
cltq
imul   $0x57619f1,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x27,%rcx
add    %edx,%ecx
imul   $0x1770,%ecx,%ecx
sub    %ecx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0xcce(%rip),%xmm0
lea    0xd28(%rip),%rdx
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r14d,%ecx
mov    $0x1,%al
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <snprintf@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"%02d %c %.1f'\00"
@.str.1 = [14 x i8] c"%03d %c %.1f'\00"
@.str.2 = [13 x i8] c"%02d\C2\B0 %.1f'\00"
@.str.3 = [13 x i8] c"%03d\C2\B0 %.1f'\00"
define i32 @coord_str(double %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca double
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store double %0, double* %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%10 = load i8*, i8** %8
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %4
store i32 -1, i32* %5
br label %82
13: ; preds = %4
%14 = load i32, i32* %7
switch i32 %14, label %81 [
i32 0, label %15
i32 1, label %34
i32 2, label %53
i32 3, label %67
]
15: ; preds = %13
%16 = load i8*, i8** %8
%17 = load i32, i32* %9
%18 = load double, double* %6
%19 = call i32 @abs(double %18)
%20 = load double, double* %6
%21 = fcmp olt double %20, 0.000000e+00
%22 = zext i1 %21 to i64
%23 = select i1 %21, i32 83, i32 78
%24 = sitofp i32 %23 to double
%25 = load double, double* %6
%26 = call i32 @fabs(double %25)
%27 = mul nsw i32 %26, 6000
%28 = call i64 @round(i32 %27)
%29 = trunc i64 %28 to i32
%30 = srem i32 %29, 6000
%31 = sitofp i32 %30 to double
%32 = fdiv double %31, 1.000000e+02
%33 = call i32 (i8*, i32, i8*, i32, double, ...) @snprintf(i8* %16, i32 %17, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %19, double %24, double %32)
store i32 %33, i32* %5
br label %82
34: ; preds = %13
%35 = load i8*, i8** %8
%36 = load i32, i32* %9
%37 = load double, double* %6
%38 = call i32 @abs(double %37)
%39 = load double, double* %6
%40 = fcmp olt double %39, 0.000000e+00
%41 = zext i1 %40 to i64
%42 = select i1 %40, i32 87, i32 69
%43 = sitofp i32 %42 to double
%44 = load double, double* %6
%45 = call i32 @fabs(double %44)
%46 = mul nsw i32 %45, 6000
%47 = call i64 @round(i32 %46)
%48 = trunc i64 %47 to i32
%49 = srem i32 %48, 6000
%50 = sitofp i32 %49 to double
%51 = fdiv double %50, 1.000000e+02
%52 = call i32 (i8*, i32, i8*, i32, double, ...) @snprintf(i8* %35, i32 %36, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %38, double %43, double %51)
store i32 %52, i32* %5
br label %82
53: ; preds = %13
%54 = load i8*, i8** %8
%55 = load i32, i32* %9
%56 = load double, double* %6
%57 = call i32 @abs(double %56)
%58 = load double, double* %6
%59 = call i32 @fabs(double %58)
%60 = mul nsw i32 %59, 6000
%61 = call i64 @round(i32 %60)
%62 = trunc i64 %61 to i32
%63 = srem i32 %62, 6000
%64 = sitofp i32 %63 to double
%65 = fdiv double %64, 1.000000e+02
%66 = call i32 (i8*, i32, i8*, i32, double, ...) @snprintf(i8* %54, i32 %55, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %57, double %65)
store i32 %66, i32* %5
br label %82
67: ; preds = %13
%68 = load i8*, i8** %8
%69 = load i32, i32* %9
%70 = load double, double* %6
%71 = call i32 @abs(double %70)
%72 = load double, double* %6
%73 = call i32 @fabs(double %72)
%74 = mul nsw i32 %73, 6000
%75 = call i64 @round(i32 %74)
%76 = trunc i64 %75 to i32
%77 = srem i32 %76, 6000
%78 = sitofp i32 %77 to double
%79 = fdiv double %78, 1.000000e+02
%80 = call i32 (i8*, i32, i8*, i32, double, ...) @snprintf(i8* %68, i32 %69, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %71, double %79)
store i32 %80, i32* %5
br label %82
81: ; preds = %13
store i32 -1, i32* %5
br label %82
82: ; preds = %81, %67, %53, %34, %15, %12
%83 = load i32, i32* %5
ret i32 %83
}

LLVM IR (-O2):
@.str = [14 x i8] c"%02d %c %.1f'\00"
@.str.1 = [14 x i8] c"%03d %c %.1f'\00"
@.str.2 = [13 x i8] c"%02d\C2\B0 %.1f'\00"
@.str.3 = [13 x i8] c"%03d\C2\B0 %.1f'\00"
define i32 @coord_str(double %0, i32 %1, i8* %2, i32 %3) {
%5 = icmp eq i8* %2, null
br i1 %5, label %51, label %6
6: ; preds = %4
switch i32 %1, label %51 [
i32 0, label %7
i32 1, label %19
i32 2, label %31
i32 3, label %41
]
7: ; preds = %6
%8 = tail call i32 @abs(double %0)
%9 = fcmp olt double %0, 0.000000e+00
%10 = select i1 %9, double 8.300000e+01, double 7.800000e+01
%11 = tail call i32 @fabs(double %0)
%12 = mul nsw i32 %11, 6000
%13 = tail call i64 @round(i32 %12)
%14 = trunc i64 %13 to i32
%15 = srem i32 %14, 6000
%16 = sitofp i32 %15 to double
%17 = fdiv double %16, 1.000000e+02
%18 = tail call i32 (i8*, i32, i8*, i32, double, ...) @snprintf(i8* %2, i32 %3, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %8, double %10, double %17)
br label %51
19: ; preds = %6
%20 = tail call i32 @abs(double %0)
%21 = fcmp olt double %0, 0.000000e+00
%22 = select i1 %21, double 8.700000e+01, double 6.900000e+01
%23 = tail call i32 @fabs(double %0)
%24 = mul nsw i32 %23, 6000
%25 = tail call i64 @round(i32 %24)
%26 = trunc i64 %25 to i32
%27 = srem i32 %26, 6000
%28 = sitofp i32 %27 to double
%29 = fdiv double %28, 1.000000e+02
%30 = tail call i32 (i8*, i32, i8*, i32, double, ...) @snprintf(i8* %2, i32 %3, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %20, double %22, double %29)
br label %51
31: ; preds = %6
%32 = tail call i32 @abs(double %0)
%33 = tail call i32 @fabs(double %0)
%34 = mul nsw i32 %33, 6000
%35 = tail call i64 @round(i32 %34)
%36 = trunc i64 %35 to i32
%37 = srem i32 %36, 6000
%38 = sitofp i32 %37 to double
%39 = fdiv double %38, 1.000000e+02
%40 = tail call i32 (i8*, i32, i8*, i32, double, ...) @snprintf(i8* %2, i32 %3, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %32, double %39)
br label %51
41: ; preds = %6
%42 = tail call i32 @abs(double %0)
%43 = tail call i32 @fabs(double %0)
%44 = mul nsw i32 %43, 6000
%45 = tail call i64 @round(i32 %44)
%46 = trunc i64 %45 to i32
%47 = srem i32 %46, 6000
%48 = sitofp i32 %47 to double
%49 = fdiv double %48, 1.000000e+02
%50 = tail call i32 (i8*, i32, i8*, i32, double, ...) @snprintf(i8* %2, i32 %3, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %42, double %49)
br label %51
51: ; preds = %6, %4, %41, %31, %19, %7
%52 = phi i32 [ %50, %41 ], [ %40, %31 ], [ %30, %19 ], [ %18, %7 ], [ -1, %4 ], [ -1, %6 ]
ret i32 %52
}