#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*/ wchar_t;

/* Variables and functions */
scalar_t__ match_suffix(int /*<<< orphan*/ *, unsigned long, char *, int);
unsigned long wcslen(int /*<<< orphan*/ *);
unsigned long strip_suffixes(wchar_t *word, unsigned long length, int uppercase,
                             int case_sensitive) {
  unsigned long string_length = wcslen(word);
  while (string_length > 3) {
    if (string_length > 5 && (match_suffix(word, string_length, L"em", 2) ||
                              match_suffix(word, string_length, L"er", 2) ||
                              match_suffix(word, string_length, L"nd", 2))) {
      string_length -= 2;
    } else if (((!uppercase) || case_sensitive) &&
               match_suffix(word, string_length, L"t", 1)) {
      string_length -= 1;
    } else if ((match_suffix(word, string_length, L"e", 1) ||
                match_suffix(word, string_length, L"s", 1) ||
                match_suffix(word, string_length, L"n", 1))) {
      string_length -= 1;
    } else {
      break;
    }
  }
  return string_length;
}


x86 assembly (clang, -O0):
<strip_suffixes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <wcslen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x3,-0x20(%rbp)
jbe    12a9 <strip_suffixes+0x189>
cmpq   $0x5,-0x20(%rbp)
jbe    11d3 <strip_suffixes+0xb3>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    0xe98(%rip),%rdx
mov    $0x2,%ecx
call   1040 <match_suffix@plt>
cmp    $0x0,%rax
jne    11c2 <strip_suffixes+0xa2>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    0xe81(%rip),%rdx
mov    $0x2,%ecx
call   1040 <match_suffix@plt>
cmp    $0x0,%rax
jne    11c2 <strip_suffixes+0xa2>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    0xe6a(%rip),%rdx
mov    $0x2,%ecx
call   1040 <match_suffix@plt>
cmp    $0x0,%rax
je     11d3 <strip_suffixes+0xb3>
mov    -0x20(%rbp),%rax
sub    $0x2,%rax
mov    %rax,-0x20(%rbp)
jmp    12a4 <strip_suffixes+0x184>
cmpl   $0x0,-0x14(%rbp)
je     11e7 <strip_suffixes+0xc7>
cmpl   $0x0,-0x18(%rbp)
je     121b <strip_suffixes+0xfb>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    0xe2e(%rip),%rdx
mov    $0x1,%ecx
call   1040 <match_suffix@plt>
cmp    $0x0,%rax
je     121b <strip_suffixes+0xfb>
mov    -0x20(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    129f <strip_suffixes+0x17f>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    0xe02(%rip),%rdx
mov    $0x1,%ecx
call   1040 <match_suffix@plt>
cmp    $0x0,%rax
jne    1284 <strip_suffixes+0x164>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    0xde7(%rip),%rdx
mov    $0x1,%ecx
call   1040 <match_suffix@plt>
cmp    $0x0,%rax
jne    1284 <strip_suffixes+0x164>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    0xdcc(%rip),%rdx
mov    $0x1,%ecx
call   1040 <match_suffix@plt>
cmp    $0x0,%rax
je     1295 <strip_suffixes+0x175>
mov    -0x20(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    129a <strip_suffixes+0x17a>
jmp    12a9 <strip_suffixes+0x189>
jmp    129f <strip_suffixes+0x17f>
jmp    12a4 <strip_suffixes+0x184>
jmp    1143 <strip_suffixes+0x23>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strip_suffixes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %edx,%ebp
mov    %rdi,%r14
call   1030 <wcslen@plt>
mov    %rax,%rbx
cmp    $0x4,%rax
jb     1270 <strip_suffixes+0x150>
test   %ebp,%ebp
sete   %al
test   %r15d,%r15d
setne  %r12b
or     %al,%r12b
lea    0xea5(%rip),%r15
lea    0xeca(%rip),%r13
jmp    11a0 <strip_suffixes+0x80>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    $0x2,%ecx
call   1040 <match_suffix@plt>
mov    $0xfffffffffffffffe,%rbp
test   %rax,%rax
je     122b <strip_suffixes+0x10b>
add    %rbp,%rbx
cmp    $0x3,%rbx
jbe    1270 <strip_suffixes+0x150>
cmp    $0x6,%rbx
jae    1170 <strip_suffixes+0x50>
test   %r12b,%r12b
je     11ce <strip_suffixes+0xae>
mov    %r14,%rdi
mov    %rbx,%rsi
lea    0xe6c(%rip),%rdx
mov    $0x1,%ecx
call   1040 <match_suffix@plt>
mov    $0xffffffffffffffff,%rbp
test   %rax,%rax
jne    1193 <strip_suffixes+0x73>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
mov    $0x1,%ecx
call   1040 <match_suffix@plt>
mov    $0xffffffffffffffff,%rbp
test   %rax,%rax
jne    1193 <strip_suffixes+0x73>
mov    %r14,%rdi
mov    %rbx,%rsi
lea    0xe3a(%rip),%rdx
mov    $0x1,%ecx
call   1040 <match_suffix@plt>
test   %rax,%rax
jne    1193 <strip_suffixes+0x73>
mov    %r14,%rdi
mov    %rbx,%rsi
lea    0xe26(%rip),%rdx
mov    $0x1,%ecx
call   1040 <match_suffix@plt>
test   %rax,%rax
jne    1193 <strip_suffixes+0x73>
jmp    1270 <strip_suffixes+0x150>
mov    %r14,%rdi
mov    %rbx,%rsi
lea    0xdd4(%rip),%rdx
mov    $0x2,%ecx
call   1040 <match_suffix@plt>
test   %rax,%rax
jne    1193 <strip_suffixes+0x73>
mov    %r14,%rdi
mov    %rbx,%rsi
lea    0xdc0(%rip),%rdx
mov    $0x2,%ecx
call   1040 <match_suffix@plt>
test   %rax,%rax
jne    1193 <strip_suffixes+0x73>
jmp    11a6 <strip_suffixes+0x86>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i32] [i32 101, i32 109, i32 0]
@.str.1 = [3 x i32] [i32 101, i32 114, i32 0]
@.str.2 = [3 x i32] [i32 110, i32 100, i32 0]
@.str.3 = [2 x i32] [i32 116, i32 0]
@.str.4 = [2 x i32] [i32 101, i32 0]
@.str.5 = [2 x i32] [i32 115, i32 0]
@.str.6 = [2 x i32] [i32 110, i32 0]
define i64 @strip_suffixes(i32* %0, i64 %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
store i32* %0, i32** %5
store i64 %1, i64* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i32*, i32** %5
%11 = call i64 @wcslen(i32* %10)
store i64 %11, i64* %9
br label %12
12: ; preds = %71, %4
%13 = load i64, i64* %9
%14 = icmp ugt i64 %13, 3
br i1 %14, label %15, label %72
15: ; preds = %12
%16 = load i64, i64* %9
%17 = icmp ugt i64 %16, 5
br i1 %17, label %18, label %36
18: ; preds = %15
%19 = load i32*, i32** %5
%20 = load i64, i64* %9
%21 = call i64 @match_suffix(i32* %19, i64 %20, i8* bitcast ([3 x i32]* @.str to i8*), i32 2)
%22 = icmp ne i64 %21, 0
br i1 %22, label %33, label %23
23: ; preds = %18
%24 = load i32*, i32** %5
%25 = load i64, i64* %9
%26 = call i64 @match_suffix(i32* %24, i64 %25, i8* bitcast ([3 x i32]* @.str.1 to i8*), i32 2)
%27 = icmp ne i64 %26, 0
br i1 %27, label %33, label %28
28: ; preds = %23
%29 = load i32*, i32** %5
%30 = load i64, i64* %9
%31 = call i64 @match_suffix(i32* %29, i64 %30, i8* bitcast ([3 x i32]* @.str.2 to i8*), i32 2)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %28, %23, %18
%34 = load i64, i64* %9
%35 = sub i64 %34, 2
store i64 %35, i64* %9
br label %71
36: ; preds = %28, %15
%37 = load i32, i32* %7
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = load i32, i32* %8
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %50
42: ; preds = %39, %36
%43 = load i32*, i32** %5
%44 = load i64, i64* %9
%45 = call i64 @match_suffix(i32* %43, i64 %44, i8* bitcast ([2 x i32]* @.str.3 to i8*), i32 1)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %42
%48 = load i64, i64* %9
%49 = sub i64 %48, 1
store i64 %49, i64* %9
br label %70
50: ; preds = %42, %39
%51 = load i32*, i32** %5
%52 = load i64, i64* %9
%53 = call i64 @match_suffix(i32* %51, i64 %52, i8* bitcast ([2 x i32]* @.str.4 to i8*), i32 1)
%54 = icmp ne i64 %53, 0
br i1 %54, label %65, label %55
55: ; preds = %50
%56 = load i32*, i32** %5
%57 = load i64, i64* %9
%58 = call i64 @match_suffix(i32* %56, i64 %57, i8* bitcast ([2 x i32]* @.str.5 to i8*), i32 1)
%59 = icmp ne i64 %58, 0
br i1 %59, label %65, label %60
60: ; preds = %55
%61 = load i32*, i32** %5
%62 = load i64, i64* %9
%63 = call i64 @match_suffix(i32* %61, i64 %62, i8* bitcast ([2 x i32]* @.str.6 to i8*), i32 1)
%64 = icmp ne i64 %63, 0
br i1 %64, label %65, label %68
65: ; preds = %60, %55, %50
%66 = load i64, i64* %9
%67 = sub i64 %66, 1
store i64 %67, i64* %9
br label %69
68: ; preds = %60
br label %72
69: ; preds = %65
br label %70
70: ; preds = %69, %47
br label %71
71: ; preds = %70, %33
br label %12
72: ; preds = %68, %12
%73 = load i64, i64* %9
ret i64 %73
}

LLVM IR (-O2):
@.str = [3 x i32] [i32 101, i32 109, i32 0]
@.str.1 = [3 x i32] [i32 101, i32 114, i32 0]
@.str.2 = [3 x i32] [i32 110, i32 100, i32 0]
@.str.3 = [2 x i32] [i32 116, i32 0]
@.str.4 = [2 x i32] [i32 101, i32 0]
@.str.5 = [2 x i32] [i32 115, i32 0]
@.str.6 = [2 x i32] [i32 110, i32 0]
define i64 @strip_suffixes(i32* %0, i64 %1, i32 %2, i32 %3) {
%5 = tail call i64 @wcslen(i32* %0)
%6 = icmp ugt i64 %5, 3
br i1 %6, label %7, label %40
7: ; preds = %4
%8 = icmp eq i32 %2, 0
%9 = icmp ne i32 %3, 0
%10 = or i1 %8, %9
br label %11
11: ; preds = %7, %36
%12 = phi i64 [ %5, %7 ], [ %38, %36 ]
%13 = icmp ugt i64 %12, 5
br i1 %13, label %14, label %23
14: ; preds = %11
%15 = tail call i64 @match_suffix(i32* %0, i64 %12, i8* bitcast ([3 x i32]* @.str to i8*), i32 2)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %36
17: ; preds = %14
%18 = tail call i64 @match_suffix(i32* %0, i64 %12, i8* bitcast ([3 x i32]* @.str.1 to i8*), i32 2)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %36
20: ; preds = %17
%21 = tail call i64 @match_suffix(i32* %0, i64 %12, i8* bitcast ([3 x i32]* @.str.2 to i8*), i32 2)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %36
23: ; preds = %20, %11
br i1 %10, label %24, label %27
24: ; preds = %23
%25 = tail call i64 @match_suffix(i32* %0, i64 %12, i8* bitcast ([2 x i32]* @.str.3 to i8*), i32 1)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %36
27: ; preds = %23, %24
%28 = tail call i64 @match_suffix(i32* %0, i64 %12, i8* bitcast ([2 x i32]* @.str.4 to i8*), i32 1)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %27
%31 = tail call i64 @match_suffix(i32* %0, i64 %12, i8* bitcast ([2 x i32]* @.str.5 to i8*), i32 1)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = tail call i64 @match_suffix(i32* %0, i64 %12, i8* bitcast ([2 x i32]* @.str.6 to i8*), i32 1)
%35 = icmp eq i64 %34, 0
br i1 %35, label %40, label %36
36: ; preds = %27, %30, %33, %24, %14, %17, %20
%37 = phi i64 [ -2, %20 ], [ -2, %17 ], [ -2, %14 ], [ -1, %24 ], [ -1, %33 ], [ -1, %30 ], [ -1, %27 ]
%38 = add i64 %12, %37
%39 = icmp ugt i64 %38, 3
br i1 %39, label %11, label %40
40: ; preds = %36, %33, %4
%41 = phi i64 [ %5, %4 ], [ %12, %33 ], [ %38, %36 ]
ret i64 %41
}