#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 int /*<<< orphan*/ bad_words;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *malloc(size_t);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
size_t strlen(char const *);
char *strstr(char *, char const *const);
char tolower(char);
void bad_word_checker_cb(const char *text) {
  const char *const bad_words[] = {"assembly", "windows", "matan", "kursach",
                                   "deadline"};
  char *low_text = malloc(strlen(text));
  strcpy(low_text, text);
  for (size_t i = 0; i < strlen(text); i++)
    low_text[i] = tolower(low_text[i]);
  for (size_t i = 0; i < (sizeof(bad_words) / sizeof((bad_words)[0])); ++i) {
    char *bad_word = strstr(low_text, bad_words[i]);
    if (bad_word) {
      printf("A bad word found: %s\n", bad_word);
      break;
    }
  }
  free(low_text);
}


x86 assembly (clang, -O0):
<bad_word_checker_cb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1070 <memset@plt>
lea    0xe5d(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe5b(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe58(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe53(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe50(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
call   1090 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
cmp    %rcx,%rax
jae    124d <bad_word_checker_cb+0xcd>
mov    -0x38(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1080 <tolower@plt>
mov    %al,%dl
mov    -0x38(%rbp),%rax
mov    -0x40(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    11fd <bad_word_checker_cb+0x7d>
movq   $0x0,-0x48(%rbp)
cmpq   $0x5,-0x48(%rbp)
jae    12ac <bad_word_checker_cb+0x12c>
mov    -0x38(%rbp),%rdi
mov    -0x48(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rsi
call   10a0 <strstr@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
je     1296 <bad_word_checker_cb+0x116>
mov    -0x50(%rbp),%rsi
lea    0xd9c(%rip),%rdi
call   1060 <printf@plt>
jmp    12ac <bad_word_checker_cb+0x12c>
jmp    129b <bad_word_checker_cb+0x11b>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    1255 <bad_word_checker_cb+0xd5>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bad_word_checker_cb>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
call   1050 <strlen@plt>
mov    %rax,%rdi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
cmpb   $0x0,(%r15)
je     11bf <bad_word_checker_cb+0x4f>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsbl (%r14,%rbx,1),%edi
call   1070 <tolower@plt>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
cmp    %rax,%rbx
jb     11a0 <bad_word_checker_cb+0x30>
lea    0xe3a(%rip),%rsi
mov    %r14,%rdi
call   1090 <strstr@plt>
test   %rax,%rax
jne    1223 <bad_word_checker_cb+0xb3>
lea    0xe2f(%rip),%rsi
mov    %r14,%rdi
call   1090 <strstr@plt>
test   %rax,%rax
jne    1223 <bad_word_checker_cb+0xb3>
lea    0xe23(%rip),%rsi
mov    %r14,%rdi
call   1090 <strstr@plt>
test   %rax,%rax
jne    1223 <bad_word_checker_cb+0xb3>
lea    0xe15(%rip),%rsi
mov    %r14,%rdi
call   1090 <strstr@plt>
test   %rax,%rax
jne    1223 <bad_word_checker_cb+0xb3>
lea    0xe09(%rip),%rsi
mov    %r14,%rdi
call   1090 <strstr@plt>
test   %rax,%rax
je     1232 <bad_word_checker_cb+0xc2>
lea    0xdfe(%rip),%rdi
mov    %rax,%rsi
call   1060 <printf@plt>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"assembly\00"
@.str.1 = [8 x i8] c"windows\00"
@.str.2 = [6 x i8] c"matan\00"
@.str.3 = [8 x i8] c"kursach\00"
@.str.4 = [9 x i8] c"deadline\00"
@.str.5 = [22 x i8] c"A bad word found: %s\0A\00"
define void @bad_word_checker_cb(i8* %0) {
%2 = alloca i8*
%3 = alloca [5 x i8*]
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
store i8* %0, i8** %2
%8 = bitcast [5 x i8*]* %3 to i8*
%9 = bitcast i8* %8 to [5 x i8*]*
%10 = getelementptr inbounds [5 x i8*], [5 x i8*]* %9, i32 0, i32 0
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i32 0, i32 0), i8** %10
%11 = getelementptr inbounds [5 x i8*], [5 x i8*]* %9, i32 0, i32 1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i32 0, i32 0), i8** %11
%12 = getelementptr inbounds [5 x i8*], [5 x i8*]* %9, i32 0, i32 2
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i32 0, i32 0), i8** %12
%13 = getelementptr inbounds [5 x i8*], [5 x i8*]* %9, i32 0, i32 3
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i32 0, i32 0), i8** %13
%14 = getelementptr inbounds [5 x i8*], [5 x i8*]* %9, i32 0, i32 4
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i32 0, i32 0), i8** %14
%15 = load i8*, i8** %2
%16 = call i64 @strlen(i8* %15)
%17 = call i8* @malloc(i64 %16)
store i8* %17, i8** %4
%18 = load i8*, i8** %4
%19 = load i8*, i8** %2
%20 = call i32 @strcpy(i8* %18, i8* %19)
store i64 0, i64* %5
br label %21
21: ; preds = %35, %1
%22 = load i64, i64* %5
%23 = load i8*, i8** %2
%24 = call i64 @strlen(i8* %23)
%25 = icmp ult i64 %22, %24
br i1 %25, label %26, label %38
26: ; preds = %21
%27 = load i8*, i8** %4
%28 = load i64, i64* %5
%29 = getelementptr inbounds i8, i8* %27, i64 %28
%30 = load i8, i8* %29
%31 = call signext i8 @tolower(i8 signext %30)
%32 = load i8*, i8** %4
%33 = load i64, i64* %5
%34 = getelementptr inbounds i8, i8* %32, i64 %33
store i8 %31, i8* %34
br label %35
35: ; preds = %26
%36 = load i64, i64* %5
%37 = add i64 %36, 1
store i64 %37, i64* %5
br label %21
38: ; preds = %21
store i64 0, i64* %6
br label %39
39: ; preds = %54, %38
%40 = load i64, i64* %6
%41 = icmp ult i64 %40, 5
br i1 %41, label %42, label %57
42: ; preds = %39
%43 = load i8*, i8** %4
%44 = load i64, i64* %6
%45 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 %44
%46 = load i8*, i8** %45
%47 = call i8* @strstr(i8* %43, i8* %46)
store i8* %47, i8** %7
%48 = load i8*, i8** %7
%49 = icmp ne i8* %48, null
br i1 %49, label %50, label %53
50: ; preds = %42
%51 = load i8*, i8** %7
%52 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %51)
br label %57
53: ; preds = %42
br label %54
54: ; preds = %53
%55 = load i64, i64* %6
%56 = add i64 %55, 1
store i64 %56, i64* %6
br label %39
57: ; preds = %50, %39
%58 = load i8*, i8** %4
%59 = call i32 @free(i8* %58)
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"assembly\00"
@.str.1 = [8 x i8] c"windows\00"
@.str.2 = [6 x i8] c"matan\00"
@.str.3 = [8 x i8] c"kursach\00"
@.str.4 = [9 x i8] c"deadline\00"
@.str.5 = [22 x i8] c"A bad word found: %s\0A\00"
define void @bad_word_checker_cb(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = tail call i8* @malloc(i64 %2)
%4 = tail call i32 @strcpy(i8* %3, i8* %0)
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %10, %1
%8 = tail call i8* @strstr(i8* dereferenceable(1) %3, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i8* %8, null
br i1 %9, label %18, label %30
10: ; preds = %1, %10
%11 = phi i64 [ %15, %10 ], [ 0, %1 ]
%12 = getelementptr inbounds i8, i8* %3, i64 %11
%13 = load i8, i8* %12
%14 = tail call signext i8 @tolower(i8 signext %13)
store i8 %14, i8* %12
%15 = add nuw i64 %11, 1
%16 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%17 = icmp ult i64 %15, %16
br i1 %17, label %10, label %7
18: ; preds = %7
%19 = tail call i8* @strstr(i8* dereferenceable(1) %3, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %30
21: ; preds = %18
%22 = tail call i8* @strstr(i8* dereferenceable(1) %3, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %30
24: ; preds = %21
%25 = tail call i8* @strstr(i8* dereferenceable(1) %3, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = tail call i8* @strstr(i8* dereferenceable(1) %3, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%29 = icmp eq i8* %28, null
br i1 %29, label %33, label %30
30: ; preds = %27, %24, %21, %18, %7
%31 = phi i8* [ %8, %7 ], [ %19, %18 ], [ %22, %21 ], [ %25, %24 ], [ %28, %27 ]
%32 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %27, %30
%34 = tail call i32 @free(i8* %3)
ret void
}