#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 /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ reverse_string(char *);
void itoa_dw(double n, char s[]) {
  int i = 0;
  float sign = 0;
  unsigned long digit = 0;
  unsigned long limit = 0;
  double word2 = 0;
  printf("\n");
  printf("size of long = %d;\n", sizeof(long));
  printf("size of unsigned long = %d;\n", sizeof(unsigned long));
  printf("size of double = %d;\n", sizeof(double));
  printf("size of float = %d;\n", sizeof(float));
  printf("size of int = %d;\n", sizeof(int));
  printf("size of short int = %d;\n", sizeof(short int));
  printf("size of long int = %d;\n", sizeof(long int));
  printf("size of char = %d;\n", sizeof(char));
  if ((sign = n) < 0) {
    n = -n;
    digit = n;
    printf("n < 0 and digit = %u; n = %u\n", digit, n);
  } else {
    digit = n;
    printf("n > 0 and digit = %llu; n = %f;\n", digit, n);
  };
  i = 0;
  do {
    s[i++] = digit % 10 + '0';
  } while ((digit /= 10) > 0);
  if (sign < 0)
    s[i++] = '-';
  s[i] = '\0';
  reverse_string(s);
}


x86 assembly (clang, -O0):
<itoa_dw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
lea    0xf06(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb3(%rip),%rdi
mov    $0x8,%esi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb4(%rip),%rdi
mov    $0x8,%esi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xebe(%rip),%rdi
mov    $0x8,%esi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec1(%rip),%rdi
mov    $0x4,%esi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec3(%rip),%rdi
mov    $0x4,%esi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec3(%rip),%rdi
mov    $0x2,%esi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec9(%rip),%rdi
mov    $0x8,%esi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xece(%rip),%rdi
mov    $0x1,%esi
mov    $0x0,%al
call   1040 <printf@plt>
movsd  -0x8(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm1
movss  %xmm1,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomiss %xmm1,%xmm0
jbe    1278 <itoa_dw+0x158>
movaps 0xdf1(%rip),%xmm1
movsd  -0x8(%rbp),%xmm0
pxor   %xmm1,%xmm0
movlpd %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xdc6(%rip),%xmm2
movaps %xmm0,%xmm1
subsd  %xmm2,%xmm1
cvttsd2si %xmm1,%rcx
cvttsd2si %xmm0,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
and    %rdx,%rcx
or     %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
movsd  -0x8(%rbp),%xmm0
lea    0xe68(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    12be <itoa_dw+0x19e>
movsd  -0x8(%rbp),%xmm0
movsd  0xd7b(%rip),%xmm2
movaps %xmm0,%xmm1
subsd  %xmm2,%xmm1
cvttsd2si %xmm1,%rcx
cvttsd2si %xmm0,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
and    %rdx,%rcx
or     %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
movsd  -0x8(%rbp),%xmm0
lea    0xe3b(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x20(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
add    $0x30,%rdx
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x14(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
ja     12c5 <itoa_dw+0x1a5>
xorps  %xmm0,%xmm0
ucomiss -0x18(%rbp),%xmm0
jbe    132b <itoa_dw+0x20b>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
movslq %ecx,%rcx
movb   $0x2d,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1030 <reverse_string@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<itoa_dw>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r14
movaps %xmm0,0x10(%rsp)
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xed0(%rip),%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xed1(%rip),%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xedb(%rip),%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xede(%rip),%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xee0(%rip),%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xee0(%rip),%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xee6(%rip),%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeeb(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movaps 0x10(%rsp),%xmm0
cvtsd2ss %xmm0,%xmm2
xorps  %xmm1,%xmm1
movss  %xmm2,0xc(%rsp)
ucomiss %xmm2,%xmm1
jbe    122c <itoa_dw+0xfc>
xorpd  0xe10(%rip),%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,%rcx
sar    $0x3f,%rcx
movapd %xmm0,%xmm1
subsd  0xde8(%rip),%xmm1
cvttsd2si %xmm1,%rbx
and    %rcx,%rbx
or     %rax,%rbx
lea    0xeaa(%rip),%rdi
jmp    1256 <itoa_dw+0x126>
cvttsd2si %xmm0,%rax
mov    %rax,%rcx
sar    $0x3f,%rcx
movapd %xmm0,%xmm1
subsd  0xdbc(%rip),%xmm1
cvttsd2si %xmm1,%rbx
and    %rcx,%rbx
or     %rax,%rbx
lea    0xe9c(%rip),%rdi
mov    %rbx,%rsi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %ecx,%ecx
movabs $0xcccccccccccccccd,%rsi
cc cc cc
nopl   0x0(%rax)
mov    %rbx,%rax
mul    %rsi
shr    $0x3,%rdx
lea    (%rdx,%rdx,1),%eax
lea    (%rax,%rax,4),%eax
mov    %ebx,%edi
sub    %eax,%edi
or     $0x30,%dil
mov    %dil,(%r14,%rcx,1)
add    $0x1,%rcx
cmp    $0x9,%rbx
mov    %rdx,%rbx
ja     1270 <itoa_dw+0x140>
xorps  %xmm0,%xmm0
ucomiss 0xc(%rsp),%xmm0
jbe    12ae <itoa_dw+0x17e>
mov    %ecx,%eax
add    $0x1,%rcx
movb   $0x2d,(%r14,%rax,1)
movslq %ecx,%rax
movb   $0x0,(%r14,%rax,1)
mov    %r14,%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r14
jmp    1040 <reverse_string@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [20 x i8] c"size of long = %d;\0A\00"
@.str.2 = [29 x i8] c"size of unsigned long = %d;\0A\00"
@.str.3 = [22 x i8] c"size of double = %d;\0A\00"
@.str.4 = [21 x i8] c"size of float = %d;\0A\00"
@.str.5 = [19 x i8] c"size of int = %d;\0A\00"
@.str.6 = [25 x i8] c"size of short int = %d;\0A\00"
@.str.7 = [24 x i8] c"size of long int = %d;\0A\00"
@.str.8 = [20 x i8] c"size of char = %d;\0A\00"
@.str.9 = [30 x i8] c"n < 0 and digit = %u; n = %u\0A\00"
@.str.10 = [33 x i8] c"n > 0 and digit = %llu; n = %f;\0A\00"
define void @itoa_dw(double %0, i8* %1) {
%3 = alloca double
%4 = alloca i8*
%5 = alloca i32
%6 = alloca float
%7 = alloca i64
%8 = alloca i64
%9 = alloca double
store double %0, double* %3
store i8* %1, i8** %4
store i32 0, i32* %5
store float 0.000000e+00, float* %6
store i64 0, i64* %7
store i64 0, i64* %8
store double 0.000000e+00, double* %9
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i64 8)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i64 8)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i64 8)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i64 4)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i64 4)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i64 2)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i64 8)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i64 1)
%19 = load double, double* %3
%20 = fptrunc double %19 to float
store float %20, float* %6
%21 = fcmp olt float %20, 0.000000e+00
br i1 %21, label %22, label %30
22: ; preds = %2
%23 = load double, double* %3
%24 = fneg double %23
store double %24, double* %3
%25 = load double, double* %3
%26 = fptoui double %25 to i64
store i64 %26, i64* %7
%27 = load i64, i64* %7
%28 = load double, double* %3
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0), i64 %27, double %28)
br label %36
30: ; preds = %2
%31 = load double, double* %3
%32 = fptoui double %31 to i64
store i64 %32, i64* %7
%33 = load i64, i64* %7
%34 = load double, double* %3
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.10, i64 0, i64 0), i64 %33, double %34)
br label %36
36: ; preds = %30, %22
store i32 0, i32* %5
br label %37
37: ; preds = %47, %36
%38 = load i64, i64* %7
%39 = urem i64 %38, 10
%40 = add i64 %39, 48
%41 = trunc i64 %40 to i8
%42 = load i8*, i8** %4
%43 = load i32, i32* %5
%44 = add nsw i32 %43, 1
store i32 %44, i32* %5
%45 = sext i32 %43 to i64
%46 = getelementptr inbounds i8, i8* %42, i64 %45
store i8 %41, i8* %46
br label %47
47: ; preds = %37
%48 = load i64, i64* %7
%49 = udiv i64 %48, 10
store i64 %49, i64* %7
%50 = icmp ugt i64 %49, 0
br i1 %50, label %37, label %51
51: ; preds = %47
%52 = load float, float* %6
%53 = fcmp olt float %52, 0.000000e+00
br i1 %53, label %54, label %60
54: ; preds = %51
%55 = load i8*, i8** %4
%56 = load i32, i32* %5
%57 = add nsw i32 %56, 1
store i32 %57, i32* %5
%58 = sext i32 %56 to i64
%59 = getelementptr inbounds i8, i8* %55, i64 %58
store i8 45, i8* %59
br label %60
60: ; preds = %54, %51
%61 = load i8*, i8** %4
%62 = load i32, i32* %5
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %61, i64 %63
store i8 0, i8* %64
%65 = load i8*, i8** %4
%66 = call i32 @reverse_string(i8* %65)
ret void
}

