#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, int);
char *fcvt_mp(double arg, int ndigits, int *decpt, int *sign, char *buffer) {
  *decpt = __dtoa(buffer, ndigits, arg, 1, 1) + 1;
  if (*decpt + ndigits <= 0 && buffer[1] >= '5' && buffer[1] <= '9') {
    buffer[1] = '1';
    buffer[2] = '0';
    buffer[3] = '\0';
    (*decpt)++;
  }
  *sign = buffer[0] == '-';
  return buffer + 1;
}


x86 assembly (clang, -O0):
<fcvt_mp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%esi
movsd  -0x8(%rbp),%xmm0
mov    $0x1,%ecx
mov    %ecx,%edx
call   1030 <__dtoa@plt>
mov    %eax,%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
add    -0xc(%rbp),%eax
cmp    $0x0,%eax
jg     11a6 <fcvt_mp+0x96>
mov    -0x28(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x35,%eax
jl     11a6 <fcvt_mp+0x96>
mov    -0x28(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x39,%eax
jg     11a6 <fcvt_mp+0x96>
mov    -0x28(%rbp),%rax
movb   $0x31,0x1(%rax)
mov    -0x28(%rbp),%rax
movb   $0x30,0x2(%rax)
mov    -0x28(%rbp),%rax
movb   $0x0,0x3(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
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    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fcvt_mp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebp
mov    %rcx,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
mov    $0x1,%ecx
call   1030 <__dtoa@plt>
add    $0x1,%eax
mov    %eax,(%r15)
add    %ebp,%eax
jg     1157 <fcvt_mp+0x47>
mov    0x1(%rbx),%al
add    $0xcb,%al
cmp    $0x4,%al
ja     1157 <fcvt_mp+0x47>
movw   $0x3031,0x1(%rbx)
movb   $0x0,0x3(%rbx)
addl   $0x1,(%r15)
xor    %eax,%eax
cmpb   $0x2d,(%rbx)
sete   %al
mov    %eax,(%r14)
add    $0x1,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @fcvt_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*
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
%11 = load i8*, i8** %10
%12 = load i32, i32* %7
%13 = load double, double* %6
%14 = call i32 @__dtoa(i8* %11, i32 %12, double %13, i32 1, i32 1)
%15 = add nsw i32 %14, 1
%16 = load i32*, i32** %8
store i32 %15, i32* %16
%17 = load i32*, i32** %8
%18 = load i32, i32* %17
%19 = load i32, i32* %7
%20 = add nsw i32 %18, %19
%21 = icmp sle i32 %20, 0
br i1 %21, label %22, label %44
22: ; preds = %5
%23 = load i8*, i8** %10
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp sge i32 %26, 53
br i1 %27, label %28, label %44
28: ; preds = %22
%29 = load i8*, i8** %10
%30 = getelementptr inbounds i8, i8* %29, i64 1
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp sle i32 %32, 57
br i1 %33, label %34, label %44
34: ; preds = %28
%35 = load i8*, i8** %10
%36 = getelementptr inbounds i8, i8* %35, i64 1
store i8 49, i8* %36
%37 = load i8*, i8** %10
%38 = getelementptr inbounds i8, i8* %37, i64 2
store i8 48, i8* %38
%39 = load i8*, i8** %10
%40 = getelementptr inbounds i8, i8* %39, i64 3
store i8 0, i8* %40
%41 = load i32*, i32** %8
%42 = load i32, i32* %41
%43 = add nsw i32 %42, 1
store i32 %43, i32* %41
br label %44
44: ; preds = %34, %28, %22, %5
%45 = load i8*, i8** %10
%46 = getelementptr inbounds i8, i8* %45, i64 0
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 45
%50 = zext i1 %49 to i32
%51 = load i32*, i32** %9
store i32 %50, i32* %51
%52 = load i8*, i8** %10
%53 = getelementptr inbounds i8, i8* %52, i64 1
ret i8* %53
}

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