#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 */
struct large {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ large_free(struct large *);
int /*<<< orphan*/ large_mul(struct large *, struct large *);
struct large *large_new(int);
int /*<<< orphan*/ large_set(struct large *, int);
struct large *large_factorial(int val) {
  int i;
  struct large *ret = large_new(val * val + 10);
  large_set(ret, 1);
  if (val == 0 || val == 1)
    return ret;
  struct large *t = large_new(32);
  for (i = 1; i <= val; ++i) {
    large_set(t, i);
    large_mul(ret, t);
  }
  large_free(t);
  return ret;
}


x86 assembly (clang, -O0):
<large_factorial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
imul   -0xc(%rbp),%edi
add    $0xa,%edi
call   1050 <large_new@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1060 <large_set@plt>
cmpl   $0x0,-0xc(%rbp)
je     1180 <large_factorial+0x40>
cmpl   $0x1,-0xc(%rbp)
jne    118d <large_factorial+0x4d>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11e6 <large_factorial+0xa6>
mov    $0x20,%edi
call   1050 <large_new@plt>
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11d5 <large_factorial+0x95>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1060 <large_set@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <large_mul@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11a2 <large_factorial+0x62>
mov    -0x20(%rbp),%rdi
call   1030 <large_free@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<large_factorial>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edi,%r15d
imul   %edi,%edi
add    $0xa,%edi
call   1050 <large_new@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x1,%esi
call   1060 <large_set@plt>
cmp    $0x2,%r15d
jb     11c0 <large_factorial+0x80>
mov    $0x20,%edi
call   1050 <large_new@plt>
mov    %rax,%r12
test   %r15d,%r15d
jle    11b8 <large_factorial+0x78>
neg    %r15d
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %ebx,%esi
call   1060 <large_set@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1040 <large_mul@plt>
lea    (%r15,%rbx,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x1,%eax
jne    1190 <large_factorial+0x50>
mov    %r12,%rdi
call   1030 <large_free@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.large = type { i32 }
define %struct.large* @large_factorial(i32 %0) {
%2 = alloca %struct.large*
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.large*
%6 = alloca %struct.large*
store i32 %0, i32* %3
%7 = load i32, i32* %3
%8 = load i32, i32* %3
%9 = mul nsw i32 %7, %8
%10 = add nsw i32 %9, 10
%11 = call %struct.large* @large_new(i32 %10)
store %struct.large* %11, %struct.large** %5
%12 = load %struct.large*, %struct.large** %5
%13 = call i32 @large_set(%struct.large* %12, i32 1)
%14 = load i32, i32* %3
%15 = icmp eq i32 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %1
%17 = load i32, i32* %3
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %21
19: ; preds = %16, %1
%20 = load %struct.large*, %struct.large** %5
store %struct.large* %20, %struct.large** %2
br label %41
21: ; preds = %16
%22 = call %struct.large* @large_new(i32 32)
store %struct.large* %22, %struct.large** %6
store i32 1, i32* %4
br label %23
23: ; preds = %34, %21
%24 = load i32, i32* %4
%25 = load i32, i32* %3
%26 = icmp sle i32 %24, %25
br i1 %26, label %27, label %37
27: ; preds = %23
%28 = load %struct.large*, %struct.large** %6
%29 = load i32, i32* %4
%30 = call i32 @large_set(%struct.large* %28, i32 %29)
%31 = load %struct.large*, %struct.large** %5
%32 = load %struct.large*, %struct.large** %6
%33 = call i32 @large_mul(%struct.large* %31, %struct.large* %32)
br label %34
34: ; preds = %27
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 1
store i32 %36, i32* %4
br label %23
37: ; preds = %23
%38 = load %struct.large*, %struct.large** %6
%39 = call i32 @large_free(%struct.large* %38)
%40 = load %struct.large*, %struct.large** %5
store %struct.large* %40, %struct.large** %2
br label %41
41: ; preds = %37, %19
%42 = load %struct.large*, %struct.large** %2
ret %struct.large* %42
}

LLVM IR (-O2):
%struct.large = type { i32 }
define %struct.large* @large_factorial(i32 %0) {
%2 = mul nsw i32 %0, %0
%3 = add nuw nsw i32 %2, 10
%4 = tail call %struct.large* @large_new(i32 %3)
%5 = tail call i32 @large_set(%struct.large* %4, i32 1)
%6 = icmp ult i32 %0, 2
br i1 %6, label %18, label %7
7: ; preds = %1
%8 = tail call %struct.large* @large_new(i32 32)
%9 = icmp slt i32 %0, 1
br i1 %9, label %16, label %10
10: ; preds = %7, %10
%11 = phi i32 [ %14, %10 ], [ 1, %7 ]
%12 = tail call i32 @large_set(%struct.large* %8, i32 %11)
%13 = tail call i32 @large_mul(%struct.large* %4, %struct.large* %8)
%14 = add nuw i32 %11, 1
%15 = icmp eq i32 %11, %0
br i1 %15, label %16, label %10
16: ; preds = %10, %7
%17 = tail call i32 @large_free(%struct.large* %8)
br label %18
18: ; preds = %1, %16
ret %struct.large* %4
}