#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 */

/* Variables and functions */
int /*<<< orphan*/ memcmp(char *, char *, int);
int strlen(char *);
int check_header(void *data, int size, char *str, int offset) {
  int len = strlen(str);
  return (size >= offset + len) && !memcmp((char *)data + offset, str, len);
}


x86 assembly (clang, -O0):
<check_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%ecx
mov    -0x1c(%rbp),%edx
add    -0x20(%rbp),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x21(%rbp)
jl     117a <check_header+0x5a>
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1040 <memcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_header>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%r15
mov    %rdx,%rdi
call   1030 <strlen@plt>
lea    (%rax,%rbx,1),%edx
xor    %ecx,%ecx
cmp    %ebp,%edx
jg     115c <check_header+0x3c>
movslq %ebx,%rcx
add    %rcx,%r15
mov    %r15,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <memcmp@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @check_header(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%10 = load i8*, i8** %7
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %9
%12 = load i32, i32* %6
%13 = load i32, i32* %8
%14 = load i32, i32* %9
%15 = add nsw i32 %13, %14
%16 = icmp sge i32 %12, %15
br i1 %16, label %17, label %27
17: ; preds = %4
%18 = load i8*, i8** %5
%19 = load i32, i32* %8
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8*, i8** %7
%23 = load i32, i32* %9
%24 = call i32 @memcmp(i8* %21, i8* %22, i32 %23)
%25 = icmp ne i32 %24, 0
%26 = xor i1 %25, true
br label %27
27: ; preds = %17, %4
%28 = phi i1 [ false, %4 ], [ %26, %17 ]
%29 = zext i1 %28 to i32
ret i32 %29
}

LLVM IR (-O2):
define i32 @check_header(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = tail call i32 @strlen(i8* %2)
%6 = add nsw i32 %5, %3
%7 = icmp sgt i32 %6, %1
br i1 %7, label %14, label %8
8: ; preds = %4
%9 = sext i32 %3 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = tail call i32 @memcmp(i8* %10, i8* %2, i32 %5)
%12 = icmp eq i32 %11, 0
%13 = zext i1 %12 to i32
br label %14
14: ; preds = %8, %4
%15 = phi i32 [ 0, %4 ], [ %13, %8 ]
ret i32 %15
}