#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 __dtoa(char *, int, double, int /*<<< orphan*/, int);
char *ecvt_mp(double arg, int ndigits, int *decpt, int *sign, char *buffer) {
  if (ndigits > 17) {
    register char *p, *e;
    *decpt = __dtoa(buffer, 17, arg, 0, 1) + 1;
    for (p = buffer + 18, e = buffer + 1 + (ndigits > 82 ? 82 : ndigits);
         p != e;)
      *p++ = '0';
    *p++ = '\0';
  } else if (ndigits <= 0) {
    *decpt = __dtoa(buffer, 1, arg, 0, 1) + 1;
    buffer[1] = '\0';
  } else {
    *decpt = __dtoa(buffer, ndigits, arg, 0, 1) + 1;
  }
  *sign = buffer[0] == '-';
  return buffer + 1;
}


x86 assembly (clang, -O0):
<ecvt_mp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpl   $0x11,-0xc(%rbp)
jle    11dd <ecvt_mp+0xcd>
mov    -0x28(%rbp),%rdi
movsd  -0x8(%rbp),%xmm0
mov    $0x11,%esi
xor    %edx,%edx
mov    $0x1,%ecx
call   1030 <__dtoa@plt>
mov    %eax,%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
add    $0x12,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
cmpl   $0x52,-0xc(%rbp)
jle    118a <ecvt_mp+0x7a>
mov    $0x52,%eax
mov    %eax,-0x44(%rbp)
jmp    1190 <ecvt_mp+0x80>
mov    -0xc(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x40(%rbp),%rax
mov    -0x44(%rbp),%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x38(%rbp),%rax
je     11c6 <ecvt_mp+0xb6>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movb   $0x30,(%rax)
jmp    11a1 <ecvt_mp+0x91>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movb   $0x0,(%rax)
jmp    123e <ecvt_mp+0x12e>
cmpl   $0x0,-0xc(%rbp)
jg     1216 <ecvt_mp+0x106>
mov    -0x28(%rbp),%rdi
movsd  -0x8(%rbp),%xmm0
mov    $0x1,%ecx
xor    %edx,%edx
mov    %ecx,%esi
call   1030 <__dtoa@plt>
mov    %eax,%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
movb   $0x0,0x1(%rax)
jmp    1239 <ecvt_mp+0x129>
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%esi
movsd  -0x8(%rbp),%xmm0
xor    %edx,%edx
mov    $0x1,%ecx
call   1030 <__dtoa@plt>
mov    %eax,%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    123e <ecvt_mp+0x12e>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
sete   %al
and    $0x1,%al
movzbl %al,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ecvt_mp>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%r12d
cmp    $0x12,%edi
jl     1179 <ecvt_mp+0x59>
mov    %rbx,%rdi
mov    $0x11,%esi
xor    %edx,%edx
mov    $0x1,%ecx
call   1040 <__dtoa@plt>
add    $0x1,%eax
mov    %eax,(%r15)
lea    0x12(%rbx),%rdi
cmp    $0x52,%r12d
mov    $0x52,%ebp
cmovb  %r12d,%ebp
lea    -0x11(%rbp),%rdx
mov    $0x30,%esi
call   1030 <memset@plt>
movb   $0x0,0x1(%rbp,%rbx,1)
jmp    11b3 <ecvt_mp+0x93>
mov    %rbx,%rdi
test   %r12d,%r12d
jle    1198 <ecvt_mp+0x78>
mov    %r12d,%esi
xor    %edx,%edx
mov    $0x1,%ecx
call   1040 <__dtoa@plt>
add    $0x1,%eax
mov    %eax,(%r15)
jmp    11b3 <ecvt_mp+0x93>
mov    $0x1,%esi
xor    %edx,%edx
mov    $0x1,%ecx
call   1040 <__dtoa@plt>
add    $0x1,%eax
mov    %eax,(%r15)
movb   $0x0,0x1(%rbx)
xor    %eax,%eax
cmpb   $0x2d,(%rbx)
sete   %al
mov    %eax,(%r14)
add    $0x1,%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @ecvt_mp(double %0, i32 %1, i32* %2, i32* %3, i8* %4) {
%6 = alloca double
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
store double %0, double* %6
store i32 %1, i32* %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store i8* %4, i8** %10
%13 = load i32, i32* %7
%14 = icmp sgt i32 %13, 17
br i1 %14, label %15, label %44
15: ; preds = %5
%16 = load i8*, i8** %10
%17 = load double, double* %6
%18 = call i32 @__dtoa(i8* %16, i32 17, double %17, i32 0, i32 1)
%19 = add nsw i32 %18, 1
%20 = load i32*, i32** %8
store i32 %19, i32* %20
%21 = load i8*, i8** %10
%22 = getelementptr inbounds i8, i8* %21, i64 18
store i8* %22, i8** %11
%23 = load i8*, i8** %10
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = load i32, i32* %7
%26 = icmp sgt i32 %25, 82
br i1 %26, label %27, label %28
27: ; preds = %15
br label %30
28: ; preds = %15
%29 = load i32, i32* %7
br label %30
30: ; preds = %28, %27
%31 = phi i32 [ 82, %27 ], [ %29, %28 ]
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %24, i64 %32
store i8* %33, i8** %12
br label %34
34: ; preds = %38, %30
%35 = load i8*, i8** %11
%36 = load i8*, i8** %12
%37 = icmp ne i8* %35, %36
br i1 %37, label %38, label %41
38: ; preds = %34
%39 = load i8*, i8** %11
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %11
store i8 48, i8* %39
br label %34
41: ; preds = %34
%42 = load i8*, i8** %11
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %11
store i8 0, i8* %42
br label %63
44: ; preds = %5
%45 = load i32, i32* %7
%46 = icmp sle i32 %45, 0
br i1 %46, label %47, label %55
47: ; preds = %44
%48 = load i8*, i8** %10
%49 = load double, double* %6
%50 = call i32 @__dtoa(i8* %48, i32 1, double %49, i32 0, i32 1)
%51 = add nsw i32 %50, 1
%52 = load i32*, i32** %8
store i32 %51, i32* %52
%53 = load i8*, i8** %10
%54 = getelementptr inbounds i8, i8* %53, i64 1
store i8 0, i8* %54
br label %62
55: ; preds = %44
%56 = load i8*, i8** %10
%57 = load i32, i32* %7
%58 = load double, double* %6
%59 = call i32 @__dtoa(i8* %56, i32 %57, double %58, i32 0, i32 1)
%60 = add nsw i32 %59, 1
%61 = load i32*, i32** %8
store i32 %60, i32* %61
br label %62
62: ; preds = %55, %47
br label %63
63: ; preds = %62, %41
%64 = load i8*, i8** %10
%65 = getelementptr inbounds i8, i8* %64, i64 0
%66 = load i8, i8* %65
%67 = sext i8 %66 to i32
%68 = icmp eq i32 %67, 45
%69 = zext i1 %68 to i32
%70 = load i32*, i32** %9
store i32 %69, i32* %70
%71 = load i8*, i8** %10
%72 = getelementptr inbounds i8, i8* %71, i64 1
ret i8* %72
}

LLVM IR (-O2):
define i8* @ecvt_mp(double %0, i32 %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3, i8* %4) {
%6 = icmp sgt i32 %1, 17
br i1 %6, label %7, label %17
7: ; preds = %5
%8 = tail call i32 @__dtoa(i8* %4, i32 17, double %0, i32 0, i32 1)
%9 = add nsw i32 %8, 1
store i32 %9, i32* %2
%10 = getelementptr i8, i8* %4, i64 18
%11 = icmp ult i32 %1, 82
%12 = select i1 %11, i32 %1, i32 82
%13 = add nuw nsw i32 %12, 1
%14 = zext i32 %13 to i64
%15 = getelementptr i8, i8* %4, i64 %14
%16 = add nsw i64 %14, -18
store i8 0, i8* %15
br label %26
17: ; preds = %5
%18 = icmp slt i32 %1, 1
br i1 %18, label %19, label %23
19: ; preds = %17
%20 = tail call i32 @__dtoa(i8* %4, i32 1, double %0, i32 0, i32 1)
%21 = add nsw i32 %20, 1
store i32 %21, i32* %2
%22 = getelementptr inbounds i8, i8* %4, i64 1
store i8 0, i8* %22
br label %26
23: ; preds = %17
%24 = tail call i32 @__dtoa(i8* %4, i32 %1, double %0, i32 0, i32 1)
%25 = add nsw i32 %24, 1
store i32 %25, i32* %2
br label %26
26: ; preds = %19, %23, %7
%27 = load i8, i8* %4
%28 = icmp eq i8 %27, 45
%29 = zext i1 %28 to i32
store i32 %29, i32* %3
%30 = getelementptr inbounds i8, i8* %4, i64 1
ret i8* %30
}