#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_i(double, unsigned int, char *);
char *strcat(char *, int /*<<< orphan*/);
char *rebase_f(double frac, unsigned base, char *fptr, char *iptr) {
  unsigned e = 0;
  double ntgr;
  do {
    frac = modf(frac * base, &ntgr);
    fptr = strcat(fptr, rebase_i(ntgr, base, iptr));
  } while (++e < (DBL_MAX_10_EXP * (log(10) / log(2)) + 1) && frac > 0.0);
  return fptr;
}


x86 assembly (clang, -O0):
<rebase_f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    -0xc(%rbp),%eax
cvtsi2sd %rax,%xmm1
mulsd  %xmm1,%xmm0
lea    -0x30(%rbp),%rdi
call   1040 <modf@plt>
movsd  %xmm0,-0x8(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
mov    -0xc(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1030 <rebase_i@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
call   1060 <strcat@plt>
mov    %rax,-0x18(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
mov    %eax,-0x24(%rbp)
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    $0xa,%edi
call   1050 <log@plt>
mov    %eax,-0x44(%rbp)
mov    $0x2,%edi
call   1050 <log@plt>
mov    -0x48(%rbp),%ecx
mov    %eax,%esi
mov    -0x44(%rbp),%eax
cltd
idiv   %esi
mov    -0x40(%rbp),%edx
imul   %eax,%edx
add    $0x1,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x39(%rbp)
jae    1208 <rebase_f+0xc8>
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
seta   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    115f <rebase_f+0x1f>
mov    -0x18(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rebase_f>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%r13
mov    %edi,%r12d
movapd %xmm0,%xmm1
mov    %edi,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,(%rsp)
mov    $0x1,%ebx
nop
mulsd  (%rsp),%xmm1
movapd %xmm1,%xmm0
lea    0x10(%rsp),%rdi
call   1040 <modf@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
mov    %r12d,%edi
mov    %r14,%rsi
call   1030 <rebase_i@plt>
mov    %r13,%rdi
mov    %eax,%esi
call   1060 <strcat@plt>
mov    %rax,%r13
mov    0x2e42(%rip),%rax
mov    (%rax),%r15d
mov    $0xa,%edi
call   1050 <log@plt>
mov    %eax,%ebp
mov    $0x2,%edi
call   1050 <log@plt>
movsd  0x8(%rsp),%xmm1
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
imul   %r15d,%eax
add    $0x1,%eax
cmp    %eax,%ebx
jae    11ec <rebase_f+0xac>
add    $0x1,%ebx
ucomisd 0xe16(%rip),%xmm1
ja     1170 <rebase_f+0x30>
mov    %r13,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@DBL_MAX_10_EXP = global i32 0
define i8* @rebase_f(double %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca double
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca double
store double %0, double* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
store i32 0, i32* %9
br label %11
11: ; preds = %36, %4
%12 = load double, double* %5
%13 = load i32, i32* %6
%14 = uitofp i32 %13 to double
%15 = fmul double %12, %14
%16 = call double @modf(double %15, double* %10)
store double %16, double* %5
%17 = load i8*, i8** %7
%18 = load double, double* %10
%19 = load i32, i32* %6
%20 = load i8*, i8** %8
%21 = call i32 @rebase_i(double %18, i32 %19, i8* %20)
%22 = call i8* @strcat(i8* %17, i32 %21)
store i8* %22, i8** %7
br label %23
23: ; preds = %11
%24 = load i32, i32* %9
%25 = add i32 %24, 1
store i32 %25, i32* %9
%26 = load i32, i32* @DBL_MAX_10_EXP
%27 = call i32 @log(i32 10)
%28 = call i32 @log(i32 2)
%29 = sdiv i32 %27, %28
%30 = mul nsw i32 %26, %29
%31 = add nsw i32 %30, 1
%32 = icmp ult i32 %25, %31
br i1 %32, label %33, label %36
33: ; preds = %23
%34 = load double, double* %5
%35 = fcmp ogt double %34, 0.000000e+00
br label %36
36: ; preds = %33, %23
%37 = phi i1 [ false, %23 ], [ %35, %33 ]
br i1 %37, label %11, label %38
38: ; preds = %36
%39 = load i8*, i8** %7
ret i8* %39
}

LLVM IR (-O2):
@DBL_MAX_10_EXP = global i32 0
define i8* @rebase_f(double %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca double
%6 = bitcast double* %5 to i8*
%7 = uitofp i32 %1 to double
br label %8
8: ; preds = %8, %4
%9 = phi i8* [ %2, %4 ], [ %16, %8 ]
%10 = phi double [ %0, %4 ], [ %13, %8 ]
%11 = phi i32 [ 0, %4 ], [ %17, %8 ]
%12 = fmul double %10, %7
%13 = call double @modf(double %12, double* %5)
%14 = load double, double* %5
%15 = tail call i32 @rebase_i(double %14, i32 %1, i8* %3)
%16 = tail call i8* @strcat(i8* %9, i32 %15)
%17 = add nuw i32 %11, 1
%18 = load i32, i32* @DBL_MAX_10_EXP
%19 = tail call i32 @log(i32 10)
%20 = tail call i32 @log(i32 2)
%21 = sdiv i32 %19, %20
%22 = mul nsw i32 %21, %18
%23 = add nsw i32 %22, 1
%24 = icmp ult i32 %17, %23
%25 = fcmp ogt double %13, 0.000000e+00
%26 = select i1 %24, i1 %25, i1 false
br i1 %26, label %8, label %27
27: ; preds = %8
ret i8* %16
}