#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 */
typedef int uint32_t;
typedef int int32_t;

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int, char);
char *coord_ntoa(int32_t coord, uint32_t islat) {
  int32_t deg, min, sec, secfrac;
  static char buf[64];
  char dir;
  coord = coord - 0x80000000;
  dir = 'N';
  if ((islat == 1) && (coord < 0)) {
    dir = 'S';
    coord = -coord;
  }
  if (islat == 0) {
    dir = 'E';
    if (coord < 0) {
      dir = 'W';
      coord = -coord;
    }
  }
  secfrac = coord % 1000;
  coord = coord / 1000;
  sec = coord % 60;
  coord = coord / 60;
  min = coord % 60;
  coord = coord / 60;
  deg = coord;
  sprintf(buf, "%d %.2d %.2d.%.3d %c", deg, min, sec, secfrac, dir);
  return buf;
}


x86 assembly (clang, -O0):
<coord_ntoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x80000000,%eax
mov    %eax,-0x4(%rbp)
movb   $0x4e,-0x19(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    114d <coord_ntoa+0x3d>
cmpl   $0x0,-0x4(%rbp)
jge    114d <coord_ntoa+0x3d>
movb   $0x53,-0x19(%rbp)
xor    %eax,%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1176 <coord_ntoa+0x66>
movb   $0x45,-0x19(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    1171 <coord_ntoa+0x61>
movb   $0x57,-0x19(%rbp)
xor    %eax,%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1176 <coord_ntoa+0x66>
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x14(%rbp),%r8d
mov    -0x18(%rbp),%r9d
lea    0x2e5b(%rip),%rdi
lea    0xe14(%rip),%rsi
movsbl -0x19(%rbp),%eax
mov    %eax,(%rsp)
call   1030 <sprintf@plt>
lea    0x2e41(%rip),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<coord_ntoa>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%eax
xor    $0x80000000,%eax
cmp    $0x1,%esi
sete   %cl
test   %edi,%edi
setns  %dl
mov    %eax,%edi
neg    %edi
xor    %ebx,%ebx
test   %cl,%dl
cmove  %eax,%edi
setne  %bl
mov    %edi,%ecx
neg    %ecx
test   %edi,%edi
mov    $0x57,%edx
mov    $0x45,%eax
cmovs  %edx,%eax
lea    0x4e(%rbx,%rbx,4),%edx
cmovns %edi,%ecx
test   %esi,%esi
cmovne %edi,%ecx
cmovne %edx,%eax
movslq %ecx,%rcx
imul   $0x10624dd3,%rcx,%rsi
mov    %rsi,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rsi
sar    $0x6,%esi
add    %edx,%esi
imul   $0x3e8,%esi,%edi
imul   $0x45e7b273,%rcx,%rbx
imul   $0x4a90be59,%rcx,%rdx
mov    %ecx,%r9d
sub    %edi,%r9d
movslq %esi,%r8
imul   $0xffffffff88888889,%r8,%rcx
shr    $0x20,%rcx
add    %r8d,%ecx
mov    %ecx,%esi
shr    $0x1f,%esi
sar    $0x5,%ecx
add    %esi,%ecx
imul   $0x3c,%ecx,%ecx
sub    %ecx,%r8d
mov    %rbx,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rbx
sar    $0xe,%ebx
add    %ecx,%ebx
movslq %ebx,%rcx
imul   $0xffffffff88888889,%rcx,%rsi
shr    $0x20,%rsi
add    %ecx,%esi
mov    %esi,%edi
shr    $0x1f,%edi
sar    $0x5,%esi
add    %edi,%esi
imul   $0x3c,%esi,%esi
sub    %esi,%ecx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x34,%rdx
add    %esi,%edx
movzbl %al,%eax
mov    %eax,(%rsp)
lea    0x2e4b(%rip),%rbx
lea    0xe04(%rip),%rsi
mov    %rbx,%rdi
call   1030 <sprintf@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@coord_ntoa.buf = internal global [64 x i8] zeroinitializer
@.str = [21 x i8] c"%d %.2d %.2d.%.3d %c\00"
define i8* @coord_ntoa(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
store i32 %0, i32* %3
store i32 %1, i32* %4
%10 = load i32, i32* %3
%11 = sub i32 %10, -2147483648
store i32 %11, i32* %3
store i8 78, i8* %9
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i32, i32* %3
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
store i8 83, i8* %9
%18 = load i32, i32* %3
%19 = sub nsw i32 0, %18
store i32 %19, i32* %3
br label %20
20: ; preds = %17, %14, %2
%21 = load i32, i32* %4
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %30
23: ; preds = %20
store i8 69, i8* %9
%24 = load i32, i32* %3
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
store i8 87, i8* %9
%27 = load i32, i32* %3
%28 = sub nsw i32 0, %27
store i32 %28, i32* %3
br label %29
29: ; preds = %26, %23
br label %30
30: ; preds = %29, %20
%31 = load i32, i32* %3
%32 = srem i32 %31, 1000
store i32 %32, i32* %8
%33 = load i32, i32* %3
%34 = sdiv i32 %33, 1000
store i32 %34, i32* %3
%35 = load i32, i32* %3
%36 = srem i32 %35, 60
store i32 %36, i32* %7
%37 = load i32, i32* %3
%38 = sdiv i32 %37, 60
store i32 %38, i32* %3
%39 = load i32, i32* %3
%40 = srem i32 %39, 60
store i32 %40, i32* %6
%41 = load i32, i32* %3
%42 = sdiv i32 %41, 60
store i32 %42, i32* %3
%43 = load i32, i32* %3
store i32 %43, i32* %5
%44 = load i32, i32* %5
%45 = load i32, i32* %6
%46 = load i32, i32* %7
%47 = load i32, i32* %8
%48 = load i8, i8* %9
%49 = call i32 @sprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @coord_ntoa.buf, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %44, i32 %45, i32 %46, i32 %47, i8 signext %48)
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @coord_ntoa.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@coord_ntoa.buf = internal global [64 x i8] zeroinitializer
@.str = [21 x i8] c"%d %.2d %.2d.%.3d %c\00"
define i8* @coord_ntoa(i32 %0, i32 %1) {
%3 = xor i32 %0, -2147483648
%4 = icmp eq i32 %1, 1
%5 = icmp sgt i32 %0, -1
%6 = and i1 %5, %4
%7 = sub nsw i32 0, %3
%8 = select i1 %6, i32 %7, i32 %3
%9 = select i1 %6, i8 83, i8 78
%10 = icmp eq i32 %1, 0
%11 = icmp slt i32 %8, 0
%12 = sub nsw i32 0, %8
%13 = select i1 %11, i8 87, i8 69
%14 = select i1 %10, i1 %11, i1 false
%15 = select i1 %14, i32 %12, i32 %8
%16 = select i1 %10, i8 %13, i8 %9
%17 = srem i32 %15, 1000
%18 = sdiv i32 %15, 1000
%19 = srem i32 %18, 60
%20 = sdiv i32 %15, 60000
%21 = srem i32 %20, 60
%22 = sdiv i32 %15, 3600000
%23 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @coord_ntoa.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %22, i32 %21, i32 %19, i32 %17, i8 signext %16)
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @coord_ntoa.buf, i64 0, i64 0)
}