#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 DBL_MAX_10_EXP;
int log(int);
double modf(double, double *);
int /*<<< orphan*/ rebase_f(double, unsigned int, char *, char *);
char *rebase_i(double, unsigned int, char *);
char *strcat(char *, char *);
int strlen(char *);
char *strncat(char *, int /*<<< orphan*/, int);
char *rebase_d(double num, unsigned base, char *dptr, char *fptr, char *iptr) {
  int sign = 1;
  double ntgr, frac;
  if (num < 0.0) {
    num *= -1;
    sign = -1;
  }
  frac = modf(num, &ntgr);
  if (sign == -1) {
    *dptr = '-';
    *(dptr + 1) = '\0';
  } else
    *dptr = '\0';
  dptr = strcat(dptr, rebase_i(ntgr, base, iptr));
  dptr = strcat(dptr, ".");
  dptr =
      strncat(dptr, rebase_f(frac, base, fptr, iptr),
              ((DBL_MAX_10_EXP * (log(10) / log(2)) + 1) <= strlen(dptr))
                  ? 1
                  : (DBL_MAX_10_EXP * (log(10) / log(2)) + 1) - strlen(dptr));
  *iptr = *fptr = '\0';
  return dptr;
}


x86 assembly (clang, -O0):
<rebase_d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    11ba <rebase_d+0x4a>
movsd  0xe57(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movl   $0xffffffff,-0x2c(%rbp)
movsd  -0x8(%rbp),%xmm0
lea    -0x38(%rbp),%rdi
call   1050 <modf@plt>
movsd  %xmm0,-0x40(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    11eb <rebase_d+0x7b>
mov    -0x18(%rbp),%rax
movb   $0x2d,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x1(%rax)
jmp    11f2 <rebase_d+0x82>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x60(%rbp)
movsd  -0x38(%rbp),%xmm0
mov    -0xc(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1030 <rebase_i@plt>
mov    -0x60(%rbp),%rdi
mov    %rax,%rsi
call   1090 <strcat@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xde2(%rip),%rsi
call   1090 <strcat@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
movsd  -0x40(%rbp),%xmm0
mov    -0xc(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1070 <rebase_f@plt>
mov    %eax,-0x50(%rbp)
mov    0x2d9a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    $0xa,%edi
call   1080 <log@plt>
mov    %eax,-0x4c(%rbp)
mov    $0x2,%edi
call   1080 <log@plt>
mov    %eax,%ecx
mov    -0x4c(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x48(%rbp),%eax
imul   %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
cmp    %ecx,%eax
jg     12ab <rebase_d+0x13b>
mov    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    12f7 <rebase_d+0x187>
mov    0x2d3e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    $0xa,%edi
call   1080 <log@plt>
mov    %eax,-0x70(%rbp)
mov    $0x2,%edi
call   1080 <log@plt>
mov    %eax,%ecx
mov    -0x70(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x6c(%rbp),%eax
imul   %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x68(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x64(%rbp)
mov    -0x50(%rbp),%esi
mov    -0x58(%rbp),%rdi
mov    -0x64(%rbp),%edx
call   1060 <strncat@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rebase_d>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %rsi,%r13
mov    %edi,%ebp
movapd %xmm0,%xmm2
movapd %xmm0,0x10(%rsp)
movapd 0xe65(%rip),%xmm1
xorpd  %xmm0,%xmm1
xorpd  %xmm3,%xmm3
cmpltsd %xmm3,%xmm0
andpd  %xmm0,%xmm1
andnpd %xmm2,%xmm0
orpd   %xmm1,%xmm0
lea    0x20(%rsp),%rdi
call   1050 <modf@plt>
movsd  %xmm0,0x8(%rsp)
xorpd  %xmm0,%xmm0
ucomisd 0x10(%rsp),%xmm0
mov    %r13,%rax
jbe    11dc <rebase_d+0x6c>
movb   $0x2d,0x0(%r13)
lea    0x1(%r13),%rax
movb   $0x0,(%rax)
movsd  0x20(%rsp),%xmm0
mov    %ebp,%edi
mov    %r15,%rsi
call   1030 <rebase_i@plt>
mov    %r13,%rdi
mov    %rax,%rsi
call   1090 <strcat@plt>
mov    %r13,%rdi
call   1040 <strlen@plt>
movw   $0x2e,0x0(%r13,%rax,1)
movsd  0x8(%rsp),%xmm0
mov    %ebp,%edi
mov    %rbx,0x8(%rsp)
mov    %rbx,%rsi
mov    %r15,%rdx
call   1070 <rebase_f@plt>
mov    %eax,0x10(%rsp)
mov    0x2dc3(%rip),%r14
mov    (%r14),%r12d
mov    $0xa,%edi
call   1080 <log@plt>
mov    %eax,%ebp
mov    $0x2,%edi
call   1080 <log@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
mov    %eax,%ebx
imul   %r12d,%ebx
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    $0x1,%ebp
cmp    %eax,%ebx
jl     1297 <rebase_d+0x127>
mov    (%r14),%r14d
mov    $0xa,%edi
call   1080 <log@plt>
mov    %eax,%ebx
mov    $0x2,%edi
call   1080 <log@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
mov    %eax,%ebp
imul   %r14d,%ebp
mov    %r13,%rdi
call   1040 <strlen@plt>
sub    %eax,%ebp
add    $0x1,%ebp
mov    %r13,%rdi
mov    0x10(%rsp),%esi
mov    %ebp,%edx
call   1060 <strncat@plt>
mov    0x8(%rsp),%rcx
movb   $0x0,(%rcx)
movb   $0x0,(%r15)
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@DBL_MAX_10_EXP = global i32 0
define i8* @rebase_d(double %0, i32 %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca double
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca double
%13 = alloca double
store double %0, double* %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i8* %4, i8** %10
store i32 1, i32* %11
%14 = load double, double* %6
%15 = fcmp olt double %14, 0.000000e+00
br i1 %15, label %16, label %19
16: ; preds = %5
%17 = load double, double* %6
%18 = fmul double %17, -1.000000e+00
store double %18, double* %6
store i32 -1, i32* %11
br label %19
19: ; preds = %16, %5
%20 = load double, double* %6
%21 = call double @modf(double %20, double* %12)
store double %21, double* %13
%22 = load i32, i32* %11
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %28
24: ; preds = %19
%25 = load i8*, i8** %8
store i8 45, i8* %25
%26 = load i8*, i8** %8
%27 = getelementptr inbounds i8, i8* %26, i64 1
store i8 0, i8* %27
br label %30
28: ; preds = %19
%29 = load i8*, i8** %8
store i8 0, i8* %29
br label %30
30: ; preds = %28, %24
%31 = load i8*, i8** %8
%32 = load double, double* %12
%33 = load i32, i32* %7
%34 = load i8*, i8** %10
%35 = call i8* @rebase_i(double %32, i32 %33, i8* %34)
%36 = call i8* @strcat(i8* %31, i8* %35)
store i8* %36, i8** %8
%37 = load i8*, i8** %8
%38 = call i8* @strcat(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %38, i8** %8
%39 = load i8*, i8** %8
%40 = load double, double* %13
%41 = load i32, i32* %7
%42 = load i8*, i8** %9
%43 = load i8*, i8** %10
%44 = call i32 @rebase_f(double %40, i32 %41, i8* %42, i8* %43)
%45 = load i32, i32* @DBL_MAX_10_EXP
%46 = call i32 @log(i32 10)
%47 = call i32 @log(i32 2)
%48 = sdiv i32 %46, %47
%49 = mul nsw i32 %45, %48
%50 = add nsw i32 %49, 1
%51 = load i8*, i8** %8
%52 = call i32 @strlen(i8* %51)
%53 = icmp sle i32 %50, %52
br i1 %53, label %54, label %55
54: ; preds = %30
br label %65
55: ; preds = %30
%56 = load i32, i32* @DBL_MAX_10_EXP
%57 = call i32 @log(i32 10)
%58 = call i32 @log(i32 2)
%59 = sdiv i32 %57, %58
%60 = mul nsw i32 %56, %59
%61 = add nsw i32 %60, 1
%62 = load i8*, i8** %8
%63 = call i32 @strlen(i8* %62)
%64 = sub nsw i32 %61, %63
br label %65
65: ; preds = %55, %54
%66 = phi i32 [ 1, %54 ], [ %64, %55 ]
%67 = call i8* @strncat(i8* %39, i32 %44, i32 %66)
store i8* %67, i8** %8
%68 = load i8*, i8** %9
store i8 0, i8* %68
%69 = load i8*, i8** %10
store i8 0, i8* %69
%70 = load i8*, i8** %8
ret i8* %70
}

LLVM IR (-O2):
@DBL_MAX_10_EXP = global i32 0
define i8* @rebase_d(double %0, i32 %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca double
%7 = bitcast double* %6 to i8*
%8 = fcmp olt double %0, 0.000000e+00
%9 = fneg double %0
%10 = select i1 %8, double %9, double %0
%11 = call double @modf(double %10, double* %6)
br i1 %8, label %12, label %14
12: ; preds = %5
store i8 45, i8* %2
%13 = getelementptr inbounds i8, i8* %2, i64 1
br label %14
14: ; preds = %5, %12
%15 = phi i8* [ %13, %12 ], [ %2, %5 ]
store i8 0, i8* %15
%16 = load double, double* %6
%17 = tail call i8* @rebase_i(double %16, i32 %1, i8* %4)
%18 = tail call i8* @strcat(i8* dereferenceable(1) %2, i8* dereferenceable(1) %17)
%19 = tail call i64 bitcast (i32 (i8*)* @strlen to i64 (i8*)*)(i8* %2)
%20 = getelementptr i8, i8* %2, i64 %19
%21 = bitcast i8* %20 to i16*
store i16 46, i16* %21
%22 = tail call i32 @rebase_f(double %11, i32 %1, i8* %3, i8* %4)
%23 = load i32, i32* @DBL_MAX_10_EXP
%24 = tail call i32 @log(i32 10)
%25 = tail call i32 @log(i32 2)
%26 = sdiv i32 %24, %25
%27 = mul nsw i32 %26, %23
%28 = tail call i32 @strlen(i8* %2)
%29 = icmp slt i32 %27, %28
br i1 %29, label %39, label %30
30: ; preds = %14
%31 = load i32, i32* @DBL_MAX_10_EXP
%32 = tail call i32 @log(i32 10)
%33 = tail call i32 @log(i32 2)
%34 = sdiv i32 %32, %33
%35 = mul nsw i32 %34, %31
%36 = add nsw i32 %35, 1
%37 = tail call i32 @strlen(i8* %2)
%38 = sub i32 %36, %37
br label %39
39: ; preds = %14, %30
%40 = phi i32 [ %38, %30 ], [ 1, %14 ]
%41 = tail call i8* @strncat(i8* %2, i32 %22, i32 %40)
store i8 0, i8* %3
store i8 0, i8* %4
ret i8* %41
}