#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 mtd_info_user {
  unsigned int erasesize;
};

/* Variables and functions */
int block_in_use(unsigned char *binary, unsigned int block,
                 struct mtd_info_user *mi) {
  int i = block * mi->erasesize;
  for (; i < block * mi->erasesize + mi->erasesize; i++) {
    if (binary[i] != 0xff)
      return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<block_in_use>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x20(%rbp),%rcx
imul   (%rcx),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x14(%rbp),%ecx
mov    -0x20(%rbp),%rdx
imul   (%rdx),%ecx
mov    -0x20(%rbp),%rdx
add    (%rdx),%ecx
cmp    %ecx,%eax
jae    116d <block_in_use+0x6d>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0xff,%eax
je     115a <block_in_use+0x5a>
movl   $0x1,-0x4(%rbp)
jmp    1174 <block_in_use+0x74>
jmp    115f <block_in_use+0x5f>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    111c <block_in_use+0x1c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<block_in_use>:
mov    (%rdx),%ecx
imul   %ecx,%esi
add    %esi,%ecx
xor    %eax,%eax
cmp    %ecx,%esi
jae    1130 <block_in_use+0x30>
movslq %esi,%rdx
add    %rdx,%rdi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmpb   $0xff,(%rdi)
jne    1131 <block_in_use+0x31>
add    $0x1,%rdi
add    $0x1,%esi
cmp    %esi,%ecx
ja     1120 <block_in_use+0x20>
ret
mov    $0x1,%eax
ret

LLVM IR (-O0):
%struct.mtd_info_user = type { i32 }
define i32 @block_in_use(i8* %0, i32 %1, %struct.mtd_info_user* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.mtd_info_user*
%8 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store %struct.mtd_info_user* %2, %struct.mtd_info_user** %7
%9 = load i32, i32* %6
%10 = load %struct.mtd_info_user*, %struct.mtd_info_user** %7
%11 = getelementptr inbounds %struct.mtd_info_user, %struct.mtd_info_user* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = mul i32 %9, %12
store i32 %13, i32* %8
br label %14
14: ; preds = %36, %3
%15 = load i32, i32* %8
%16 = load i32, i32* %6
%17 = load %struct.mtd_info_user*, %struct.mtd_info_user** %7
%18 = getelementptr inbounds %struct.mtd_info_user, %struct.mtd_info_user* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = mul i32 %16, %19
%21 = load %struct.mtd_info_user*, %struct.mtd_info_user** %7
%22 = getelementptr inbounds %struct.mtd_info_user, %struct.mtd_info_user* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = add i32 %20, %23
%25 = icmp ult i32 %15, %24
br i1 %25, label %26, label %39
26: ; preds = %14
%27 = load i8*, i8** %5
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = icmp ne i32 %32, 255
br i1 %33, label %34, label %35
34: ; preds = %26
store i32 1, i32* %4
br label %40
35: ; preds = %26
br label %36
36: ; preds = %35
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
store i32 %38, i32* %8
br label %14
39: ; preds = %14
store i32 0, i32* %4
br label %40
40: ; preds = %39, %34
%41 = load i32, i32* %4
ret i32 %41
}

LLVM IR (-O2):
%struct.mtd_info_user = type { i32 }
define i32 @block_in_use(i8* nocapture %0, i32 %1, %struct.mtd_info_user* nocapture %2) {
%4 = getelementptr inbounds %struct.mtd_info_user, %struct.mtd_info_user* %2, i64 0, i32 0
%5 = load i32, i32* %4
%6 = mul i32 %5, %1
%7 = add i32 %6, %5
%8 = icmp ult i32 %6, %7
br i1 %8, label %9, label %20
9: ; preds = %3
%10 = sext i32 %6 to i64
br label %14
11: ; preds = %14
%12 = trunc i64 %19 to i32
%13 = icmp ugt i32 %7, %12
br i1 %13, label %14, label %20
14: ; preds = %9, %11
%15 = phi i64 [ %10, %9 ], [ %19, %11 ]
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, -1
%19 = add nsw i64 %15, 1
br i1 %18, label %11, label %20
20: ; preds = %14, %11, %3
%21 = phi i32 [ 0, %3 ], [ 0, %11 ], [ 1, %14 ]
ret i32 %21
}