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

/* Variables and functions */
int mpfr_cmp(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_get_emax();
int /*<<< orphan*/ mpfr_get_emax_max();
int /*<<< orphan*/ mpfr_get_emin();
int /*<<< orphan*/ mpfr_get_emin_min();
int /*<<< orphan*/ mpfr_get_exp(int /*<<< orphan*/);
scalar_t__ mpfr_regular_p(int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_set_emax(int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_set_emin(int /*<<< orphan*/);
int stub1(int /*<<< orphan*/, int /*<<< orphan*/, void const *);
int cmp_rev(mpfr_ptr r, mpfr_srcptr c, mpfr_t tmp,
            int (*fwd_fun)(mpfr_ptr rop, mpfr_srcptr op, const void *env),
            const void *env, int decrease) {
  mpfr_exp_t saved_emin = mpfr_get_emin();
  mpfr_exp_t saved_emax = mpfr_get_emax();
  if (mpfr_regular_p(c)) {
    mpfr_set_emin(mpfr_get_exp(c));
    mpfr_set_emax(mpfr_get_exp(c));
  } else {
    mpfr_set_emin(mpfr_get_emin_min());
    mpfr_set_emax(mpfr_get_emax_max());
  }
  int t = (*fwd_fun)(tmp, r, env);
  mpfr_set_emin(saved_emin);
  mpfr_set_emax(saved_emax);
  int cmp = mpfr_cmp(c, tmp);
  if (cmp == 0)
    cmp = t;
  if (!decrease)
    cmp = -cmp;
  return cmp;
}


x86 assembly (clang, -O0):
<cmp_rev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
mov    $0x0,%al
call   1060 <mpfr_get_emin@plt>
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1070 <mpfr_get_emax@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%edi
call   10a0 <mpfr_regular_p@plt>
cmp    $0x0,%rax
je     11f6 <cmp_rev+0x66>
mov    -0x8(%rbp),%edi
call   1040 <mpfr_get_exp@plt>
mov    %eax,%edi
call   1030 <mpfr_set_emin@plt>
mov    -0x8(%rbp),%edi
call   1040 <mpfr_get_exp@plt>
mov    %eax,%edi
call   1050 <mpfr_set_emax@plt>
jmp    1212 <cmp_rev+0x82>
mov    $0x0,%al
call   10b0 <mpfr_get_emin_min@plt>
mov    %eax,%edi
call   1030 <mpfr_set_emin@plt>
mov    $0x0,%al
call   1080 <mpfr_get_emax_max@plt>
mov    %eax,%edi
call   1050 <mpfr_set_emax@plt>
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   *%rax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%edi
call   1030 <mpfr_set_emin@plt>
mov    -0x2c(%rbp),%edi
call   1050 <mpfr_set_emax@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1090 <mpfr_cmp@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jne    1253 <cmp_rev+0xc3>
mov    -0x30(%rbp),%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    1265 <cmp_rev+0xd5>
xor    %eax,%eax
sub    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmp_rev>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,0xc(%rsp)
mov    %r8,%rbp
mov    %rcx,0x10(%rsp)
mov    %edx,%r12d
mov    %esi,%ebx
mov    %edi,%r13d
xor    %eax,%eax
call   1060 <mpfr_get_emin@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1070 <mpfr_get_emax@plt>
mov    %eax,%r15d
mov    %ebx,%edi
call   10a0 <mpfr_regular_p@plt>
test   %rax,%rax
je     11ea <cmp_rev+0x5a>
mov    %ebx,%edi
call   1040 <mpfr_get_exp@plt>
mov    %eax,%edi
call   1030 <mpfr_set_emin@plt>
mov    %ebx,%edi
call   1040 <mpfr_get_exp@plt>
jmp    11ff <cmp_rev+0x6f>
xor    %eax,%eax
call   10b0 <mpfr_get_emin_min@plt>
mov    %eax,%edi
call   1030 <mpfr_set_emin@plt>
xor    %eax,%eax
call   1080 <mpfr_get_emax_max@plt>
mov    %eax,%edi
call   1050 <mpfr_set_emax@plt>
mov    %r12d,%edi
mov    %r13d,%esi
mov    %rbp,%rdx
call   *0x10(%rsp)
mov    %eax,%ebp
mov    %r14d,%edi
call   1030 <mpfr_set_emin@plt>
mov    %r15d,%edi
call   1050 <mpfr_set_emax@plt>
mov    %ebx,%edi
mov    %r12d,%esi
call   1090 <mpfr_cmp@plt>
test   %eax,%eax
cmove  %ebp,%eax
mov    %eax,%ecx
neg    %ecx
cmpl   $0x0,0xc(%rsp)
cmove  %ecx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @cmp_rev(i32 %0, i32 %1, i32 %2, i32 (i32, i32, i8*)* %3, i8* %4, i32 %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32 (i32, i32, i8*)*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 (i32, i32, i8*)* %3, i32 (i32, i32, i8*)** %10
store i8* %4, i8** %11
store i32 %5, i32* %12
%17 = call i32 (...) @mpfr_get_emin()
store i32 %17, i32* %13
%18 = call i32 (...) @mpfr_get_emax()
store i32 %18, i32* %14
%19 = load i32, i32* %8
%20 = call i64 @mpfr_regular_p(i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %29
22: ; preds = %6
%23 = load i32, i32* %8
%24 = call i32 @mpfr_get_exp(i32 %23)
%25 = call i32 @mpfr_set_emin(i32 %24)
%26 = load i32, i32* %8
%27 = call i32 @mpfr_get_exp(i32 %26)
%28 = call i32 @mpfr_set_emax(i32 %27)
br label %34
29: ; preds = %6
%30 = call i32 (...) @mpfr_get_emin_min()
%31 = call i32 @mpfr_set_emin(i32 %30)
%32 = call i32 (...) @mpfr_get_emax_max()
%33 = call i32 @mpfr_set_emax(i32 %32)
br label %34
34: ; preds = %29, %22
%35 = load i32 (i32, i32, i8*)*, i32 (i32, i32, i8*)** %10
%36 = load i32, i32* %9
%37 = load i32, i32* %7
%38 = load i8*, i8** %11
%39 = call i32 %35(i32 %36, i32 %37, i8* %38)
store i32 %39, i32* %15
%40 = load i32, i32* %13
%41 = call i32 @mpfr_set_emin(i32 %40)
%42 = load i32, i32* %14
%43 = call i32 @mpfr_set_emax(i32 %42)
%44 = load i32, i32* %8
%45 = load i32, i32* %9
%46 = call i32 @mpfr_cmp(i32 %44, i32 %45)
store i32 %46, i32* %16
%47 = load i32, i32* %16
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %34
%50 = load i32, i32* %15
store i32 %50, i32* %16
br label %51
51: ; preds = %49, %34
%52 = load i32, i32* %12
%53 = icmp ne i32 %52, 0
br i1 %53, label %57, label %54
54: ; preds = %51
%55 = load i32, i32* %16
%56 = sub nsw i32 0, %55
store i32 %56, i32* %16
br label %57
57: ; preds = %54, %51
%58 = load i32, i32* %16
ret i32 %58
}

LLVM IR (-O2):
define i32 @cmp_rev(i32 %0, i32 %1, i32 %2, i32 (i32, i32, i8*)* nocapture %3, i8* %4, i32 %5) {
%7 = tail call i32 (...) @mpfr_get_emin()
%8 = tail call i32 (...) @mpfr_get_emax()
%9 = tail call i64 @mpfr_regular_p(i32 %1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %6
%12 = tail call i32 @mpfr_get_exp(i32 %1)
%13 = tail call i32 @mpfr_set_emin(i32 %12)
%14 = tail call i32 @mpfr_get_exp(i32 %1)
br label %19
15: ; preds = %6
%16 = tail call i32 (...) @mpfr_get_emin_min()
%17 = tail call i32 @mpfr_set_emin(i32 %16)
%18 = tail call i32 (...) @mpfr_get_emax_max()
br label %19
19: ; preds = %15, %11
%20 = phi i32 [ %18, %15 ], [ %14, %11 ]
%21 = tail call i32 @mpfr_set_emax(i32 %20)
%22 = tail call i32 %3(i32 %2, i32 %0, i8* %4)
%23 = tail call i32 @mpfr_set_emin(i32 %7)
%24 = tail call i32 @mpfr_set_emax(i32 %8)
%25 = tail call i32 @mpfr_cmp(i32 %1, i32 %2)
%26 = icmp eq i32 %25, 0
%27 = select i1 %26, i32 %22, i32 %25
%28 = icmp eq i32 %5, 0
%29 = sub nsw i32 0, %27
%30 = select i1 %28, i32 %29, i32 %27
ret i32 %30
}