#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;

/* Variables and functions */
int /*<<< orphan*/ MPFR_RNDD;
int /*<<< orphan*/ MPFR_RNDN;
int /*<<< orphan*/ MPFR_RNDU;
int /*<<< orphan*/ MPFR_RNDZ;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ mpfr_clear(int /*<<< orphan*/);
scalar_t__ mpfr_cmpabs(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_init2(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpfr_printf(char *, char *);
int /*<<< orphan*/ mpfr_set_default_prec(int);
int /*<<< orphan*/ mpfr_set_emax(int);
int /*<<< orphan*/ mpfr_set_emin(int);
int /*<<< orphan*/ mpfr_set_str(int /*<<< orphan*/, char *, int /*<<< orphan*/,
                                int /*<<< orphan*/);
int /*<<< orphan*/ print_fp(int /*<<< orphan*/, char const *, char *);
int string_to_fp(int /*<<< orphan*/, char const *, int /*<<< orphan*/);
void round_str(const char *s, const char *suffix, int prec, int emin, int emax,
               bool need_exact) {
  mpfr_t f;
  mpfr_set_default_prec(prec);
  mpfr_set_emin(emin);
  mpfr_set_emax(emax);
  mpfr_init(f);
  int r = string_to_fp(f, s, MPFR_RNDD);
  if (need_exact) {
    assert(prec == 106 && emin == -1073 && emax == 1024);
    mpfr_t max_value;
    mpfr_init2(max_value, 107);
    mpfr_set_str(max_value, "0x1.fffffffffffff7ffffffffffffcp+1023", 0,
                 MPFR_RNDN);
    if (mpfr_cmpabs(f, max_value) > 0)
      r = 1;
    mpfr_printf("\t%s,\n", r ? "false" : "true");
    mpfr_clear(max_value);
  }
  print_fp(f, suffix, ",\n");
  string_to_fp(f, s, MPFR_RNDN);
  print_fp(f, suffix, ",\n");
  string_to_fp(f, s, MPFR_RNDZ);
  print_fp(f, suffix, ",\n");
  string_to_fp(f, s, MPFR_RNDU);
  print_fp(f, suffix, "");
  mpfr_clear(f);
}


x86 assembly (clang, -O0):
<round_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9d,-0x20(%rbp)
mov    -0x14(%rbp),%edi
call   10c0 <mpfr_set_default_prec@plt>
mov    -0x18(%rbp),%edi
call   1060 <mpfr_set_emin@plt>
mov    -0x1c(%rbp),%edi
call   10a0 <mpfr_set_emax@plt>
mov    -0x24(%rbp),%edi
call   1040 <mpfr_init@plt>
mov    -0x24(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    0x2dcc(%rip),%rax
mov    (%rax),%edx
call   1030 <string_to_fp@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     12ca <round_str+0x10a>
xor    %eax,%eax
cmpl   $0x6a,-0x14(%rbp)
mov    %al,-0x2d(%rbp)
jne    124e <round_str+0x8e>
xor    %eax,%eax
cmpl   $0xfffffbcf,-0x18(%rbp)
mov    %al,-0x2d(%rbp)
jne    124e <round_str+0x8e>
cmpl   $0x400,-0x1c(%rbp)
sete   %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x2c(%rbp),%edi
mov    $0x6b,%esi
call   10e0 <mpfr_init2@plt>
mov    -0x2c(%rbp),%edi
mov    0x2d76(%rip),%rax
mov    (%rax),%ecx
lea    0xd85(%rip),%rsi
xor    %edx,%edx
call   10b0 <mpfr_set_str@plt>
mov    -0x24(%rbp),%edi
mov    -0x2c(%rbp),%esi
call   10d0 <mpfr_cmpabs@plt>
cmp    $0x0,%rax
jle    129e <round_str+0xde>
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%ecx
lea    0xd8a(%rip),%rsi
lea    0xd7d(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
lea    0xd69(%rip),%rdi
call   1080 <mpfr_printf@plt>
mov    -0x2c(%rbp),%edi
call   1070 <mpfr_clear@plt>
mov    -0x24(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xd51(%rip),%rdx
call   1050 <print_fp@plt>
mov    -0x24(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    0x2cfd(%rip),%rax
mov    (%rax),%edx
call   1030 <string_to_fp@plt>
mov    -0x24(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xd29(%rip),%rdx
call   1050 <print_fp@plt>
mov    -0x24(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    0x2ccd(%rip),%rax
mov    (%rax),%edx
call   1030 <string_to_fp@plt>
mov    -0x24(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xd01(%rip),%rdx
call   1050 <print_fp@plt>
mov    -0x24(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    0x2c8d(%rip),%rax
mov    (%rax),%edx
call   1030 <string_to_fp@plt>
mov    -0x24(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xcdb(%rip),%rdx
call   1050 <print_fp@plt>
mov    -0x24(%rbp),%edi
call   1070 <mpfr_clear@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<round_str>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,%r15d
mov    %r8d,%ebp
mov    %ecx,%ebx
mov    %edx,%r13d
mov    %rsi,%r14
mov    %rdi,%r12
mov    %edx,%edi
call   10c0 <mpfr_set_default_prec@plt>
mov    %ebx,%edi
call   1060 <mpfr_set_emin@plt>
mov    %ebp,%edi
call   10a0 <mpfr_set_emax@plt>
call   1040 <mpfr_init@plt>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rsi
call   1030 <string_to_fp@plt>
test   %r15d,%r15d
je     1280 <round_str+0xc0>
xor    $0x6a,%r13d
xor    $0xfffffbcf,%ebx
or     %r13d,%ebx
xor    $0x400,%ebp
xor    %edi,%edi
or     %ebx,%ebp
sete   %dil
mov    %eax,%ebx
call   1090 <assert@plt>
mov    $0x6b,%esi
call   10e0 <mpfr_init2@plt>
mov    0x2da9(%rip),%rax
mov    (%rax),%ecx
lea    0xdb8(%rip),%rsi
xor    %edx,%edx
call   10b0 <mpfr_set_str@plt>
call   10d0 <mpfr_cmpabs@plt>
test   %ebx,%ebx
lea    0xdd5(%rip),%rsi
lea    0xdc8(%rip),%rcx
cmovne %rcx,%rsi
test   %rax,%rax
cmovg  %rcx,%rsi
lea    0xdb0(%rip),%rdi
call   1080 <mpfr_printf@plt>
call   1070 <mpfr_clear@plt>
lea    0xda2(%rip),%rbx
mov    %r14,%rsi
mov    %rbx,%rdx
call   1050 <print_fp@plt>
mov    0x2d4f(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rsi
call   1030 <string_to_fp@plt>
mov    %r14,%rsi
mov    %rbx,%rdx
call   1050 <print_fp@plt>
mov    0x2d2b(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rsi
call   1030 <string_to_fp@plt>
mov    %r14,%rsi
mov    %rbx,%rdx
call   1050 <print_fp@plt>
mov    0x2cf7(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rsi
call   1030 <string_to_fp@plt>
lea    0xd49(%rip),%rdx
mov    %r14,%rsi
call   1050 <print_fp@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <mpfr_clear@plt>

LLVM IR (-O0):
@MPFR_RNDD = global i32 0
@.str = [38 x i8] c"0x1.fffffffffffff7ffffffffffffcp+1023\00"
@MPFR_RNDN = global i32 0
@.str.1 = [6 x i8] c"\09%s,\0A\00"
@.str.2 = [6 x i8] c"false\00"
@.str.3 = [5 x i8] c"true\00"
@.str.4 = [3 x i8] c",\0A\00"
@MPFR_RNDZ = global i32 0
@MPFR_RNDU = global i32 0
@.str.5 = [1 x i8] zeroinitializer
define void @round_str(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i8* %0, i8** %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 %5, i32* %12
%16 = load i32, i32* %9
%17 = call i32 @mpfr_set_default_prec(i32 %16)
%18 = load i32, i32* %10
%19 = call i32 @mpfr_set_emin(i32 %18)
%20 = load i32, i32* %11
%21 = call i32 @mpfr_set_emax(i32 %20)
%22 = load i32, i32* %13
%23 = call i32 @mpfr_init(i32 %22)
%24 = load i32, i32* %13
%25 = load i8*, i8** %7
%26 = load i32, i32* @MPFR_RNDD
%27 = call i32 @string_to_fp(i32 %24, i8* %25, i32 %26)
store i32 %27, i32* %14
%28 = load i32, i32* %12
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %61
30: ; preds = %6
%31 = load i32, i32* %9
%32 = icmp eq i32 %31, 106
br i1 %32, label %33, label %39
33: ; preds = %30
%34 = load i32, i32* %10
%35 = icmp eq i32 %34, -1073
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = load i32, i32* %11
%38 = icmp eq i32 %37, 1024
br label %39
39: ; preds = %36, %33, %30
%40 = phi i1 [ false, %33 ], [ false, %30 ], [ %38, %36 ]
%41 = zext i1 %40 to i32
%42 = call i32 @assert(i32 %41)
%43 = load i32, i32* %15
%44 = call i32 @mpfr_init2(i32 %43, i32 107)
%45 = load i32, i32* %15
%46 = load i32, i32* @MPFR_RNDN
%47 = call i32 @mpfr_set_str(i32 %45, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 0, i32 %46)
%48 = load i32, i32* %13
%49 = load i32, i32* %15
%50 = call i64 @mpfr_cmpabs(i32 %48, i32 %49)
%51 = icmp sgt i64 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %39
store i32 1, i32* %14
br label %53
53: ; preds = %52, %39
%54 = load i32, i32* %14
%55 = icmp ne i32 %54, 0
%56 = zext i1 %55 to i64
%57 = select i1 %55, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0)
%58 = call i32 @mpfr_printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %57)
%59 = load i32, i32* %15
%60 = call i32 @mpfr_clear(i32 %59)
br label %61
61: ; preds = %53, %6
%62 = load i32, i32* %13
%63 = load i8*, i8** %8
%64 = call i32 @print_fp(i32 %62, i8* %63, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%65 = load i32, i32* %13
%66 = load i8*, i8** %7
%67 = load i32, i32* @MPFR_RNDN
%68 = call i32 @string_to_fp(i32 %65, i8* %66, i32 %67)
%69 = load i32, i32* %13
%70 = load i8*, i8** %8
%71 = call i32 @print_fp(i32 %69, i8* %70, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%72 = load i32, i32* %13
%73 = load i8*, i8** %7
%74 = load i32, i32* @MPFR_RNDZ
%75 = call i32 @string_to_fp(i32 %72, i8* %73, i32 %74)
%76 = load i32, i32* %13
%77 = load i8*, i8** %8
%78 = call i32 @print_fp(i32 %76, i8* %77, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%79 = load i32, i32* %13
%80 = load i8*, i8** %7
%81 = load i32, i32* @MPFR_RNDU
%82 = call i32 @string_to_fp(i32 %79, i8* %80, i32 %81)
%83 = load i32, i32* %13
%84 = load i8*, i8** %8
%85 = call i32 @print_fp(i32 %83, i8* %84, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0))
%86 = load i32, i32* %13
%87 = call i32 @mpfr_clear(i32 %86)
ret void
}

LLVM IR (-O2):
@MPFR_RNDD = global i32 0
@.str = [38 x i8] c"0x1.fffffffffffff7ffffffffffffcp+1023\00"
@MPFR_RNDN = global i32 0
@.str.1 = [6 x i8] c"\09%s,\0A\00"
@.str.2 = [6 x i8] c"false\00"
@.str.3 = [5 x i8] c"true\00"
@.str.4 = [3 x i8] c",\0A\00"
@MPFR_RNDZ = global i32 0
@MPFR_RNDU = global i32 0
@.str.5 = [1 x i8] zeroinitializer
define void @round_str(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = tail call i32 @mpfr_set_default_prec(i32 %2)
%8 = tail call i32 @mpfr_set_emin(i32 %3)
%9 = tail call i32 @mpfr_set_emax(i32 %4)
%10 = tail call i32 @mpfr_init(i32 undef)
%11 = load i32, i32* @MPFR_RNDD
%12 = tail call i32 @string_to_fp(i32 undef, i8* %0, i32 %11)
%13 = icmp eq i32 %5, 0
br i1 %13, label %32, label %14
14: ; preds = %6
%15 = icmp eq i32 %2, 106
%16 = icmp eq i32 %3, -1073
%17 = and i1 %15, %16
%18 = icmp eq i32 %4, 1024
%19 = and i1 %17, %18
%20 = zext i1 %19 to i32
%21 = tail call i32 @assert(i32 %20)
%22 = tail call i32 @mpfr_init2(i32 undef, i32 107)
%23 = load i32, i32* @MPFR_RNDN
%24 = tail call i32 @mpfr_set_str(i32 undef, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 0, i32 %23)
%25 = tail call i64 @mpfr_cmpabs(i32 undef, i32 undef)
%26 = icmp slt i64 %25, 1
%27 = icmp eq i32 %12, 0
%28 = select i1 %26, i1 %27, i1 false
%29 = select i1 %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0)
%30 = tail call i32 @mpfr_printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = tail call i32 @mpfr_clear(i32 undef)
br label %32
32: ; preds = %14, %6
%33 = tail call i32 @print_fp(i32 undef, i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%34 = load i32, i32* @MPFR_RNDN
%35 = tail call i32 @string_to_fp(i32 undef, i8* %0, i32 %34)
%36 = tail call i32 @print_fp(i32 undef, i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%37 = load i32, i32* @MPFR_RNDZ
%38 = tail call i32 @string_to_fp(i32 undef, i8* %0, i32 %37)
%39 = tail call i32 @print_fp(i32 undef, i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%40 = load i32, i32* @MPFR_RNDU
%41 = tail call i32 @string_to_fp(i32 undef, i8* %0, i32 %40)
%42 = tail call i32 @print_fp(i32 undef, i8* %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0))
%43 = tail call i32 @mpfr_clear(i32 undef)
ret void
}