#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 */
struct flashrom_flashctx {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ check_block_eraser(struct flashrom_flashctx const *, int,
                                      int /*<<< orphan*/);
unsigned int count_usable_erasers(const struct flashrom_flashctx *flash) {
  unsigned int usable_erasefunctions = 0;
  int k;
  for (k = 0; k < 8; k++) {
    if (!check_block_eraser(flash, k, 0))
      usable_erasefunctions++;
  }
  return usable_erasefunctions;
}


x86 assembly (clang, -O0):
<count_usable_erasers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x8,-0x10(%rbp)
jge    1167 <count_usable_erasers+0x57>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
xor    %edx,%edx
call   1030 <check_block_eraser@plt>
cmp    $0x0,%eax
jne    1154 <count_usable_erasers+0x44>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1159 <count_usable_erasers+0x49>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112a <count_usable_erasers+0x1a>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_usable_erasers>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %esi,%esi
xor    %edx,%edx
call   1030 <check_block_eraser@plt>
mov    %eax,0x4(%rsp)
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %edx,%edx
call   1030 <check_block_eraser@plt>
mov    %eax,(%rsp)
mov    %rbx,%rdi
mov    $0x2,%esi
xor    %edx,%edx
call   1030 <check_block_eraser@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
mov    $0x3,%esi
xor    %edx,%edx
call   1030 <check_block_eraser@plt>
mov    %eax,%r13d
mov    %rbx,%rdi
mov    $0x4,%esi
xor    %edx,%edx
call   1030 <check_block_eraser@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    $0x5,%esi
xor    %edx,%edx
call   1030 <check_block_eraser@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
mov    $0x6,%esi
xor    %edx,%edx
call   1030 <check_block_eraser@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
mov    $0x7,%esi
xor    %edx,%edx
call   1030 <check_block_eraser@plt>
movd   %ebp,%xmm0
movd   %r14d,%xmm1
punpckldq %xmm1,%xmm0
movd   %r15d,%xmm1
movd   %eax,%xmm2
punpckldq %xmm2,%xmm1
punpcklqdq %xmm1,%xmm0
movd   %r12d,%xmm1
movd   %r13d,%xmm2
punpckldq %xmm2,%xmm1
movd   (%rsp),%xmm2
movd   0x4(%rsp),%xmm3
punpckldq %xmm2,%xmm3
punpcklqdq %xmm1,%xmm3
pxor   %xmm1,%xmm1
pcmpeqd %xmm1,%xmm0
pcmpeqd %xmm1,%xmm3
packssdw %xmm0,%xmm3
packsswb %xmm3,%xmm3
pmovmskb %xmm3,%eax
mov    %eax,%ecx
shr    %cl
and    $0x55,%cl
sub    %cl,%al
mov    %eax,%ecx
and    $0x33,%cl
shr    $0x2,%al
and    $0x33,%al
add    %cl,%al
mov    %eax,%ecx
shr    $0x4,%cl
add    %al,%cl
and    $0xf,%cl
movzbl %cl,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.flashrom_flashctx = type { i32 }
define i32 @count_usable_erasers(%struct.flashrom_flashctx* %0) {
%2 = alloca %struct.flashrom_flashctx*
%3 = alloca i32
%4 = alloca i32
store %struct.flashrom_flashctx* %0, %struct.flashrom_flashctx** %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %17, %1
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 8
br i1 %7, label %8, label %20
8: ; preds = %5
%9 = load %struct.flashrom_flashctx*, %struct.flashrom_flashctx** %2
%10 = load i32, i32* %4
%11 = call i32 @check_block_eraser(%struct.flashrom_flashctx* %9, i32 %10, i32 0)
%12 = icmp ne i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %8
%14 = load i32, i32* %3
%15 = add i32 %14, 1
store i32 %15, i32* %3
br label %16
16: ; preds = %13, %8
br label %17
17: ; preds = %16
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %4
br label %5
20: ; preds = %5
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
%struct.flashrom_flashctx = type { i32 }
define i32 @count_usable_erasers(%struct.flashrom_flashctx* %0) {
%2 = tail call i32 @check_block_eraser(%struct.flashrom_flashctx* %0, i32 0, i32 0)
%3 = tail call i32 @check_block_eraser(%struct.flashrom_flashctx* %0, i32 1, i32 0)
%4 = tail call i32 @check_block_eraser(%struct.flashrom_flashctx* %0, i32 2, i32 0)
%5 = tail call i32 @check_block_eraser(%struct.flashrom_flashctx* %0, i32 3, i32 0)
%6 = tail call i32 @check_block_eraser(%struct.flashrom_flashctx* %0, i32 4, i32 0)
%7 = tail call i32 @check_block_eraser(%struct.flashrom_flashctx* %0, i32 5, i32 0)
%8 = tail call i32 @check_block_eraser(%struct.flashrom_flashctx* %0, i32 6, i32 0)
%9 = tail call i32 @check_block_eraser(%struct.flashrom_flashctx* %0, i32 7, i32 0)
%10 = insertelement <8 x i32> poison, i32 %2, i64 0
%11 = insertelement <8 x i32> %10, i32 %3, i64 1
%12 = insertelement <8 x i32> %11, i32 %4, i64 2
%13 = insertelement <8 x i32> %12, i32 %5, i64 3
%14 = insertelement <8 x i32> %13, i32 %6, i64 4
%15 = insertelement <8 x i32> %14, i32 %7, i64 5
%16 = insertelement <8 x i32> %15, i32 %8, i64 6
%17 = insertelement <8 x i32> %16, i32 %9, i64 7
%18 = icmp eq <8 x i32> %17, zeroinitializer
%19 = bitcast <8 x i1> %18 to i8
%20 = call i8 @llvm.ctpop.i8(i8 %19)
%21 = zext i8 %20 to i32
ret i32 %21
}