char *SAOconvert(buff, val, type, prec)
char *buff;
double val;
int type;
int prec;
{
  char fmt[32];
  char *sign = "";
  float degrees = val;
  float minutes;
  float seconds;
  char ch1, ch2;
  switch (type) {
  case 'b': {
    int v = val;
    unsigned int i;
    int c = 2;
    buff[0] = '0';
    buff[1] = 'b';
    for (i = 0x8000; i; i /= 2) {
      if (v & i || c > 2) {
        buff[c] = v & i ? '1' : '0';
        c++;
      }
    }
    buff[c] = '\0';
    return buff;
  }
  case 'o':
    sprintf(buff, "0o%o", (int)val);
    return buff;
  case 'x':
    sprintf(buff, "0x%x", (int)val);
    return buff;
  case ':':
    ch1 = ':';
    ch2 = ':';
    break;
  case ' ':
    ch1 = ' ';
    ch2 = ' ';
    break;
  case 'h':
    ch1 = 'h';
    ch2 = 'm';
    break;
  case 'd':
    ch1 = 'd';
    ch2 = 'm';
    break;
  case 'm':
    ch1 = 'm';
    ch2 = 'm';
    break;
  default:
    return 0;
  }
  if (degrees < 0.0) {
    sign = "-";
    degrees = -degrees;
  }
  minutes = (degrees - ((int)degrees)) * 60;
  if (minutes < 0)
    minutes = 0.0;
  seconds = (minutes - ((int)minutes)) * 60;
  if (seconds < 0)
    seconds = 0.0;
  if (prec == -1) {
    if (type == 'h')
      prec = 4;
    else
      prec = 3;
  }
  if (prec == -2) {
    if (type == 'm') {
      if (seconds < 10.0)
        sprintf(buff, "%s%d%c0%g", sign, (int)(minutes + degrees * 60), ch2,
                seconds);
      else
        sprintf(buff, "%s%d%c%g", sign, (int)(minutes + degrees * 60), ch2,
                seconds);
    } else if (seconds < 10.0)
      sprintf(buff, "%s%d%c0%2d%c0%g", sign, (int)(degrees), ch1,
              (int)(minutes), ch2, seconds);
    else
      sprintf(buff, "%s%d%c%2d%c%g", sign, (int)(degrees), ch1, (int)(minutes),
              ch2, seconds);
  } else {
    double p = pow(10.0, (double)prec);
    int m = minutes;
    int d = degrees;
    if ((((int)(seconds * p + .5)) / p) >= 60) {
      seconds = 0.0;
      m++;
      if (m >= 60) {
        m = 0;
        d++;
      }
    }
    if ((((int)(seconds * p + .5)) / p) < 10.0)
      sprintf(fmt, "%%s%%d%c%%2.2d%c0%%.%df", ch1, ch2, prec);
    else
      sprintf(fmt, "%%s%%d%c%%2.2d%c%%.%df", ch1, ch2, prec);
    sprintf(buff, fmt, sign, d, m, seconds);
  }
  return buff;
}


