#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(void *, int, int, int /*<<< orphan*/ *);
scalar_t__ strncmp(char const *, char *, int);
int StateCheckRetrieveHeader(FILE *fp, const char *name, int *version,
                             int *size) {
  char id[4];
  size_t ret;
  if ((ret = fread((void *)id, 1, 4, fp)) != 4)
    return -1;
  if (strncmp(name, id, 4) != 0)
    return -2;
  if ((ret = fread((void *)version, 4, 1, fp)) != 1)
    return -1;
  if (fread((void *)size, 4, 1, fp) != 1)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<StateCheckRetrieveHeader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
lea    -0x2c(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4,%edx
call   1040 <fread@plt>
cltq
mov    %rax,-0x38(%rbp)
cmp    $0x4,%rax
je     116b <StateCheckRetrieveHeader+0x4b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f9 <StateCheckRetrieveHeader+0xd9>
mov    -0x18(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1193 <StateCheckRetrieveHeader+0x73>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11f9 <StateCheckRetrieveHeader+0xd9>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
cltq
mov    %rax,-0x38(%rbp)
cmp    $0x1,%rax
je     11c6 <StateCheckRetrieveHeader+0xa6>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f9 <StateCheckRetrieveHeader+0xd9>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x1,%eax
je     11f2 <StateCheckRetrieveHeader+0xd2>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f9 <StateCheckRetrieveHeader+0xd9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<StateCheckRetrieveHeader>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r12
lea    0x4(%rsp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0x4,%ecx
jne    11b8 <StateCheckRetrieveHeader+0x98>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
mov    $0xfffffffe,%eax
test   %rcx,%rcx
jne    11b8 <StateCheckRetrieveHeader+0x98>
mov    %r15,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0x1,%ecx
jne    11b8 <StateCheckRetrieveHeader+0x98>
mov    %r14,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
setne  %al
neg    %eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @StateCheckRetrieveHeader(i32* %0, i8* %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca [4 x i8]
%11 = alloca i64
store i32* %0, i32** %6
store i8* %1, i8** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %10, i64 0, i64 0
%13 = load i32*, i32** %6
%14 = call i32 @fread(i8* %12, i32 1, i32 4, i32* %13)
%15 = sext i32 %14 to i64
store i64 %15, i64* %11
%16 = icmp ne i64 %15, 4
br i1 %16, label %17, label %18
17: ; preds = %4
store i32 -1, i32* %5
br label %40
18: ; preds = %4
%19 = load i8*, i8** %7
%20 = getelementptr inbounds [4 x i8], [4 x i8]* %10, i64 0, i64 0
%21 = call i64 @strncmp(i8* %19, i8* %20, i32 4)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %18
store i32 -2, i32* %5
br label %40
24: ; preds = %18
%25 = load i32*, i32** %8
%26 = bitcast i32* %25 to i8*
%27 = load i32*, i32** %6
%28 = call i32 @fread(i8* %26, i32 4, i32 1, i32* %27)
%29 = sext i32 %28 to i64
store i64 %29, i64* %11
%30 = icmp ne i64 %29, 1
br i1 %30, label %31, label %32
31: ; preds = %24
store i32 -1, i32* %5
br label %40
32: ; preds = %24
%33 = load i32*, i32** %9
%34 = bitcast i32* %33 to i8*
%35 = load i32*, i32** %6
%36 = call i32 @fread(i8* %34, i32 4, i32 1, i32* %35)
%37 = icmp ne i32 %36, 1
br i1 %37, label %38, label %39
38: ; preds = %32
store i32 -1, i32* %5
br label %40
39: ; preds = %32
store i32 0, i32* %5
br label %40
40: ; preds = %39, %38, %31, %23, %17
%41 = load i32, i32* %5
ret i32 %41
}

LLVM IR (-O2):
define i32 @StateCheckRetrieveHeader(i32* nocapture %0, i8* %1, i32* nocapture %2, i32* nocapture %3) {
%5 = alloca [4 x i8]
%6 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%7 = call i32 @fread(i8* %6, i32 1, i32 4, i32* %0)
%8 = icmp eq i32 %7, 4
br i1 %8, label %9, label %21
9: ; preds = %4
%10 = call i64 @strncmp(i8* %1, i8* %6, i32 4)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %21
12: ; preds = %9
%13 = bitcast i32* %2 to i8*
%14 = call i32 @fread(i8* %13, i32 4, i32 1, i32* %0)
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = bitcast i32* %3 to i8*
%18 = call i32 @fread(i8* %17, i32 4, i32 1, i32* %0)
%19 = icmp ne i32 %18, 1
%20 = sext i1 %19 to i32
br label %21
21: ; preds = %16, %12, %9, %4
%22 = phi i32 [ -1, %4 ], [ -2, %9 ], [ -1, %12 ], [ %20, %16 ]
ret i32 %22
}