#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 */
scalar_t__ memcmp(char *, char *, size_t);
size_t strlen(char *);
int same_word(char *word, char *haystack_start, char *haystack_end) {
  size_t word_len = strlen(word);
  size_t haystack_len = haystack_end - haystack_start;
  if (word_len != haystack_len)
    return 0;
  return 0 == memcmp(word, haystack_start, word_len);
}


x86 assembly (clang, -O0):
<same_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
je     116a <same_word+0x4a>
movl   $0x0,-0x4(%rbp)
jmp    118e <same_word+0x6e>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <memcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<same_word>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
sub    %r14,%rbx
xor    %ecx,%ecx
cmp    %rbx,%rax
jne    1153 <same_word+0x33>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1040 <memcmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
mov    %ecx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @same_word(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%10 = load i8*, i8** %5
%11 = call i64 @strlen(i8* %10)
store i64 %11, i64* %8
%12 = load i8*, i8** %7
%13 = load i8*, i8** %6
%14 = ptrtoint i8* %12 to i64
%15 = ptrtoint i8* %13 to i64
%16 = sub i64 %14, %15
store i64 %16, i64* %9
%17 = load i64, i64* %8
%18 = load i64, i64* %9
%19 = icmp ne i64 %17, %18
br i1 %19, label %20, label %21
20: ; preds = %3
store i32 0, i32* %4
br label %28
21: ; preds = %3
%22 = load i8*, i8** %5
%23 = load i8*, i8** %6
%24 = load i64, i64* %8
%25 = call i64 @memcmp(i8* %22, i8* %23, i64 %24)
%26 = icmp eq i64 0, %25
%27 = zext i1 %26 to i32
store i32 %27, i32* %4
br label %28
28: ; preds = %21, %20
%29 = load i32, i32* %4
ret i32 %29
}

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