#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*/ mpq_t;

/* Variables and functions */
double INFINITY;
int /*<<< orphan*/ mpq_clear(int /*<<< orphan*/);
int mpq_cmp(int /*<<< orphan*/, int /*<<< orphan*/);
double mpq_get_d(int /*<<< orphan*/);
int /*<<< orphan*/ mpq_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpq_set_d(int /*<<< orphan*/, double);
double nexttoward(double, double);
void convertNum(mpq_t q, int isInfinity, double *inf, double *sup) {
  if (isInfinity > 0) {
    *inf = *sup = +INFINITY;
    return;
  } else if (isInfinity < 0) {
    *inf = *sup = -INFINITY;
    return;
  }
  double d = mpq_get_d(q);
  if (d == +INFINITY) {
    *inf = nexttoward(d, -INFINITY);
    *sup = d;
  } else if (d == -INFINITY) {
    *inf = d;
    *sup = nexttoward(d, +INFINITY);
  } else {
    mpq_t dq;
    mpq_init(dq);
    mpq_set_d(dq, d);
    int cmp = mpq_cmp(q, dq);
    if (cmp > 0) {
      *inf = d;
      *sup = nexttoward(d, +INFINITY);
    } else if (cmp < 0) {
      *inf = nexttoward(d, -INFINITY);
      *sup = d;
    } else {
      *inf = *sup = d;
    }
    mpq_clear(dq);
  }
}


