#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 */
unsigned char eeread(int);
int findend(int addr) {
  while (++addr < 2047) {
    unsigned char c = eeread(addr);
    if (c == ((unsigned char)255))
      return addr;
    if (!c)
      return (++addr);
  }
  return 2047;
}


x86 assembly (clang, -O0):
<findend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x7ff,%eax
jge    1174 <findend+0x64>
mov    -0x8(%rbp),%edi
call   1030 <eeread@plt>
mov    %al,-0x9(%rbp)
movzbl -0x9(%rbp),%eax
cmp    $0xff,%eax
jne    1154 <findend+0x44>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    117b <findend+0x6b>
cmpb   $0x0,-0x9(%rbp)
jne    116f <findend+0x5f>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    %eax,-0x4(%rbp)
jmp    117b <findend+0x6b>
jmp    111b <findend+0xb>
movl   $0x7ff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findend>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
cmp    $0x7ff,%edi
mov    $0x7fe,%ebp
cmovge %edi,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    %ebx,%ebp
je     114b <findend+0x3b>
add    $0x1,%ebx
mov    %ebx,%edi
call   1030 <eeread@plt>
cmp    $0xff,%al
je     1150 <findend+0x40>
test   %al,%al
jne    1130 <findend+0x20>
add    $0x1,%ebx
jmp    1150 <findend+0x40>
mov    $0x7ff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @findend(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
store i32 %0, i32* %3
br label %5
5: ; preds = %23, %1
%6 = load i32, i32* %3
%7 = add nsw i32 %6, 1
store i32 %7, i32* %3
%8 = icmp slt i32 %7, 2047
br i1 %8, label %9, label %24
9: ; preds = %5
%10 = load i32, i32* %3
%11 = call zeroext i8 @eeread(i32 %10)
store i8 %11, i8* %4
%12 = load i8, i8* %4
%13 = zext i8 %12 to i32
%14 = icmp eq i32 %13, 255
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = load i32, i32* %3
store i32 %16, i32* %2
br label %25
17: ; preds = %9
%18 = load i8, i8* %4
%19 = icmp ne i8 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
store i32 %22, i32* %3
store i32 %22, i32* %2
br label %25
23: ; preds = %17
br label %5
24: ; preds = %5
store i32 2047, i32* %2
br label %25
25: ; preds = %24, %20, %15
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
define i32 @findend(i32 %0) {
%2 = call i32 @llvm.smax.i32(i32 %0, i32 2046)
br label %3
3: ; preds = %7, %1
%4 = phi i32 [ %0, %1 ], [ %5, %7 ]
%5 = add i32 %4, 1
%6 = icmp eq i32 %4, %2
br i1 %6, label %11, label %7
7: ; preds = %3
%8 = tail call zeroext i8 @eeread(i32 %5)
switch i8 %8, label %3 [
i8 -1, label %11
i8 0, label %9
]
9: ; preds = %7
%10 = add nsw i32 %4, 2
br label %11
11: ; preds = %7, %3, %9
%12 = phi i32 [ %10, %9 ], [ %5, %7 ], [ 2047, %3 ]
ret i32 %12
}