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

/* Variables and functions */
scalar_t__ is_c_type_char(char);
size_t strlen(char const *);
scalar_t__ strncmp(char const *, char const *, size_t);
int64_t match_words(const char *str, const char *beginning_of_line,
                    const char **words, int64_t word_count) {
  for (int64_t i = 0; i < word_count; ++i) {
    int64_t word_len = strlen(words[i]);
    if (strncmp(words[i], str, word_len) == 0) {
      char post_char = str[word_len];
      if (is_c_type_char(post_char))
        return 0;
      if (str > beginning_of_line) {
        char pre_char = *(str - 1);
        if (is_c_type_char(pre_char))
          return 0;
      }
      return word_len;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<match_words>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1224 <match_words+0xf4>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    120e <match_words+0xde>
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x39(%rbp)
movsbl -0x39(%rbp),%edi
call   1040 <is_c_type_char@plt>
cmp    $0x0,%rax
je     11c4 <match_words+0x94>
movq   $0x0,-0x8(%rbp)
jmp    122c <match_words+0xfc>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jbe    1201 <match_words+0xd1>
mov    -0x10(%rbp),%rax
mov    -0x1(%rax),%al
mov    %al,-0x3a(%rbp)
movsbl -0x3a(%rbp),%edi
call   1040 <is_c_type_char@plt>
cmp    $0x0,%rax
je     11fc <match_words+0xcc>
movq   $0x0,-0x8(%rbp)
jmp    122c <match_words+0xfc>
jmp    1201 <match_words+0xd1>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    122c <match_words+0xfc>
jmp    1213 <match_words+0xe3>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1150 <match_words+0x20>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<match_words>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rcx,%rcx
je     118d <match_words+0x5d>
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rdi,%r14
mov    %rsi,(%rsp)
xor    %r15d,%r15d
mov    0x0(%r13,%r15,8),%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1030 <strncmp@plt>
test   %rax,%rax
je     117e <match_words+0x4e>
add    $0x1,%r15
cmp    %r15,%r12
jne    1150 <match_words+0x20>
jmp    118d <match_words+0x5d>
movsbl (%r14,%rbx,1),%edi
call   1040 <is_c_type_char@plt>
test   %rax,%rax
je     11a1 <match_words+0x71>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cmp    (%rsp),%r14
jbe    118f <match_words+0x5f>
movsbl -0x1(%r14),%edi
call   1040 <is_c_type_char@plt>
test   %rax,%rax
jne    118d <match_words+0x5d>
jmp    118f <match_words+0x5f>

LLVM IR (-O0):
define i64 @match_words(i8* %0, i8* %1, i8** %2, i64 %3) {
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8**
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i8
%13 = alloca i8
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8** %2, i8*** %8
store i64 %3, i64* %9
store i64 0, i64* %10
br label %14
14: ; preds = %57, %4
%15 = load i64, i64* %10
%16 = load i64, i64* %9
%17 = icmp ult i64 %15, %16
br i1 %17, label %18, label %60
18: ; preds = %14
%19 = load i8**, i8*** %8
%20 = load i64, i64* %10
%21 = getelementptr inbounds i8*, i8** %19, i64 %20
%22 = load i8*, i8** %21
%23 = call i64 @strlen(i8* %22)
store i64 %23, i64* %11
%24 = load i8**, i8*** %8
%25 = load i64, i64* %10
%26 = getelementptr inbounds i8*, i8** %24, i64 %25
%27 = load i8*, i8** %26
%28 = load i8*, i8** %6
%29 = load i64, i64* %11
%30 = call i64 @strncmp(i8* %27, i8* %28, i64 %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %56
32: ; preds = %18
%33 = load i8*, i8** %6
%34 = load i64, i64* %11
%35 = getelementptr inbounds i8, i8* %33, i64 %34
%36 = load i8, i8* %35
store i8 %36, i8* %12
%37 = load i8, i8* %12
%38 = call i64 @is_c_type_char(i8 signext %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %32
store i64 0, i64* %5
br label %61
41: ; preds = %32
%42 = load i8*, i8** %6
%43 = load i8*, i8** %7
%44 = icmp ugt i8* %42, %43
br i1 %44, label %45, label %54
45: ; preds = %41
%46 = load i8*, i8** %6
%47 = getelementptr inbounds i8, i8* %46, i64 -1
%48 = load i8, i8* %47
store i8 %48, i8* %13
%49 = load i8, i8* %13
%50 = call i64 @is_c_type_char(i8 signext %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %45
store i64 0, i64* %5
br label %61
53: ; preds = %45
br label %54
54: ; preds = %53, %41
%55 = load i64, i64* %11
store i64 %55, i64* %5
br label %61
56: ; preds = %18
br label %57
57: ; preds = %56
%58 = load i64, i64* %10
%59 = add i64 %58, 1
store i64 %59, i64* %10
br label %14
60: ; preds = %14
store i64 0, i64* %5
br label %61
61: ; preds = %60, %54, %52, %40
%62 = load i64, i64* %5
ret i64 %62
}

LLVM IR (-O2):
define i64 @match_words(i8* %0, i8* readnone %1, i8** nocapture %2, i64 %3) {
%5 = icmp eq i64 %3, 0
br i1 %5, label %29, label %8
6: ; preds = %8
%7 = icmp eq i64 %15, %3
br i1 %7, label %29, label %8
8: ; preds = %4, %6
%9 = phi i64 [ %15, %6 ], [ 0, %4 ]
%10 = getelementptr inbounds i8*, i8** %2, i64 %9
%11 = load i8*, i8** %10
%12 = tail call i64 @strlen(i8* dereferenceable(1) %11)
%13 = tail call i64 @strncmp(i8* %11, i8* %0, i64 %12)
%14 = icmp eq i64 %13, 0
%15 = add nuw i64 %9, 1
br i1 %14, label %16, label %6
16: ; preds = %8
%17 = getelementptr inbounds i8, i8* %0, i64 %12
%18 = load i8, i8* %17
%19 = tail call i64 @is_c_type_char(i8 signext %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %16
%22 = icmp ugt i8* %0, %1
br i1 %22, label %23, label %28
23: ; preds = %21
%24 = getelementptr inbounds i8, i8* %0, i64 -1
%25 = load i8, i8* %24
%26 = tail call i64 @is_c_type_char(i8 signext %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %23, %21
br label %29
29: ; preds = %6, %4, %16, %23, %28
%30 = phi i64 [ 0, %16 ], [ 0, %23 ], [ %12, %28 ], [ 0, %4 ], [ 0, %6 ]
ret i64 %30
}