x86 assembly (clang, -O0):
<convertNum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    11a0 <convertNum+0x40>
mov    0x2e61(%rip),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    138e <convertNum+0x22e>
cmpl   $0x0,-0x8(%rbp)
jge    11e1 <convertNum+0x81>
mov    0x2e37(%rip),%rax
movsd  (%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    138e <convertNum+0x22e>
jmp    11e6 <convertNum+0x86>
mov    -0x4(%rbp),%edi
call   1080 <mpq_get_d@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
mov    0x2de9(%rip),%rax
ucomisd (%rax),%xmm0
jne    1255 <convertNum+0xf5>
jp     1255 <convertNum+0xf5>
movsd  -0x20(%rbp),%xmm0
mov    0x2dcd(%rip),%rax
movsd  (%rax),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
call   1030 <nexttoward@plt>
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    138e <convertNum+0x22e>
movsd  -0x20(%rbp),%xmm0
mov    0x2d87(%rip),%rax
movsd  (%rax),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
ucomisd %xmm1,%xmm0
jne    12bb <convertNum+0x15b>
jp     12bb <convertNum+0x15b>
movsd  -0x20(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x20(%rbp),%xmm0
mov    0x2d43(%rip),%rax
movsd  (%rax),%xmm1
call   1030 <nexttoward@plt>
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1389 <convertNum+0x229>
mov    -0x24(%rbp),%edi
call   1060 <mpq_init@plt>
mov    -0x24(%rbp),%edi
movsd  -0x20(%rbp),%xmm0
call   1040 <mpq_set_d@plt>
mov    -0x4(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1070 <mpq_cmp@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jle    1317 <convertNum+0x1b7>
movsd  -0x20(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x20(%rbp),%xmm0
mov    0x2ce7(%rip),%rax
movsd  (%rax),%xmm1
call   1030 <nexttoward@plt>
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1381 <convertNum+0x221>
cmpl   $0x0,-0x28(%rbp)
jge    1367 <convertNum+0x207>
movsd  -0x20(%rbp),%xmm0
mov    0x2cbb(%rip),%rax
movsd  (%rax),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
call   1030 <nexttoward@plt>
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    137c <convertNum+0x21c>
movsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1381 <convertNum+0x221>
mov    -0x24(%rbp),%edi
call   1050 <mpq_clear@plt>
jmp    138e <convertNum+0x22e>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convertNum>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%rbx
test   %esi,%esi
jle    1187 <convertNum+0x27>
mov    0x2e70(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,(%r14)
movsd  %xmm0,(%rbx)
jmp    11fa <convertNum+0x9a>
js     11c1 <convertNum+0x61>
mov    %edi,%ebp
call   1080 <mpq_get_d@plt>
mov    0x2e51(%rip),%r15
movsd  (%r15),%xmm1
ucomisd %xmm1,%xmm0
xorpd  0xe58(%rip),%xmm1
jne    11df <convertNum+0x7f>
jp     11df <convertNum+0x7f>
movsd  %xmm0,(%rsp)
call   1030 <nexttoward@plt>
movsd  %xmm0,(%rbx)
movsd  (%rsp),%xmm0
jmp    11f5 <convertNum+0x95>
mov    0x2e20(%rip),%rax
movsd  (%rax),%xmm0
xorpd  0xe2c(%rip),%xmm0
movlpd %xmm0,(%r14)
movlpd %xmm0,(%rbx)
jmp    11fa <convertNum+0x9a>
ucomisd %xmm1,%xmm0
jne    1205 <convertNum+0xa5>
jp     1205 <convertNum+0xa5>
movsd  %xmm0,(%rbx)
movsd  (%r15),%xmm1
call   1030 <nexttoward@plt>
movsd  %xmm0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
movsd  %xmm0,(%rsp)
call   1060 <mpq_init@plt>
movsd  (%rsp),%xmm0
call   1040 <mpq_set_d@plt>
mov    %ebp,%edi
call   1070 <mpq_cmp@plt>
test   %eax,%eax
jle    123e <convertNum+0xde>
movsd  (%rsp),%xmm0
movsd  %xmm0,(%rbx)
movsd  (%r15),%xmm1
call   1030 <nexttoward@plt>
movsd  %xmm0,(%r14)
jmp    124e <convertNum+0xee>
movsd  (%rsp),%xmm0
js     125d <convertNum+0xfd>
movsd  %xmm0,(%r14)
movsd  %xmm0,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <mpq_clear@plt>
movsd  (%r15),%xmm1
xorpd  0xd96(%rip),%xmm1
call   1030 <nexttoward@plt>
movsd  %xmm0,(%rbx)
movsd  (%rsp),%xmm0
jmp    1237 <convertNum+0xd7>

LLVM IR (-O0):
@INFINITY = global double 0.000000e+00
define void @convertNum(i32 %0, i32 %1, double* %2, double* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca double*
%8 = alloca double*
%9 = alloca double
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store double* %2, double** %7
store double* %3, double** %8
%12 = load i32, i32* %6
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %4
%15 = load double, double* @INFINITY
%16 = load double*, double** %8
store double %15, double* %16
%17 = load double*, double** %7
store double %15, double* %17
br label %91
18: ; preds = %4
%19 = load i32, i32* %6
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = load double, double* @INFINITY
%23 = fneg double %22
%24 = load double*, double** %8
store double %23, double* %24
%25 = load double*, double** %7
store double %23, double* %25
br label %91
26: ; preds = %18
br label %27
27: ; preds = %26
%28 = load i32, i32* %5
%29 = call double @mpq_get_d(i32 %28)
store double %29, double* %9
%30 = load double, double* %9
%31 = load double, double* @INFINITY
%32 = fcmp oeq double %30, %31
br i1 %32, label %33, label %41
33: ; preds = %27
%34 = load double, double* %9
%35 = load double, double* @INFINITY
%36 = fneg double %35
%37 = call double @nexttoward(double %34, double %36)
%38 = load double*, double** %7
store double %37, double* %38
%39 = load double, double* %9
%40 = load double*, double** %8
store double %39, double* %40
br label %91
41: ; preds = %27
%42 = load double, double* %9
%43 = load double, double* @INFINITY
%44 = fneg double %43
%45 = fcmp oeq double %42, %44
br i1 %45, label %46, label %53
46: ; preds = %41
%47 = load double, double* %9
%48 = load double*, double** %7
store double %47, double* %48
%49 = load double, double* %9
%50 = load double, double* @INFINITY
%51 = call double @nexttoward(double %49, double %50)
%52 = load double*, double** %8
store double %51, double* %52
br label %90
53: ; preds = %41
%54 = load i32, i32* %10
%55 = call i32 @mpq_init(i32 %54)
%56 = load i32, i32* %10
%57 = load double, double* %9
%58 = call i32 @mpq_set_d(i32 %56, double %57)
%59 = load i32, i32* %5
%60 = load i32, i32* %10
%61 = call i32 @mpq_cmp(i32 %59, i32 %60)
store i32 %61, i32* %11
%62 = load i32, i32* %11
%63 = icmp sgt i32 %62, 0
br i1 %63, label %64, label %71
64: ; preds = %53
%65 = load double, double* %9
%66 = load double*, double** %7
store double %65, double* %66
%67 = load double, double* %9
%68 = load double, double* @INFINITY
%69 = call double @nexttoward(double %67, double %68)
%70 = load double*, double** %8
store double %69, double* %70
br label %87
71: ; preds = %53
%72 = load i32, i32* %11
%73 = icmp slt i32 %72, 0
br i1 %73, label %74, label %82
74: ; preds = %71
%75 = load double, double* %9
%76 = load double, double* @INFINITY
%77 = fneg double %76
%78 = call double @nexttoward(double %75, double %77)
%79 = load double*, double** %7
store double %78, double* %79
%80 = load double, double* %9
%81 = load double*, double** %8
store double %80, double* %81
br label %86
82: ; preds = %71
%83 = load double, double* %9
%84 = load double*, double** %8
store double %83, double* %84
%85 = load double*, double** %7
store double %83, double* %85
br label %86
86: ; preds = %82, %74
br label %87
87: ; preds = %86, %64
%88 = load i32, i32* %10
%89 = call i32 @mpq_clear(i32 %88)
br label %90
90: ; preds = %87, %46
br label %91
91: ; preds = %14, %21, %90, %33
ret void
}

LLVM IR (-O2):
@INFINITY = global double 0.000000e+00
define void @convertNum(i32 %0, i32 %1, double* nocapture writeonly %2, double* nocapture writeonly %3) {
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = load double, double* @INFINITY
store double %7, double* %3
store double %7, double* %2
br label %42
8: ; preds = %4
%9 = icmp slt i32 %1, 0
br i1 %9, label %10, label %13
10: ; preds = %8
%11 = load double, double* @INFINITY
%12 = fneg double %11
store double %12, double* %3
store double %12, double* %2
br label %42
13: ; preds = %8
%14 = tail call double @mpq_get_d(i32 %0)
%15 = load double, double* @INFINITY
%16 = fcmp oeq double %14, %15
%17 = fneg double %15
br i1 %16, label %18, label %20
18: ; preds = %13
%19 = tail call double @nexttoward(double %14, double %17)
store double %19, double* %2
store double %14, double* %3
br label %42
20: ; preds = %13
%21 = fcmp oeq double %14, %17
br i1 %21, label %22, label %25
22: ; preds = %20
store double %14, double* %2
%23 = load double, double* @INFINITY
%24 = tail call double @nexttoward(double %14, double %23)
store double %24, double* %3
br label %42
25: ; preds = %20
%26 = tail call i32 @mpq_init(i32 undef)
%27 = tail call i32 @mpq_set_d(i32 undef, double %14)
%28 = tail call i32 @mpq_cmp(i32 %0, i32 undef)
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %25
store double %14, double* %2
%31 = load double, double* @INFINITY
%32 = tail call double @nexttoward(double %14, double %31)
store double %32, double* %3
br label %40
33: ; preds = %25
%34 = icmp slt i32 %28, 0
br i1 %34, label %35, label %39
35: ; preds = %33
%36 = load double, double* @INFINITY
%37 = fneg double %36
%38 = tail call double @nexttoward(double %14, double %37)
store double %38, double* %2
store double %14, double* %3
br label %40
39: ; preds = %33
store double %14, double* %3
store double %14, double* %2
br label %40
40: ; preds = %35, %39, %30
%41 = tail call i32 @mpq_clear(i32 undef)
br label %42
42: ; preds = %18, %40, %22, %10, %6
ret void
}