LLVM IR (-O2):
@.str.1 = [20 x i8] c"size of long = %d;\0A\00"
@.str.2 = [29 x i8] c"size of unsigned long = %d;\0A\00"
@.str.3 = [22 x i8] c"size of double = %d;\0A\00"
@.str.4 = [21 x i8] c"size of float = %d;\0A\00"
@.str.5 = [19 x i8] c"size of int = %d;\0A\00"
@.str.6 = [25 x i8] c"size of short int = %d;\0A\00"
@.str.7 = [24 x i8] c"size of long int = %d;\0A\00"
@.str.8 = [20 x i8] c"size of char = %d;\0A\00"
@.str.9 = [30 x i8] c"n < 0 and digit = %u; n = %u\0A\00"
@.str.10 = [33 x i8] c"n > 0 and digit = %llu; n = %f;\0A\00"
define void @itoa_dw(double %0, i8* %1) {
%3 = tail call i32 @putchar(i32 10)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i64 8)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i64 8)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i64 8)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i64 4)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i64 4)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i64 2)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i64 8)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i64 1)
%12 = fptrunc double %0 to float
%13 = fcmp olt float %12, 0.000000e+00
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = fneg double %0
%16 = fptoui double %15 to i64
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0), i64 %16, double %15)
br label %21
18: ; preds = %2
%19 = fptoui double %0 to i64
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.10, i64 0, i64 0), i64 %19, double %0)
br label %21
21: ; preds = %18, %14
%22 = phi i64 [ %16, %14 ], [ %19, %18 ]
br label %23
23: ; preds = %21, %23
%24 = phi i64 [ %29, %23 ], [ 0, %21 ]
%25 = phi i64 [ %31, %23 ], [ %22, %21 ]
%26 = urem i64 %25, 10
%27 = trunc i64 %26 to i8
%28 = or i8 %27, 48
%29 = add nuw i64 %24, 1
%30 = getelementptr inbounds i8, i8* %1, i64 %24
store i8 %28, i8* %30
%31 = udiv i64 %25, 10
%32 = icmp ult i64 %25, 10
br i1 %32, label %33, label %23
33: ; preds = %23
br i1 %13, label %34, label %38
34: ; preds = %33
%35 = add i64 %24, 2
%36 = and i64 %29, 4294967295
%37 = getelementptr inbounds i8, i8* %1, i64 %36
store i8 45, i8* %37
br label %38
38: ; preds = %34, %33
%39 = phi i64 [ %35, %34 ], [ %29, %33 ]
%40 = shl i64 %39, 32
%41 = ashr exact i64 %40, 32
%42 = getelementptr inbounds i8, i8* %1, i64 %41
store i8 0, i8* %42
%43 = tail call i32 @reverse_string(i8* %1)
ret void
}