#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 floor(double);
char *malloc(scalar_t__);
double pow(int, double);
int /*<<< orphan*/ sprintf(char *, char *, ...);
scalar_t__ strlen(char *);
char *G_double_to_basename_format(double number, size_t ndigits,
                                  size_t ndecimals) {
  double integer, decimal;
  integer = floor(number);
  char intfmt[100] = "%d";
  char intstr[100];
  char decfmt[100] = "";
  char decstr[100] = "";
  char *result;
  if (ndigits != 0) {
    sprintf(intfmt, "%%0%zud", ndigits);
  }
  sprintf(intstr, intfmt, (int)integer);
  if (ndecimals != 0) {
    sprintf(decfmt, "_%%0%zud", ndecimals);
    decimal = ((number - integer) * pow(10., (double)ndecimals));
    sprintf(decstr, decfmt, (int)decimal);
  }
  result = malloc(strlen(intstr) + strlen(decstr) + 1);
  sprintf(result, "%s%s", intstr, decstr);
  return result;
}


x86 assembly (clang, -O0):
<G_double_to_basename_format>:
push   %rbp
mov    %rsp,%rbp
sub    $0x200,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1080 <floor@plt>
movsd  %xmm0,-0x20(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1040 <memset@plt>
movb   $0x25,-0x90(%rbp)
movb   $0x64,-0x8f(%rbp)
lea    -0x170(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1040 <memset@plt>
lea    -0x1e0(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1040 <memset@plt>
cmpq   $0x0,-0x10(%rbp)
je     11f2 <G_double_to_basename_format+0x92>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe36(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
lea    -0x100(%rbp),%rdi
lea    -0x90(%rbp),%rsi
cvttsd2si -0x20(%rbp),%edx
mov    $0x0,%al
call   1070 <sprintf@plt>
cmpq   $0x0,-0x18(%rbp)
je     12a5 <G_double_to_basename_format+0x145>
mov    -0x18(%rbp),%rdx
lea    0xdfe(%rip),%rsi
xor    %eax,%eax
lea    -0x170(%rbp),%rdi
call   1070 <sprintf@plt>
movsd  -0x8(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x1f0(%rbp)
ff
movaps 0xdb3(%rip),%xmm1
movq   -0x18(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xdb2(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
mov    $0xa,%edi
call   1060 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x1f0(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
lea    -0x1e0(%rbp),%rdi
lea    -0x170(%rbp),%rsi
cvttsd2si -0x28(%rbp),%edx
mov    $0x0,%al
call   1070 <sprintf@plt>
lea    -0x100(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x1f8(%rbp)
lea    -0x1e0(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x1f8(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x1e8(%rbp)
mov    -0x1e8(%rbp),%rdi
lea    -0x100(%rbp),%rdx
lea    -0x1e0(%rbp),%rcx
lea    0xd2f(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    -0x1e8(%rbp),%rax
add    $0x200,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<G_double_to_basename_format>:
push   %r15
push   %r14
push   %rbx
sub    $0x1d0,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movsd  %xmm0,(%rsp)
call   1070 <floor@plt>
xorpd  %xmm1,%xmm1
movapd %xmm1,0x10(%rsp)
movapd %xmm1,0x60(%rsp)
movapd %xmm1,0x50(%rsp)
movapd %xmm1,0x40(%rsp)
movapd %xmm1,0x30(%rsp)
movapd %xmm1,0x20(%rsp)
movl   $0x0,0x70(%rsp)
movw   $0x6425,0x10(%rsp)
movapd %xmm1,0x140(%rsp)
movapd %xmm1,0x130(%rsp)
movapd %xmm1,0x120(%rsp)
movapd %xmm1,0x110(%rsp)
movapd %xmm1,0x100(%rsp)
movapd %xmm1,0xf0(%rsp)
movl   $0x0,0x150(%rsp)
movapd %xmm1,0xd0(%rsp)
movapd %xmm1,0xc0(%rsp)
movapd %xmm1,0xb0(%rsp)
movapd %xmm1,0xa0(%rsp)
movapd %xmm1,0x90(%rsp)
movapd %xmm1,0x80(%rsp)
movl   $0x0,0xe0(%rsp)
test   %rbx,%rbx
movsd  %xmm0,0x8(%rsp)
je     124c <G_double_to_basename_format+0xfc>
lea    0xdea(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <sprintf@plt>
movsd  0x8(%rsp),%xmm0
cvttsd2si %xmm0,%edx
lea    0x160(%rsp),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1060 <sprintf@plt>
test   %r14,%r14
je     12db <G_double_to_basename_format+0x18b>
lea    0xdb0(%rip),%rsi
lea    0xf0(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <sprintf@plt>
movsd  (%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%rsp)
movq   %r14,%xmm1
punpckldq 0xd5e(%rip),%xmm1
subpd  0xd66(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mov    $0xa,%edi
call   1050 <pow@plt>
mulsd  (%rsp),%xmm0
cvttsd2si %xmm0,%edx
lea    0x80(%rsp),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <sprintf@plt>
lea    0x160(%rsp),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
lea    0x80(%rsp),%r15
mov    %r15,%rdi
call   1030 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x1,%rdi
call   1040 <malloc@plt>
mov    %rax,%rbx
lea    0xd14(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1060 <sprintf@plt>
mov    %rbx,%rax
add    $0x1d0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"%%0%zud\00"
@.str.1 = [9 x i8] c"_%%0%zud\00"
@.str.2 = [5 x i8] c"%s%s\00"
define i8* @G_double_to_basename_format(double %0, i64 %1, i64 %2) {
%4 = alloca double
%5 = alloca i64
%6 = alloca i64
%7 = alloca double
%8 = alloca double
%9 = alloca [100 x i8]
%10 = alloca [100 x i8]
%11 = alloca [100 x i8]
%12 = alloca [100 x i8]
%13 = alloca i8*
store double %0, double* %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%14 = load double, double* %4
%15 = call double @llvm.floor.f64(double %14)
store double %15, double* %7
%16 = bitcast [100 x i8]* %9 to i8*
%17 = bitcast i8* %16 to [100 x i8]*
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %17, i32 0, i32 0
store i8 37, i8* %18
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %17, i32 0, i32 1
store i8 100, i8* %19
%20 = bitcast [100 x i8]* %11 to i8*
%21 = bitcast [100 x i8]* %12 to i8*
%22 = load i64, i64* %5
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %3
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%26 = load i64, i64* %5
%27 = call i32 (i8*, i8*, ...) @sprintf(i8* %25, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 %26)
br label %28
28: ; preds = %24, %3
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%31 = load double, double* %7
%32 = fptosi double %31 to i32
%33 = call i32 (i8*, i8*, ...) @sprintf(i8* %29, i8* %30, i32 %32)
%34 = load i64, i64* %6
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %52
36: ; preds = %28
%37 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%38 = load i64, i64* %6
%39 = call i32 (i8*, i8*, ...) @sprintf(i8* %37, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i64 %38)
%40 = load double, double* %4
%41 = load double, double* %7
%42 = fsub double %40, %41
%43 = load i64, i64* %6
%44 = uitofp i64 %43 to double
%45 = call double @pow(i32 10, double %44)
%46 = fmul double %42, %45
store double %46, double* %8
%47 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%48 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%49 = load double, double* %8
%50 = fptosi double %49 to i32
%51 = call i32 (i8*, i8*, ...) @sprintf(i8* %47, i8* %48, i32 %50)
br label %52
52: ; preds = %36, %28
%53 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%54 = call i64 @strlen(i8* %53)
%55 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%56 = call i64 @strlen(i8* %55)
%57 = add nsw i64 %54, %56
%58 = add nsw i64 %57, 1
%59 = call i8* @malloc(i64 %58)
store i8* %59, i8** %13
%60 = load i8*, i8** %13
%61 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%62 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%63 = call i32 (i8*, i8*, ...) @sprintf(i8* %60, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %61, i8* %62)
%64 = load i8*, i8** %13
ret i8* %64
}

LLVM IR (-O2):
@.str = [8 x i8] c"%%0%zud\00"
@.str.1 = [9 x i8] c"_%%0%zud\00"
@.str.2 = [5 x i8] c"%s%s\00"
define noalias i8* @G_double_to_basename_format(double %0, i64 %1, i64 %2) {
%4 = alloca [100 x i8]
%5 = alloca [100 x i8]
%6 = alloca [100 x i8]
%7 = alloca [100 x i8]
%8 = tail call double @llvm.floor.f64(double %0)
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
store i8 37, i8* %9
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 1
store i8 100, i8* %10
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%14 = icmp eq i64 %1, 0
br i1 %14, label %17, label %15
15: ; preds = %3
%16 = call i32 (i8*, i8*, ...) @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 %1)
br label %17
17: ; preds = %15, %3
%18 = fptosi double %8 to i32
%19 = call i32 (i8*, i8*, ...) @sprintf(i8* %11, i8* %9, i32 %18)
%20 = icmp eq i64 %2, 0
br i1 %20, label %29, label %21
21: ; preds = %17
%22 = call i32 (i8*, i8*, ...) @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i64 %2)
%23 = fsub double %0, %8
%24 = uitofp i64 %2 to double
%25 = tail call double @pow(i32 10, double %24)
%26 = fmul double %23, %25
%27 = fptosi double %26 to i32
%28 = call i32 (i8*, i8*, ...) @sprintf(i8* %13, i8* %12, i32 %27)
br label %29
29: ; preds = %21, %17
%30 = call i64 @strlen(i8* %11)
%31 = call i64 @strlen(i8* %13)
%32 = add i64 %30, 1
%33 = add i64 %32, %31
%34 = tail call i8* @malloc(i64 %33)
%35 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %34, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %11, i8* %13)
ret i8* %34
}