#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__ iswordpart(char);
int strlen(char const *);
char *word_strstr(char *, char const *);
char *word_find(char *line, const char *word) {
  const int wordlen = strlen(word);
  char *pos = line;
  while ((pos = word_strstr(pos, word))) {
    char *fin;
    if (pos > line && iswordpart(pos[-1])) {
      pos++;
      continue;
    }
    fin = pos + wordlen;
    if (iswordpart(*fin)) {
      pos++;
      continue;
    }
    return pos;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<word_find>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <word_strstr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11e8 <word_find+0xb8>
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jbe    11a5 <word_find+0x75>
mov    -0x28(%rbp),%rax
movsbl -0x1(%rax),%edi
call   1040 <iswordpart@plt>
cmp    $0x0,%rax
je     11a5 <word_find+0x75>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1154 <word_find+0x24>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%edi
call   1040 <iswordpart@plt>
cmp    $0x0,%rax
je     11db <word_find+0xab>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1154 <word_find+0x24>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11f0 <word_find+0xc0>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<word_find>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <word_strstr@plt>
test   %rax,%rax
je     119a <word_find+0x6a>
mov    %rax,%rbx
movslq %ebp,%rbp
jmp    1185 <word_find+0x55>
nop
movsbl (%rbx,%rbp,1),%edi
call   1040 <iswordpart@plt>
test   %rax,%rax
je     119c <word_find+0x6c>
add    $0x1,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <word_strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
je     119a <word_find+0x6a>
cmp    %r14,%rbx
jbe    1160 <word_find+0x30>
movsbl -0x1(%rbx),%edi
call   1040 <iswordpart@plt>
test   %rax,%rax
jne    116e <word_find+0x3e>
jmp    1160 <word_find+0x30>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @word_find(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = tail call i8* @word_strstr(i8* %0, i8* %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %25, label %6
6: ; preds = %2
%7 = sext i32 %3 to i64
br label %8
8: ; preds = %6, %21
%9 = phi i8* [ %4, %6 ], [ %23, %21 ]
%10 = icmp ugt i8* %9, %0
br i1 %10, label %11, label %16
11: ; preds = %8
%12 = getelementptr inbounds i8, i8* %9, i64 -1
%13 = load i8, i8* %12
%14 = tail call i64 @iswordpart(i8 signext %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %11, %8
%17 = getelementptr inbounds i8, i8* %9, i64 %7
%18 = load i8, i8* %17
%19 = tail call i64 @iswordpart(i8 signext %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %16, %11
%22 = getelementptr inbounds i8, i8* %9, i64 1
%23 = tail call i8* @word_strstr(i8* %22, i8* %1)
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %8
25: ; preds = %21, %16, %2
%26 = phi i8* [ null, %2 ], [ %9, %16 ], [ null, %21 ]
ret i8* %26
}