#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 strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int /*<<< orphan*/ strspn(char *, char *);
int contains_word(char *string, char *word, char *list) {
  int len = strlen(word);
  char *p = string, *cur = NULL;
  do {
    if (!strncmp(p, word, len))
      return 1;
    cur = p;
  } while ((p += strspn(p, list)) != cur || *(p++) != '\0');
  return 0;
}


x86 assembly (clang, -O0):
<contains_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1185 <contains_word+0x55>
movl   $0x1,-0x4(%rbp)
jmp    11e3 <contains_word+0xb3>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <strspn@plt>
mov    -0x30(%rbp),%rcx
cltq
add    %rax,%rcx
mov    %rcx,-0x30(%rbp)
mov    $0x1,%al
cmp    -0x38(%rbp),%rcx
mov    %al,-0x39(%rbp)
jne    11d1 <contains_word+0xa1>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    1160 <contains_word+0x30>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<contains_word>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
mov    $0x1,%r12d
jmp    116d <contains_word+0x3d>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1193 <contains_word+0x63>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strspn@plt>
cltq
add    %rax,%rbx
test   %eax,%eax
jne    1160 <contains_word+0x30>
cmpb   $0x0,(%rbx)
je     1190 <contains_word+0x60>
add    $0x1,%rbx
jmp    1160 <contains_word+0x30>
xor    %r12d,%r12d
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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