#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 int /*<<< orphan*/ mpfr_rnd_t;

/* Variables and functions */
int /*<<< orphan*/ mpfr_clear(int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_init2(int /*<<< orphan*/, int);
int mpfr_set(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int mpfr_strtofr(int /*<<< orphan*/, char const *, int /*<<< orphan*/ *,
                 int /*<<< orphan*/, int /*<<< orphan*/);
int mpfr_subnormalize(int /*<<< orphan*/, int, int /*<<< orphan*/);
int string_to_fp(mpfr_t f, const char *s, mpfr_rnd_t rnd) {
  mpfr_t f2;
  mpfr_init2(f2, 100000);
  int r0 = mpfr_strtofr(f2, s, NULL, 0, rnd);
  int r = mpfr_set(f, f2, rnd);
  r |= mpfr_subnormalize(f, r, rnd);
  mpfr_clear(f2);
  return r0 | r;
}


x86 assembly (clang, -O0):
<string_to_fp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x18(%rbp),%edi
mov    $0x186a0,%esi
call   1070 <mpfr_init2@plt>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edx
xor    %ecx,%ecx
call   1030 <mpfr_strtofr@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1050 <mpfr_set@plt>
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1060 <mpfr_subnormalize@plt>
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <mpfr_clear@plt>
mov    -0x1c(%rbp),%eax
or     -0x20(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_to_fp>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r12d
mov    %rsi,%r14
mov    %edi,%r15d
mov    $0x186a0,%esi
call   1070 <mpfr_init2@plt>
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r12d,%r8d
call   1030 <mpfr_strtofr@plt>
mov    %eax,%ebp
mov    %r15d,%edi
mov    %r12d,%edx
call   1050 <mpfr_set@plt>
mov    %eax,%ebx
mov    %r15d,%edi
mov    %eax,%esi
mov    %r12d,%edx
call   1060 <mpfr_subnormalize@plt>
mov    %eax,%r14d
call   1040 <mpfr_clear@plt>
or     %ebx,%ebp
or     %r14d,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @string_to_fp(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = load i32, i32* %7
%11 = call i32 @mpfr_init2(i32 %10, i32 100000)
%12 = load i32, i32* %7
%13 = load i8*, i8** %5
%14 = load i32, i32* %6
%15 = call i32 @mpfr_strtofr(i32 %12, i8* %13, i32* null, i32 0, i32 %14)
store i32 %15, i32* %8
%16 = load i32, i32* %4
%17 = load i32, i32* %7
%18 = load i32, i32* %6
%19 = call i32 @mpfr_set(i32 %16, i32 %17, i32 %18)
store i32 %19, i32* %9
%20 = load i32, i32* %4
%21 = load i32, i32* %9
%22 = load i32, i32* %6
%23 = call i32 @mpfr_subnormalize(i32 %20, i32 %21, i32 %22)
%24 = load i32, i32* %9
%25 = or i32 %24, %23
store i32 %25, i32* %9
%26 = load i32, i32* %7
%27 = call i32 @mpfr_clear(i32 %26)
%28 = load i32, i32* %8
%29 = load i32, i32* %9
%30 = or i32 %28, %29
ret i32 %30
}

LLVM IR (-O2):
define i32 @string_to_fp(i32 %0, i8* %1, i32 %2) {
%4 = tail call i32 @mpfr_init2(i32 undef, i32 100000)
%5 = tail call i32 @mpfr_strtofr(i32 undef, i8* %1, i32* null, i32 0, i32 %2)
%6 = tail call i32 @mpfr_set(i32 %0, i32 undef, i32 %2)
%7 = tail call i32 @mpfr_subnormalize(i32 %0, i32 %6, i32 %2)
%8 = tail call i32 @mpfr_clear(i32 undef)
%9 = or i32 %6, %5
%10 = or i32 %9, %7
ret i32 %10
}