char *pr_spherical(value, pos, neg)
int value;
char *pos;
char *neg;
{
  static char buf[256];
  register char *p = buf;
  char *direction;
  int degrees, minutes, seconds, fracsec;
  value -= (int)((unsigned)1 << 31);
  direction = pos;
  if (value < 0) {
    direction = neg;
    value = -value;
  }
  fracsec = value % 1000;
  value /= 1000;
  seconds = value % 60;
  value /= 60;
  minutes = value % 60;
  value /= 60;
  degrees = value;
  (void)sprintf(p, "%d", degrees);
  p += (int)strlen(p);
  if (minutes > 0 || seconds > 0 || fracsec > 0) {
    (void)sprintf(p, " %02d", minutes);
    p += (int)strlen(p);
  }
  if (seconds > 0 || fracsec > 0) {
    (void)sprintf(p, " %02d", seconds);
    p += (int)strlen(p);
  }
  if (fracsec > 0) {
    (void)sprintf(p, ".%03d", fracsec);
    p += (int)strlen(p);
  }
  (void)sprintf(p, " %s", direction);
  return (buf);
}


x86 assembly (clang, -O0):
<pr_spherical>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0x2f06(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x80000000,%eax
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    116b <pr_spherical+0x4b>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %edx,-0x38(%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,-0x34(%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,-0x30(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%edx
lea    0xe2d(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x30(%rbp)
jg     1211 <pr_spherical+0xf1>
cmpl   $0x0,-0x34(%rbp)
jg     1211 <pr_spherical+0xf1>
cmpl   $0x0,-0x38(%rbp)
jle    123f <pr_spherical+0x11f>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%edx
lea    0xde4(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x34(%rbp)
jg     1253 <pr_spherical+0x133>
cmpl   $0x0,-0x38(%rbp)
jle    1281 <pr_spherical+0x161>
mov    -0x20(%rbp),%rdi
mov    -0x34(%rbp),%edx
lea    0xda2(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x38(%rbp)
jle    12b9 <pr_spherical+0x199>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%edx
lea    0xd70(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xd47(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
lea    0x2d6a(%rip),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pr_spherical>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%r12d
mov    %edi,%eax
xor    $0x80000000,%eax
mov    %eax,%ecx
neg    %ecx
test   %edi,%edi
cmovs  %eax,%ecx
mov    %rdx,0x8(%rsp)
mov    %rsi,0x10(%rsp)
movslq %ecx,%rax
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
sar    $0x6,%ecx
add    %edx,%ecx
imul   $0x3e8,%ecx,%esi
imul   $0x45e7b273,%rax,%rdi
imul   $0x4a90be59,%rax,%rdx
mov    %eax,%r13d
sub    %esi,%r13d
movslq %ecx,%rbx
imul   $0xffffffff88888889,%rbx,%rax
shr    $0x20,%rax
add    %ebx,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x5,%eax
add    %ecx,%eax
imul   $0x3c,%eax,%eax
sub    %eax,%ebx
mov    %rdi,%rax
shr    $0x3f,%rax
shr    $0x20,%rdi
sar    $0xe,%edi
add    %eax,%edi
movslq %edi,%r14
imul   $0xffffffff88888889,%r14,%rax
shr    $0x20,%rax
add    %r14d,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x5,%eax
add    %ecx,%eax
imul   $0x3c,%eax,%eax
sub    %eax,%r14d
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x34,%rdx
add    %eax,%edx
lea    0x2e5d(%rip),%r15
lea    0xe16(%rip),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <sprintf@plt>
mov    %r15,%rdi
call   1030 <strlen@plt>
movslq %eax,%rbp
add    %r15,%rbp
test   %r14d,%r14d
jg     1210 <pr_spherical+0xf0>
test   %ebx,%ebx
jg     1210 <pr_spherical+0xf0>
test   %r13d,%r13d
jle    1231 <pr_spherical+0x111>
lea    0xdec(%rip),%rsi
mov    %rbp,%rdi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <sprintf@plt>
mov    %rbp,%rdi
call   1030 <strlen@plt>
cltq
add    %rax,%rbp
mov    0x8(%rsp),%r14
test   %ebx,%ebx
jg     123f <pr_spherical+0x11f>
test   %r13d,%r13d
jle    125f <pr_spherical+0x13f>
lea    0xdbd(%rip),%rsi
mov    %rbp,%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <sprintf@plt>
mov    %rbp,%rdi
call   1030 <strlen@plt>
cltq
add    %rax,%rbp
mov    0x10(%rsp),%rbx
test   %r13d,%r13d
jle    128a <pr_spherical+0x16a>
lea    0xd99(%rip),%rsi
mov    %rbp,%rdi
mov    %r13d,%edx
xor    %eax,%eax
call   1040 <sprintf@plt>
mov    %rbp,%rdi
call   1030 <strlen@plt>
cltq
add    %rax,%rbp
test   %r12d,%r12d
cmovns %r14,%rbx
lea    0xd77(%rip),%rsi
mov    %rbp,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <sprintf@plt>
lea    0x2d94(%rip),%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@pr_spherical.buf = internal global [256 x i8] zeroinitializer
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c" %02d\00"
@.str.2 = [6 x i8] c".%03d\00"
@.str.3 = [4 x i8] c" %s\00"
define i8* @pr_spherical(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @pr_spherical.buf, i64 0, i64 0), i8** %7
%13 = load i32, i32* %4
%14 = sub nsw i32 %13, -2147483648
store i32 %14, i32* %4
%15 = load i8*, i8** %5
store i8* %15, i8** %8
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %3
%19 = load i8*, i8** %6
store i8* %19, i8** %8
%20 = load i32, i32* %4
%21 = sub nsw i32 0, %20
store i32 %21, i32* %4
br label %22
22: ; preds = %18, %3
%23 = load i32, i32* %4
%24 = srem i32 %23, 1000
store i32 %24, i32* %12
%25 = load i32, i32* %4
%26 = sdiv i32 %25, 1000
store i32 %26, i32* %4
%27 = load i32, i32* %4
%28 = srem i32 %27, 60
store i32 %28, i32* %11
%29 = load i32, i32* %4
%30 = sdiv i32 %29, 60
store i32 %30, i32* %4
%31 = load i32, i32* %4
%32 = srem i32 %31, 60
store i32 %32, i32* %10
%33 = load i32, i32* %4
%34 = sdiv i32 %33, 60
store i32 %34, i32* %4
%35 = load i32, i32* %4
store i32 %35, i32* %9
%36 = load i8*, i8** %7
%37 = load i32, i32* %9
%38 = call i32 (i8*, i8*, ...) @sprintf(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %37)
%39 = load i8*, i8** %7
%40 = call i64 @strlen(i8* %39)
%41 = trunc i64 %40 to i32
%42 = load i8*, i8** %7
%43 = sext i32 %41 to i64
%44 = getelementptr inbounds i8, i8* %42, i64 %43
store i8* %44, i8** %7
%45 = load i32, i32* %10
%46 = icmp sgt i32 %45, 0
br i1 %46, label %53, label %47
47: ; preds = %22
%48 = load i32, i32* %11
%49 = icmp sgt i32 %48, 0
br i1 %49, label %53, label %50
50: ; preds = %47
%51 = load i32, i32* %12
%52 = icmp sgt i32 %51, 0
br i1 %52, label %53, label %63
53: ; preds = %50, %47, %22
%54 = load i8*, i8** %7
%55 = load i32, i32* %10
%56 = call i32 (i8*, i8*, ...) @sprintf(i8* %54, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %55)
%57 = load i8*, i8** %7
%58 = call i64 @strlen(i8* %57)
%59 = trunc i64 %58 to i32
%60 = load i8*, i8** %7
%61 = sext i32 %59 to i64
%62 = getelementptr inbounds i8, i8* %60, i64 %61
store i8* %62, i8** %7
br label %63
63: ; preds = %53, %50
%64 = load i32, i32* %11
%65 = icmp sgt i32 %64, 0
br i1 %65, label %69, label %66
66: ; preds = %63
%67 = load i32, i32* %12
%68 = icmp sgt i32 %67, 0
br i1 %68, label %69, label %79
69: ; preds = %66, %63
%70 = load i8*, i8** %7
%71 = load i32, i32* %11
%72 = call i32 (i8*, i8*, ...) @sprintf(i8* %70, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %71)
%73 = load i8*, i8** %7
%74 = call i64 @strlen(i8* %73)
%75 = trunc i64 %74 to i32
%76 = load i8*, i8** %7
%77 = sext i32 %75 to i64
%78 = getelementptr inbounds i8, i8* %76, i64 %77
store i8* %78, i8** %7
br label %79
79: ; preds = %69, %66
%80 = load i32, i32* %12
%81 = icmp sgt i32 %80, 0
br i1 %81, label %82, label %92
82: ; preds = %79
%83 = load i8*, i8** %7
%84 = load i32, i32* %12
%85 = call i32 (i8*, i8*, ...) @sprintf(i8* %83, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %84)
%86 = load i8*, i8** %7
%87 = call i64 @strlen(i8* %86)
%88 = trunc i64 %87 to i32
%89 = load i8*, i8** %7
%90 = sext i32 %88 to i64
%91 = getelementptr inbounds i8, i8* %89, i64 %90
store i8* %91, i8** %7
br label %92
92: ; preds = %82, %79
%93 = load i8*, i8** %7
%94 = load i8*, i8** %8
%95 = call i32 (i8*, i8*, ...) @sprintf(i8* %93, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %94)
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @pr_spherical.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@pr_spherical.buf = internal global [256 x i8] zeroinitializer
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c" %02d\00"
@.str.2 = [6 x i8] c".%03d\00"
@.str.3 = [4 x i8] c" %s\00"
define i8* @pr_spherical(i32 %0, i8* %1, i8* %2) {
%4 = xor i32 %0, -2147483648
%5 = icmp sgt i32 %0, -1
%6 = sub nsw i32 0, %4
%7 = select i1 %5, i32 %6, i32 %4
%8 = srem i32 %7, 1000
%9 = sdiv i32 %7, 1000
%10 = srem i32 %9, 60
%11 = sdiv i32 %7, 60000
%12 = srem i32 %11, 60
%13 = sdiv i32 %7, 3600000
%14 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([256 x i8], [256 x i8]* @pr_spherical.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = tail call i64 @strlen(i8* dereferenceable(1) getelementptr inbounds ([256 x i8], [256 x i8]* @pr_spherical.buf, i64 0, i64 0))
%16 = shl i64 %15, 32
%17 = ashr exact i64 %16, 32
%18 = getelementptr inbounds [256 x i8], [256 x i8]* @pr_spherical.buf, i64 0, i64 %17
%19 = icmp sgt i32 %12, 0
%20 = icmp sgt i32 %10, 0
%21 = select i1 %19, i1 true, i1 %20
%22 = icmp sgt i32 %8, 0
%23 = select i1 %21, i1 true, i1 %22
br i1 %23, label %24, label %30
24: ; preds = %3
%25 = tail call i32 (i8*, i8*, ...) @sprintf(i8* %18, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%26 = tail call i64 @strlen(i8* %18)
%27 = shl i64 %26, 32
%28 = ashr exact i64 %27, 32
%29 = getelementptr inbounds i8, i8* %18, i64 %28
br label %30
30: ; preds = %3, %24
%31 = phi i8* [ %29, %24 ], [ %18, %3 ]
%32 = select i1 %20, i1 true, i1 %22
br i1 %32, label %33, label %39
33: ; preds = %30
%34 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %31, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%35 = tail call i64 @strlen(i8* dereferenceable(1) %31)
%36 = shl i64 %35, 32
%37 = ashr exact i64 %36, 32
%38 = getelementptr inbounds i8, i8* %31, i64 %37
br label %39
39: ; preds = %30, %33
%40 = phi i8* [ %38, %33 ], [ %31, %30 ]
br i1 %22, label %41, label %47
41: ; preds = %39
%42 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %40, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%43 = tail call i64 @strlen(i8* dereferenceable(1) %40)
%44 = shl i64 %43, 32
%45 = ashr exact i64 %44, 32
%46 = getelementptr inbounds i8, i8* %40, i64 %45
br label %47
47: ; preds = %41, %39
%48 = phi i8* [ %46, %41 ], [ %40, %39 ]
%49 = select i1 %5, i8* %2, i8* %1
%50 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %48, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %49)
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @pr_spherical.buf, i64 0, i64 0)
}