#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 _qtoa(char *, int, long double, int);
char *qfcvt_mp(long double arg, int ndigits, int *decpt, int *sign,
               char *buffer) {
  *decpt = _qtoa(buffer, ndigits, arg, 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):
<qfcvt_mp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
fldt   0x10(%rbp)
fstpt  -0x10(%rbp)
mov    %edi,-0x14(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
mov    %rcx,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%esi
fldt   -0x10(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
mov    $0x1,%edx
call   1030 <_qtoa@plt>
mov    %eax,%ecx
add    $0x1,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
add    -0x14(%rbp),%eax
cmp    $0x0,%eax
jg     11a8 <qfcvt_mp+0x98>
mov    -0x30(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x35,%eax
jl     11a8 <qfcvt_mp+0x98>
mov    -0x30(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x39,%eax
jg     11a8 <qfcvt_mp+0x98>
mov    -0x30(%rbp),%rax
movb   $0x31,0x1(%rax)
mov    -0x30(%rbp),%rax
movb   $0x30,0x2(%rax)
mov    -0x30(%rbp),%rax
movb   $0x0,0x3(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
sete   %al
and    $0x1,%al
movzbl %al,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qfcvt_mp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebp
fldt   0x40(%rsp)
fstpt  (%rsp)
mov    %rcx,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
call   1030 <_qtoa@plt>
add    $0x1,%eax
mov    %eax,(%r15)
add    %ebp,%eax
jg     115c <qfcvt_mp+0x4c>
mov    0x1(%rbx),%al
add    $0xcb,%al
cmp    $0x4,%al
ja     115c <qfcvt_mp+0x4c>
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    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @qfcvt_mp(x86_fp80 %0, i32 %1, i32* %2, i32* %3, i8* %4) {
%6 = alloca x86_fp80
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i8*
store x86_fp80 %0, x86_fp80* %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 x86_fp80, x86_fp80* %6
%14 = call i32 @_qtoa(i8* %11, i32 %12, x86_fp80 %13, 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* @qfcvt_mp(x86_fp80 %0, i32 %1, i32* nocapture %2, i32* nocapture writeonly %3, i8* %4) {
%6 = tail call i32 @_qtoa(i8* %4, i32 %1, x86_fp80 %0, 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
}