#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*/ mpz_t;
typedef int /*<<< orphan*/ mpf_t;

/* Variables and functions */
int /*<<< orphan*/ mpf_clear(int /*<<< orphan*/);
int /*<<< orphan*/ mpf_div(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
double mpf_get_d(int /*<<< orphan*/);
int /*<<< orphan*/ mpf_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpf_set_z(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_abs(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/);
scalar_t__ mpz_cmp(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_fac_ui(int /*<<< orphan*/, long);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_mul(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpz_set(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_sqrt(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_sub(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpz_tdiv_q(int /*<<< orphan*/, int /*<<< orphan*/,
                              int /*<<< orphan*/);
int /*<<< orphan*/ mpz_tdiv_q_2exp(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
long int compute_space_dimensions(long int n, mpz_t num_rows, mpz_t num_col) {
  mpz_t fact;
  mpz_init(fact);
  mpz_t rnf;
  mpz_init(rnf);
  mpz_t tmp;
  mpz_init(tmp);
  mpz_t diff;
  mpz_init(diff);
  mpz_fac_ui(fact, n);
  mpz_sqrt(rnf, fact);
  mpz_set(diff, fact);
  long int count = 1;
  do {
    mpz_set(tmp, diff);
    mpz_fac_ui(num_col, n - count);
    mpz_tdiv_q_2exp(num_col, num_col, 1);
    mpz_tdiv_q(num_rows, fact, num_col);
    mpz_sub(diff, num_col, num_rows);
    mpz_abs(diff, diff);
    count++;
  } while (mpz_cmp(tmp, diff) >= 0);
  mpz_clear(diff);
  mpz_clear(rnf);
  mpz_clear(tmp);
  long int short_perm = n - (count - 2);
  mpz_fac_ui(num_col, short_perm);
  mpz_tdiv_q_2exp(num_col, num_col, 1);
  mpz_tdiv_q(num_rows, fact, num_col);
  mpz_t fact_check;
  mpz_init(fact_check);
  mpz_mul(fact_check, num_rows, num_col);
  if (mpz_cmp(fact, fact_check) != 0) {
    printf("error, the space does not have the number of solutions as n!\n");
  }
  mpz_clear(fact_check);
  mpz_clear(fact);
  mpf_t ratio_q, num_rows_f, num_col_f;
  mpf_init(ratio_q);
  mpf_init(num_rows_f);
  mpf_init(num_col_f);
  mpf_set_z(num_rows_f, num_rows);
  mpf_set_z(num_col_f, num_col);
  mpf_div(ratio_q, num_col_f, num_rows_f);
  double ratio_q_d = mpf_get_d(ratio_q);
  mpf_clear(num_rows_f);
  mpf_clear(num_col_f);
  mpf_clear(ratio_q);
  printf("\nthe ratio: %f\n", ratio_q_d);
  return short_perm;
}


x86 assembly (clang, -O0):
<compute_space_dimensions>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <mpz_init@plt>
mov    -0x18(%rbp),%edi
call   1060 <mpz_init@plt>
mov    -0x1c(%rbp),%edi
call   1060 <mpz_init@plt>
mov    -0x20(%rbp),%edi
call   1060 <mpz_init@plt>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   10b0 <mpz_fac_ui@plt>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
call   10e0 <mpz_sqrt@plt>
mov    -0x20(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1030 <mpz_set@plt>
movq   $0x1,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1030 <mpz_set@plt>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%rsi
sub    -0x28(%rbp),%rsi
call   10b0 <mpz_fac_ui@plt>
mov    -0x10(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    $0x1,%edx
call   10d0 <mpz_tdiv_q_2exp@plt>
mov    -0xc(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1130 <mpz_tdiv_q@plt>
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1040 <mpz_sub@plt>
mov    -0x20(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1090 <mpz_abs@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
call   10f0 <mpz_cmp@plt>
cmp    $0x0,%rax
jge    126c <compute_space_dimensions+0x5c>
mov    -0x20(%rbp),%edi
call   1100 <mpz_clear@plt>
mov    -0x18(%rbp),%edi
call   1100 <mpz_clear@plt>
mov    -0x1c(%rbp),%edi
call   1100 <mpz_clear@plt>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x2,%rcx
sub    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   10b0 <mpz_fac_ui@plt>
mov    -0x10(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    $0x1,%edx
call   10d0 <mpz_tdiv_q_2exp@plt>
mov    -0xc(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1130 <mpz_tdiv_q@plt>
mov    -0x34(%rbp),%edi
call   1060 <mpz_init@plt>
mov    -0x34(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   10a0 <mpz_mul@plt>
mov    -0x14(%rbp),%edi
mov    -0x34(%rbp),%esi
call   10f0 <mpz_cmp@plt>
cmp    $0x0,%rax
je     136d <compute_space_dimensions+0x15d>
lea    0xc9a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x34(%rbp),%edi
call   1100 <mpz_clear@plt>
mov    -0x14(%rbp),%edi
call   1100 <mpz_clear@plt>
mov    -0x38(%rbp),%edi
call   1070 <mpf_init@plt>
mov    -0x3c(%rbp),%edi
call   1070 <mpf_init@plt>
mov    -0x40(%rbp),%edi
call   1070 <mpf_init@plt>
mov    -0x3c(%rbp),%edi
mov    -0xc(%rbp),%esi
call   10c0 <mpf_set_z@plt>
mov    -0x40(%rbp),%edi
mov    -0x10(%rbp),%esi
call   10c0 <mpf_set_z@plt>
mov    -0x38(%rbp),%edi
mov    -0x40(%rbp),%esi
mov    -0x3c(%rbp),%edx
call   1120 <mpf_div@plt>
mov    -0x38(%rbp),%edi
call   1110 <mpf_get_d@plt>
movsd  %xmm0,-0x48(%rbp)
mov    -0x3c(%rbp),%edi
call   1080 <mpf_clear@plt>
mov    -0x40(%rbp),%edi
call   1080 <mpf_clear@plt>
mov    -0x38(%rbp),%edi
call   1080 <mpf_clear@plt>
movsd  -0x48(%rbp),%xmm0
lea    0xc54(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_space_dimensions>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebp
mov    %esi,%r14d
mov    %rdi,%rbx
call   1070 <mpz_init@plt>
call   1070 <mpz_init@plt>
call   1070 <mpz_init@plt>
call   1070 <mpz_init@plt>
mov    %rbx,%rsi
call   10c0 <mpz_fac_ui@plt>
call   10f0 <mpz_sqrt@plt>
call   1040 <mpz_set@plt>
add    $0x1,%rbx
nopw   0x0(%rax,%rax,1)
call   1040 <mpz_set@plt>
lea    -0x2(%rbx),%rsi
mov    %ebp,%edi
call   10c0 <mpz_fac_ui@plt>
mov    %ebp,%edi
mov    %ebp,%esi
mov    $0x1,%edx
call   10e0 <mpz_tdiv_q_2exp@plt>
mov    %r14d,%edi
mov    %ebp,%edx
call   1140 <mpz_tdiv_q@plt>
mov    %ebp,%esi
mov    %r14d,%edx
call   1050 <mpz_sub@plt>
call   10a0 <mpz_abs@plt>
call   1100 <mpz_cmp@plt>
add    $0xffffffffffffffff,%rbx
test   %rax,%rax
jns    1260 <compute_space_dimensions+0x40>
call   1110 <mpz_clear@plt>
call   1110 <mpz_clear@plt>
call   1110 <mpz_clear@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   10c0 <mpz_fac_ui@plt>
mov    %ebp,%edi
mov    %ebp,%esi
mov    $0x1,%edx
call   10e0 <mpz_tdiv_q_2exp@plt>
mov    %r14d,%edi
mov    %ebp,%edx
call   1140 <mpz_tdiv_q@plt>
call   1070 <mpz_init@plt>
mov    %r14d,%esi
mov    %ebp,%edx
call   10b0 <mpz_mul@plt>
call   1100 <mpz_cmp@plt>
test   %rax,%rax
je     12fb <compute_space_dimensions+0xdb>
lea    0xd1a(%rip),%rdi
call   1030 <puts@plt>
call   1110 <mpz_clear@plt>
call   1110 <mpz_clear@plt>
call   1080 <mpf_init@plt>
call   1080 <mpf_init@plt>
call   1080 <mpf_init@plt>
mov    %r14d,%esi
call   10d0 <mpf_set_z@plt>
mov    %ebp,%esi
call   10d0 <mpf_set_z@plt>
call   1130 <mpf_div@plt>
call   1120 <mpf_get_d@plt>
movsd  %xmm0,0x8(%rsp)
call   1090 <mpf_clear@plt>
call   1090 <mpf_clear@plt>
call   1090 <mpf_clear@plt>
lea    0xcb7(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1060 <printf@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [62 x i8] c"error, the space does not have the number of solutions as n!\0A\00"
@.str.1 = [16 x i8] c"\0Athe ratio: %f\0A\00"
define i64 @compute_space_dimensions(i64 %0, i32 %1, i32 %2) {
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
%12 = alloca i64
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca double
store i64 %0, i64* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%18 = load i32, i32* %7
%19 = call i32 @mpz_init(i32 %18)
%20 = load i32, i32* %8
%21 = call i32 @mpz_init(i32 %20)
%22 = load i32, i32* %9
%23 = call i32 @mpz_init(i32 %22)
%24 = load i32, i32* %10
%25 = call i32 @mpz_init(i32 %24)
%26 = load i32, i32* %7
%27 = load i64, i64* %4
%28 = call i32 @mpz_fac_ui(i32 %26, i64 %27)
%29 = load i32, i32* %8
%30 = load i32, i32* %7
%31 = call i32 @mpz_sqrt(i32 %29, i32 %30)
%32 = load i32, i32* %10
%33 = load i32, i32* %7
%34 = call i32 @mpz_set(i32 %32, i32 %33)
store i64 1, i64* %11
br label %35
35: ; preds = %60, %3
%36 = load i32, i32* %9
%37 = load i32, i32* %10
%38 = call i32 @mpz_set(i32 %36, i32 %37)
%39 = load i32, i32* %6
%40 = load i64, i64* %4
%41 = load i64, i64* %11
%42 = sub nsw i64 %40, %41
%43 = call i32 @mpz_fac_ui(i32 %39, i64 %42)
%44 = load i32, i32* %6
%45 = load i32, i32* %6
%46 = call i32 @mpz_tdiv_q_2exp(i32 %44, i32 %45, i32 1)
%47 = load i32, i32* %5
%48 = load i32, i32* %7
%49 = load i32, i32* %6
%50 = call i32 @mpz_tdiv_q(i32 %47, i32 %48, i32 %49)
%51 = load i32, i32* %10
%52 = load i32, i32* %6
%53 = load i32, i32* %5
%54 = call i32 @mpz_sub(i32 %51, i32 %52, i32 %53)
%55 = load i32, i32* %10
%56 = load i32, i32* %10
%57 = call i32 @mpz_abs(i32 %55, i32 %56)
%58 = load i64, i64* %11
%59 = add nsw i64 %58, 1
store i64 %59, i64* %11
br label %60
60: ; preds = %35
%61 = load i32, i32* %9
%62 = load i32, i32* %10
%63 = call i64 @mpz_cmp(i32 %61, i32 %62)
%64 = icmp sge i64 %63, 0
br i1 %64, label %35, label %65
65: ; preds = %60
%66 = load i32, i32* %10
%67 = call i32 @mpz_clear(i32 %66)
%68 = load i32, i32* %8
%69 = call i32 @mpz_clear(i32 %68)
%70 = load i32, i32* %9
%71 = call i32 @mpz_clear(i32 %70)
%72 = load i64, i64* %4
%73 = load i64, i64* %11
%74 = sub nsw i64 %73, 2
%75 = sub nsw i64 %72, %74
store i64 %75, i64* %12
%76 = load i32, i32* %6
%77 = load i64, i64* %12
%78 = call i32 @mpz_fac_ui(i32 %76, i64 %77)
%79 = load i32, i32* %6
%80 = load i32, i32* %6
%81 = call i32 @mpz_tdiv_q_2exp(i32 %79, i32 %80, i32 1)
%82 = load i32, i32* %5
%83 = load i32, i32* %7
%84 = load i32, i32* %6
%85 = call i32 @mpz_tdiv_q(i32 %82, i32 %83, i32 %84)
%86 = load i32, i32* %13
%87 = call i32 @mpz_init(i32 %86)
%88 = load i32, i32* %13
%89 = load i32, i32* %5
%90 = load i32, i32* %6
%91 = call i32 @mpz_mul(i32 %88, i32 %89, i32 %90)
%92 = load i32, i32* %7
%93 = load i32, i32* %13
%94 = call i64 @mpz_cmp(i32 %92, i32 %93)
%95 = icmp ne i64 %94, 0
br i1 %95, label %96, label %98
96: ; preds = %65
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
br label %98
98: ; preds = %96, %65
%99 = load i32, i32* %13
%100 = call i32 @mpz_clear(i32 %99)
%101 = load i32, i32* %7
%102 = call i32 @mpz_clear(i32 %101)
%103 = load i32, i32* %14
%104 = call i32 @mpf_init(i32 %103)
%105 = load i32, i32* %15
%106 = call i32 @mpf_init(i32 %105)
%107 = load i32, i32* %16
%108 = call i32 @mpf_init(i32 %107)
%109 = load i32, i32* %15
%110 = load i32, i32* %5
%111 = call i32 @mpf_set_z(i32 %109, i32 %110)
%112 = load i32, i32* %16
%113 = load i32, i32* %6
%114 = call i32 @mpf_set_z(i32 %112, i32 %113)
%115 = load i32, i32* %14
%116 = load i32, i32* %16
%117 = load i32, i32* %15
%118 = call i32 @mpf_div(i32 %115, i32 %116, i32 %117)
%119 = load i32, i32* %14
%120 = call double @mpf_get_d(i32 %119)
store double %120, double* %17
%121 = load i32, i32* %15
%122 = call i32 @mpf_clear(i32 %121)
%123 = load i32, i32* %16
%124 = call i32 @mpf_clear(i32 %123)
%125 = load i32, i32* %14
%126 = call i32 @mpf_clear(i32 %125)
%127 = load double, double* %17
%128 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), double %127)
%129 = load i64, i64* %12
ret i64 %129
}

LLVM IR (-O2):
@.str.1 = [16 x i8] c"\0Athe ratio: %f\0A\00"
@str = [61 x i8] c"error, the space does not have the number of solutions as n!\00"
define i64 @compute_space_dimensions(i64 %0, i32 %1, i32 %2) {
%4 = tail call i32 @mpz_init(i32 undef)
%5 = tail call i32 @mpz_init(i32 undef)
%6 = tail call i32 @mpz_init(i32 undef)
%7 = tail call i32 @mpz_init(i32 undef)
%8 = tail call i32 @mpz_fac_ui(i32 undef, i64 %0)
%9 = tail call i32 @mpz_sqrt(i32 undef, i32 undef)
%10 = tail call i32 @mpz_set(i32 undef, i32 undef)
br label %11
11: ; preds = %11, %3
%12 = phi i64 [ 1, %3 ], [ %20, %11 ]
%13 = tail call i32 @mpz_set(i32 undef, i32 undef)
%14 = sub nsw i64 %0, %12
%15 = tail call i32 @mpz_fac_ui(i32 %2, i64 %14)
%16 = tail call i32 @mpz_tdiv_q_2exp(i32 %2, i32 %2, i32 1)
%17 = tail call i32 @mpz_tdiv_q(i32 %1, i32 undef, i32 %2)
%18 = tail call i32 @mpz_sub(i32 undef, i32 %2, i32 %1)
%19 = tail call i32 @mpz_abs(i32 undef, i32 undef)
%20 = add nuw nsw i64 %12, 1
%21 = tail call i64 @mpz_cmp(i32 undef, i32 undef)
%22 = icmp sgt i64 %21, -1
br i1 %22, label %11, label %23
23: ; preds = %11
%24 = tail call i32 @mpz_clear(i32 undef)
%25 = tail call i32 @mpz_clear(i32 undef)
%26 = tail call i32 @mpz_clear(i32 undef)
%27 = add i64 %0, 1
%28 = sub i64 %27, %12
%29 = tail call i32 @mpz_fac_ui(i32 %2, i64 %28)
%30 = tail call i32 @mpz_tdiv_q_2exp(i32 %2, i32 %2, i32 1)
%31 = tail call i32 @mpz_tdiv_q(i32 %1, i32 undef, i32 %2)
%32 = tail call i32 @mpz_init(i32 undef)
%33 = tail call i32 @mpz_mul(i32 undef, i32 %1, i32 %2)
%34 = tail call i64 @mpz_cmp(i32 undef, i32 undef)
%35 = icmp eq i64 %34, 0
br i1 %35, label %38, label %36
36: ; preds = %23
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @str, i64 0, i64 0))
br label %38
38: ; preds = %36, %23
%39 = tail call i32 @mpz_clear(i32 undef)
%40 = tail call i32 @mpz_clear(i32 undef)
%41 = tail call i32 @mpf_init(i32 undef)
%42 = tail call i32 @mpf_init(i32 undef)
%43 = tail call i32 @mpf_init(i32 undef)
%44 = tail call i32 @mpf_set_z(i32 undef, i32 %1)
%45 = tail call i32 @mpf_set_z(i32 undef, i32 %2)
%46 = tail call i32 @mpf_div(i32 undef, i32 undef, i32 undef)
%47 = tail call double @mpf_get_d(i32 undef)
%48 = tail call i32 @mpf_clear(i32 undef)
%49 = tail call i32 @mpf_clear(i32 undef)
%50 = tail call i32 @mpf_clear(i32 undef)
%51 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), double %47)
ret i64 %28
}