#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 scalar_t__ wchar_t;

/* Variables and functions */
int /*<<< orphan*/ copy_and_denormalize(scalar_t__ *, unsigned long,
                                        scalar_t__ *);
int /*<<< orphan*/ copy_and_normalize(scalar_t__ *, unsigned long, scalar_t__ *,
                                      int);
unsigned long count_double_characters(scalar_t__ *, unsigned long);
int /*<<< orphan*/ free(scalar_t__ *);
int /*<<< orphan*/ iswlower(scalar_t__);
scalar_t__ *malloc(unsigned long);
unsigned long strip_suffixes(scalar_t__ *, unsigned long, int, int);
unsigned long wcslen(scalar_t__ *);
wchar_t *stem_internal(wchar_t *word, int case_insensitive) {
  int uppercase = !iswlower(word[0]);
  unsigned long length = wcslen(word);
  unsigned long intermediate_length =
      length + count_double_characters(word, length) + 16;
  wchar_t *intermediate = malloc(intermediate_length * sizeof(wchar_t));
  wchar_t *result = malloc(intermediate_length * sizeof(wchar_t));
  copy_and_normalize(word, length, intermediate, 1);
  unsigned long stem_length = strip_suffixes(intermediate, intermediate_length,
                                             uppercase, case_insensitive);
  intermediate[stem_length] = 0;
  copy_and_denormalize(intermediate, stem_length, result);
  free(intermediate);
  return result;
}


x86 assembly (clang, -O0):
<stem_internal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <iswlower@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <wcslen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <count_double_characters@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
add    %rcx,%rax
add    $0x10,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
shl    $0x3,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
shl    $0x3,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    $0x1,%ecx
call   10a0 <copy_and_normalize@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%edx
mov    -0xc(%rbp),%ecx
call   1090 <strip_suffixes@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x38(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1080 <copy_and_denormalize@plt>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stem_internal>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,0x4(%rsp)
mov    %rdi,%r13
mov    (%rdi),%rdi
call   1030 <iswlower@plt>
xor    %r15d,%r15d
test   %eax,%eax
sete   %r15b
mov    %r13,%rdi
call   1060 <wcslen@plt>
mov    %rax,%rbp
mov    %r13,%rdi
mov    %rax,%rsi
call   1050 <count_double_characters@plt>
lea    (%rax,%rbp,1),%rcx
lea    (%rax,%rbp,1),%r12
add    $0x10,%r12
lea    0x80(,%rcx,8),%rbx
mov    %rbx,%rdi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
mov    $0x1,%ecx
call   10a0 <copy_and_normalize@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r15d,%edx
mov    0x4(%rsp),%ecx
call   1090 <strip_suffixes@plt>
movq   $0x0,(%r14,%rax,8)
mov    %r14,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1080 <copy_and_denormalize@plt>
mov    %r14,%rdi
call   1040 <free@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i64* @stem_internal(i64* %0, i32 %1) {
%3 = alloca i64*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64*
%9 = alloca i64*
%10 = alloca i64
store i64* %0, i64** %3
store i32 %1, i32* %4
%11 = load i64*, i64** %3
%12 = getelementptr inbounds i64, i64* %11, i64 0
%13 = load i64, i64* %12
%14 = call i32 @iswlower(i64 %13)
%15 = icmp ne i32 %14, 0
%16 = xor i1 %15, true
%17 = zext i1 %16 to i32
store i32 %17, i32* %5
%18 = load i64*, i64** %3
%19 = call i64 @wcslen(i64* %18)
store i64 %19, i64* %6
%20 = load i64, i64* %6
%21 = load i64*, i64** %3
%22 = load i64, i64* %6
%23 = call i64 @count_double_characters(i64* %21, i64 %22)
%24 = add i64 %20, %23
%25 = add i64 %24, 16
store i64 %25, i64* %7
%26 = load i64, i64* %7
%27 = mul i64 %26, 8
%28 = call i64* @malloc(i64 %27)
store i64* %28, i64** %8
%29 = load i64, i64* %7
%30 = mul i64 %29, 8
%31 = call i64* @malloc(i64 %30)
store i64* %31, i64** %9
%32 = load i64*, i64** %3
%33 = load i64, i64* %6
%34 = load i64*, i64** %8
%35 = call i32 @copy_and_normalize(i64* %32, i64 %33, i64* %34, i32 1)
%36 = load i64*, i64** %8
%37 = load i64, i64* %7
%38 = load i32, i32* %5
%39 = load i32, i32* %4
%40 = call i64 @strip_suffixes(i64* %36, i64 %37, i32 %38, i32 %39)
store i64 %40, i64* %10
%41 = load i64*, i64** %8
%42 = load i64, i64* %10
%43 = getelementptr inbounds i64, i64* %41, i64 %42
store i64 0, i64* %43
%44 = load i64*, i64** %8
%45 = load i64, i64* %10
%46 = load i64*, i64** %9
%47 = call i32 @copy_and_denormalize(i64* %44, i64 %45, i64* %46)
%48 = load i64*, i64** %8
%49 = call i32 @free(i64* %48)
%50 = load i64*, i64** %9
ret i64* %50
}

LLVM IR (-O2):
define i64* @stem_internal(i64* %0, i32 %1) {
%3 = load i64, i64* %0
%4 = tail call i32 @iswlower(i64 %3)
%5 = icmp eq i32 %4, 0
%6 = zext i1 %5 to i32
%7 = tail call i64 @wcslen(i64* %0)
%8 = tail call i64 @count_double_characters(i64* %0, i64 %7)
%9 = add i64 %7, 16
%10 = add i64 %9, %8
%11 = shl i64 %10, 3
%12 = tail call i64* @malloc(i64 %11)
%13 = tail call i64* @malloc(i64 %11)
%14 = tail call i32 @copy_and_normalize(i64* %0, i64 %7, i64* %12, i32 1)
%15 = tail call i64 @strip_suffixes(i64* %12, i64 %10, i32 %6, i32 %1)
%16 = getelementptr inbounds i64, i64* %12, i64 %15
store i64 0, i64* %16
%17 = tail call i32 @copy_and_denormalize(i64* %12, i64 %15, i64* %13)
%18 = tail call i32 @free(i64* %12)
ret i64* %13
}