#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__ strchr(char const *, char);
int strlen(char const *);
char *strstr(char *, char const *);
int search_for_flag(char *flags, const char *flag) {
  char *p = strstr(flags, flag);
  int l = strlen(flag);
  int front = 0, back = 0;
  if (strlen(flag) == 0 || strchr(flag, ' '))
    return 0;
  while (p) {
    if (p == flags)
      front = 1;
    else if (*(p - 1) == ' ')
      front = 1;
    if (*(p + l) == ' ' || *(p + l) == '\0')
      back = 1;
    if (front && back)
      return 1;
    p = strstr(p + l, flag);
  }
  return 0;
}


x86 assembly (clang, -O0):
<search_for_flag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
je     1195 <search_for_flag+0x65>
mov    -0x18(%rbp),%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     11a1 <search_for_flag+0x71>
movl   $0x0,-0x4(%rbp)
jmp    125d <search_for_flag+0x12d>
jmp    11a6 <search_for_flag+0x76>
cmpq   $0x0,-0x20(%rbp)
je     1256 <search_for_flag+0x126>
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    11cb <search_for_flag+0x9b>
movl   $0x1,-0x28(%rbp)
jmp    11e8 <search_for_flag+0xb8>
mov    -0x20(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0x20,%eax
jne    11e3 <search_for_flag+0xb3>
movl   $0x1,-0x28(%rbp)
jmp    11e8 <search_for_flag+0xb8>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
je     1212 <search_for_flag+0xe2>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    1219 <search_for_flag+0xe9>
movl   $0x1,-0x2c(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     1239 <search_for_flag+0x109>
cmpl   $0x0,-0x2c(%rbp)
je     1239 <search_for_flag+0x109>
movl   $0x1,-0x4(%rbp)
jmp    125d <search_for_flag+0x12d>
mov    -0x20(%rbp),%rdi
movslq -0x24(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x20(%rbp)
jmp    11a6 <search_for_flag+0x76>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<search_for_flag>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
call   1050 <strstr@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%r12d
mov    %r15,%rdi
call   1030 <strlen@plt>
xor    %ebp,%ebp
test   %eax,%eax
je     11e2 <search_for_flag+0xb2>
mov    %r15,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    11e2 <search_for_flag+0xb2>
test   %rbx,%rbx
je     11e2 <search_for_flag+0xb2>
movslq %r12d,%rbp
xor    %r13d,%r13d
xor    %eax,%eax
jmp    11a9 <search_for_flag+0x79>
nopw   0x0(%rax,%rax,1)
add    %rbp,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strstr@plt>
mov    %rax,%rbx
mov    %r12d,%eax
test   %rbx,%rbx
je     11e0 <search_for_flag+0xb0>
mov    $0x1,%r12d
cmp    %r14,%rbx
je     11c3 <search_for_flag+0x93>
cmpb   $0x20,-0x1(%rbx)
mov    $0x1,%ecx
cmove  %ecx,%eax
mov    %eax,%r12d
testb  $0xdf,(%rbx,%rbp,1)
jne    11cf <search_for_flag+0x9f>
mov    $0x1,%r13d
test   %r12d,%r12d
je     1190 <search_for_flag+0x60>
test   %r13d,%r13d
je     1190 <search_for_flag+0x60>
mov    $0x1,%ebp
jmp    11e2 <search_for_flag+0xb2>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @search_for_flag(i8* %0, i8* %1) {
%3 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%4 = tail call i32 @strlen(i8* %1)
%5 = tail call i32 @strlen(i8* %1)
%6 = icmp eq i32 %5, 0
br i1 %6, label %37, label %7
7: ; preds = %2
%8 = tail call i64 @strchr(i8* %1, i8 signext 32)
%9 = icmp ne i64 %8, 0
%10 = icmp eq i8* %3, null
%11 = select i1 %9, i1 true, i1 %10
br i1 %11, label %37, label %12
12: ; preds = %7
%13 = sext i32 %4 to i64
br label %14
14: ; preds = %12, %34
%15 = phi i32 [ 0, %12 ], [ %30, %34 ]
%16 = phi i32 [ 0, %12 ], [ %25, %34 ]
%17 = phi i8* [ %3, %12 ], [ %35, %34 ]
%18 = icmp eq i8* %17, %0
br i1 %18, label %24, label %19
19: ; preds = %14
%20 = getelementptr inbounds i8, i8* %17, i64 -1
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 32
%23 = select i1 %22, i32 1, i32 %16
br label %24
24: ; preds = %19, %14
%25 = phi i32 [ 1, %14 ], [ %23, %19 ]
%26 = getelementptr inbounds i8, i8* %17, i64 %13
%27 = load i8, i8* %26
switch i8 %27, label %29 [
i8 32, label %28
i8 0, label %28
]
28: ; preds = %24, %24
br label %29
29: ; preds = %24, %28
%30 = phi i32 [ 1, %28 ], [ %15, %24 ]
%31 = icmp ne i32 %25, 0
%32 = icmp ne i32 %30, 0
%33 = select i1 %31, i1 %32, i1 false
br i1 %33, label %37, label %34
34: ; preds = %29
%35 = tail call i8* @strstr(i8* %26, i8* dereferenceable(1) %1)
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %14
37: ; preds = %29, %34, %2, %7
%38 = phi i32 [ 0, %7 ], [ 0, %2 ], [ 1, %29 ], [ 0, %34 ]
ret i32 %38
}