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

/* Variables and functions */
int factorial(int);
uint64_t lah(uint64_t n, uint64_t k) {
  if (k == 1)
    return factorial(n);
  if (k == n)
    return 1;
  if (k > n)
    return 0;
  if (k < 1 || n < 1)
    return 0;
  return (factorial(n) * factorial(n - 1)) / (factorial(k) * factorial(k - 1)) /
         factorial(n - k);
}


x86 assembly (clang, -O0):
<lah>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    1138 <lah+0x28>
mov    -0x8(%rbp),%edi
call   1030 <factorial@plt>
mov    %eax,-0x4(%rbp)
jmp    11e6 <lah+0xd6>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    1150 <lah+0x40>
movl   $0x1,-0x4(%rbp)
jmp    11e6 <lah+0xd6>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jle    1168 <lah+0x58>
movl   $0x0,-0x4(%rbp)
jmp    11e6 <lah+0xd6>
cmpl   $0x1,-0xc(%rbp)
jl     117c <lah+0x6c>
cmpl   $0x1,-0x8(%rbp)
jge    1188 <lah+0x78>
movl   $0x0,-0x4(%rbp)
jmp    11e6 <lah+0xd6>
mov    -0x8(%rbp),%edi
call   1030 <factorial@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
call   1030 <factorial@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <factorial@plt>
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
sub    $0x1,%edi
call   1030 <factorial@plt>
mov    -0x18(%rbp),%ecx
mov    %eax,%edx
mov    -0x14(%rbp),%eax
imul   %edx,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
sub    -0xc(%rbp),%edi
call   1030 <factorial@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lah>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebp
cmp    $0x1,%esi
jne    112f <lah+0x1f>
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <factorial@plt>
mov    %esi,%ebx
mov    $0x1,%eax
cmp    %esi,%ebp
je     1196 <lah+0x86>
xor    %eax,%eax
mov    %ebp,%r14d
sub    %ebx,%r14d
jl     1196 <lah+0x86>
test   %ebp,%ebp
jle    1196 <lah+0x86>
test   %ebx,%ebx
jle    1196 <lah+0x86>
mov    %ebp,%edi
call   1030 <factorial@plt>
mov    %eax,%r15d
add    $0xffffffff,%ebp
mov    %ebp,%edi
call   1030 <factorial@plt>
mov    %eax,%ebp
imul   %r15d,%ebp
mov    %ebx,%edi
call   1030 <factorial@plt>
mov    %eax,%r15d
add    $0xffffffff,%ebx
mov    %ebx,%edi
call   1030 <factorial@plt>
mov    %eax,%ecx
imul   %r15d,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
mov    %eax,%ebx
mov    %r14d,%edi
call   1030 <factorial@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @lah(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%6 = load i32, i32* %5
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* %4
%10 = call i32 @factorial(i32 %9)
store i32 %10, i32* %3
br label %47
11: ; preds = %2
%12 = load i32, i32* %5
%13 = load i32, i32* %4
%14 = icmp eq i32 %12, %13
br i1 %14, label %15, label %16
15: ; preds = %11
store i32 1, i32* %3
br label %47
16: ; preds = %11
%17 = load i32, i32* %5
%18 = load i32, i32* %4
%19 = icmp sgt i32 %17, %18
br i1 %19, label %20, label %21
20: ; preds = %16
store i32 0, i32* %3
br label %47
21: ; preds = %16
%22 = load i32, i32* %5
%23 = icmp slt i32 %22, 1
br i1 %23, label %27, label %24
24: ; preds = %21
%25 = load i32, i32* %4
%26 = icmp slt i32 %25, 1
br i1 %26, label %27, label %28
27: ; preds = %24, %21
store i32 0, i32* %3
br label %47
28: ; preds = %24
%29 = load i32, i32* %4
%30 = call i32 @factorial(i32 %29)
%31 = load i32, i32* %4
%32 = sub nsw i32 %31, 1
%33 = call i32 @factorial(i32 %32)
%34 = mul nsw i32 %30, %33
%35 = load i32, i32* %5
%36 = call i32 @factorial(i32 %35)
%37 = load i32, i32* %5
%38 = sub nsw i32 %37, 1
%39 = call i32 @factorial(i32 %38)
%40 = mul nsw i32 %36, %39
%41 = sdiv i32 %34, %40
%42 = load i32, i32* %4
%43 = load i32, i32* %5
%44 = sub nsw i32 %42, %43
%45 = call i32 @factorial(i32 %44)
%46 = sdiv i32 %41, %45
store i32 %46, i32* %3
br label %47
47: ; preds = %28, %27, %20, %15, %8
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
define i32 @lah(i32 %0, i32 %1) {
%3 = icmp eq i32 %1, 1
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @factorial(i32 %0)
br label %27
6: ; preds = %2
%7 = icmp eq i32 %0, %1
br i1 %7, label %27, label %8
8: ; preds = %6
%9 = icmp slt i32 %0, %1
br i1 %9, label %27, label %10
10: ; preds = %8
%11 = icmp slt i32 %1, 1
%12 = icmp slt i32 %0, 1
%13 = or i1 %12, %11
br i1 %13, label %27, label %14
14: ; preds = %10
%15 = tail call i32 @factorial(i32 %0)
%16 = add nsw i32 %0, -1
%17 = tail call i32 @factorial(i32 %16)
%18 = mul nsw i32 %17, %15
%19 = tail call i32 @factorial(i32 %1)
%20 = add nsw i32 %1, -1
%21 = tail call i32 @factorial(i32 %20)
%22 = mul nsw i32 %21, %19
%23 = sdiv i32 %18, %22
%24 = sub nsw i32 %0, %1
%25 = tail call i32 @factorial(i32 %24)
%26 = sdiv i32 %23, %25
br label %27
27: ; preds = %10, %8, %6, %14, %4
%28 = phi i32 [ %5, %4 ], [ %26, %14 ], [ 1, %6 ], [ 0, %8 ], [ 0, %10 ]
ret i32 %28
}