#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__ isspace(char const);
size_t strlen(char const *);
char *strstr(char const *, char const *);
const char *strword(const char *haystack, const char *needle) {
  const char *tmp;
  size_t needle_length = strlen(needle);
  tmp = strstr(haystack, needle);
  while (tmp) {
    if ((tmp == haystack || isspace(tmp[-1])) &&
        (tmp[needle_length] == 0 || tmp[needle_length] == '=' ||
         isspace(tmp[needle_length])))
      return tmp;
    tmp = strstr(tmp + 1, needle);
  }
  return 0;
}


x86 assembly (clang, -O0):
<strword>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11fa <strword+0xca>
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     118e <strword+0x5e>
mov    -0x20(%rbp),%rax
movsbl -0x1(%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     11e0 <strword+0xb0>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11d3 <strword+0xa3>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3d,%eax
je     11d3 <strword+0xa3>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     11e0 <strword+0xb0>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1202 <strword+0xd2>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x20(%rbp)
jmp    115e <strword+0x2e>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strword>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %rax,%r12
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     11a6 <strword+0x76>
mov    %rax,%rbx
jmp    1177 <strword+0x47>
xchg   %ax,%ax
add    $0x1,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11a6 <strword+0x76>
cmp    %r15,%rbx
je     118a <strword+0x5a>
movsbl -0x1(%rbx),%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     1160 <strword+0x30>
movzbl (%rbx,%r12,1),%eax
test   %al,%al
je     11a8 <strword+0x78>
cmp    $0x3d,%al
je     11a8 <strword+0x78>
movsbl %al,%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     1160 <strword+0x30>
jmp    11a8 <strword+0x78>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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