#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 *, double);
void format_latlon(double lat, double lon, char *slat, char *slon, int res) {
  if (res == 3) {
    if (lat < 0.)
      sprintf(slat, "%6.3fS", -lat);
    else
      sprintf(slat, "%6.3fN", lat);
    if (lon < 0.)
      sprintf(slon, "%7.3fW", -lon);
    else
      sprintf(slon, "%7.3fE", lon);
  } else if (res == 2) {
    if (lat < 0.)
      sprintf(slat, "%5.2fS", -lat);
    else
      sprintf(slat, "%5.2fN", lat);
    if (lon < 0.)
      sprintf(slon, "%6.2fW", -lon);
    else
      sprintf(slon, "%6.2fE", lon);
  }
}


x86 assembly (clang, -O0):
<format_latlon>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %edx,-0x24(%rbp)
cmpl   $0x3,-0x24(%rbp)
jne    11e4 <format_latlon+0xd4>
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1176 <format_latlon+0x66>
mov    -0x18(%rbp),%rdi
movsd  -0x8(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
lea    0xe94(%rip),%rsi
call   1030 <sprintf@plt>
jmp    118b <format_latlon+0x7b>
mov    -0x18(%rbp),%rdi
movsd  -0x8(%rbp),%xmm0
lea    0xe81(%rip),%rsi
call   1030 <sprintf@plt>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11ca <format_latlon+0xba>
mov    -0x20(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
lea    0xe4e(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11df <format_latlon+0xcf>
mov    -0x20(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
lea    0xe3b(%rip),%rsi
call   1030 <sprintf@plt>
jmp    12a0 <format_latlon+0x190>
cmpl   $0x2,-0x24(%rbp)
jne    129b <format_latlon+0x18b>
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    122d <format_latlon+0x11d>
mov    -0x18(%rbp),%rdi
movsd  -0x8(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
lea    0xdf9(%rip),%rsi
call   1030 <sprintf@plt>
jmp    1242 <format_latlon+0x132>
mov    -0x18(%rbp),%rdi
movsd  -0x8(%rbp),%xmm0
lea    0xde6(%rip),%rsi
call   1030 <sprintf@plt>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1281 <format_latlon+0x171>
mov    -0x20(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
lea    0xdb3(%rip),%rsi
call   1030 <sprintf@plt>
jmp    1296 <format_latlon+0x186>
mov    -0x20(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
lea    0xda0(%rip),%rsi
call   1030 <sprintf@plt>
jmp    129b <format_latlon+0x18b>
jmp    12a0 <format_latlon+0x190>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_latlon>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edx
je     1142 <format_latlon+0x32>
cmp    $0x3,%edx
jne    1162 <format_latlon+0x52>
movapd %xmm1,(%rsp)
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    1168 <format_latlon+0x58>
xorpd  0xec7(%rip),%xmm0
lea    0xed0(%rip),%rsi
jmp    116f <format_latlon+0x5f>
movapd %xmm1,(%rsp)
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    1194 <format_latlon+0x84>
xorpd  0xea7(%rip),%xmm0
lea    0xecc(%rip),%rsi
jmp    119b <format_latlon+0x8b>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xea8(%rip),%rsi
call   1030 <sprintf@plt>
xorpd  %xmm1,%xmm1
movapd (%rsp),%xmm0
ucomisd %xmm0,%xmm1
jbe    11c0 <format_latlon+0xb0>
xorpd  0xe75(%rip),%xmm0
lea    0xe8c(%rip),%rsi
jmp    11d0 <format_latlon+0xc0>
lea    0xe98(%rip),%rsi
call   1030 <sprintf@plt>
xorpd  %xmm1,%xmm1
movapd (%rsp),%xmm0
ucomisd %xmm0,%xmm1
jbe    11c9 <format_latlon+0xb9>
xorpd  0xe49(%rip),%xmm0
lea    0xe7c(%rip),%rsi
jmp    11d0 <format_latlon+0xc0>
lea    0xe5e(%rip),%rsi
jmp    11d0 <format_latlon+0xc0>
lea    0xe71(%rip),%rsi
mov    %rbx,%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1030 <sprintf@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"%6.3fS\00"
@.str.1 = [7 x i8] c"%6.3fN\00"
@.str.2 = [7 x i8] c"%7.3fW\00"
@.str.3 = [7 x i8] c"%7.3fE\00"
@.str.4 = [7 x i8] c"%5.2fS\00"
@.str.5 = [7 x i8] c"%5.2fN\00"
@.str.6 = [7 x i8] c"%6.2fW\00"
@.str.7 = [7 x i8] c"%6.2fE\00"
define void @format_latlon(double %0, double %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca double
%7 = alloca double
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store double %0, double* %6
store double %1, double* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i32 %4, i32* %10
%11 = load i32, i32* %10
%12 = icmp eq i32 %11, 3
br i1 %12, label %13, label %38
13: ; preds = %5
%14 = load double, double* %6
%15 = fcmp olt double %14, 0.000000e+00
br i1 %15, label %16, label %21
16: ; preds = %13
%17 = load i8*, i8** %8
%18 = load double, double* %6
%19 = fneg double %18
%20 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %19)
br label %25
21: ; preds = %13
%22 = load i8*, i8** %8
%23 = load double, double* %6
%24 = call i32 @sprintf(i8* %22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %23)
br label %25
25: ; preds = %21, %16
%26 = load double, double* %7
%27 = fcmp olt double %26, 0.000000e+00
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = load i8*, i8** %9
%30 = load double, double* %7
%31 = fneg double %30
%32 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %31)
br label %37
33: ; preds = %25
%34 = load i8*, i8** %9
%35 = load double, double* %7
%36 = call i32 @sprintf(i8* %34, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), double %35)
br label %37
37: ; preds = %33, %28
br label %67
38: ; preds = %5
%39 = load i32, i32* %10
%40 = icmp eq i32 %39, 2
br i1 %40, label %41, label %66
41: ; preds = %38
%42 = load double, double* %6
%43 = fcmp olt double %42, 0.000000e+00
br i1 %43, label %44, label %49
44: ; preds = %41
%45 = load i8*, i8** %8
%46 = load double, double* %6
%47 = fneg double %46
%48 = call i32 @sprintf(i8* %45, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), double %47)
br label %53
49: ; preds = %41
%50 = load i8*, i8** %8
%51 = load double, double* %6
%52 = call i32 @sprintf(i8* %50, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), double %51)
br label %53
53: ; preds = %49, %44
%54 = load double, double* %7
%55 = fcmp olt double %54, 0.000000e+00
br i1 %55, label %56, label %61
56: ; preds = %53
%57 = load i8*, i8** %9
%58 = load double, double* %7
%59 = fneg double %58
%60 = call i32 @sprintf(i8* %57, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), double %59)
br label %65
61: ; preds = %53
%62 = load i8*, i8** %9
%63 = load double, double* %7
%64 = call i32 @sprintf(i8* %62, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), double %63)
br label %65
65: ; preds = %61, %56
br label %66
66: ; preds = %65, %38
br label %67
67: ; preds = %66, %37
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%6.3fS\00"
@.str.1 = [7 x i8] c"%6.3fN\00"
@.str.2 = [7 x i8] c"%7.3fW\00"
@.str.3 = [7 x i8] c"%7.3fE\00"
@.str.4 = [7 x i8] c"%5.2fS\00"
@.str.5 = [7 x i8] c"%5.2fN\00"
@.str.6 = [7 x i8] c"%6.2fW\00"
@.str.7 = [7 x i8] c"%6.2fE\00"
define void @format_latlon(double %0, double %1, i8* nocapture writeonly %2, i8* nocapture writeonly %3, i32 %4) {
switch i32 %4, label %34 [
i32 3, label %6
i32 2, label %20
]
6: ; preds = %5
%7 = fcmp olt double %0, 0.000000e+00
br i1 %7, label %8, label %11
8: ; preds = %6
%9 = fneg double %0
%10 = tail call i32 @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %9)
br label %13
11: ; preds = %6
%12 = tail call i32 @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %0)
br label %13
13: ; preds = %11, %8
%14 = fcmp olt double %1, 0.000000e+00
br i1 %14, label %15, label %18
15: ; preds = %13
%16 = fneg double %1
%17 = tail call i32 @sprintf(i8* dereferenceable(1) %3, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %16)
br label %34
18: ; preds = %13
%19 = tail call i32 @sprintf(i8* dereferenceable(1) %3, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), double %1)
br label %34
20: ; preds = %5
%21 = fcmp olt double %0, 0.000000e+00
br i1 %21, label %22, label %25
22: ; preds = %20
%23 = fneg double %0
%24 = tail call i32 @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), double %23)
br label %27
25: ; preds = %20
%26 = tail call i32 @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), double %0)
br label %27
27: ; preds = %25, %22
%28 = fcmp olt double %1, 0.000000e+00
br i1 %28, label %29, label %32
29: ; preds = %27
%30 = fneg double %1
%31 = tail call i32 @sprintf(i8* dereferenceable(1) %3, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), double %30)
br label %34
32: ; preds = %27
%33 = tail call i32 @sprintf(i8* dereferenceable(1) %3, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), double %1)
br label %34
34: ; preds = %5, %32, %29, %15, %18
ret void
}