#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int fread_bo(int *, int, int, int /*<<< orphan*/ *, int);
int find_fillcount(FILE *fp) {
  int word, ncount = 0;
  while (ncount < 15000) {
    if (fread_bo(&word, sizeof(int), 1, fp, sizeof(int)) != 1)
      return (-2);
    if ((word & 0x80000000) != 0)
      return (0);
    else
      ncount++;
  }
  return (-1);
}


x86 assembly (clang, -O0):
<find_fillcount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x3a98,-0x18(%rbp)
jge    118b <find_fillcount+0x7b>
mov    -0x10(%rbp),%rcx
lea    -0x14(%rbp),%rdi
mov    $0x4,%r8d
mov    $0x1,%edx
mov    %r8d,%esi
call   1030 <fread_bo@plt>
cmp    $0x1,%eax
je     1160 <find_fillcount+0x50>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1192 <find_fillcount+0x82>
mov    -0x14(%rbp),%eax
and    $0x80000000,%eax
cmp    $0x0,%eax
je     117d <find_fillcount+0x6d>
movl   $0x0,-0x4(%rbp)
jmp    1192 <find_fillcount+0x82>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1123 <find_fillcount+0x13>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_fillcount>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    $0x3a98,%ebp
lea    0xc(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
mov    $0x4,%r8d
call   1030 <fread_bo@plt>
cmp    $0x1,%eax
jne    1163 <find_fillcount+0x53>
cmpl   $0x0,0xc(%rsp)
js     116a <find_fillcount+0x5a>
add    $0xffffffff,%ebp
jne    1130 <find_fillcount+0x20>
mov    $0xffffffff,%eax
jmp    116c <find_fillcount+0x5c>
mov    $0xfffffffe,%eax
jmp    116c <find_fillcount+0x5c>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @find_fillcount(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store i32 0, i32* %5
br label %6
6: ; preds = %22, %1
%7 = load i32, i32* %5
%8 = icmp slt i32 %7, 15000
br i1 %8, label %9, label %23
9: ; preds = %6
%10 = load i32*, i32** %3
%11 = call i32 @fread_bo(i32* %4, i32 4, i32 1, i32* %10, i32 4)
%12 = icmp ne i32 %11, 1
br i1 %12, label %13, label %14
13: ; preds = %9
store i32 -2, i32* %2
br label %24
14: ; preds = %9
%15 = load i32, i32* %4
%16 = and i32 %15, -2147483648
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %14
store i32 0, i32* %2
br label %24
19: ; preds = %14
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 1
store i32 %21, i32* %5
br label %22
22: ; preds = %19
br label %6
23: ; preds = %6
store i32 -1, i32* %2
br label %24
24: ; preds = %23, %18, %13
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
define i32 @find_fillcount(i32* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
br label %7
4: ; preds = %11
%5 = add nuw nsw i32 %8, 1
%6 = icmp eq i32 %5, 15000
br i1 %6, label %14, label %7
7: ; preds = %1, %4
%8 = phi i32 [ 0, %1 ], [ %5, %4 ]
%9 = call i32 @fread_bo(i32* %2, i32 4, i32 1, i32* %0, i32 4)
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = load i32, i32* %2
%13 = icmp sgt i32 %12, -1
br i1 %13, label %4, label %14
14: ; preds = %4, %11, %7
%15 = phi i32 [ -2, %7 ], [ 0, %11 ], [ -1, %4 ]
ret i32 %15
}