#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*/ DestroyString(char **);
char *malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
int FindWord(char *thisString, char *token, int minLength) {
  char *minStr;
  char *tokenFound;
  char *tmp;
  int position, tmpInt;
  tmpInt = strlen(token);
  if (tmpInt < minLength) {
    printf(" Warning : bad use of FindWord %s \n", token);
    minLength = tmpInt;
  }
  if (minLength < 1) {
    printf(" Warning : bad use of FindWord %s \n", token);
    return -1;
  }
  minStr = malloc(sizeof(*minStr) * minLength + 1);
  strncpy(minStr, token, minLength);
  minStr[minLength] = 0;
  tokenFound = strstr(thisString, minStr);
  if (!tokenFound) {
    DestroyString(&minStr);
    return -1;
  }
  tmp = thisString;
  position = 0;
  while (tmp != tokenFound) {
    position++;
    tmp++;
  }
  while (*tokenFound == *token && *tokenFound != 0) {
    *tokenFound = 32;
    tokenFound++;
    token++;
  }
  DestroyString(&minStr);
  return position;
}


x86 assembly (clang, -O0):
<FindWord>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11a1 <FindWord+0x41>
mov    -0x18(%rbp),%rsi
lea    0xe6a(%rip),%rdi
call   1060 <printf@plt>
mov    -0x40(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jge    11c7 <FindWord+0x67>
mov    -0x18(%rbp),%rsi
lea    0xe4a(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d5 <FindWord+0x175>
movslq -0x1c(%rbp),%rax
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    122b <FindWord+0xcb>
lea    -0x28(%rbp),%rdi
call   1050 <DestroyString@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d5 <FindWord+0x175>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x30(%rbp),%rax
je     1262 <FindWord+0x102>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    123a <FindWord+0xda>
jmp    1267 <FindWord+0x107>
mov    -0x30(%rbp),%rax
movsbl (%rax),%ecx
mov    -0x18(%rbp),%rax
movsbl (%rax),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x41(%rbp)
jne    1292 <FindWord+0x132>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    12a2 <FindWord+0x142>
jmp    12c6 <FindWord+0x166>
mov    -0x30(%rbp),%rax
movb   $0x20,(%rax)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1267 <FindWord+0x107>
lea    -0x28(%rbp),%rdi
call   1050 <DestroyString@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FindWord>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
cmp    %ebp,%eax
jge    1195 <FindWord+0x35>
mov    %eax,%r15d
lea    0xe76(%rip),%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    %r15d,%ebp
test   %ebp,%ebp
jle    1215 <FindWord+0xb5>
mov    %ebp,%r12d
lea    0x1(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %rax,0x8(%rsp)
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%r15,%r12,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1080 <strstr@plt>
test   %rax,%rax
je     1226 <FindWord+0xc6>
mov    %eax,%ecx
sub    %r14d,%ecx
xor    %ebp,%ebp
cmp    %r14,%rax
cmovne %ecx,%ebp
mov    (%rax),%cl
test   %cl,%cl
je     1209 <FindWord+0xa9>
cmp    (%rbx),%cl
jne    1209 <FindWord+0xa9>
mov    $0x1,%ecx
nopw   0x0(%rax,%rax,1)
movb   $0x20,-0x1(%rax,%rcx,1)
movzbl (%rax,%rcx,1),%edx
test   %dl,%dl
je     1209 <FindWord+0xa9>
lea    0x1(%rcx),%rsi
cmp    (%rbx,%rcx,1),%dl
mov    %rsi,%rcx
je     11f0 <FindWord+0x90>
lea    0x8(%rsp),%rdi
call   1050 <DestroyString@plt>
jmp    1235 <FindWord+0xd5>
lea    0xde4(%rip),%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
jmp    1230 <FindWord+0xd0>
lea    0x8(%rsp),%rdi
call   1050 <DestroyString@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c" Warning : bad use of FindWord %s \0A\00"
define i32 @FindWord(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%13 = load i8*, i8** %6
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %12
%15 = load i32, i32* %12
%16 = load i32, i32* %7
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %22
18: ; preds = %3
%19 = load i8*, i8** %6
%20 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = load i32, i32* %12
store i32 %21, i32* %7
br label %22
22: ; preds = %18, %3
%23 = load i32, i32* %7
%24 = icmp slt i32 %23, 1
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i8*, i8** %6
%27 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %26)
store i32 -1, i32* %4
br label %86
28: ; preds = %22
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = mul i64 1, %30
%32 = add i64 %31, 1
%33 = trunc i64 %32 to i32
%34 = call i8* @malloc(i32 %33)
store i8* %34, i8** %8
%35 = load i8*, i8** %8
%36 = load i8*, i8** %6
%37 = load i32, i32* %7
%38 = call i32 @strncpy(i8* %35, i8* %36, i32 %37)
%39 = load i8*, i8** %8
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
store i8 0, i8* %42
%43 = load i8*, i8** %5
%44 = load i8*, i8** %8
%45 = call i8* @strstr(i8* %43, i8* %44)
store i8* %45, i8** %9
%46 = load i8*, i8** %9
%47 = icmp ne i8* %46, null
br i1 %47, label %50, label %48
48: ; preds = %28
%49 = call i32 @DestroyString(i8** %8)
store i32 -1, i32* %4
br label %86
50: ; preds = %28
%51 = load i8*, i8** %5
store i8* %51, i8** %10
store i32 0, i32* %11
br label %52
52: ; preds = %56, %50
%53 = load i8*, i8** %10
%54 = load i8*, i8** %9
%55 = icmp ne i8* %53, %54
br i1 %55, label %56, label %61
56: ; preds = %52
%57 = load i32, i32* %11
%58 = add nsw i32 %57, 1
store i32 %58, i32* %11
%59 = load i8*, i8** %10
%60 = getelementptr inbounds i8, i8* %59, i32 1
store i8* %60, i8** %10
br label %52
61: ; preds = %52
br label %62
62: ; preds = %77, %61
%63 = load i8*, i8** %9
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = load i8*, i8** %6
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = icmp eq i32 %65, %68
br i1 %69, label %70, label %75
70: ; preds = %62
%71 = load i8*, i8** %9
%72 = load i8, i8* %71
%73 = sext i8 %72 to i32
%74 = icmp ne i32 %73, 0
br label %75
75: ; preds = %70, %62
%76 = phi i1 [ false, %62 ], [ %74, %70 ]
br i1 %76, label %77, label %83
77: ; preds = %75
%78 = load i8*, i8** %9
store i8 32, i8* %78
%79 = load i8*, i8** %9
%80 = getelementptr inbounds i8, i8* %79, i32 1
store i8* %80, i8** %9
%81 = load i8*, i8** %6
%82 = getelementptr inbounds i8, i8* %81, i32 1
store i8* %82, i8** %6
br label %62
83: ; preds = %75
%84 = call i32 @DestroyString(i8** %8)
%85 = load i32, i32* %11
store i32 %85, i32* %4
br label %86
86: ; preds = %83, %48, %25
%87 = load i32, i32* %4
ret i32 %87
}

LLVM IR (-O2):
@.str = [36 x i8] c" Warning : bad use of FindWord %s \0A\00"
define i32 @FindWord(i8* %0, i8* %1, i32 %2) {
%4 = ptrtoint i8* %0 to i64
%5 = alloca i8*
%6 = bitcast i8** %5 to i8*
%7 = tail call i32 @strlen(i8* %1)
%8 = icmp slt i32 %7, %2
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %11
11: ; preds = %9, %3
%12 = phi i32 [ %7, %9 ], [ %2, %3 ]
%13 = icmp slt i32 %12, 1
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %50
16: ; preds = %11
%17 = zext i32 %12 to i64
%18 = add nuw i32 %12, 1
%19 = tail call i8* @malloc(i32 %18)
store i8* %19, i8** %5
%20 = tail call i32 @strncpy(i8* %19, i8* %1, i32 %12)
%21 = getelementptr inbounds i8, i8* %19, i64 %17
store i8 0, i8* %21
%22 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %19)
%23 = icmp eq i8* %22, null
br i1 %23, label %36, label %24
24: ; preds = %16
%25 = ptrtoint i8* %22 to i64
%26 = icmp eq i8* %22, %0
%27 = trunc i64 %4 to i32
%28 = trunc i64 %25 to i32
%29 = sub i32 %28, %27
%30 = select i1 %26, i32 0, i32 %29
%31 = load i8, i8* %22
%32 = load i8, i8* %1
%33 = icmp ne i8 %31, %32
%34 = icmp eq i8 %31, 0
%35 = or i1 %34, %33
br i1 %35, label %48, label %38
36: ; preds = %16
%37 = call i32 @DestroyString(i8** %5)
br label %50
38: ; preds = %24, %38
%39 = phi i8* [ %41, %38 ], [ %22, %24 ]
%40 = phi i8* [ %42, %38 ], [ %1, %24 ]
store i8 32, i8* %39
%41 = getelementptr inbounds i8, i8* %39, i64 1
%42 = getelementptr inbounds i8, i8* %40, i64 1
%43 = load i8, i8* %41
%44 = load i8, i8* %42
%45 = icmp ne i8 %43, %44
%46 = icmp eq i8 %43, 0
%47 = or i1 %46, %45
br i1 %47, label %48, label %38
48: ; preds = %38, %24
%49 = call i32 @DestroyString(i8** %5)
br label %50
50: ; preds = %48, %36, %14
%51 = phi i32 [ -1, %14 ], [ %30, %48 ], [ -1, %36 ]
ret i32 %51
}