#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(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int ivec_fread(FILE *f, int *v) {
  int d;
  int ret = fread(&d, sizeof(int), 1, f);
  if (ret != 1) {
    perror("# ivec_fread error 1");
    return -1;
  }
  ret = fread(v, sizeof(*v), d, f);
  if (ret != d) {
    perror("# ivec_fread error 2");
    return -1;
  }
  return d;
}


x86 assembly (clang, -O0):
<ivec_fread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x1c(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x20(%rbp)
je     116c <ivec_fread+0x4c>
lea    0xea5(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ae <ivec_fread+0x8e>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    $0x4,%esi
call   1030 <fread@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     11a8 <ivec_fread+0x88>
lea    0xe7e(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ae <ivec_fread+0x8e>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ivec_fread>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    116f <ivec_fread+0x4f>
mov    0xc(%rsp),%ebp
mov    %r14,%rdi
mov    $0x4,%esi
mov    %ebp,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
cmp    %ebp,%eax
jne    1178 <ivec_fread+0x58>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe8a(%rip),%rdi
jmp    117f <ivec_fread+0x5f>
lea    0xe96(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%ebp
jmp    1164 <ivec_fread+0x44>

LLVM IR (-O0):
@.str = [21 x i8] c"# ivec_fread error 1\00"
@.str.1 = [21 x i8] c"# ivec_fread error 2\00"
define i32 @ivec_fread(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
%8 = load i32*, i32** %4
%9 = call i32 @fread(i32* %6, i32 4, i32 1, i32* %8)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp ne i32 %10, 1
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %26
14: ; preds = %2
%15 = load i32*, i32** %5
%16 = load i32, i32* %6
%17 = load i32*, i32** %4
%18 = call i32 @fread(i32* %15, i32 4, i32 %16, i32* %17)
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = load i32, i32* %6
%21 = icmp ne i32 %19, %20
br i1 %21, label %22, label %24
22: ; preds = %14
%23 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %26
24: ; preds = %14
%25 = load i32, i32* %6
store i32 %25, i32* %3
br label %26
26: ; preds = %24, %22, %12
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@.str = [21 x i8] c"# ivec_fread error 1\00"
@.str.1 = [21 x i8] c"# ivec_fread error 2\00"
define i32 @ivec_fread(i32* nocapture %0, i32* nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @fread(i32* %3, i32 4, i32 1, i32* %0)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i32, i32* %3
%9 = tail call i32 @fread(i32* %1, i32 4, i32 %8, i32* %0)
%10 = icmp eq i32 %9, %8
br i1 %10, label %14, label %11
11: ; preds = %7, %2
%12 = phi i8* [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), %7 ]
%13 = tail call i32 @perror(i8* %12)
br label %14
14: ; preds = %11, %7
%15 = phi i32 [ %8, %7 ], [ -1, %11 ]
ret i32 %15
}