#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 *pstrdup(char *);
int /*<<< orphan*/ sprintf(char *, char *, double);
int strlen(char *);
char *pdbl_to_str(double d) {
  char *trail;
  char str[128];
  ;
  ;
  sprintf(str, "%lf", d);
  ;
  for (trail = str + strlen(str) - 1; *trail == '0'; trail--)
    ;
  *(trail + 1) = '\0';
  ;
  return pstrdup(str);
}


x86 assembly (clang, -O0):
<pdbl_to_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movsd  %xmm0,-0x8(%rbp)
lea    -0x90(%rbp),%rdi
movsd  -0x8(%rbp),%xmm0
lea    0xead(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x90(%rbp),%rax
mov    %rax,-0x98(%rbp)
lea    -0x90(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x98(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    11af <pdbl_to_str+0x7f>
jmp    119e <pdbl_to_str+0x6e>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1189 <pdbl_to_str+0x59>
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
lea    -0x90(%rbp),%rdi
call   1040 <pstrdup@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pdbl_to_str>:
push   %rbx
sub    $0x80,%rsp
lea    0xec1(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
add    %rbx,%rax
add    $0x1,%rax
nopl   0x0(%rax,%rax,1)
cmpb   $0x30,-0x2(%rax)
lea    -0x1(%rax),%rax
je     1160 <pdbl_to_str+0x30>
movb   $0x0,(%rax)
mov    %rsp,%rdi
call   1040 <pstrdup@plt>
add    $0x80,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%lf\00"
define i8* @pdbl_to_str(double %0) {
%2 = alloca double
%3 = alloca i8*
%4 = alloca [128 x i8]
store double %0, double* %2
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%6 = load double, double* %2
%7 = call i32 @sprintf(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %6)
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%10 = call i32 @strlen(i8* %9)
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %8, i64 %11
%13 = getelementptr inbounds i8, i8* %12, i64 -1
store i8* %13, i8** %3
br label %14
14: ; preds = %20, %1
%15 = load i8*, i8** %3
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 48
br i1 %18, label %19, label %23
19: ; preds = %14
br label %20
20: ; preds = %19
%21 = load i8*, i8** %3
%22 = getelementptr inbounds i8, i8* %21, i32 -1
store i8* %22, i8** %3
br label %14
23: ; preds = %14
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i64 1
store i8 0, i8* %25
%26 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%27 = call i8* @pstrdup(i8* %26)
ret i8* %27
}

LLVM IR (-O2):
@.str = [4 x i8] c"%lf\00"
define i8* @pdbl_to_str(double %0) {
%2 = alloca [128 x i8]
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%4 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %0)
%5 = call i32 @strlen(i8* %3)
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 %6
br label %8
8: ; preds = %8, %1
%9 = phi i8* [ %7, %1 ], [ %10, %8 ]
%10 = getelementptr inbounds i8, i8* %9, i64 -1
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 48
br i1 %12, label %8, label %13
13: ; preds = %8
store i8 0, i8* %9
%14 = call i8* @pstrdup(i8* %3)
ret i8* %14
}