#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 flashctx {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ check_block_eraser(struct flashctx const *, int,
                                      int /*<<< orphan*/);
unsigned int count_usable_erasers(const struct flashctx *flash) {
  unsigned int usable_erasefunctions = 0;
  int k;
  for (k = 0; k < 6; 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   $0x6,-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   %rbx
push   %rax
mov    %rdi,%rbx
xor    %esi,%esi
xor    %edx,%edx
call   1030 <check_block_eraser@plt>
xor    %ebp,%ebp
test   %eax,%eax
sete   %bpl
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %edx,%edx
call   1030 <check_block_eraser@plt>
cmp    $0x1,%eax
adc    $0x0,%ebp
mov    %rbx,%rdi
mov    $0x2,%esi
xor    %edx,%edx
call   1030 <check_block_eraser@plt>
cmp    $0x1,%eax
adc    $0x0,%ebp
mov    %rbx,%rdi
mov    $0x3,%esi
xor    %edx,%edx
call   1030 <check_block_eraser@plt>
cmp    $0x1,%eax
adc    $0x0,%ebp
mov    %rbx,%rdi
mov    $0x4,%esi
xor    %edx,%edx
call   1030 <check_block_eraser@plt>
cmp    $0x1,%eax
adc    $0x0,%ebp
mov    %rbx,%rdi
mov    $0x5,%esi
xor    %edx,%edx
call   1030 <check_block_eraser@plt>
cmp    $0x1,%eax
adc    $0x0,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.flashctx = type { i32 }
define i32 @count_usable_erasers(%struct.flashctx* %0) {
%2 = alloca %struct.flashctx*
%3 = alloca i32
%4 = alloca i32
store %struct.flashctx* %0, %struct.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, 6
br i1 %7, label %8, label %20
8: ; preds = %5
%9 = load %struct.flashctx*, %struct.flashctx** %2
%10 = load i32, i32* %4
%11 = call i32 @check_block_eraser(%struct.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.flashctx = type { i32 }
define i32 @count_usable_erasers(%struct.flashctx* %0) {
%2 = tail call i32 @check_block_eraser(%struct.flashctx* %0, i32 0, i32 0)
%3 = icmp eq i32 %2, 0
%4 = zext i1 %3 to i32
%5 = tail call i32 @check_block_eraser(%struct.flashctx* %0, i32 1, i32 0)
%6 = icmp eq i32 %5, 0
%7 = zext i1 %6 to i32
%8 = add nuw nsw i32 %4, %7
%9 = tail call i32 @check_block_eraser(%struct.flashctx* %0, i32 2, i32 0)
%10 = icmp eq i32 %9, 0
%11 = zext i1 %10 to i32
%12 = add nuw nsw i32 %8, %11
%13 = tail call i32 @check_block_eraser(%struct.flashctx* %0, i32 3, i32 0)
%14 = icmp eq i32 %13, 0
%15 = zext i1 %14 to i32
%16 = add nuw nsw i32 %12, %15
%17 = tail call i32 @check_block_eraser(%struct.flashctx* %0, i32 4, i32 0)
%18 = icmp eq i32 %17, 0
%19 = zext i1 %18 to i32
%20 = add nuw nsw i32 %16, %19
%21 = tail call i32 @check_block_eraser(%struct.flashctx* %0, i32 5, i32 0)
%22 = icmp eq i32 %21, 0
%23 = zext i1 %22 to i32
%24 = add nuw nsw i32 %20, %23
ret i32 %24
}