#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;

/* Variables and functions */
scalar_t__ memcmp(int /*<<< orphan*/ *, char *, int);
int patch_is_ips(uint8_t *patch, size_t patch_size) {
  if (patch_size < 8)
    return 0;
  if (memcmp(patch, "PATCH", 5) != 0)
    return 0;
  if ((memcmp(patch + patch_size - 3, "EOF", 3) != 0) &&
      (memcmp(patch + patch_size - 6, "EOF", 3) != 0)) {
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<patch_is_ips>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x8,-0x18(%rbp)
jae    1137 <patch_is_ips+0x27>
movl   $0x0,-0x4(%rbp)
jmp    11d1 <patch_is_ips+0xc1>
mov    -0x10(%rbp),%rdi
lea    0xebe(%rip),%rsi
mov    $0x5,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
je     1162 <patch_is_ips+0x52>
movl   $0x0,-0x4(%rbp)
jmp    11d1 <patch_is_ips+0xc1>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
add    $0xfffffffffffffff4,%rdi
lea    0xe8a(%rip),%rsi
mov    $0x3,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
je     11ca <patch_is_ips+0xba>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
add    $0xffffffffffffffe8,%rdi
lea    0xe5c(%rip),%rsi
mov    $0x3,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
je     11ca <patch_is_ips+0xba>
movl   $0x0,-0x4(%rbp)
jmp    11d1 <patch_is_ips+0xc1>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<patch_is_ips>:
push   %rbp
push   %r14
push   %rbx
xor    %r14d,%r14d
cmp    $0x8,%rsi
jb     1185 <patch_is_ips+0x75>
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0xed6(%rip),%rsi
mov    $0x5,%edx
call   1030 <memcmp@plt>
test   %rax,%rax
jne    1185 <patch_is_ips+0x75>
lea    -0xc(,%rbx,4),%rdi
ff
add    %rbp,%rdi
lea    0xebb(%rip),%rsi
mov    $0x3,%edx
call   1030 <memcmp@plt>
test   %rax,%rax
je     117f <patch_is_ips+0x6f>
lea    0x0(,%rbx,4),%rdi
add    %rbp,%rdi
add    $0xffffffffffffffe8,%rdi
lea    0xe96(%rip),%rsi
mov    $0x3,%edx
call   1030 <memcmp@plt>
test   %rax,%rax
jne    1185 <patch_is_ips+0x75>
mov    $0x1,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"PATCH\00"
@.str.1 = [4 x i8] c"EOF\00"
define i32 @patch_is_ips(i32* %0, i64 %1) {
%3 = icmp ult i64 %1, 8
br i1 %3, label %17, label %4
4: ; preds = %2
%5 = tail call i64 @memcmp(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %17
7: ; preds = %4
%8 = getelementptr inbounds i32, i32* %0, i64 %1
%9 = getelementptr inbounds i32, i32* %8, i64 -3
%10 = tail call i64 @memcmp(i32* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%11 = icmp eq i64 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %7
%13 = getelementptr inbounds i32, i32* %8, i64 -6
%14 = tail call i64 @memcmp(i32* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %12, %7
br label %17
17: ; preds = %12, %4, %2, %16
%18 = phi i32 [ 1, %16 ], [ 0, %2 ], [ 0, %4 ], [ 0, %12 ]
ret i32 %18
}