#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;
typedef int uint32_t;
typedef int uint16_t;

/* Variables and functions */
int combination(int, int);
uint32_t count_combinations(uint32_t nmax, uint32_t maxval) {
  uint32_t count = 0;
  for (uint16_t n = 1; n <= nmax; n++) {
    for (uint16_t r = 1; r < n / 2; r++) {
      uint64_t k = combination(n, r);
      if (k > maxval) {
        count += !(n % 2) + (2 * (n / 2 - r) + 1);
        break;
      }
    }
  }
  return count;
}


x86 assembly (clang, -O0):
<count_combinations>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     11de <count_combinations+0xce>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    11cb <count_combinations+0xbb>
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1030 <combination@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jle    11b8 <count_combinations+0xa8>
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
sub    -0x14(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
add    %ecx,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    11cb <count_combinations+0xbb>
jmp    11bd <count_combinations+0xad>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113f <count_combinations+0x2f>
jmp    11d0 <count_combinations+0xc0>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112c <count_combinations+0x1c>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_combinations>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edi,%edi
jle    11ac <count_combinations+0x9c>
mov    %esi,%r12d
mov    $0x1,%r13d
xor    %r15d,%r15d
mov    %edi,0x4(%rsp)
jmp    115d <count_combinations+0x4d>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13d,%r15d
or     $0xfffffffe,%r15d
add    %r14d,%r15d
neg    %r15d
mov    0x4(%rsp),%edi
lea    0x1(%r13),%eax
cmp    %edi,%r13d
mov    %eax,%r13d
je     11af <count_combinations+0x9f>
mov    %r13d,%eax
shr    %eax
cmp    $0x3,%eax
mov    $0x2,%ebp
cmovae %eax,%ebp
cmp    $0x4,%r13d
jb     1151 <count_combinations+0x41>
add    %eax,%eax
add    %r15d,%eax
mov    $0x2,%r14d
sub    %eax,%r14d
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %r13d,%edi
mov    %ebx,%esi
call   1030 <combination@plt>
cmp    %r12d,%eax
jg     1140 <count_combinations+0x30>
add    $0x1,%ebx
add    $0x2,%r14d
cmp    %ebx,%ebp
jne    1190 <count_combinations+0x80>
jmp    114d <count_combinations+0x3d>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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