#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 /*<<< orphan*/ sprintf(char *, char *, double);
char *_doubleToStr(double n, char *cp) {
  cp += sprintf(cp, "%f", n);
  while (cp[-1] == '0' && cp[-2] != '.')
    --cp;
  return cp;
}


x86 assembly (clang, -O0):
<_doubleToStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
movsd  -0x8(%rbp),%xmm0
lea    0xecf(%rip),%rsi
call   1030 <sprintf@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl -0x1(%rax),%ecx
xor    %eax,%eax
cmp    $0x30,%ecx
mov    %al,-0x11(%rbp)
jne    116d <_doubleToStr+0x5d>
mov    -0x10(%rbp),%rax
movsbl -0x2(%rax),%eax
cmp    $0x2e,%eax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    117d <_doubleToStr+0x6d>
jmp    118e <_doubleToStr+0x7e>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1146 <_doubleToStr+0x36>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_doubleToStr>:
push   %rbx
mov    %rdi,%rbx
lea    0xee5(%rip),%rsi
call   1030 <sprintf@plt>
movslq %eax,%rcx
add    %rbx,%rcx
cs nopw 0x0(%rax,%rax,1)
mov    %rcx,%rax
cmpb   $0x30,-0x1(%rcx)
jne    1143 <_doubleToStr+0x33>
lea    -0x1(%rax),%rcx
cmpb   $0x2e,-0x2(%rax)
jne    1130 <_doubleToStr+0x20>
pop    %rbx
ret

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

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