void dtos(deci, string, prec) double *deci;
char *string;
int prec;
{
  char sign;
  int h, m;
  double dd, s, md, fabs();
  sign = '+';
  if (*deci < 0.0)
    sign = '-';
  dd = fabs(*deci) + 0.0000000001;
  h = (int)dd;
  md = (dd - h) * 60.;
  m = (int)md;
  s = (md - m) * 60.;
  if (prec == 3)
    sprintf(string, "%c%02d %02d %06.3f", sign, h, m, s);
  else if (prec == 1)
    sprintf(string, "%c%02d %02d %04.1f", sign, h, m, s);
  else if (prec == 0)
    sprintf(string, "%c%02d %02d %02.0f", sign, h, m, s);
  else if (prec == -1)
    sprintf(string, "%c%02d %04.1f", sign, h, md);
  else
    sprintf(string, "%c%02d %02d %05.2f", sign, h, m, s);
  return;
}


x86 assembly (clang, -O0):
<dtos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movb   $0x2b,-0x15(%rbp)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
ucomisd (%rax),%xmm0
jbe    113c <dtos+0x2c>
movb   $0x2d,-0x15(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movaps 0xec5(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xeb1(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
cvttsd2si -0x28(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  0xe82(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
cvttsd2si -0x38(%rbp),%eax
mov    %eax,-0x20(%rbp)
movsd  -0x38(%rbp),%xmm0
cvtsi2sdl -0x20(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  0xe5b(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
cmpl   $0x3,-0x14(%rbp)
jne    11df <dtos+0xcf>
mov    -0x10(%rbp),%rdi
movsbl -0x15(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
movsd  -0x30(%rbp),%xmm0
lea    0xe4d(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    129f <dtos+0x18f>
cmpl   $0x1,-0x14(%rbp)
jne    1210 <dtos+0x100>
mov    -0x10(%rbp),%rdi
movsbl -0x15(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
movsd  -0x30(%rbp),%xmm0
lea    0xe2f(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    129a <dtos+0x18a>
cmpl   $0x0,-0x14(%rbp)
jne    1241 <dtos+0x131>
mov    -0x10(%rbp),%rdi
movsbl -0x15(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
movsd  -0x30(%rbp),%xmm0
lea    0xe11(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    1295 <dtos+0x185>
cmpl   $0xffffffff,-0x14(%rbp)
jne    126e <dtos+0x15e>
mov    -0x10(%rbp),%rdi
movsbl -0x15(%rbp),%edx
mov    -0x1c(%rbp),%ecx
movsd  -0x38(%rbp),%xmm0
lea    0xdf7(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    1290 <dtos+0x180>
mov    -0x10(%rbp),%rdi
movsbl -0x15(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
movsd  -0x30(%rbp),%xmm0
lea    0xdde(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    1295 <dtos+0x185>
jmp    129a <dtos+0x18a>
jmp    129f <dtos+0x18f>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dtos>:
mov    %edx,%eax
mov    %rsi,%r9
movsd  (%rdi),%xmm1
xorpd  %xmm0,%xmm0
xor    %edx,%edx
ucomisd %xmm1,%xmm0
seta   %dl
andpd  0xed2(%rip),%xmm1
addsd  0xeda(%rip),%xmm1
cvttsd2si %xmm1,%ecx
cvttpd2dq %xmm1,%xmm0
lea    0x2b(%rdx,%rdx,1),%edx
cvtdq2pd %xmm0,%xmm0
subsd  %xmm0,%xmm1
movsd  0xec6(%rip),%xmm2
mulsd  %xmm2,%xmm1
cvttsd2si %xmm1,%r8d
cvttpd2dq %xmm1,%xmm0
cvtdq2pd %xmm0,%xmm3
movapd %xmm1,%xmm0
subsd  %xmm3,%xmm0
mulsd  %xmm2,%xmm0
add    $0x1,%eax
cmp    $0x4,%eax
ja     11ae <dtos+0x9e>
lea    0xea2(%rip),%rsi
movslq (%rsi,%rax,4),%rax
add    %rsi,%rax
jmp    *%rax
lea    0xedf(%rip),%rsi
mov    %r9,%rdi
movapd %xmm1,%xmm0
mov    $0x1,%al
jmp    1030 <sprintf@plt>
lea    0xeb7(%rip),%rsi
jmp    11be <dtos+0xae>
lea    0xe9b(%rip),%rsi
jmp    11be <dtos+0xae>
lea    0xec6(%rip),%rsi
jmp    11be <dtos+0xae>
lea    0xe76(%rip),%rsi
mov    %r9,%rdi
mov    $0x1,%al
jmp    1030 <sprintf@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"%c%02d %02d %06.3f\00"
@.str.1 = [19 x i8] c"%c%02d %02d %04.1f\00"
@.str.2 = [19 x i8] c"%c%02d %02d %02.0f\00"
@.str.3 = [14 x i8] c"%c%02d %04.1f\00"
@.str.4 = [19 x i8] c"%c%02d %02d %05.2f\00"
define void @dtos(double* %0, i8* %1, i32 %2) {
%4 = alloca double*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = alloca double
store double* %0, double** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i8 43, i8* %7
%13 = load double*, double** %4
%14 = load double, double* %13
%15 = fcmp olt double %14, 0.000000e+00
br i1 %15, label %16, label %17
16: ; preds = %3
store i8 45, i8* %7
br label %17
17: ; preds = %16, %3
%18 = load double*, double** %4
%19 = load double, double* %18
%20 = call double @llvm.fabs.f64(double %19)
%21 = fadd double %20, 1.000000e-10
store double %21, double* %10
%22 = load double, double* %10
%23 = fptosi double %22 to i32
store i32 %23, i32* %8
%24 = load double, double* %10
%25 = load i32, i32* %8
%26 = sitofp i32 %25 to double
%27 = fsub double %24, %26
%28 = fmul double %27, 6.000000e+01
store double %28, double* %12
%29 = load double, double* %12
%30 = fptosi double %29 to i32
store i32 %30, i32* %9
%31 = load double, double* %12
%32 = load i32, i32* %9
%33 = sitofp i32 %32 to double
%34 = fsub double %31, %33
%35 = fmul double %34, 6.000000e+01
store double %35, double* %11
%36 = load i32, i32* %6
%37 = icmp eq i32 %36, 3
br i1 %37, label %38, label %46
38: ; preds = %17
%39 = load i8*, i8** %5
%40 = load i8, i8* %7
%41 = sext i8 %40 to i32
%42 = load i32, i32* %8
%43 = load i32, i32* %9
%44 = load double, double* %11
%45 = call i32 (i8*, i8*, ...) @sprintf(i8* %39, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %41, i32 %42, i32 %43, double %44)
br label %89
46: ; preds = %17
%47 = load i32, i32* %6
%48 = icmp eq i32 %47, 1
br i1 %48, label %49, label %57
49: ; preds = %46
%50 = load i8*, i8** %5
%51 = load i8, i8* %7
%52 = sext i8 %51 to i32
%53 = load i32, i32* %8
%54 = load i32, i32* %9
%55 = load double, double* %11
%56 = call i32 (i8*, i8*, ...) @sprintf(i8* %50, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %52, i32 %53, i32 %54, double %55)
br label %88
57: ; preds = %46
%58 = load i32, i32* %6
%59 = icmp eq i32 %58, 0
br i1 %59, label %60, label %68
60: ; preds = %57
%61 = load i8*, i8** %5
%62 = load i8, i8* %7
%63 = sext i8 %62 to i32
%64 = load i32, i32* %8
%65 = load i32, i32* %9
%66 = load double, double* %11
%67 = call i32 (i8*, i8*, ...) @sprintf(i8* %61, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %63, i32 %64, i32 %65, double %66)
br label %87
68: ; preds = %57
%69 = load i32, i32* %6
%70 = icmp eq i32 %69, -1
br i1 %70, label %71, label %78
71: ; preds = %68
%72 = load i8*, i8** %5
%73 = load i8, i8* %7
%74 = sext i8 %73 to i32
%75 = load i32, i32* %8
%76 = load double, double* %12
%77 = call i32 (i8*, i8*, ...) @sprintf(i8* %72, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %74, i32 %75, double %76)
br label %86
78: ; preds = %68
%79 = load i8*, i8** %5
%80 = load i8, i8* %7
%81 = sext i8 %80 to i32
%82 = load i32, i32* %8
%83 = load i32, i32* %9
%84 = load double, double* %11
%85 = call i32 (i8*, i8*, ...) @sprintf(i8* %79, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %81, i32 %82, i32 %83, double %84)
br label %86
86: ; preds = %78, %71
br label %87
87: ; preds = %86, %60
br label %88
88: ; preds = %87, %49
br label %89
89: ; preds = %88, %38
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"%c%02d %02d %06.3f\00"
@.str.1 = [19 x i8] c"%c%02d %02d %04.1f\00"
@.str.2 = [19 x i8] c"%c%02d %02d %02.0f\00"
@.str.3 = [14 x i8] c"%c%02d %04.1f\00"
@.str.4 = [19 x i8] c"%c%02d %02d %05.2f\00"
define void @dtos(double* nocapture %0, i8* nocapture writeonly %1, i32 %2) {
%4 = load double, double* %0
%5 = fcmp olt double %4, 0.000000e+00
%6 = select i1 %5, i32 45, i32 43
%7 = tail call double @llvm.fabs.f64(double %4)
%8 = fadd double %7, 1.000000e-10
%9 = fptosi double %8 to i32
%10 = sitofp i32 %9 to double
%11 = fsub double %8, %10
%12 = fmul double %11, 6.000000e+01
%13 = fptosi double %12 to i32
%14 = sitofp i32 %13 to double
%15 = fsub double %12, %14
%16 = fmul double %15, 6.000000e+01
switch i32 %2, label %25 [
i32 3, label %17
i32 1, label %19
i32 0, label %21
i32 -1, label %23
]
17: ; preds = %3
%18 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %9, i32 %13, double %16)
br label %27
19: ; preds = %3
%20 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %6, i32 %9, i32 %13, double %16)
br label %27
21: ; preds = %3
%22 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %6, i32 %9, i32 %13, double %16)
br label %27
23: ; preds = %3
%24 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %6, i32 %9, double %12)
br label %27
25: ; preds = %3
%26 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %6, i32 %9, i32 %13, double %16)
br label %27
27: ; preds = %19, %23, %25, %21, %17
ret void
}