#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 */
typedef int /*<<< orphan*/ mpfr_t;
typedef scalar_t__ mpfr_exp_t;

/* Variables and functions */
int /*<<< orphan*/ GMP_RNDN;
char *malloc(scalar_t__);
int /*<<< orphan*/ mpfr_abs(int /*<<< orphan*/, int /*<<< orphan*/,
                            int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_clears(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ mpfr_free_str(char *);
int /*<<< orphan*/ mpfr_get_prec(int /*<<< orphan*/);
char *mpfr_get_str(int /*<<< orphan*/ *, scalar_t__ *, int, int /*<<< orphan*/,
                   int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_init2(int /*<<< orphan*/, int /*<<< orphan*/);
int mpfr_sgn(int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *mpfrToStr(mpfr_t m) {
  mpfr_t fra;
  mpfr_init2(fra, mpfr_get_prec(m));
  mpfr_abs(fra, m, GMP_RNDN);
  mpfr_exp_t e;
  char *s = mpfr_get_str(NULL, &e, 10, 0, fra, GMP_RNDN);
  char *ret = malloc(strlen(s) + 20);
  if (mpfr_sgn(m) == -1)
    ret[0] = '-';
  else
    ret[0] = '+';
  ret[1] = '0';
  ret[2] = '.';
  strcpy(&ret[3], s);
  mpfr_free_str(s);
  char estr[10];
  sprintf(estr, "e%+d", (int)e);
  strcat(ret, estr);
  mpfr_clears(fra, NULL);
  return ret;
}


x86 assembly (clang, -O0):
<mpfrToStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x4(%rbp),%edi
call   10b0 <mpfr_get_prec@plt>
mov    -0x30(%rbp),%edi
mov    %eax,%esi
call   10d0 <mpfr_init2@plt>
mov    -0x8(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    0x2df0(%rip),%rax
mov    (%rax),%edx
call   1030 <mpfr_abs@plt>
mov    -0x8(%rbp),%r8d
mov    0x2dde(%rip),%rax
mov    (%rax),%r9d
xor    %eax,%eax
mov    %eax,%edi
lea    -0x10(%rbp),%rsi
mov    $0xa,%edx
xor    %ecx,%ecx
call   1070 <mpfr_get_str@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x14,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
call   1090 <mpfr_sgn@plt>
cmp    $0xffffffff,%eax
jne    1253 <mpfrToStr+0x93>
mov    -0x20(%rbp),%rax
movb   $0x2d,(%rax)
jmp    125a <mpfrToStr+0x9a>
mov    -0x20(%rbp),%rax
movb   $0x2b,(%rax)
mov    -0x20(%rbp),%rax
movb   $0x30,0x1(%rax)
mov    -0x20(%rbp),%rax
movb   $0x2e,0x2(%rax)
mov    -0x20(%rbp),%rdi
add    $0x3,%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
call   10a0 <mpfr_free_str@plt>
lea    -0x2a(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    %eax,%edx
lea    0xd6b(%rip),%rsi
call   10e0 <sprintf@plt>
mov    -0x20(%rbp),%rdi
lea    -0x2a(%rbp),%rsi
call   10c0 <strcat@plt>
mov    -0x8(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <mpfr_clears@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mpfrToStr>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edi,%r14d
call   10b0 <mpfr_get_prec@plt>
mov    %eax,%esi
call   10d0 <mpfr_init2@plt>
mov    0x2e02(%rip),%rbx
mov    (%rbx),%edx
mov    %r14d,%esi
call   1030 <mpfr_abs@plt>
mov    (%rbx),%r9d
lea    0x8(%rsp),%rsi
xor    %edi,%edi
mov    $0xa,%edx
xor    %ecx,%ecx
call   1070 <mpfr_get_str@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1050 <strlen@plt>
lea    0x14(%rax),%rdi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %r14d,%edi
call   1090 <mpfr_sgn@plt>
cmp    $0xffffffff,%eax
sete   %al
add    %al,%al
add    $0x2b,%al
mov    %al,(%rbx)
movw   $0x2e30,0x1(%rbx)
lea    0x3(%rbx),%rdi
mov    %rbp,%rsi
call   1040 <strcpy@plt>
mov    %rbp,%rdi
call   10a0 <mpfr_free_str@plt>
mov    0x8(%rsp),%edx
lea    0xdb2(%rip),%rsi
lea    0x16(%rsp),%rbp
mov    %rbp,%rdi
call   10e0 <sprintf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10c0 <strcat@plt>
xor    %esi,%esi
call   1060 <mpfr_clears@plt>
mov    %rbx,%rax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@GMP_RNDN = global i32 0
@.str = [5 x i8] c"e%+d\00"
define i8* @mpfrToStr(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [10 x i8]
store i32 %0, i32* %2
%8 = load i32, i32* %3
%9 = load i32, i32* %2
%10 = call i32 @mpfr_get_prec(i32 %9)
%11 = call i32 @mpfr_init2(i32 %8, i32 %10)
%12 = load i32, i32* %3
%13 = load i32, i32* %2
%14 = load i32, i32* @GMP_RNDN
%15 = call i32 @mpfr_abs(i32 %12, i32 %13, i32 %14)
%16 = load i32, i32* %3
%17 = load i32, i32* @GMP_RNDN
%18 = call i8* @mpfr_get_str(i32* null, i64* %4, i32 10, i32 0, i32 %16, i32 %17)
store i8* %18, i8** %5
%19 = load i8*, i8** %5
%20 = call i64 @strlen(i8* %19)
%21 = add nsw i64 %20, 20
%22 = call i8* @malloc(i64 %21)
store i8* %22, i8** %6
%23 = load i32, i32* %2
%24 = call i32 @mpfr_sgn(i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %1
%27 = load i8*, i8** %6
%28 = getelementptr inbounds i8, i8* %27, i64 0
store i8 45, i8* %28
br label %32
29: ; preds = %1
%30 = load i8*, i8** %6
%31 = getelementptr inbounds i8, i8* %30, i64 0
store i8 43, i8* %31
br label %32
32: ; preds = %29, %26
%33 = load i8*, i8** %6
%34 = getelementptr inbounds i8, i8* %33, i64 1
store i8 48, i8* %34
%35 = load i8*, i8** %6
%36 = getelementptr inbounds i8, i8* %35, i64 2
store i8 46, i8* %36
%37 = load i8*, i8** %6
%38 = getelementptr inbounds i8, i8* %37, i64 3
%39 = load i8*, i8** %5
%40 = call i32 @strcpy(i8* %38, i8* %39)
%41 = load i8*, i8** %5
%42 = call i32 @mpfr_free_str(i8* %41)
%43 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%44 = load i64, i64* %4
%45 = trunc i64 %44 to i32
%46 = call i32 @sprintf(i8* %43, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %45)
%47 = load i8*, i8** %6
%48 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%49 = call i32 @strcat(i8* %47, i8* %48)
%50 = load i32, i32* %3
%51 = call i32 @mpfr_clears(i32 %50, i32* null)
%52 = load i8*, i8** %6
ret i8* %52
}

LLVM IR (-O2):
@GMP_RNDN = global i32 0
@.str = [5 x i8] c"e%+d\00"
define i8* @mpfrToStr(i32 %0) {
%2 = alloca i64
%3 = alloca [10 x i8]
%4 = tail call i32 @mpfr_get_prec(i32 %0)
%5 = tail call i32 @mpfr_init2(i32 undef, i32 %4)
%6 = load i32, i32* @GMP_RNDN
%7 = tail call i32 @mpfr_abs(i32 undef, i32 %0, i32 %6)
%8 = bitcast i64* %2 to i8*
%9 = load i32, i32* @GMP_RNDN
%10 = call i8* @mpfr_get_str(i32* null, i64* %2, i32 10, i32 0, i32 undef, i32 %9)
%11 = call i64 @strlen(i8* dereferenceable(1) %10)
%12 = add nsw i64 %11, 20
%13 = call i8* @malloc(i64 %12)
%14 = call i32 @mpfr_sgn(i32 %0)
%15 = icmp eq i32 %14, -1
%16 = select i1 %15, i8 45, i8 43
store i8 %16, i8* %13
%17 = getelementptr inbounds i8, i8* %13, i64 1
store i8 48, i8* %17
%18 = getelementptr inbounds i8, i8* %13, i64 2
store i8 46, i8* %18
%19 = getelementptr inbounds i8, i8* %13, i64 3
%20 = call i32 @strcpy(i8* %19, i8* %10)
%21 = call i32 @mpfr_free_str(i8* %10)
%22 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%23 = load i64, i64* %2
%24 = trunc i64 %23 to i32
%25 = call i32 @sprintf(i8* %22, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = call i32 @strcat(i8* %13, i8* %22)
%27 = call i32 @mpfr_clears(i32 undef, i32* null)
ret i8* %13
}