#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 */
scalar_t__ ferror(int /*<<< orphan*/ *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ reportError(char *);
int target(FILE *stream, int wanted) {
  char buf[10];
  size_t b = fread(buf, 7, wanted, stream);
  if (b < wanted) {
    if (ferror(stream)) {
      reportError(buf);
      return -22;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<target>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0x1e(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    $0x7,%esi
call   1040 <fread@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmp    %rcx,%rax
jae    1196 <target+0x66>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1191 <target+0x61>
lea    -0x1e(%rbp),%rdi
call   1050 <reportError@plt>
movl   $0xffffffea,-0x4(%rbp)
jmp    119d <target+0x6d>
jmp    1196 <target+0x66>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<target>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xe(%rsp),%rdi
mov    $0x7,%esi
mov    %ebp,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
movslq %ebp,%rcx
xor    %ebp,%ebp
cmp    %rcx,%rax
jae    1175 <target+0x45>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     1175 <target+0x45>
lea    0xe(%rsp),%rdi
call   1050 <reportError@plt>
mov    $0xffffffea,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @target(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca [10 x i8]
%7 = alloca i64
store i32* %0, i32** %4
store i32 %1, i32* %5
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%9 = load i32, i32* %5
%10 = load i32*, i32** %4
%11 = call i64 @fread(i8* %8, i32 7, i32 %9, i32* %10)
store i64 %11, i64* %7
%12 = load i64, i64* %7
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = icmp ult i64 %12, %14
br i1 %15, label %16, label %24
16: ; preds = %2
%17 = load i32*, i32** %4
%18 = call i64 @ferror(i32* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%22 = call i32 @reportError(i8* %21)
store i32 -22, i32* %3
br label %25
23: ; preds = %16
br label %24
24: ; preds = %23, %2
store i32 0, i32* %3
br label %25
25: ; preds = %24, %20
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
define i32 @target(i32* nocapture %0, i32 %1) {
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%5 = call i64 @fread(i8* %4, i32 7, i32 %1, i32* %0)
%6 = sext i32 %1 to i64
%7 = icmp ult i64 %5, %6
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = tail call i64 @ferror(i32* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = call i32 @reportError(i8* %4)
br label %13
13: ; preds = %2, %8, %11
%14 = phi i32 [ -22, %11 ], [ 0, %8 ], [ 0, %2 ]
ret i32 %14
}