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

/* Variables and functions */
scalar_t__ MPFR_RNDD;
scalar_t__ MPFR_RNDU;
int /*<<< orphan*/ assert(int);
int cmp_rev(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
            int (*)(int /*<<< orphan*/, int /*<<< orphan*/, void const *),
            void const *, int);
int /*<<< orphan*/ mpfr_clear(int /*<<< orphan*/);
int mpfr_cmp(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_get_prec(int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_init2(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_nextabove(int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_nextbelow(int /*<<< orphan*/);
int p1788_rev_lin(mpfr_ptr rop, mpfr_srcptr rlim, mpfr_srcptr op,
                  int (*fwd_fun)(mpfr_ptr rop, mpfr_srcptr op, const void *env),
                  const void *env, int decrease, mpfr_rnd_t rnd) {
  assert(rnd == MPFR_RNDU || rnd == MPFR_RNDD);
  assert(mpfr_cmp(rop, rlim) == (rnd == MPFR_RNDU ? 1 : -1));
  mpfr_t tmp_op;
  mpfr_init2(tmp_op, mpfr_get_prec(op));
  int t;
  for (;;) {
    if (rnd == MPFR_RNDU)
      mpfr_nextbelow(rop);
    else
      mpfr_nextabove(rop);
    if (mpfr_cmp(rop, rlim) != 0) {
      t = -cmp_rev(rop, op, tmp_op, fwd_fun, env, decrease);
      if (t == 0)
        break;
      if (rnd == MPFR_RNDU ? t < 0 : t > 0)
        continue;
    }
    if (rnd == MPFR_RNDU)
      mpfr_nextabove(rop);
    else
      mpfr_nextbelow(rop);
    break;
  }
  mpfr_clear(tmp_op);
  return t;
}


x86 assembly (clang, -O0):
<p1788_rev_lin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x10(%rbp),%rax
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    0x10(%rbp),%rcx
mov    $0x1,%al
mov    0x2e2a(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0x2d(%rbp)
je     11ce <p1788_rev_lin+0x4e>
mov    0x10(%rbp),%rax
mov    0x2e23(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1080 <mpfr_cmp@plt>
mov    0x10(%rbp),%rsi
mov    0x2de7(%rip),%rcx
mov    (%rcx),%rdi
mov    $0xffffffff,%ecx
mov    $0x1,%edx
cmp    %rdi,%rsi
cmove  %edx,%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0xc(%rbp),%edi
call   1090 <mpfr_get_prec@plt>
mov    -0x34(%rbp),%edi
mov    %eax,%esi
call   10a0 <mpfr_init2@plt>
mov    0x10(%rbp),%rax
mov    0x2da2(%rip),%rcx
cmp    (%rcx),%rax
jne    124c <p1788_rev_lin+0xcc>
mov    -0x4(%rbp),%edi
call   1030 <mpfr_nextbelow@plt>
jmp    1254 <p1788_rev_lin+0xd4>
mov    -0x4(%rbp),%edi
call   1050 <mpfr_nextabove@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1080 <mpfr_cmp@plt>
cmp    $0x0,%eax
je     12d1 <p1788_rev_lin+0x151>
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x28(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x24(%rbp),%r9d
call   1060 <cmp_rev@plt>
mov    %eax,%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    129a <p1788_rev_lin+0x11a>
jmp    12ff <p1788_rev_lin+0x17f>
mov    0x10(%rbp),%rax
mov    0x2d33(%rip),%rcx
cmp    (%rcx),%rax
jne    12bd <p1788_rev_lin+0x13d>
cmpl   $0x0,-0x2c(%rbp)
jl     12c7 <p1788_rev_lin+0x147>
jmp    12cc <p1788_rev_lin+0x14c>
cmpl   $0x0,-0x2c(%rbp)
jle    12cc <p1788_rev_lin+0x14c>
jmp    122b <p1788_rev_lin+0xab>
jmp    12d1 <p1788_rev_lin+0x151>
mov    0x10(%rbp),%rax
mov    0x2cfc(%rip),%rcx
cmp    (%rcx),%rax
jne    12f2 <p1788_rev_lin+0x172>
mov    -0x4(%rbp),%edi
call   1050 <mpfr_nextabove@plt>
jmp    12fa <p1788_rev_lin+0x17a>
mov    -0x4(%rbp),%edi
call   1030 <mpfr_nextbelow@plt>
jmp    12ff <p1788_rev_lin+0x17f>
mov    -0x28(%rbp),%edi
call   1040 <mpfr_clear@plt>
mov    -0x2c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<p1788_rev_lin>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x50(%rsp),%r15
mov    0x2e3e(%rip),%r14
cmp    %r15,(%r14)
sete   %al
mov    0x2e41(%rip),%rbp
cmp    %r15,0x0(%rbp)
mov    %r9d,0xc(%rsp)
mov    %r8,0x10(%rsp)
mov    %rcx,%r12
mov    %edx,%r13d
mov    %esi,%ebp
mov    %edi,%ebx
sete   %cl
or     %al,%cl
movzbl %cl,%edi
call   1070 <assert@plt>
mov    %ebx,%edi
mov    %ebp,%esi
call   1080 <mpfr_cmp@plt>
xor    %ecx,%ecx
cmp    %r15,(%r14)
sete   %cl
add    %ecx,%ecx
add    $0xffffffff,%ecx
xor    %edi,%edi
cmp    %ecx,%eax
sete   %dil
call   1070 <assert@plt>
mov    %r13d,%edi
call   1090 <mpfr_get_prec@plt>
mov    %eax,%esi
call   10a0 <mpfr_init2@plt>
mov    (%r14),%rcx
jmp    1214 <p1788_rev_lin+0x94>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
test   %eax,%eax
jns    1282 <p1788_rev_lin+0x102>
mov    %ebx,%edi
cmp    %r15,%rcx
jne    1230 <p1788_rev_lin+0xb0>
call   1030 <mpfr_nextbelow@plt>
jmp    1235 <p1788_rev_lin+0xb5>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
call   1050 <mpfr_nextabove@plt>
mov    %ebx,%edi
mov    %ebp,%esi
call   1080 <mpfr_cmp@plt>
test   %eax,%eax
je     1278 <p1788_rev_lin+0xf8>
mov    %ebx,%edi
mov    %r13d,%esi
mov    %r12,%rcx
mov    0x10(%rsp),%r8
mov    0xc(%rsp),%r9d
call   1060 <cmp_rev@plt>
test   %eax,%eax
je     1290 <p1788_rev_lin+0x110>
mov    %eax,%r14d
neg    %r14d
mov    0x2d6e(%rip),%rcx
mov    (%rcx),%rcx
cmp    %r15,%rcx
jne    1210 <p1788_rev_lin+0x90>
test   %eax,%eax
jg     1214 <p1788_rev_lin+0x94>
jmp    1282 <p1788_rev_lin+0x102>
mov    0x2d59(%rip),%rax
mov    (%rax),%rcx
mov    %ebx,%edi
cmp    %r15,%rcx
jne    1295 <p1788_rev_lin+0x115>
call   1050 <mpfr_nextabove@plt>
jmp    129a <p1788_rev_lin+0x11a>
xor    %r14d,%r14d
jmp    129a <p1788_rev_lin+0x11a>
call   1030 <mpfr_nextbelow@plt>
call   1040 <mpfr_clear@plt>
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@MPFR_RNDU = global i64 0
@MPFR_RNDD = global i64 0
define i32 @p1788_rev_lin(i32 %0, i32 %1, i32 %2, i32 (i32, i32, i8*)* %3, i8* %4, i32 %5, i64 %6) {
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32 (i32, i32, i8*)*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i64
%15 = alloca i32
%16 = alloca i32
store i32 %0, i32* %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i32 (i32, i32, i8*)* %3, i32 (i32, i32, i8*)** %11
store i8* %4, i8** %12
store i32 %5, i32* %13
store i64 %6, i64* %14
%17 = load i64, i64* %14
%18 = load i64, i64* @MPFR_RNDU
%19 = icmp eq i64 %17, %18
br i1 %19, label %24, label %20
20: ; preds = %7
%21 = load i64, i64* %14
%22 = load i64, i64* @MPFR_RNDD
%23 = icmp eq i64 %21, %22
br label %24
24: ; preds = %20, %7
%25 = phi i1 [ true, %7 ], [ %23, %20 ]
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
%28 = load i32, i32* %8
%29 = load i32, i32* %9
%30 = call i32 @mpfr_cmp(i32 %28, i32 %29)
%31 = load i64, i64* %14
%32 = load i64, i64* @MPFR_RNDU
%33 = icmp eq i64 %31, %32
%34 = zext i1 %33 to i64
%35 = select i1 %33, i32 1, i32 -1
%36 = icmp eq i32 %30, %35
%37 = zext i1 %36 to i32
%38 = call i32 @assert(i32 %37)
%39 = load i32, i32* %15
%40 = load i32, i32* %10
%41 = call i32 @mpfr_get_prec(i32 %40)
%42 = call i32 @mpfr_init2(i32 %39, i32 %41)
br label %43
43: ; preds = %80, %24
%44 = load i64, i64* %14
%45 = load i64, i64* @MPFR_RNDU
%46 = icmp eq i64 %44, %45
br i1 %46, label %47, label %50
47: ; preds = %43
%48 = load i32, i32* %8
%49 = call i32 @mpfr_nextbelow(i32 %48)
br label %53
50: ; preds = %43
%51 = load i32, i32* %8
%52 = call i32 @mpfr_nextabove(i32 %51)
br label %53
53: ; preds = %50, %47
%54 = load i32, i32* %8
%55 = load i32, i32* %9
%56 = call i32 @mpfr_cmp(i32 %54, i32 %55)
%57 = icmp ne i32 %56, 0
br i1 %57, label %58, label %82
58: ; preds = %53
%59 = load i32, i32* %8
%60 = load i32, i32* %10
%61 = load i32, i32* %15
%62 = load i32 (i32, i32, i8*)*, i32 (i32, i32, i8*)** %11
%63 = load i8*, i8** %12
%64 = load i32, i32* %13
%65 = call i32 @cmp_rev(i32 %59, i32 %60, i32 %61, i32 (i32, i32, i8*)* %62, i8* %63, i32 %64)
%66 = sub nsw i32 0, %65
store i32 %66, i32* %16
%67 = load i32, i32* %16
%68 = icmp eq i32 %67, 0
br i1 %68, label %69, label %70
69: ; preds = %58
br label %93
70: ; preds = %58
%71 = load i64, i64* %14
%72 = load i64, i64* @MPFR_RNDU
%73 = icmp eq i64 %71, %72
br i1 %73, label %74, label %77
74: ; preds = %70
%75 = load i32, i32* %16
%76 = icmp slt i32 %75, 0
br i1 %76, label %80, label %81
77: ; preds = %70
%78 = load i32, i32* %16
%79 = icmp sgt i32 %78, 0
br i1 %79, label %80, label %81
80: ; preds = %77, %74
br label %43
81: ; preds = %77, %74
br label %82
82: ; preds = %81, %53
%83 = load i64, i64* %14
%84 = load i64, i64* @MPFR_RNDU
%85 = icmp eq i64 %83, %84
br i1 %85, label %86, label %89
86: ; preds = %82
%87 = load i32, i32* %8
%88 = call i32 @mpfr_nextabove(i32 %87)
br label %92
89: ; preds = %82
%90 = load i32, i32* %8
%91 = call i32 @mpfr_nextbelow(i32 %90)
br label %92
92: ; preds = %89, %86
br label %93
93: ; preds = %92, %69
%94 = load i32, i32* %15
%95 = call i32 @mpfr_clear(i32 %94)
%96 = load i32, i32* %16
ret i32 %96
}

LLVM IR (-O2):
@MPFR_RNDU = global i64 0
@MPFR_RNDD = global i64 0
define i32 @p1788_rev_lin(i32 %0, i32 %1, i32 %2, i32 (i32, i32, i8*)* %3, i8* %4, i32 %5, i64 %6) {
%8 = load i64, i64* @MPFR_RNDU
%9 = icmp eq i64 %8, %6
%10 = load i64, i64* @MPFR_RNDD
%11 = icmp eq i64 %10, %6
%12 = select i1 %9, i1 true, i1 %11
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = tail call i32 @mpfr_cmp(i32 %0, i32 %1)
%16 = load i64, i64* @MPFR_RNDU
%17 = icmp eq i64 %16, %6
%18 = select i1 %17, i32 1, i32 -1
%19 = icmp eq i32 %15, %18
%20 = zext i1 %19 to i32
%21 = tail call i32 @assert(i32 %20)
%22 = tail call i32 @mpfr_get_prec(i32 %2)
%23 = tail call i32 @mpfr_init2(i32 undef, i32 %22)
%24 = load i64, i64* @MPFR_RNDU
br label %25
25: ; preds = %49, %7
%26 = phi i64 [ %24, %7 ], [ %43, %49 ]
%27 = phi i32 [ undef, %7 ], [ %40, %49 ]
%28 = icmp eq i64 %26, %6
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = tail call i32 @mpfr_nextbelow(i32 %0)
br label %33
31: ; preds = %25
%32 = tail call i32 @mpfr_nextabove(i32 %0)
br label %33
33: ; preds = %31, %29
%34 = tail call i32 @mpfr_cmp(i32 %0, i32 %1)
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = load i64, i64* @MPFR_RNDU
br label %50
38: ; preds = %33
%39 = tail call i32 @cmp_rev(i32 %0, i32 %2, i32 undef, i32 (i32, i32, i8*)* %3, i8* %4, i32 %5)
%40 = sub nsw i32 0, %39
%41 = icmp eq i32 %39, 0
br i1 %41, label %58, label %42
42: ; preds = %38
%43 = load i64, i64* @MPFR_RNDU
%44 = icmp eq i64 %43, %6
br i1 %44, label %45, label %47
45: ; preds = %42
%46 = icmp sgt i32 %39, 0
br i1 %46, label %49, label %50
47: ; preds = %42
%48 = icmp slt i32 %39, 0
br i1 %48, label %49, label %50
49: ; preds = %47, %45
br label %25
50: ; preds = %45, %47, %36
%51 = phi i64 [ %37, %36 ], [ %43, %47 ], [ %43, %45 ]
%52 = phi i32 [ %27, %36 ], [ %40, %47 ], [ %40, %45 ]
%53 = icmp eq i64 %51, %6
br i1 %53, label %54, label %56
54: ; preds = %50
%55 = tail call i32 @mpfr_nextabove(i32 %0)
br label %58
56: ; preds = %50
%57 = tail call i32 @mpfr_nextbelow(i32 %0)
br label %58
58: ; preds = %38, %54, %56
%59 = phi i32 [ %52, %54 ], [ %52, %56 ], [ 0, %38 ]
%60 = tail call i32 @mpfr_clear(i32 undef)
ret i32 %59
}