x86 assembly (clang, -O0):
<SAOconvert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
mov    %edx,-0x20(%rbp)
lea    0xeea(%rip),%rax
mov    %rax,-0x48(%rbp)
movsd  -0x18(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x4c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x7c(%rbp)
sub    $0x20,%eax
je     12d3 <SAOconvert+0x1b3>
jmp    1167 <SAOconvert+0x47>
mov    -0x7c(%rbp),%eax
sub    $0x3a,%eax
je     12c6 <SAOconvert+0x1a6>
jmp    1178 <SAOconvert+0x58>
mov    -0x7c(%rbp),%eax
sub    $0x62,%eax
je     11de <SAOconvert+0xbe>
jmp    1189 <SAOconvert+0x69>
mov    -0x7c(%rbp),%eax
sub    $0x64,%eax
je     12ed <SAOconvert+0x1cd>
jmp    119a <SAOconvert+0x7a>
mov    -0x7c(%rbp),%eax
sub    $0x68,%eax
je     12e0 <SAOconvert+0x1c0>
jmp    11ab <SAOconvert+0x8b>
mov    -0x7c(%rbp),%eax
sub    $0x6d,%eax
je     12fa <SAOconvert+0x1da>
jmp    11bc <SAOconvert+0x9c>
mov    -0x7c(%rbp),%eax
sub    $0x6f,%eax
je     127e <SAOconvert+0x15e>
jmp    11cd <SAOconvert+0xad>
mov    -0x7c(%rbp),%eax
sub    $0x78,%eax
je     12a2 <SAOconvert+0x182>
jmp    1307 <SAOconvert+0x1e7>
cvttsd2si -0x18(%rbp),%eax
mov    %eax,-0x5c(%rbp)
movl   $0x2,-0x64(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x30,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x62,0x1(%rax)
movl   $0x8000,-0x60(%rbp)
cmpl   $0x0,-0x60(%rbp)
je     1265 <SAOconvert+0x145>
mov    -0x5c(%rbp),%eax
and    -0x60(%rbp),%eax
cmp    $0x0,%eax
jne    1226 <SAOconvert+0x106>
cmpl   $0x2,-0x64(%rbp)
jle    1252 <SAOconvert+0x132>
mov    -0x5c(%rbp),%edx
and    -0x60(%rbp),%edx
mov    $0x30,%eax
mov    $0x31,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x64(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1257 <SAOconvert+0x137>
mov    -0x60(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x60(%rbp)
jmp    1203 <SAOconvert+0xe3>
mov    -0x10(%rbp),%rax
movslq -0x64(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1678 <SAOconvert+0x558>
mov    -0x10(%rbp),%rdi
cvttsd2si -0x18(%rbp),%edx
lea    0xd92(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1678 <SAOconvert+0x558>
mov    -0x10(%rbp),%rdi
cvttsd2si -0x18(%rbp),%edx
lea    0xd73(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1678 <SAOconvert+0x558>
movb   $0x3a,-0x55(%rbp)
movb   $0x3a,-0x56(%rbp)
jmp    1314 <SAOconvert+0x1f4>
movb   $0x20,-0x55(%rbp)
movb   $0x20,-0x56(%rbp)
jmp    1314 <SAOconvert+0x1f4>
movb   $0x68,-0x55(%rbp)
movb   $0x6d,-0x56(%rbp)
jmp    1314 <SAOconvert+0x1f4>
movb   $0x64,-0x55(%rbp)
movb   $0x6d,-0x56(%rbp)
jmp    1314 <SAOconvert+0x1f4>
movb   $0x6d,-0x55(%rbp)
movb   $0x6d,-0x56(%rbp)
jmp    1314 <SAOconvert+0x1f4>
movq   $0x0,-0x8(%rbp)
jmp    1678 <SAOconvert+0x558>
movss  -0x4c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    134c <SAOconvert+0x22c>
lea    0xcf9(%rip),%rax
mov    %rax,-0x48(%rbp)
movss  -0x4c(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x4c(%rbp)
movss  -0x4c(%rbp),%xmm0
cvttss2si -0x4c(%rbp),%eax
cvtsi2ss %eax,%xmm1
subss  %xmm1,%xmm0
movss  0xc9a(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  %xmm0,-0x50(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0x50(%rbp),%xmm0
jbe    1384 <SAOconvert+0x264>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x50(%rbp)
movss  -0x50(%rbp),%xmm0
cvttss2si -0x50(%rbp),%eax
cvtsi2ss %eax,%xmm1
subss  %xmm1,%xmm0
movss  0xc62(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  %xmm0,-0x54(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0x54(%rbp),%xmm0
jbe    13bc <SAOconvert+0x29c>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x54(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    13e8 <SAOconvert+0x2c8>
cmpl   $0x68,-0x1c(%rbp)
jne    13dc <SAOconvert+0x2bc>
movl   $0x4,-0x20(%rbp)
jmp    13e3 <SAOconvert+0x2c3>
movl   $0x3,-0x20(%rbp)
jmp    13e8 <SAOconvert+0x2c8>
cmpl   $0xfffffffe,-0x20(%rbp)
jne    153b <SAOconvert+0x41b>
cmpl   $0x6d,-0x1c(%rbp)
jne    14a5 <SAOconvert+0x385>
movss  -0x54(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xc0b(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    145e <SAOconvert+0x33e>
mov    -0x10(%rbp),%rdi
mov    -0x48(%rbp),%rdx
movss  -0x50(%rbp),%xmm1
movss  -0x4c(%rbp),%xmm0
movss  0xbcf(%rip),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
cvttss2si %xmm0,%ecx
movsbl -0x56(%rbp),%r8d
movss  -0x54(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xbda(%rip),%rsi
mov    $0x1,%al
call   1040 <sprintf@plt>
jmp    14a0 <SAOconvert+0x380>
mov    -0x10(%rbp),%rdi
mov    -0x48(%rbp),%rdx
movss  -0x50(%rbp),%xmm1
movss  -0x4c(%rbp),%xmm0
movss  0xb88(%rip),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
cvttss2si %xmm0,%ecx
movsbl -0x56(%rbp),%r8d
movss  -0x54(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xb9d(%rip),%rsi
mov    $0x1,%al
call   1040 <sprintf@plt>
jmp    1536 <SAOconvert+0x416>
movss  -0x54(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xb62(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    14fb <SAOconvert+0x3db>
mov    -0x10(%rbp),%rdi
mov    -0x48(%rbp),%rdx
cvttss2si -0x4c(%rbp),%ecx
movsbl -0x55(%rbp),%r8d
cvttss2si -0x50(%rbp),%r9d
movsbl -0x56(%rbp),%eax
movss  -0x54(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xb53(%rip),%rsi
mov    %eax,(%rsp)
mov    $0x1,%al
call   1040 <sprintf@plt>
jmp    1531 <SAOconvert+0x411>
mov    -0x10(%rbp),%rdi
mov    -0x48(%rbp),%rdx
cvttss2si -0x4c(%rbp),%ecx
movsbl -0x55(%rbp),%r8d
cvttss2si -0x50(%rbp),%r9d
movsbl -0x56(%rbp),%eax
movss  -0x54(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xb28(%rip),%rsi
mov    %eax,(%rsp)
mov    $0x1,%al
call   1040 <sprintf@plt>
jmp    1536 <SAOconvert+0x416>
jmp    1670 <SAOconvert+0x550>
cvtsi2sdl -0x20(%rbp),%xmm1
movsd  0xad0(%rip),%xmm0
call   1030 <pow@plt>
movsd  %xmm0,-0x70(%rbp)
cvttss2si -0x50(%rbp),%eax
mov    %eax,-0x74(%rbp)
cvttss2si -0x4c(%rbp),%eax
mov    %eax,-0x78(%rbp)
movss  -0x54(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  -0x70(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xa94(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
cvtsi2sd %eax,%xmm0
divsd  -0x70(%rbp),%xmm0
movsd  0xa73(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     15cf <SAOconvert+0x4af>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x54(%rbp)
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
cmpl   $0x3c,-0x74(%rbp)
jl     15ca <SAOconvert+0x4aa>
movl   $0x0,-0x74(%rbp)
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    15cf <SAOconvert+0x4af>
movss  -0x54(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  -0x70(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xa27(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
cvtsi2sd %eax,%xmm1
divsd  -0x70(%rbp),%xmm1
movsd  0xa16(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    162f <SAOconvert+0x50f>
lea    -0x40(%rbp),%rdi
movsbl -0x55(%rbp),%edx
movsbl -0x56(%rbp),%ecx
mov    -0x20(%rbp),%r8d
lea    0xa3a(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    164d <SAOconvert+0x52d>
lea    -0x40(%rbp),%rdi
movsbl -0x55(%rbp),%edx
movsbl -0x56(%rbp),%ecx
mov    -0x20(%rbp),%r8d
lea    0xa2f(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    -0x48(%rbp),%rdx
mov    -0x78(%rbp),%ecx
mov    -0x74(%rbp),%r8d
movss  -0x54(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    $0x1,%al
call   1040 <sprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SAOconvert>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
xor    %eax,%eax
lea    -0x3a(%rbx),%ecx
cmp    $0x3e,%ecx
ja     1158 <SAOconvert+0x38>
lea    0xeec(%rip),%rsi
movslq (%rsi,%rcx,4),%rcx
add    %rsi,%rcx
mov    %ebx,%r8d
jmp    *%rcx
mov    $0x6d,%r8d
jmp    1164 <SAOconvert+0x44>
mov    %ebx,%r8d
cmp    $0x20,%ebx
jne    1400 <SAOconvert+0x2e0>
cvtsd2ss %xmm0,%xmm1
xorps  %xmm5,%xmm5
ucomiss %xmm1,%xmm5
lea    0xfc1(%rip),%rax
lea    0xfbb(%rip),%rbp
cmova  %rax,%rbp
jbe    1189 <SAOconvert+0x69>
xorps  0xe77(%rip),%xmm1
cvttss2si %xmm1,%r13d
cvttps2dq %xmm1,%xmm0
cvtdq2ps %xmm0,%xmm0
movaps %xmm1,%xmm3
subss  %xmm0,%xmm3
movss  0xe6c(%rip),%xmm0
mulss  %xmm0,%xmm3
xorps  %xmm2,%xmm2
maxss  %xmm3,%xmm2
cvttss2si %xmm2,%r15d
cvttps2dq %xmm2,%xmm3
cvtdq2ps %xmm3,%xmm3
movaps %xmm2,%xmm4
subss  %xmm3,%xmm4
mulss  %xmm0,%xmm4
maxss  %xmm4,%xmm5
xor    %r12d,%r12d
cmp    $0x68,%ebx
sete   %r12b
add    $0x3,%r12d
cmp    $0xffffffff,%edx
cmovne %edx,%r12d
cmp    $0xfffffffe,%r12d
jne    1222 <SAOconvert+0x102>
xorps  %xmm0,%xmm0
cvtss2sd %xmm5,%xmm0
cmp    $0x6d,%ebx
jne    1278 <SAOconvert+0x158>
movss  0xe17(%rip),%xmm3
ucomiss %xmm5,%xmm3
mulss  0xe08(%rip),%xmm1
addss  %xmm2,%xmm1
cvttss2si %xmm1,%ecx
jbe    13c6 <SAOconvert+0x2a6>
lea    0xf1b(%rip),%rsi
jmp    13cd <SAOconvert+0x2ad>
mov    %r8d,0x10(%rsp)
xorps  %xmm1,%xmm1
cvtsi2sd %r12d,%xmm1
movsd  0xde1(%rip),%xmm0
movss  %xmm5,0x1c(%rsp)
call   1030 <pow@plt>
movss  0x1c(%rsp),%xmm2
xorps  %xmm1,%xmm1
cvtss2sd %xmm2,%xmm1
mulsd  %xmm0,%xmm1
addsd  0xdc5(%rip),%xmm1
cvttpd2dq %xmm1,%xmm1
cvtdq2pd %xmm1,%xmm1
divsd  %xmm0,%xmm1
ucomisd 0xdb9(%rip),%xmm1
jae    1299 <SAOconvert+0x179>
mov    %r13d,0xc(%rsp)
jmp    12b9 <SAOconvert+0x199>
movss  0xd94(%rip),%xmm1
ucomiss %xmm5,%xmm1
jbe    13dc <SAOconvert+0x2bc>
mov    %r8d,(%rsp)
lea    0xeb7(%rip),%rsi
jmp    13e7 <SAOconvert+0x2c7>
lea    0x1(%r15),%eax
xor    %ecx,%ecx
xor    %edx,%edx
cmp    $0x3b,%r15d
setge  %dl
cmovl  %eax,%ecx
add    %edx,%r13d
mov    %r13d,0xc(%rsp)
xorps  %xmm2,%xmm2
mov    %ecx,%r15d
mov    0x10(%rsp),%ecx
xorps  %xmm1,%xmm1
cvtss2sd %xmm2,%xmm1
movsd  %xmm1,0x10(%rsp)
mulsd  %xmm0,%xmm1
addsd  0xd4a(%rip),%xmm1
cvttpd2dq %xmm1,%xmm1
cvtdq2pd %xmm1,%xmm1
divsd  %xmm0,%xmm1
movsd  0xd2e(%rip),%xmm0
ucomisd %xmm1,%xmm0
lea    0xe74(%rip),%rax
lea    0xe85(%rip),%rsi
cmova  %rax,%rsi
lea    0x20(%rsp),%r13
mov    %r13,%rdi
mov    %ebx,%edx
mov    %r12d,%r8d
xor    %eax,%eax
call   1040 <sprintf@plt>
mov    %r14,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
mov    0xc(%rsp),%ecx
mov    %r15d,%r8d
movsd  0x10(%rsp),%xmm0
jmp    13d3 <SAOconvert+0x2b3>
cvttsd2si %xmm0,%eax
movw   $0x6230,(%r14)
mov    $0x8000,%edx
mov    $0x2,%ecx
jmp    136e <SAOconvert+0x24e>
cs nopw 0x0(%rax,%rax,1)
nop
test   %eax,%esi
setne  %bl
or     $0x30,%bl
movslq %ecx,%rsi
mov    %bl,(%r14,%rsi,1)
add    $0x1,%ecx
mov    %edx,%esi
shr    $0x2,%esi
cmp    $0x3,%edx
mov    %esi,%edx
jbe    13bc <SAOconvert+0x29c>
test   %eax,%edx
jne    1377 <SAOconvert+0x257>
cmp    $0x3,%ecx
jl     1389 <SAOconvert+0x269>
test   %eax,%edx
setne  %bl
or     $0x30,%bl
movslq %ecx,%rsi
mov    %bl,(%r14,%rsi,1)
add    $0x1,%ecx
mov    %edx,%esi
shr    %esi
test   %eax,%esi
jne    1350 <SAOconvert+0x230>
cmp    $0x3,%ecx
jl     1362 <SAOconvert+0x242>
jmp    1350 <SAOconvert+0x230>
cvttsd2si %xmm0,%edx
lea    0xd89(%rip),%rsi
jmp    13b0 <SAOconvert+0x290>
cvttsd2si %xmm0,%edx
lea    0xd81(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <sprintf@plt>
jmp    13fd <SAOconvert+0x2dd>
movslq %ecx,%rax
movb   $0x0,(%r14,%rax,1)
jmp    13fd <SAOconvert+0x2dd>
lea    0xd75(%rip),%rsi
mov    %r14,%rdi
mov    %rbp,%rdx
mov    $0x1,%al
call   1040 <sprintf@plt>
jmp    13fd <SAOconvert+0x2dd>
mov    %r8d,(%rsp)
lea    0xd74(%rip),%rsi
mov    %r14,%rdi
mov    %rbp,%rdx
mov    %r13d,%ecx
mov    %ebx,%r8d
mov    %r15d,%r9d
mov    $0x1,%al
call   1040 <sprintf@plt>
mov    %r14,%rax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [5 x i8] c"0o%o\00"
@.str.2 = [5 x i8] c"0x%x\00"
@.str.3 = [2 x i8] c"-\00"
@.str.4 = [10 x i8] c"%s%d%c0%g\00"
@.str.5 = [9 x i8] c"%s%d%c%g\00"
@.str.6 = [16 x i8] c"%s%d%c0%2d%c0%g\00"
@.str.7 = [14 x i8] c"%s%d%c%2d%c%g\00"
@.str.8 = [24 x i8] c"%%s%%d%c%%2.2d%c0%%.%df\00"
@.str.9 = [23 x i8] c"%%s%%d%c%%2.2d%c%%.%df\00"
define i8* @SAOconvert(i8* %0, double %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
%10 = alloca [32 x i8]
%11 = alloca i8*
%12 = alloca float
%13 = alloca float
%14 = alloca float
%15 = alloca i8
%16 = alloca i8
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca double
%21 = alloca i32
%22 = alloca i32
store i8* %0, i8** %6
store double %1, double* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %11
%23 = load double, double* %7
%24 = fptrunc double %23 to float
store float %24, float* %12
%25 = load i32, i32* %8
switch i32 %25, label %85 [
i32 98, label %26
i32 111, label %68
i32 120, label %74
i32 58, label %80
i32 32, label %81
i32 104, label %82
i32 100, label %83
i32 109, label %84
]
26: ; preds = %4
%27 = load double, double* %7
%28 = fptosi double %27 to i32
store i32 %28, i32* %17
store i32 2, i32* %19
%29 = load i8*, i8** %6
%30 = getelementptr inbounds i8, i8* %29, i64 0
store i8 48, i8* %30
%31 = load i8*, i8** %6
%32 = getelementptr inbounds i8, i8* %31, i64 1
store i8 98, i8* %32
store i32 32768, i32* %18
br label %33
33: ; preds = %59, %26
%34 = load i32, i32* %18
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %62
36: ; preds = %33
%37 = load i32, i32* %17
%38 = load i32, i32* %18
%39 = and i32 %37, %38
%40 = icmp ne i32 %39, 0
br i1 %40, label %44, label %41
41: ; preds = %36
%42 = load i32, i32* %19
%43 = icmp sgt i32 %42, 2
br i1 %43, label %44, label %58
44: ; preds = %41, %36
%45 = load i32, i32* %17
%46 = load i32, i32* %18
%47 = and i32 %45, %46
%48 = icmp ne i32 %47, 0
%49 = zext i1 %48 to i64
%50 = select i1 %48, i32 49, i32 48
%51 = trunc i32 %50 to i8
%52 = load i8*, i8** %6
%53 = load i32, i32* %19
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
store i8 %51, i8* %55
%56 = load i32, i32* %19
%57 = add nsw i32 %56, 1
store i32 %57, i32* %19
br label %58
58: ; preds = %44, %41
br label %59
59: ; preds = %58
%60 = load i32, i32* %18
%61 = udiv i32 %60, 2
store i32 %61, i32* %18
br label %33
62: ; preds = %33
%63 = load i8*, i8** %6
%64 = load i32, i32* %19
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %63, i64 %65
store i8 0, i8* %66
%67 = load i8*, i8** %6
store i8* %67, i8** %5
br label %254
68: ; preds = %4
%69 = load i8*, i8** %6
%70 = load double, double* %7
%71 = fptosi double %70 to i32
%72 = call i32 (i8*, i8*, ...) @sprintf(i8* %69, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %71)
%73 = load i8*, i8** %6
store i8* %73, i8** %5
br label %254
74: ; preds = %4
%75 = load i8*, i8** %6
%76 = load double, double* %7
%77 = fptosi double %76 to i32
%78 = call i32 (i8*, i8*, ...) @sprintf(i8* %75, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %77)
%79 = load i8*, i8** %6
store i8* %79, i8** %5
br label %254
80: ; preds = %4
store i8 58, i8* %15
store i8 58, i8* %16
br label %86
81: ; preds = %4
store i8 32, i8* %15
store i8 32, i8* %16
br label %86
82: ; preds = %4
store i8 104, i8* %15
store i8 109, i8* %16
br label %86
83: ; preds = %4
store i8 100, i8* %15
store i8 109, i8* %16
br label %86
84: ; preds = %4
store i8 109, i8* %15
store i8 109, i8* %16
br label %86
85: ; preds = %4
store i8* null, i8** %5
br label %254
86: ; preds = %84, %83, %82, %81, %80
%87 = load float, float* %12
%88 = fpext float %87 to double
%89 = fcmp olt double %88, 0.000000e+00
br i1 %89, label %90, label %93
90: ; preds = %86
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8** %11
%91 = load float, float* %12
%92 = fneg float %91
store float %92, float* %12
br label %93
93: ; preds = %90, %86
%94 = load float, float* %12
%95 = load float, float* %12
%96 = fptosi float %95 to i32
%97 = sitofp i32 %96 to float
%98 = fsub float %94, %97
%99 = fmul float %98, 6.000000e+01
store float %99, float* %13
%100 = load float, float* %13
%101 = fcmp olt float %100, 0.000000e+00
br i1 %101, label %102, label %103
102: ; preds = %93
store float 0.000000e+00, float* %13
br label %103
103: ; preds = %102, %93
%104 = load float, float* %13
%105 = load float, float* %13
%106 = fptosi float %105 to i32
%107 = sitofp i32 %106 to float
%108 = fsub float %104, %107
%109 = fmul float %108, 6.000000e+01
store float %109, float* %14
%110 = load float, float* %14
%111 = fcmp olt float %110, 0.000000e+00
br i1 %111, label %112, label %113
112: ; preds = %103
store float 0.000000e+00, float* %14
br label %113
113: ; preds = %112, %103
%114 = load i32, i32* %9
%115 = icmp eq i32 %114, -1
br i1 %115, label %116, label %122
116: ; preds = %113
%117 = load i32, i32* %8
%118 = icmp eq i32 %117, 104
br i1 %118, label %119, label %120
119: ; preds = %116
store i32 4, i32* %9
br label %121
120: ; preds = %116
store i32 3, i32* %9
br label %121
121: ; preds = %120, %119
br label %122
122: ; preds = %121, %113
%123 = load i32, i32* %9
%124 = icmp eq i32 %123, -2
br i1 %124, label %125, label %191
125: ; preds = %122
%126 = load i32, i32* %8
%127 = icmp eq i32 %126, 109
br i1 %127, label %128, label %157
128: ; preds = %125
%129 = load float, float* %14
%130 = fpext float %129 to double
%131 = fcmp olt double %130, 1.000000e+01
br i1 %131, label %132, label %144
132: ; preds = %128
%133 = load i8*, i8** %6
%134 = load i8*, i8** %11
%135 = load float, float* %13
%136 = load float, float* %12
%137 = call float @llvm.fmuladd.f32(float %136, float 6.000000e+01, float %135)
%138 = fptosi float %137 to i32
%139 = load i8, i8* %16
%140 = sext i8 %139 to i32
%141 = load float, float* %14
%142 = fpext float %141 to double
%143 = call i32 (i8*, i8*, ...) @sprintf(i8* %133, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %134, i32 %138, i32 %140, double %142)
br label %156
144: ; preds = %128
%145 = load i8*, i8** %6
%146 = load i8*, i8** %11
%147 = load float, float* %13
%148 = load float, float* %12
%149 = call float @llvm.fmuladd.f32(float %148, float 6.000000e+01, float %147)
%150 = fptosi float %149 to i32
%151 = load i8, i8* %16
%152 = sext i8 %151 to i32
%153 = load float, float* %14
%154 = fpext float %153 to double
%155 = call i32 (i8*, i8*, ...) @sprintf(i8* %145, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %146, i32 %150, i32 %152, double %154)
br label %156
156: ; preds = %144, %132
br label %190
157: ; preds = %125
%158 = load float, float* %14
%159 = fpext float %158 to double
%160 = fcmp olt double %159, 1.000000e+01
br i1 %160, label %161, label %175
161: ; preds = %157
%162 = load i8*, i8** %6
%163 = load i8*, i8** %11
%164 = load float, float* %12
%165 = fptosi float %164 to i32
%166 = load i8, i8* %15
%167 = sext i8 %166 to i32
%168 = load float, float* %13
%169 = fptosi float %168 to i32
%170 = load i8, i8* %16
%171 = sext i8 %170 to i32
%172 = load float, float* %14
%173 = fpext float %172 to double
%174 = call i32 (i8*, i8*, ...) @sprintf(i8* %162, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i8* %163, i32 %165, i32 %167, i32 %169, i32 %171, double %173)
br label %189
175: ; preds = %157
%176 = load i8*, i8** %6
%177 = load i8*, i8** %11
%178 = load float, float* %12
%179 = fptosi float %178 to i32
%180 = load i8, i8* %15
%181 = sext i8 %180 to i32
%182 = load float, float* %13
%183 = fptosi float %182 to i32
%184 = load i8, i8* %16
%185 = sext i8 %184 to i32
%186 = load float, float* %14
%187 = fpext float %186 to double
%188 = call i32 (i8*, i8*, ...) @sprintf(i8* %176, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* %177, i32 %179, i32 %181, i32 %183, i32 %185, double %187)
br label %189
189: ; preds = %175, %161
br label %190
190: ; preds = %189, %156
br label %252
191: ; preds = %122
%192 = load i32, i32* %9
%193 = sitofp i32 %192 to double
%194 = call double @pow(double 1.000000e+01, double %193)
store double %194, double* %20
%195 = load float, float* %13
%196 = fptosi float %195 to i32
store i32 %196, i32* %21
%197 = load float, float* %12
%198 = fptosi float %197 to i32
store i32 %198, i32* %22
%199 = load float, float* %14
%200 = fpext float %199 to double
%201 = load double, double* %20
%202 = call double @llvm.fmuladd.f64(double %200, double %201, double 5.000000e-01)
%203 = fptosi double %202 to i32
%204 = sitofp i32 %203 to double
%205 = load double, double* %20
%206 = fdiv double %204, %205
%207 = fcmp oge double %206, 6.000000e+01
br i1 %207, label %208, label %217
208: ; preds = %191
store float 0.000000e+00, float* %14
%209 = load i32, i32* %21
%210 = add nsw i32 %209, 1
store i32 %210, i32* %21
%211 = load i32, i32* %21
%212 = icmp sge i32 %211, 60
br i1 %212, label %213, label %216
213: ; preds = %208
store i32 0, i32* %21
%214 = load i32, i32* %22
%215 = add nsw i32 %214, 1
store i32 %215, i32* %22
br label %216
216: ; preds = %213, %208
br label %217
217: ; preds = %216, %191
%218 = load float, float* %14
%219 = fpext float %218 to double
%220 = load double, double* %20
%221 = call double @llvm.fmuladd.f64(double %219, double %220, double 5.000000e-01)
%222 = fptosi double %221 to i32
%223 = sitofp i32 %222 to double
%224 = load double, double* %20
%225 = fdiv double %223, %224
%226 = fcmp olt double %225, 1.000000e+01
br i1 %226, label %227, label %235
227: ; preds = %217
%228 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%229 = load i8, i8* %15
%230 = sext i8 %229 to i32
%231 = load i8, i8* %16
%232 = sext i8 %231 to i32
%233 = load i32, i32* %9
%234 = call i32 (i8*, i8*, ...) @sprintf(i8* %228, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i32 %230, i32 %232, i32 %233)
br label %243
235: ; preds = %217
%236 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%237 = load i8, i8* %15
%238 = sext i8 %237 to i32
%239 = load i8, i8* %16
%240 = sext i8 %239 to i32
%241 = load i32, i32* %9
%242 = call i32 (i8*, i8*, ...) @sprintf(i8* %236, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0), i32 %238, i32 %240, i32 %241)
br label %243
243: ; preds = %235, %227
%244 = load i8*, i8** %6
%245 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%246 = load i8*, i8** %11
%247 = load i32, i32* %22
%248 = load i32, i32* %21
%249 = load float, float* %14
%250 = fpext float %249 to double
%251 = call i32 (i8*, i8*, ...) @sprintf(i8* %244, i8* %245, i8* %246, i32 %247, i32 %248, double %250)
br label %252
252: ; preds = %243, %190
%253 = load i8*, i8** %6
store i8* %253, i8** %5
br label %254
254: ; preds = %252, %85, %74, %68, %62
%255 = load i8*, i8** %5
ret i8* %255
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [5 x i8] c"0o%o\00"
@.str.2 = [5 x i8] c"0x%x\00"
@.str.3 = [2 x i8] c"-\00"
@.str.4 = [10 x i8] c"%s%d%c0%g\00"
@.str.5 = [9 x i8] c"%s%d%c%g\00"
@.str.6 = [16 x i8] c"%s%d%c0%2d%c0%g\00"
@.str.7 = [14 x i8] c"%s%d%c%2d%c%g\00"
@.str.8 = [24 x i8] c"%%s%%d%c%%2.2d%c0%%.%df\00"
@.str.9 = [23 x i8] c"%%s%%d%c%%2.2d%c%%.%df\00"
define i8* @SAOconvert(i8* writeonly %0, double %1, i32 %2, i32 %3) {
%5 = alloca [32 x i8]
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%7 = fptrunc double %1 to float
switch i32 %2, label %117 [
i32 98, label %8
i32 111, label %42
i32 120, label %45
i32 58, label %50
i32 32, label %50
i32 104, label %48
i32 100, label %49
i32 109, label %50
]
8: ; preds = %4
%9 = fptosi double %1 to i32
store i8 48, i8* %0
%10 = getelementptr inbounds i8, i8* %0, i64 1
store i8 98, i8* %10
br label %11
11: ; preds = %35, %8
%12 = phi i32 [ 2, %8 ], [ %36, %35 ]
%13 = phi i32 [ 32768, %8 ], [ %37, %35 ]
%14 = and i32 %13, %9
%15 = icmp ne i32 %14, 0
%16 = icmp sgt i32 %12, 2
%17 = select i1 %15, i1 true, i1 %16
br i1 %17, label %18, label %23
18: ; preds = %11
%19 = select i1 %15, i8 49, i8 48
%20 = sext i32 %12 to i64
%21 = getelementptr inbounds i8, i8* %0, i64 %20
store i8 %19, i8* %21
%22 = add nsw i32 %12, 1
br label %23
23: ; preds = %18, %11
%24 = phi i32 [ %22, %18 ], [ %12, %11 ]
%25 = lshr i32 %13, 1
%26 = and i32 %25, %9
%27 = icmp ne i32 %26, 0
%28 = icmp sgt i32 %24, 2
%29 = select i1 %27, i1 true, i1 %28
br i1 %29, label %30, label %35
30: ; preds = %23
%31 = select i1 %27, i8 49, i8 48
%32 = sext i32 %24 to i64
%33 = getelementptr inbounds i8, i8* %0, i64 %32
store i8 %31, i8* %33
%34 = add nsw i32 %24, 1
br label %35
35: ; preds = %30, %23
%36 = phi i32 [ %34, %30 ], [ %24, %23 ]
%37 = lshr i32 %13, 2
%38 = icmp ult i32 %13, 4
br i1 %38, label %39, label %11
39: ; preds = %35
%40 = sext i32 %36 to i64
%41 = getelementptr inbounds i8, i8* %0, i64 %40
store i8 0, i8* %41
br label %117
42: ; preds = %4
%43 = fptosi double %1 to i32
%44 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %43)
br label %117
45: ; preds = %4
%46 = fptosi double %1 to i32
%47 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %46)
br label %117
48: ; preds = %4
br label %50
49: ; preds = %4
br label %50
50: ; preds = %4, %4, %4, %49, %48
%51 = phi i32 [ 109, %49 ], [ 109, %48 ], [ %2, %4 ], [ %2, %4 ], [ %2, %4 ]
%52 = fcmp olt float %7, 0.000000e+00
%53 = fneg float %7
%54 = select i1 %52, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0)
%55 = select i1 %52, float %53, float %7
%56 = fptosi float %55 to i32
%57 = sitofp i32 %56 to float
%58 = fsub float %55, %57
%59 = fmul float %58, 6.000000e+01
%60 = fcmp olt float %59, 0.000000e+00
%61 = select i1 %60, float 0.000000e+00, float %59
%62 = fptosi float %61 to i32
%63 = sitofp i32 %62 to float
%64 = fsub float %61, %63
%65 = fmul float %64, 6.000000e+01
%66 = fcmp olt float %65, 0.000000e+00
%67 = select i1 %66, float 0.000000e+00, float %65
%68 = icmp eq i32 %3, -1
%69 = icmp eq i32 %2, 104
%70 = select i1 %69, i32 4, i32 3
%71 = select i1 %68, i32 %70, i32 %3
%72 = icmp eq i32 %71, -2
br i1 %72, label %73, label %89
73: ; preds = %50
%74 = icmp eq i32 %2, 109
%75 = fpext float %67 to double
%76 = fcmp olt float %67, 1.000000e+01
br i1 %74, label %77, label %84
77: ; preds = %73
%78 = tail call float @llvm.fmuladd.f32(float %55, float 6.000000e+01, float %61)
%79 = fptosi float %78 to i32
br i1 %76, label %80, label %82
80: ; preds = %77
%81 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %54, i32 %79, i32 %51, double %75)
br label %117
82: ; preds = %77
%83 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %54, i32 %79, i32 %51, double %75)
br label %117
84: ; preds = %73
br i1 %76, label %85, label %87
85: ; preds = %84
%86 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i8* %54, i32 %56, i32 %2, i32 %62, i32 %51, double %75)
br label %117
87: ; preds = %84
%88 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* %54, i32 %56, i32 %2, i32 %62, i32 %51, double %75)
br label %117
89: ; preds = %50
%90 = sitofp i32 %71 to double
%91 = tail call double @pow(double 1.000000e+01, double %90)
%92 = fpext float %67 to double
%93 = tail call double @llvm.fmuladd.f64(double %92, double %91, double 5.000000e-01)
%94 = fptosi double %93 to i32
%95 = sitofp i32 %94 to double
%96 = fdiv double %95, %91
%97 = fcmp ult double %96, 6.000000e+01
br i1 %97, label %104, label %98
98: ; preds = %89
%99 = add nsw i32 %62, 1
%100 = icmp sgt i32 %62, 58
%101 = select i1 %100, i32 0, i32 %99
%102 = zext i1 %100 to i32
%103 = add nsw i32 %102, %56
br label %104
104: ; preds = %98, %89
%105 = phi float [ %67, %89 ], [ 0.000000e+00, %98 ]
%106 = phi i32 [ %62, %89 ], [ %101, %98 ]
%107 = phi i32 [ %56, %89 ], [ %103, %98 ]
%108 = fpext float %105 to double
%109 = tail call double @llvm.fmuladd.f64(double %108, double %91, double 5.000000e-01)
%110 = fptosi double %109 to i32
%111 = sitofp i32 %110 to double
%112 = fdiv double %111, %91
%113 = fcmp olt double %112, 1.000000e+01
%114 = select i1 %113, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0)
%115 = call i32 (i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) %114, i32 %2, i32 %51, i32 %71)
%116 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* %6, i8* %54, i32 %107, i32 %106, double %108)
br label %117
117: ; preds = %104, %85, %87, %80, %82, %4, %45, %42, %39
%118 = phi i8* [ %0, %45 ], [ %0, %42 ], [ %0, %39 ], [ null, %4 ], [ %0, %82 ], [ %0, %80 ], [ %0, %87 ], [ %0, %85 ], [ %0, %104 ]
ret i8* %118
}