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

/* Variables and functions */
scalar_t__ mpz_cmp_ui(int /*<<< orphan*/, unsigned int);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init_set(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_mul(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpz_set(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_set_ui(int /*<<< orphan*/, int);
scalar_t__ mpz_sgn(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_sub_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
void mpz_fact(mpz_t ret, mpz_t n) {
  int cmp;
  mpz_t result, m;
  mpz_init(result);
  mpz_set_ui(result, 1);
  if (mpz_cmp_ui(n, 2u) < 0) {
    mpz_set(ret, result);
    return;
  }
  mpz_init_set(m, n);
  while (mpz_sgn(m)) {
    mpz_mul(result, result, m);
    mpz_sub_ui(m, m, 1);
  }
  mpz_set(ret, result);
}


x86 assembly (clang, -O0):
<mpz_fact>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <mpz_init@plt>
mov    -0x10(%rbp),%edi
mov    $0x1,%esi
call   1080 <mpz_set_ui@plt>
mov    -0x8(%rbp),%edi
mov    $0x2,%esi
call   1070 <mpz_cmp_ui@plt>
cmp    $0x0,%rax
jge    11ca <mpz_fact+0x4a>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <mpz_set@plt>
jmp    1215 <mpz_fact+0x95>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1090 <mpz_init_set@plt>
mov    -0x14(%rbp),%edi
call   10a0 <mpz_sgn@plt>
cmp    $0x0,%rax
je     120a <mpz_fact+0x8a>
mov    -0x10(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1050 <mpz_mul@plt>
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    $0x1,%edx
call   1060 <mpz_sub_ui@plt>
jmp    11d5 <mpz_fact+0x55>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <mpz_set@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mpz_fact>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
call   1040 <mpz_init@plt>
mov    $0x1,%esi
call   1080 <mpz_set_ui@plt>
mov    %ebp,%edi
mov    $0x2,%esi
call   1070 <mpz_cmp_ui@plt>
test   %rax,%rax
js     11cb <mpz_fact+0x4b>
mov    %ebp,%esi
call   1090 <mpz_init_set@plt>
xchg   %ax,%ax
call   10a0 <mpz_sgn@plt>
test   %rax,%rax
je     11cb <mpz_fact+0x4b>
call   1050 <mpz_mul@plt>
mov    $0x1,%edx
call   1060 <mpz_sub_ui@plt>
jmp    11b0 <mpz_fact+0x30>
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <mpz_set@plt>

LLVM IR (-O0):
define void @mpz_fact(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %6
%9 = call i32 @mpz_init(i32 %8)
%10 = load i32, i32* %6
%11 = call i32 @mpz_set_ui(i32 %10, i32 1)
%12 = load i32, i32* %4
%13 = call i64 @mpz_cmp_ui(i32 %12, i32 2)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i32, i32* %3
%17 = load i32, i32* %6
%18 = call i32 @mpz_set(i32 %16, i32 %17)
br label %39
19: ; preds = %2
%20 = load i32, i32* %7
%21 = load i32, i32* %4
%22 = call i32 @mpz_init_set(i32 %20, i32 %21)
br label %23
23: ; preds = %27, %19
%24 = load i32, i32* %7
%25 = call i64 @mpz_sgn(i32 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %35
27: ; preds = %23
%28 = load i32, i32* %6
%29 = load i32, i32* %6
%30 = load i32, i32* %7
%31 = call i32 @mpz_mul(i32 %28, i32 %29, i32 %30)
%32 = load i32, i32* %7
%33 = load i32, i32* %7
%34 = call i32 @mpz_sub_ui(i32 %32, i32 %33, i32 1)
br label %23
35: ; preds = %23
%36 = load i32, i32* %3
%37 = load i32, i32* %6
%38 = call i32 @mpz_set(i32 %36, i32 %37)
br label %39
39: ; preds = %35, %15
ret void
}

LLVM IR (-O2):
define void @mpz_fact(i32 %0, i32 %1) {
%3 = tail call i32 @mpz_init(i32 undef)
%4 = tail call i32 @mpz_set_ui(i32 undef, i32 1)
%5 = tail call i64 @mpz_cmp_ui(i32 %1, i32 2)
%6 = icmp slt i64 %5, 0
br i1 %6, label %16, label %7
7: ; preds = %2
%8 = tail call i32 @mpz_init_set(i32 undef, i32 %1)
%9 = tail call i64 @mpz_sgn(i32 undef)
%10 = icmp eq i64 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %7, %11
%12 = tail call i32 @mpz_mul(i32 undef, i32 undef, i32 undef)
%13 = tail call i32 @mpz_sub_ui(i32 undef, i32 undef, i32 1)
%14 = tail call i64 @mpz_sgn(i32 undef)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %11
16: ; preds = %11, %7, %2
%17 = tail call i32 @mpz_set(i32 %0, i32 undef)
ret void
}