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

/* Variables and functions */
int /*<<< orphan*/ fread(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ puts(char *);
scalar_t__ strncmp(char *, char *, int);
int check_header(FILE *patch) {
  uint8_t buf[5];
  fread(buf, 5 * sizeof(uint8_t), 1, patch);
  if (strncmp((char *)buf, "PATCH", 5) != 0) {
    puts("Invalid patch file.");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<check_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x14,%esi
mov    $0x1,%edx
call   1050 <fread@plt>
lea    -0x30(%rbp),%rdi
lea    0xea2(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     118a <check_header+0x5a>
lea    0xe8d(%rip),%rdi
call   1040 <puts@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1191 <check_header+0x61>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_header>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rcx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x14,%esi
mov    $0x1,%edx
call   1050 <fread@plt>
lea    0xeac(%rip),%rsi
mov    %rbx,%rdi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1179 <check_header+0x49>
lea    0xe99(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
jmp    117b <check_header+0x4b>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"PATCH\00"
@.str.1 = [20 x i8] c"Invalid patch file.\00"
define i32 @check_header(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca [5 x i32]
store i32* %0, i32** %3
%5 = getelementptr inbounds [5 x i32], [5 x i32]* %4, i64 0, i64 0
%6 = load i32*, i32** %3
%7 = call i32 @fread(i32* %5, i32 20, i32 1, i32* %6)
%8 = getelementptr inbounds [5 x i32], [5 x i32]* %4, i64 0, i64 0
%9 = bitcast i32* %8 to i8*
%10 = call i64 @strncmp(i8* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %15
14: ; preds = %1
store i32 0, i32* %2
br label %15
15: ; preds = %14, %12
%16 = load i32, i32* %2
ret i32 %16
}

LLVM IR (-O2):
@.str = [6 x i8] c"PATCH\00"
@.str.1 = [20 x i8] c"Invalid patch file.\00"
define i32 @check_header(i32* nocapture %0) {
%2 = alloca [5 x i32]
%3 = bitcast [5 x i32]* %2 to i8*
%4 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 0
%5 = call i32 @fread(i32* %4, i32 20, i32 1, i32* %0)
%6 = call i64 @strncmp(i8* %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %1
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %1, %8
%11 = phi i32 [ -1, %8 ], [ 0, %1 ]
ret i32 %11
}