#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 degreeToDMS(double, int, int *, int *, int *, double *);
int degreeToHMS(double, int, int *, int *, int *, double *);
int /*<<< orphan*/ sprintf(char *, char *, char *, int, int, double);
int degreeToSex(double lon, double lat, char *lonstr, char *latstr) {
  int status, prec;
  int neg, d, m, h;
  double s;
  prec = 2;
  status = degreeToHMS(lon, prec, &neg, &h, &m, &s);
  if (status < 0)
    return (status);
  sprintf(lonstr, "%s%02dh %02dm %05.2fs", (neg ? "-" : ""), h, m, s);
  status = degreeToDMS(lat, prec, &neg, &d, &m, &s);
  if (status < 0)
    return (status);
  sprintf(latstr, "%s%02dd %02dm %05.2fs", (neg ? "-" : ""), d, m, s);
  return (0);
}


x86 assembly (clang, -O0):
<degreeToSex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %rdi,-0x20(%rbp)
mov    %rsi,-0x28(%rbp)
movl   $0x2,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
mov    -0x30(%rbp),%edi
lea    -0x34(%rbp),%rsi
lea    -0x40(%rbp),%rdx
lea    -0x3c(%rbp),%rcx
lea    -0x48(%rbp),%r8
call   1030 <degreeToHMS@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1186 <degreeToSex+0x56>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    122a <degreeToSex+0xfa>
mov    -0x20(%rbp),%rdi
mov    -0x34(%rbp),%ecx
lea    0xe83(%rip),%rdx
lea    0xe7b(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
mov    -0x40(%rbp),%ecx
mov    -0x3c(%rbp),%r8d
movsd  -0x48(%rbp),%xmm0
lea    0xe4b(%rip),%rsi
call   1040 <sprintf@plt>
movsd  -0x18(%rbp),%xmm0
mov    -0x30(%rbp),%edi
lea    -0x34(%rbp),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x3c(%rbp),%rcx
lea    -0x48(%rbp),%r8
call   1050 <degreeToDMS@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    11ef <degreeToSex+0xbf>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    122a <degreeToSex+0xfa>
mov    -0x28(%rbp),%rdi
mov    -0x34(%rbp),%ecx
lea    0xe1a(%rip),%rdx
lea    0xe12(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
mov    -0x38(%rbp),%ecx
mov    -0x3c(%rbp),%r8d
movsd  -0x48(%rbp),%xmm0
lea    0xdfa(%rip),%rsi
call   1040 <sprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<degreeToSex>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
movsd  %xmm1,0x20(%rsp)
lea    0xc(%rsp),%rsi
lea    0x18(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0x10(%rsp),%r8
mov    $0x2,%edi
call   1030 <degreeToHMS@plt>
test   %eax,%eax
js     11f9 <degreeToSex+0xc9>
cmpl   $0x0,0xc(%rsp)
lea    0xe9e(%rip),%r12
lea    0xe96(%rip),%rbx
mov    %rbx,%rdx
cmove  %r12,%rdx
mov    0x18(%rsp),%ecx
mov    0x8(%rsp),%r8d
movsd  0x10(%rsp),%xmm0
lea    0xe63(%rip),%rsi
mov    %r15,%rdi
call   1040 <sprintf@plt>
lea    0xc(%rsp),%rsi
lea    0x1c(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0x10(%rsp),%r8
movsd  0x20(%rsp),%xmm0
mov    $0x2,%edi
call   1050 <degreeToDMS@plt>
test   %eax,%eax
js     11f9 <degreeToSex+0xc9>
cmpl   $0x0,0xc(%rsp)
cmove  %r12,%rbx
mov    0x1c(%rsp),%ecx
mov    0x8(%rsp),%r8d
movsd  0x10(%rsp),%xmm0
lea    0xe2c(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1040 <sprintf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [22 x i8] c"%s%02dh %02dm %05.2fs\00"
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [22 x i8] c"%s%02dd %02dm %05.2fs\00"
define i32 @degreeToSex(double %0, double %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca double
store double %0, double* %6
store double %1, double* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i32 2, i32* %11
%17 = load double, double* %6
%18 = load i32, i32* %11
%19 = call i32 @degreeToHMS(double %17, i32 %18, i32* %12, i32* %15, i32* %14, double* %16)
store i32 %19, i32* %10
%20 = load i32, i32* %10
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %4
%23 = load i32, i32* %10
store i32 %23, i32* %5
br label %51
24: ; preds = %4
%25 = load i8*, i8** %8
%26 = load i32, i32* %12
%27 = icmp ne i32 %26, 0
%28 = zext i1 %27 to i64
%29 = select i1 %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%30 = load i32, i32* %15
%31 = load i32, i32* %14
%32 = load double, double* %16
%33 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %29, i32 %30, i32 %31, double %32)
%34 = load double, double* %7
%35 = load i32, i32* %11
%36 = call i32 @degreeToDMS(double %34, i32 %35, i32* %12, i32* %13, i32* %14, double* %16)
store i32 %36, i32* %10
%37 = load i32, i32* %10
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %24
%40 = load i32, i32* %10
store i32 %40, i32* %5
br label %51
41: ; preds = %24
%42 = load i8*, i8** %9
%43 = load i32, i32* %12
%44 = icmp ne i32 %43, 0
%45 = zext i1 %44 to i64
%46 = select i1 %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%47 = load i32, i32* %13
%48 = load i32, i32* %14
%49 = load double, double* %16
%50 = call i32 @sprintf(i8* %42, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %46, i32 %47, i32 %48, double %49)
store i32 0, i32* %5
br label %51
51: ; preds = %41, %39, %22
%52 = load i32, i32* %5
ret i32 %52
}

LLVM IR (-O2):
@.str = [22 x i8] c"%s%02dh %02dm %05.2fs\00"
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [22 x i8] c"%s%02dd %02dm %05.2fs\00"
define i32 @degreeToSex(double %0, double %1, i8* nocapture writeonly %2, i8* nocapture writeonly %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = bitcast i32* %5 to i8*
%11 = bitcast i32* %6 to i8*
%12 = bitcast i32* %7 to i8*
%13 = bitcast i32* %8 to i8*
%14 = bitcast double* %9 to i8*
%15 = call i32 @degreeToHMS(double %0, i32 2, i32* %5, i32* %8, i32* %7, double* %9)
%16 = icmp slt i32 %15, 0
br i1 %16, label %35, label %17
17: ; preds = %4
%18 = load i32, i32* %5
%19 = icmp eq i32 %18, 0
%20 = select i1 %19, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%21 = load i32, i32* %8
%22 = load i32, i32* %7
%23 = load double, double* %9
%24 = call i32 @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %20, i32 %21, i32 %22, double %23)
%25 = call i32 @degreeToDMS(double %1, i32 2, i32* %5, i32* %6, i32* %7, double* %9)
%26 = icmp slt i32 %25, 0
br i1 %26, label %35, label %27
27: ; preds = %17
%28 = load i32, i32* %5
%29 = icmp eq i32 %28, 0
%30 = select i1 %29, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%31 = load i32, i32* %6
%32 = load i32, i32* %7
%33 = load double, double* %9
%34 = call i32 @sprintf(i8* dereferenceable(1) %3, i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %30, i32 %31, i32 %32, double %33)
br label %35
35: ; preds = %17, %4, %27
%36 = phi i32 [ 0, %27 ], [ %15, %4 ], [ %25, %17 ]
ret i32 %36
}