#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 */
int /*<<< orphan*/ *malloc(int);
int /*<<< orphan*/ mpz_init_set_str(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ mpz_mul_si(int /*<<< orphan*/, int /*<<< orphan*/, long);
mpz_t *fak(int n) {
  int i;
  mpz_t *result = malloc(sizeof(mpz_t) * 1);
  ;
  mpz_init_set_str(*result, "1", 10);
  for (i = 1; i < n; i++)
    mpz_mul_si(*result, *result, (long)i + 1);
  return result;
}


x86 assembly (clang, -O0):
<fak>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
lea    0xeaa(%rip),%rsi
mov    $0xa,%edx
call   1040 <mpz_init_set_str@plt>
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    119a <fak+0x6a>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
movslq -0x8(%rbp),%rdx
add    $0x1,%rdx
call   1030 <mpz_mul_si@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1167 <fak+0x37>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fak>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    (%rax),%ebp
lea    0xeb1(%rip),%rsi
mov    %ebp,%edi
mov    $0xa,%edx
call   1040 <mpz_init_set_str@plt>
cmp    $0x2,%ebx
jl     118e <fak+0x5e>
mov    %ebx,%eax
mov    $0x1,%r15d
sub    %rax,%r15
mov    $0x2,%ebx
mov    %ebp,%edi
mov    %ebp,%esi
mov    %rbx,%rdx
call   1030 <mpz_mul_si@plt>
lea    (%r15,%rbx,1),%rax
add    $0x1,%rax
add    $0x1,%rbx
cmp    $0x2,%rax
jne    1170 <fak+0x40>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"1\00"
define i32* @fak(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
store i32 %0, i32* %2
%5 = call i32* @malloc(i32 4)
store i32* %5, i32** %4
%6 = load i32*, i32** %4
%7 = load i32, i32* %6
%8 = call i32 @mpz_init_set_str(i32 %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 10)
store i32 1, i32* %3
br label %9
9: ; preds = %22, %1
%10 = load i32, i32* %3
%11 = load i32, i32* %2
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %25
13: ; preds = %9
%14 = load i32*, i32** %4
%15 = load i32, i32* %14
%16 = load i32*, i32** %4
%17 = load i32, i32* %16
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = add nsw i64 %19, 1
%21 = call i32 @mpz_mul_si(i32 %15, i32 %17, i64 %20)
br label %22
22: ; preds = %13
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
br label %9
25: ; preds = %9
%26 = load i32*, i32** %4
ret i32* %26
}

LLVM IR (-O2):
@.str = [2 x i8] c"1\00"
define noalias i32* @fak(i32 %0) {
%2 = tail call i32* @malloc(i32 4)
%3 = load i32, i32* %2
%4 = tail call i32 @mpz_init_set_str(i32 %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 10)
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %13
6: ; preds = %1
%7 = zext i32 %0 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 1, %6 ], [ %10, %8 ]
%10 = add nuw nsw i64 %9, 1
%11 = tail call i32 @mpz_mul_si(i32 %3, i32 %3, i64 %10)
%12 = icmp eq i64 %10, %7
br i1 %12, label %13, label %8
13: ; preds = %8, %1
ret i32* %2
}