#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 */

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned long,
                           unsigned long);
unsigned long n_choose_k(unsigned long, unsigned long, int *);
int /*<<< orphan*/ printf(char *, unsigned long, unsigned long, unsigned long);
int /*<<< orphan*/ stderr;
int strtoul(char *, int /*<<< orphan*/ *, int);
int main(int argc, char **argv) {
  unsigned long n, k, r;
  int error;
  n = argc > 1 ? strtoul(argv[1], NULL, 10) : 8;
  k = argc > 2 ? strtoul(argv[2], NULL, 10) : 3;
  error = 0;
  r = n_choose_k(n, k, &error);
  if (error) {
    fprintf(stderr, "%lu choose %lu: factorials overflow\n", n, k);
  } else {
    printf("n_choose_k(%lu, %lu) = %lu\n", n, k, r);
  }
  return error ? 1 : 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    117e <main+0x3e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1060 <strtoul@plt>
mov    %eax,-0x30(%rbp)
jmp    118b <main+0x4b>
mov    $0x8,%eax
mov    %eax,-0x30(%rbp)
jmp    118b <main+0x4b>
mov    -0x30(%rbp),%eax
cltq
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    11bc <main+0x7c>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1060 <strtoul@plt>
mov    %eax,-0x34(%rbp)
jmp    11c9 <main+0x89>
mov    $0x3,%eax
mov    %eax,-0x34(%rbp)
jmp    11c9 <main+0x89>
mov    -0x34(%rbp),%eax
cltq
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   1030 <n_choose_k@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     121a <main+0xda>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xdf0(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1232 <main+0xf2>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xdf8(%rip),%rdi
call   1040 <printf@plt>
mov    -0x2c(%rbp),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x3,%r14d
mov    $0x8,%ebx
cmp    $0x2,%edi
jl     1187 <main+0x47>
mov    %rsi,%r15
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtoul@plt>
movslq %eax,%rbx
cmp    $0x2,%ebp
je     1187 <main+0x47>
mov    0x10(%r15),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtoul@plt>
movslq %eax,%r14
movl   $0x0,0x4(%rsp)
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <n_choose_k@plt>
cmpl   $0x0,0x4(%rsp)
je     11c3 <main+0x83>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1050 <fprintf@plt>
jmp    11d8 <main+0x98>
lea    0xe5b(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %rax,%rcx
call   1040 <printf@plt>
xor    %eax,%eax
cmpl   $0x0,0x4(%rsp)
setne  %al
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [37 x i8] c"%lu choose %lu: factorials overflow\0A\00"
@.str.1 = [28 x i8] c"n_choose_k(%lu, %lu) = %lu\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @strtoul(i8* %15, i32* null, i32 10)
br label %18
17: ; preds = %2
br label %18
18: ; preds = %17, %12
%19 = phi i32 [ %16, %12 ], [ 8, %17 ]
%20 = sext i32 %19 to i64
store i64 %20, i64* %6
%21 = load i32, i32* %4
%22 = icmp sgt i32 %21, 2
br i1 %22, label %23, label %28
23: ; preds = %18
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i32 @strtoul(i8* %26, i32* null, i32 10)
br label %29
28: ; preds = %18
br label %29
29: ; preds = %28, %23
%30 = phi i32 [ %27, %23 ], [ 3, %28 ]
%31 = sext i32 %30 to i64
store i64 %31, i64* %7
store i32 0, i32* %9
%32 = load i64, i64* %6
%33 = load i64, i64* %7
%34 = call i64 @n_choose_k(i64 %32, i64 %33, i32* %9)
store i64 %34, i64* %8
%35 = load i32, i32* %9
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %29
%38 = load i32, i32* @stderr
%39 = load i64, i64* %6
%40 = load i64, i64* %7
%41 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i64 %39, i64 %40)
br label %47
42: ; preds = %29
%43 = load i64, i64* %6
%44 = load i64, i64* %7
%45 = load i64, i64* %8
%46 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i64 %43, i64 %44, i64 %45)
br label %47
47: ; preds = %42, %37
%48 = load i32, i32* %9
%49 = icmp ne i32 %48, 0
%50 = zext i1 %49 to i64
%51 = select i1 %49, i32 1, i32 0
ret i32 %51
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [37 x i8] c"%lu choose %lu: factorials overflow\0A\00"
@.str.1 = [28 x i8] c"n_choose_k(%lu, %lu) = %lu\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %17
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @strtoul(i8* nocapture %8, i32* null, i32 10)
%10 = sext i32 %9 to i64
%11 = icmp eq i32 %0, 2
br i1 %11, label %17, label %12
12: ; preds = %6
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i32 @strtoul(i8* nocapture %14, i32* null, i32 10)
%16 = sext i32 %15 to i64
br label %17
17: ; preds = %2, %6, %12
%18 = phi i64 [ %10, %12 ], [ %10, %6 ], [ 8, %2 ]
%19 = phi i64 [ %16, %12 ], [ 3, %6 ], [ 3, %2 ]
store i32 0, i32* %3
%20 = call i64 @n_choose_k(i64 %18, i64 %19, i32* %3)
%21 = load i32, i32* %3
%22 = icmp eq i32 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %17
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i64 %18, i64 %19)
br label %28
26: ; preds = %17
%27 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i64 %18, i64 %19, i64 %20)
br label %28
28: ; preds = %26, %23
%29 = load i32, i32* %3
%30 = icmp ne i32 %29, 0
%31 = zext i1 %30 to i32
ret i32 %31
}