#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 getHammingDistance(int, int);
int getNumHamming(int N, int hammingDist, int base, int result[]) {
  int numResult = 0, upperBound = (1 << N), num;
  for (num = 0; num < upperBound; num++)
    if (getHammingDistance(num, base) == hammingDist) {
      result[numResult] = num;
      numResult++;
    }
  return numResult;
}


x86 assembly (clang, -O0):
<getNumHamming>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x4(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    118a <getNumHamming+0x7a>
mov    -0x24(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <getHammingDistance@plt>
cmp    -0x8(%rbp),%eax
jne    1177 <getNumHamming+0x67>
mov    -0x24(%rbp),%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    117c <getNumHamming+0x6c>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1140 <getNumHamming+0x30>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getNumHamming>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %ebp,%ebp
cmp    $0x1f,%edi
jne    1133 <getNumHamming+0x23>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rcx,%r14
mov    %edx,%r15d
mov    %esi,%r12d
mov    $0x1,%eax
mov    $0x1,%r13d
mov    %edi,%ecx
shl    %cl,%r13d
cmp    $0x2,%r13d
cmovl  %eax,%r13d
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    1168 <getNumHamming+0x58>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebx
cmp    %ebx,%r13d
je     1122 <getNumHamming+0x12>
mov    %ebx,%edi
mov    %r15d,%esi
call   1030 <getHammingDistance@plt>
cmp    %r12d,%eax
jne    1160 <getNumHamming+0x50>
movslq %ebp,%rbp
mov    %ebx,(%r14,%rbp,4)
add    $0x1,%ebp
jmp    1160 <getNumHamming+0x50>

LLVM IR (-O0):
define i32 @getNumHamming(i32 %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32* %3, i32** %8
store i32 0, i32* %9
%12 = load i32, i32* %5
%13 = shl i32 1, %12
store i32 %13, i32* %10
store i32 0, i32* %11
br label %14
14: ; preds = %33, %4
%15 = load i32, i32* %11
%16 = load i32, i32* %10
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %36
18: ; preds = %14
%19 = load i32, i32* %11
%20 = load i32, i32* %7
%21 = call i32 @getHammingDistance(i32 %19, i32 %20)
%22 = load i32, i32* %6
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %32
24: ; preds = %18
%25 = load i32, i32* %11
%26 = load i32*, i32** %8
%27 = load i32, i32* %9
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
store i32 %25, i32* %29
%30 = load i32, i32* %9
%31 = add nsw i32 %30, 1
store i32 %31, i32* %9
br label %32
32: ; preds = %24, %18
br label %33
33: ; preds = %32
%34 = load i32, i32* %11
%35 = add nsw i32 %34, 1
store i32 %35, i32* %11
br label %14
36: ; preds = %14
%37 = load i32, i32* %9
ret i32 %37
}

LLVM IR (-O2):
define i32 @getNumHamming(i32 %0, i32 %1, i32 %2, i32* nocapture writeonly %3) {
%5 = icmp eq i32 %0, 31
br i1 %5, label %22, label %6
6: ; preds = %4
%7 = shl nuw nsw i32 1, %0
%8 = call i32 @llvm.smax.i32(i32 %7, i32 1)
br label %9
9: ; preds = %6, %18
%10 = phi i32 [ %20, %18 ], [ 0, %6 ]
%11 = phi i32 [ %19, %18 ], [ 0, %6 ]
%12 = tail call i32 @getHammingDistance(i32 %10, i32 %2)
%13 = icmp eq i32 %12, %1
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = sext i32 %11 to i64
%16 = getelementptr inbounds i32, i32* %3, i64 %15
store i32 %10, i32* %16
%17 = add nsw i32 %11, 1
br label %18
18: ; preds = %9, %14
%19 = phi i32 [ %17, %14 ], [ %11, %9 ]
%20 = add nuw nsw i32 %10, 1
%21 = icmp eq i32 %20, %8
br i1 %21, label %22, label %9
22: ; preds = %18, %4
%23 = phi i32 [ 0, %4 ], [ %19, %18 ]
ret i32 %23
}