#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 /*<<< orphan*/ isalnum(char const);
size_t strlen(char const *);
char *strstr(char const *, char *);
bool is_box(const char format[]) {
  const char *p = strstr(format, "box");
  if (!p)
    return false;
  if (p == format || !isalnum(p[-1])) {
    return !isalnum(p[strlen(p)]);
  }
  return false;
}


x86 assembly (clang, -O0):
<is_box>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1167 <is_box+0x37>
movl   $0x0,-0x4(%rbp)
jmp    11c8 <is_box+0x98>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     118b <is_box+0x5b>
mov    -0x18(%rbp),%rax
movsbl -0x1(%rax),%edi
call   1040 <isalnum@plt>
cmp    $0x0,%eax
jne    11c1 <is_box+0x91>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
movsbl (%rax,%rcx,1),%edi
call   1040 <isalnum@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    11c8 <is_box+0x98>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_box>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbp
lea    0xec2(%rip),%rsi
call   1050 <strstr@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     117a <is_box+0x4a>
mov    %rax,%rbx
cmp    %rbp,%rax
je     1160 <is_box+0x30>
movsbl -0x1(%rbx),%edi
call   1040 <isalnum@plt>
test   %eax,%eax
jne    117a <is_box+0x4a>
mov    %rbx,%rdi
call   1030 <strlen@plt>
movsbl (%rbx,%rax,1),%edi
call   1040 <isalnum@plt>
xor    %r14d,%r14d
test   %eax,%eax
sete   %r14b
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"box\00"
define i32 @is_box(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i8* @strstr(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %1
store i32 0, i32* %2
br label %31
10: ; preds = %1
%11 = load i8*, i8** %4
%12 = load i8*, i8** %3
%13 = icmp eq i8* %11, %12
br i1 %13, label %20, label %14
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i64 -1
%17 = load i8, i8* %16
%18 = call i32 @isalnum(i8 signext %17)
%19 = icmp ne i32 %18, 0
br i1 %19, label %30, label %20
20: ; preds = %14, %10
%21 = load i8*, i8** %4
%22 = load i8*, i8** %4
%23 = call i64 @strlen(i8* %22)
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = call i32 @isalnum(i8 signext %25)
%27 = icmp ne i32 %26, 0
%28 = xor i1 %27, true
%29 = zext i1 %28 to i32
store i32 %29, i32* %2
br label %31
30: ; preds = %14
store i32 0, i32* %2
br label %31
31: ; preds = %30, %20, %9
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
@.str = [4 x i8] c"box\00"
define i32 @is_box(i8* %0) {
%2 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %18, label %4
4: ; preds = %1
%5 = icmp eq i8* %2, %0
br i1 %5, label %11, label %6
6: ; preds = %4
%7 = getelementptr inbounds i8, i8* %2, i64 -1
%8 = load i8, i8* %7
%9 = tail call i32 @isalnum(i8 signext %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %6, %4
%12 = tail call i64 @strlen(i8* %2)
%13 = getelementptr inbounds i8, i8* %2, i64 %12
%14 = load i8, i8* %13
%15 = tail call i32 @isalnum(i8 signext %14)
%16 = icmp eq i32 %15, 0
%17 = zext i1 %16 to i32
br label %18
18: ; preds = %6, %1, %11
%19 = phi i32 [ %17, %11 ], [ 0, %1 ], [ 0, %6 ]
ret i32 %19
}