#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 ceil(double);
int fabs(double);
scalar_t__ floor(double);
scalar_t__ lround(double);
int /*<<< orphan*/ sprintf(char *, char *, int, char *, int, int);
int swh_geod2c(double coord, int maxdeg, char *ret) {
  int deg, dir, min, sec;
  if (coord < -(maxdeg) || coord > maxdeg)
    return -1;
  if (coord >= 0) {
    deg = (int)floor(coord);
    dir = 1;
  } else {
    deg = (int)fabs(ceil(coord));
    dir = 0;
  }
  coord = fabs(coord) - deg;
  min = (int)lround(coord * 60);
  coord -= min / 60.0;
  sec = (int)lround(coord * 3600);
  if (maxdeg == 90)
    sprintf(ret, "%.2d:%s:%.2d:%.2d", deg, dir ? "N" : "S", min, sec);
  else
    sprintf(ret, "%.3d:%s:%.2d:%.2d", deg, dir ? "E" : "W", min, sec);
  return 0;
}


x86 assembly (clang, -O0):
<swh_geod2c>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
mov    %rsi,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm1
xor    %eax,%eax
sub    -0x14(%rbp),%eax
cvtsi2sd %eax,%xmm0
ucomisd %xmm1,%xmm0
ja     1190 <swh_geod2c+0x40>
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jbe    119c <swh_geod2c+0x4c>
movl   $0xffffffff,-0x4(%rbp)
jmp    12bb <swh_geod2c+0x16b>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11c7 <swh_geod2c+0x77>
movsd  -0x10(%rbp),%xmm0
call   1070 <floor@plt>
mov    %eax,-0x24(%rbp)
movl   $0x1,-0x28(%rbp)
jmp    11e0 <swh_geod2c+0x90>
movsd  -0x10(%rbp),%xmm0
call   1040 <ceil@plt>
call   1050 <fabs@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <fabs@plt>
sub    -0x24(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe0a(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
call   1030 <lround@plt>
mov    %eax,-0x2c(%rbp)
cvtsi2sdl -0x2c(%rbp),%xmm1
movsd  0xdf0(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  -0x10(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xdce(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
call   1030 <lround@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x5a,-0x14(%rbp)
jne    1281 <swh_geod2c+0x131>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%esi
lea    0xdca(%rip),%rcx
lea    0xdc1(%rip),%rax
cmp    $0x0,%esi
cmovne %rax,%rcx
mov    -0x2c(%rbp),%r8d
mov    -0x30(%rbp),%r9d
lea    0xd99(%rip),%rsi
call   1060 <sprintf@plt>
jmp    12b4 <swh_geod2c+0x164>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%esi
lea    0xda8(%rip),%rcx
lea    0xd9f(%rip),%rax
cmp    $0x0,%esi
cmovne %rax,%rcx
mov    -0x2c(%rbp),%r8d
mov    -0x30(%rbp),%r9d
lea    0xd77(%rip),%rsi
call   1060 <sprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<swh_geod2c>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%eax
neg    %eax
cvtsi2sd %eax,%xmm1
ucomisd %xmm0,%xmm1
mov    $0xffffffff,%eax
ja     1267 <swh_geod2c+0x117>
mov    %edi,%ebp
xorps  %xmm1,%xmm1
cvtsi2sd %edi,%xmm1
ucomisd %xmm1,%xmm0
ja     1267 <swh_geod2c+0x117>
mov    %rsi,%r14
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
jae    11a6 <swh_geod2c+0x56>
call   1040 <ceil@plt>
call   1050 <fabs@plt>
mov    %eax,%r15d
jmp    11ae <swh_geod2c+0x5e>
call   1070 <floor@plt>
mov    %rax,%r15
movsd  0x8(%rsp),%xmm0
call   1050 <fabs@plt>
sub    %r15d,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x10(%rsp)
mulsd  0xe2f(%rip),%xmm0
call   1030 <lround@plt>
mov    %rax,%rbx
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
divsd  0xe18(%rip),%xmm0
movsd  0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
mulsd  0xe0e(%rip),%xmm1
movapd %xmm1,%xmm0
call   1030 <lround@plt>
xorpd  %xmm0,%xmm0
cmp    $0x5a,%ebp
jne    1231 <swh_geod2c+0xe1>
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
lea    0xe07(%rip),%rdx
lea    0xdfe(%rip),%rcx
cmovb  %rdx,%rcx
lea    0xde1(%rip),%rsi
jmp    1254 <swh_geod2c+0x104>
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
lea    0xdf8(%rip),%rdx
lea    0xdef(%rip),%rcx
cmovb  %rdx,%rcx
lea    0xdd2(%rip),%rsi
mov    %r14,%rdi
mov    %r15d,%edx
mov    %ebx,%r8d
mov    %eax,%r9d
call   1060 <sprintf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"%.2d:%s:%.2d:%.2d\00"
@.str.1 = [2 x i8] c"N\00"
@.str.2 = [2 x i8] c"S\00"
@.str.3 = [18 x i8] c"%.3d:%s:%.2d:%.2d\00"
@.str.4 = [2 x i8] c"E\00"
@.str.5 = [2 x i8] c"W\00"
define i32 @swh_geod2c(double %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca double
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store double %0, double* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%12 = load double, double* %5
%13 = load i32, i32* %6
%14 = sub nsw i32 0, %13
%15 = sitofp i32 %14 to double
%16 = fcmp olt double %12, %15
br i1 %16, label %22, label %17
17: ; preds = %3
%18 = load double, double* %5
%19 = load i32, i32* %6
%20 = sitofp i32 %19 to double
%21 = fcmp ogt double %18, %20
br i1 %21, label %22, label %23
22: ; preds = %17, %3
store i32 -1, i32* %4
br label %76
23: ; preds = %17
%24 = load double, double* %5
%25 = fcmp oge double %24, 0.000000e+00
br i1 %25, label %26, label %30
26: ; preds = %23
%27 = load double, double* %5
%28 = call i64 @floor(double %27)
%29 = trunc i64 %28 to i32
store i32 %29, i32* %8
store i32 1, i32* %9
br label %34
30: ; preds = %23
%31 = load double, double* %5
%32 = call double @llvm.ceil.f64(double %31)
%33 = call i32 @fabs(double %32)
store i32 %33, i32* %8
store i32 0, i32* %9
br label %34
34: ; preds = %30, %26
%35 = load double, double* %5
%36 = call i32 @fabs(double %35)
%37 = load i32, i32* %8
%38 = sub nsw i32 %36, %37
%39 = sitofp i32 %38 to double
store double %39, double* %5
%40 = load double, double* %5
%41 = fmul double %40, 6.000000e+01
%42 = call i64 @lround(double %41)
%43 = trunc i64 %42 to i32
store i32 %43, i32* %10
%44 = load i32, i32* %10
%45 = sitofp i32 %44 to double
%46 = fdiv double %45, 6.000000e+01
%47 = load double, double* %5
%48 = fsub double %47, %46
store double %48, double* %5
%49 = load double, double* %5
%50 = fmul double %49, 3.600000e+03
%51 = call i64 @lround(double %50)
%52 = trunc i64 %51 to i32
store i32 %52, i32* %11
%53 = load i32, i32* %6
%54 = icmp eq i32 %53, 90
br i1 %54, label %55, label %65
55: ; preds = %34
%56 = load i8*, i8** %7
%57 = load i32, i32* %8
%58 = load i32, i32* %9
%59 = icmp ne i32 %58, 0
%60 = zext i1 %59 to i64
%61 = select i1 %59, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%62 = load i32, i32* %10
%63 = load i32, i32* %11
%64 = call i32 @sprintf(i8* %56, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %57, i8* %61, i32 %62, i32 %63)
br label %75
65: ; preds = %34
%66 = load i8*, i8** %7
%67 = load i32, i32* %8
%68 = load i32, i32* %9
%69 = icmp ne i32 %68, 0
%70 = zext i1 %69 to i64
%71 = select i1 %69, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0)
%72 = load i32, i32* %10
%73 = load i32, i32* %11
%74 = call i32 @sprintf(i8* %66, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %67, i8* %71, i32 %72, i32 %73)
br label %75
75: ; preds = %65, %55
store i32 0, i32* %4
br label %76
76: ; preds = %75, %22
%77 = load i32, i32* %4
ret i32 %77
}

LLVM IR (-O2):
@.str = [18 x i8] c"%.2d:%s:%.2d:%.2d\00"
@.str.1 = [2 x i8] c"N\00"
@.str.2 = [2 x i8] c"S\00"
@.str.3 = [18 x i8] c"%.3d:%s:%.2d:%.2d\00"
@.str.4 = [2 x i8] c"E\00"
@.str.5 = [2 x i8] c"W\00"
define i32 @swh_geod2c(double %0, i32 %1, i8* nocapture writeonly %2) {
%4 = sub nsw i32 0, %1
%5 = sitofp i32 %4 to double
%6 = fcmp ogt double %5, %0
%7 = sitofp i32 %1 to double
%8 = fcmp olt double %7, %0
%9 = or i1 %6, %8
br i1 %9, label %39, label %10
10: ; preds = %3
%11 = fcmp ult double %0, 0.000000e+00
br i1 %11, label %15, label %12
12: ; preds = %10
%13 = tail call i64 @floor(double %0)
%14 = trunc i64 %13 to i32
br label %18
15: ; preds = %10
%16 = tail call double @llvm.ceil.f64(double %0)
%17 = tail call i32 @fabs(double %16)
br label %18
18: ; preds = %15, %12
%19 = phi i32 [ %14, %12 ], [ %17, %15 ]
%20 = tail call i32 @fabs(double %0)
%21 = sub nsw i32 %20, %19
%22 = sitofp i32 %21 to double
%23 = fmul double %22, 6.000000e+01
%24 = tail call i64 @lround(double %23)
%25 = trunc i64 %24 to i32
%26 = sitofp i32 %25 to double
%27 = fdiv double %26, 6.000000e+01
%28 = fsub double %22, %27
%29 = fmul double %28, 3.600000e+03
%30 = tail call i64 @lround(double %29)
%31 = trunc i64 %30 to i32
%32 = icmp eq i32 %1, 90
br i1 %32, label %33, label %36
33: ; preds = %18
%34 = select i1 %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%35 = tail call i32 @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %19, i8* %34, i32 %25, i32 %31)
br label %39
36: ; preds = %18
%37 = select i1 %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0)
%38 = tail call i32 @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %19, i8* %37, i32 %25, i32 %31)
br label %39
39: ; preds = %33, %36, %3
%40 = phi i32 [ -1, %3 ], [ 0, %36 ], [ 0, %33 ]
ret i32 %40
}