#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 unsigned int uint16_t;
struct filter_mask {
  int dummy;
};

/* Variables and functions */
scalar_t__ test_mask_bit(struct filter_mask *, unsigned int);
unsigned int compute_mask_ids(uint16_t *array, struct filter_mask *mask,
                              unsigned int max_bit_count) {
  unsigned int count = 0;
  for (uint16_t bit = 0; bit < max_bit_count; bit++)
    if (test_mask_bit(mask, bit)) {
      *array++ = bit;
      count += 1;
    }
  return count;
}


x86 assembly (clang, -O0):
<compute_mask_ids>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    1183 <compute_mask_ids+0x73>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <test_mask_bit@plt>
cmp    $0x0,%rax
je     1170 <compute_mask_ids+0x60>
mov    -0x1c(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x8(%rbp)
mov    %ecx,(%rax)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1175 <compute_mask_ids+0x65>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1131 <compute_mask_ids+0x21>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_mask_ids>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %edx,%edx
je     1153 <compute_mask_ids+0x43>
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %ebp,%ebp
xor    %r12d,%r12d
jmp    1138 <compute_mask_ids+0x28>
nopl   0x0(%rax)
add    $0x1,%ebp
cmp    %ebp,%r15d
je     1156 <compute_mask_ids+0x46>
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <test_mask_bit@plt>
test   %rax,%rax
je     1130 <compute_mask_ids+0x20>
mov    %ebp,(%rbx)
add    $0x4,%rbx
add    $0x1,%r12d
jmp    1130 <compute_mask_ids+0x20>
xor    %r12d,%r12d
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.filter_mask = type { i32 }
define i32 @compute_mask_ids(i32* %0, %struct.filter_mask* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca %struct.filter_mask*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store %struct.filter_mask* %1, %struct.filter_mask** %5
store i32 %2, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
br label %9
9: ; preds = %25, %3
%10 = load i32, i32* %8
%11 = load i32, i32* %6
%12 = icmp ult i32 %10, %11
br i1 %12, label %13, label %28
13: ; preds = %9
%14 = load %struct.filter_mask*, %struct.filter_mask** %5
%15 = load i32, i32* %8
%16 = call i64 @test_mask_bit(%struct.filter_mask* %14, i32 %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %13
%19 = load i32, i32* %8
%20 = load i32*, i32** %4
%21 = getelementptr inbounds i32, i32* %20, i32 1
store i32* %21, i32** %4
store i32 %19, i32* %20
%22 = load i32, i32* %7
%23 = add i32 %22, 1
store i32 %23, i32* %7
br label %24
24: ; preds = %18, %13
br label %25
25: ; preds = %24
%26 = load i32, i32* %8
%27 = add i32 %26, 1
store i32 %27, i32* %8
br label %9
28: ; preds = %9
%29 = load i32, i32* %7
ret i32 %29
}

LLVM IR (-O2):
%struct.filter_mask = type { i32 }
define i32 @compute_mask_ids(i32* nocapture writeonly %0, %struct.filter_mask* %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %5, label %7
5: ; preds = %16, %3
%6 = phi i32 [ 0, %3 ], [ %18, %16 ]
ret i32 %6
7: ; preds = %3, %16
%8 = phi i32 [ %19, %16 ], [ 0, %3 ]
%9 = phi i32 [ %18, %16 ], [ 0, %3 ]
%10 = phi i32* [ %17, %16 ], [ %0, %3 ]
%11 = tail call i64 @test_mask_bit(%struct.filter_mask* %1, i32 %8)
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %7
%14 = getelementptr inbounds i32, i32* %10, i64 1
store i32 %8, i32* %10
%15 = add i32 %9, 1
br label %16
16: ; preds = %7, %13
%17 = phi i32* [ %14, %13 ], [ %10, %7 ]
%18 = phi i32 [ %15, %13 ], [ %9, %7 ]
%19 = add nuw i32 %8, 1
%20 = icmp eq i32 %19, %2
br i1 %20, label %5, label %7
}