#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 */
char *G_double_to_basename_format(double, size_t, size_t);
char *G_get_basename_separator();
char *malloc(scalar_t__);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char *, char *);
scalar_t__ strlen(char const *);
char *G_generate_basename(const char *basename, double number, size_t ndigits,
                          size_t ndecimals) {
  char *separator, *numberstr, *result;
  separator = G_get_basename_separator();
  numberstr = G_double_to_basename_format(number, ndigits, ndecimals);
  result = malloc(strlen(basename) + strlen(separator) + strlen(numberstr) + 1);
  if (result)
    sprintf(result, "%s%s%s", basename, separator, numberstr);
  return result;
}


x86 assembly (clang, -O0):
<G_generate_basename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    $0x0,%al
call   1040 <G_get_basename_separator@plt>
mov    %rax,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <G_double_to_basename_format@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x40(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11f2 <G_generate_basename+0xa2>
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
lea    0xe13(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x38(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<G_generate_basename>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r12
mov    %rsi,%rbx
movsd  %xmm0,0x8(%rsp)
mov    %rdi,%r14
xor    %eax,%eax
call   1040 <G_get_basename_separator@plt>
mov    %rax,%r15
movsd  0x8(%rsp),%xmm0
mov    %rbx,%rdi
mov    %r12,%rsi
call   1070 <G_double_to_basename_format@plt>
mov    %rax,%r12
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%r13
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1030 <strlen@plt>
add    %r13,%rbx
lea    (%rax,%rbx,1),%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11d8 <G_generate_basename+0x88>
lea    0xe39(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %r12,%r8
call   1060 <sprintf@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%s%s%s\00"
define i8* @G_generate_basename(i8* %0, double %1, i64 %2, i64 %3) {
%5 = alloca i8*
%6 = alloca double
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %5
store double %1, double* %6
store i64 %2, i64* %7
store i64 %3, i64* %8
%12 = call i8* (...) @G_get_basename_separator()
store i8* %12, i8** %9
%13 = load double, double* %6
%14 = load i64, i64* %7
%15 = load i64, i64* %8
%16 = call i8* @G_double_to_basename_format(double %13, i64 %14, i64 %15)
store i8* %16, i8** %10
%17 = load i8*, i8** %5
%18 = call i64 @strlen(i8* %17)
%19 = load i8*, i8** %9
%20 = call i64 @strlen(i8* %19)
%21 = add nsw i64 %18, %20
%22 = load i8*, i8** %10
%23 = call i64 @strlen(i8* %22)
%24 = add nsw i64 %21, %23
%25 = add nsw i64 %24, 1
%26 = call i8* @malloc(i64 %25)
store i8* %26, i8** %11
%27 = load i8*, i8** %11
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %35
29: ; preds = %4
%30 = load i8*, i8** %11
%31 = load i8*, i8** %5
%32 = load i8*, i8** %9
%33 = load i8*, i8** %10
%34 = call i32 @sprintf(i8* %30, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %31, i8* %32, i8* %33)
br label %35
35: ; preds = %29, %4
%36 = load i8*, i8** %11
ret i8* %36
}

LLVM IR (-O2):
@.str = [7 x i8] c"%s%s%s\00"
define noalias i8* @G_generate_basename(i8* %0, double %1, i64 %2, i64 %3) {
%5 = tail call i8* (...) @G_get_basename_separator()
%6 = tail call i8* @G_double_to_basename_format(double %1, i64 %2, i64 %3)
%7 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%8 = tail call i64 @strlen(i8* dereferenceable(1) %5)
%9 = tail call i64 @strlen(i8* dereferenceable(1) %6)
%10 = add i64 %7, 1
%11 = add i64 %10, %8
%12 = add i64 %11, %9
%13 = tail call i8* @malloc(i64 %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %17, label %15
15: ; preds = %4
%16 = tail call i32 @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %5, i8* %6)
br label %17
17: ; preds = %15, %4
ret i8* %13
}