#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 */
double fmod(double, double);
int /*<<< orphan*/ my_putchar(char);
double trunc(double);
int my_put_double_base(double d, int base, int capitalized) {
  if (d < 0) {
    my_putchar('-');
    my_put_double_base(-d, base, capitalized);
  } else if (d >= base) {
    my_put_double_base(trunc(d / (double)base), base, capitalized);
    my_put_double_base(fmod(d, (double)base), base, capitalized);
  } else if (d <= 9) {
    my_putchar(d + '0');
  } else {
    my_putchar((capitalized == 1 ? 'A' : 'a') + d - 10);
  }
  return (0);
}


x86 assembly (clang, -O0):
<my_put_double_base>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1197 <my_put_double_base+0x57>
mov    $0x2d,%edi
call   1050 <my_putchar@plt>
movsd  -0x8(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <my_put_double_base@plt>
jmp    125e <my_put_double_base+0x11e>
movsd  -0x8(%rbp),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jb     11e8 <my_put_double_base+0xa8>
movsd  -0x8(%rbp),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1060 <trunc@plt>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <my_put_double_base@plt>
movsd  -0x8(%rbp),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
call   1040 <fmod@plt>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <my_put_double_base@plt>
jmp    1259 <my_put_double_base+0x119>
movsd  0xe10(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jb     121d <my_put_double_base+0xdd>
movsd  -0x8(%rbp),%xmm0
movsd  0xe08(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
movsbl %al,%edi
call   1050 <my_putchar@plt>
jmp    1254 <my_put_double_base+0x114>
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
setne  %al
movzbl %al,%eax
shl    $0x5,%eax
or     $0x41,%eax
cvtsi2sd %eax,%xmm0
movsd  -0x8(%rbp),%xmm1
addsd  %xmm1,%xmm0
movsd  0xdc4(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
movsbl %al,%edi
call   1050 <my_putchar@plt>
jmp    1259 <my_put_double_base+0x119>
jmp    125e <my_put_double_base+0x11e>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_put_double_base>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    %esi,%ebx
mov    %edi,%ebp
movapd %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %edi,%xmm0
movsd  %xmm0,0x8(%rsp)
jmp    1178 <my_put_double_base+0x38>
nopl   (%rax)
mov    $0x2d,%edi
call   1050 <my_putchar@plt>
movapd 0x10(%rsp),%xmm1
xorpd  0xea8(%rip),%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
movapd %xmm1,0x10(%rsp)
ja     1160 <my_put_double_base+0x20>
movsd  0x8(%rsp),%xmm2
ucomisd %xmm2,%xmm1
jb     11c1 <my_put_double_base+0x81>
movapd %xmm1,%xmm0
divsd  %xmm2,%xmm0
call   1060 <trunc@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1030 <my_put_double_base@plt>
movapd 0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
call   1040 <fmod@plt>
movapd %xmm0,%xmm1
jmp    1178 <my_put_double_base+0x38>
movsd  0xe37(%rip),%xmm0
ucomisd %xmm1,%xmm0
jae    11f2 <my_put_double_base+0xb2>
xor    %eax,%eax
cmp    $0x1,%ebx
setne  %al
shl    $0x5,%eax
or     $0x41,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  %xmm0,%xmm1
addsd  0xe20(%rip),%xmm1
jmp    11fa <my_put_double_base+0xba>
addsd  0xe0e(%rip),%xmm1
cvttsd2si %xmm1,%eax
movsbl %al,%edi
call   1050 <my_putchar@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @my_put_double_base(double %0, i32 %1, i32 %2) {
%4 = alloca double
%5 = alloca i32
%6 = alloca i32
store double %0, double* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%7 = load double, double* %4
%8 = fcmp olt double %7, 0.000000e+00
br i1 %8, label %9, label %16
9: ; preds = %3
%10 = call i32 @my_putchar(i8 signext 45)
%11 = load double, double* %4
%12 = fneg double %11
%13 = load i32, i32* %5
%14 = load i32, i32* %6
%15 = call i32 @my_put_double_base(double %12, i32 %13, i32 %14)
br label %58
16: ; preds = %3
%17 = load double, double* %4
%18 = load i32, i32* %5
%19 = sitofp i32 %18 to double
%20 = fcmp oge double %17, %19
br i1 %20, label %21, label %37
21: ; preds = %16
%22 = load double, double* %4
%23 = load i32, i32* %5
%24 = sitofp i32 %23 to double
%25 = fdiv double %22, %24
%26 = call double @llvm.trunc.f64(double %25)
%27 = load i32, i32* %5
%28 = load i32, i32* %6
%29 = call i32 @my_put_double_base(double %26, i32 %27, i32 %28)
%30 = load double, double* %4
%31 = load i32, i32* %5
%32 = sitofp i32 %31 to double
%33 = call double @fmod(double %30, double %32)
%34 = load i32, i32* %5
%35 = load i32, i32* %6
%36 = call i32 @my_put_double_base(double %33, i32 %34, i32 %35)
br label %57
37: ; preds = %16
%38 = load double, double* %4
%39 = fcmp ole double %38, 9.000000e+00
br i1 %39, label %40, label %45
40: ; preds = %37
%41 = load double, double* %4
%42 = fadd double %41, 4.800000e+01
%43 = fptosi double %42 to i8
%44 = call i32 @my_putchar(i8 signext %43)
br label %56
45: ; preds = %37
%46 = load i32, i32* %6
%47 = icmp eq i32 %46, 1
%48 = zext i1 %47 to i64
%49 = select i1 %47, i32 65, i32 97
%50 = sitofp i32 %49 to double
%51 = load double, double* %4
%52 = fadd double %50, %51
%53 = fsub double %52, 1.000000e+01
%54 = fptosi double %53 to i8
%55 = call i32 @my_putchar(i8 signext %54)
br label %56
56: ; preds = %45, %40
br label %57
57: ; preds = %56, %21
br label %58
58: ; preds = %57, %9
ret i32 0
}

LLVM IR (-O2):
define i32 @my_put_double_base(double %0, i32 %1, i32 %2) {
%4 = sitofp i32 %1 to double
br label %5
5: ; preds = %11, %3
%6 = phi double [ %0, %3 ], [ %12, %11 ]
%7 = fcmp olt double %6, 0.000000e+00
br i1 %7, label %8, label %13
8: ; preds = %5
%9 = tail call i32 @my_putchar(i8 signext 45)
%10 = fneg double %6
br label %11
11: ; preds = %8, %15
%12 = phi double [ %10, %8 ], [ %19, %15 ]
br label %5
13: ; preds = %5
%14 = fcmp ult double %6, %4
br i1 %14, label %20, label %15
15: ; preds = %13
%16 = fdiv double %6, %4
%17 = tail call double @llvm.trunc.f64(double %16)
%18 = tail call i32 @my_put_double_base(double %17, i32 %1, i32 %2)
%19 = tail call double @fmod(double %6, double %4)
br label %11
20: ; preds = %13
%21 = fcmp ugt double %6, 9.000000e+00
br i1 %21, label %24, label %22
22: ; preds = %20
%23 = fadd double %6, 4.800000e+01
br label %30
24: ; preds = %20
%25 = icmp eq i32 %2, 1
%26 = select i1 %25, i32 65, i32 97
%27 = sitofp i32 %26 to double
%28 = fadd double %6, %27
%29 = fadd double %28, -1.000000e+01
br label %30
30: ; preds = %24, %22
%31 = phi double [ %29, %24 ], [ %23, %22 ]
%32 = fptosi double %31 to i8
%33 = tail call i32 @my_putchar(i8 signext %32)
ret i32 0
}