#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__ *);
unsigned long copy_and_normalize(scalar_t__ *, unsigned long, scalar_t__ *,
                                 int /*<<< orphan*/);
unsigned long count_double_characters(scalar_t__ *, unsigned long);
int /*<<< orphan*/ free(scalar_t__ *);
int /*<<< orphan*/ iswlower(scalar_t__);
void *malloc(unsigned long);
unsigned long strip_suffixes(scalar_t__ *, unsigned long, int, int);
unsigned long wcslen(scalar_t__ *);
int /*<<< orphan*/ wcsncpy(scalar_t__ *, scalar_t__ *, unsigned long);
wchar_t **segment_internal(wchar_t *word, int case_insensitive) {
  wchar_t **result = malloc(2 * sizeof(wchar_t *));
  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 *stem_result = malloc(intermediate_length * sizeof(wchar_t));
  wchar_t *suffix_result = malloc(intermediate_length * sizeof(wchar_t));
  unsigned long normalized_length =
      copy_and_normalize(word, length, intermediate, 0);
  unsigned long stem_length = strip_suffixes(intermediate, intermediate_length,
                                             uppercase, case_insensitive);
  wcsncpy(suffix_result, intermediate + stem_length,
          normalized_length - stem_length);
  suffix_result[normalized_length - stem_length] = 0;
  intermediate[stem_length] = 0;
  copy_and_denormalize(intermediate, stem_length, stem_result);
  free(intermediate);
  result[0] = stem_result;
  result[1] = suffix_result;
  return result;
}


x86 assembly (clang, -O0):
<segment_internal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x10,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%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,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <wcslen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <count_double_characters@plt>
mov    %rax,%rcx
mov    -0x60(%rbp),%rax
add    %rcx,%rax
add    $0x10,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
shl    $0x3,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
shl    $0x3,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
shl    $0x3,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
xor    %ecx,%ecx
call   10b0 <copy_and_normalize@plt>
mov    %rax,-0x50(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0xc(%rbp),%ecx
call   10a0 <strip_suffixes@plt>
mov    %rax,-0x58(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x58(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
mov    -0x50(%rbp),%rdx
sub    -0x58(%rbp),%rdx
call   1070 <wcsncpy@plt>
mov    -0x48(%rbp),%rax
mov    -0x50(%rbp),%rcx
sub    -0x58(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x38(%rbp),%rax
mov    -0x58(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x38(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    -0x40(%rbp),%rdx
call   1090 <copy_and_denormalize@plt>
mov    -0x38(%rbp),%rdi
call   1040 <free@plt>
mov    -0x40(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x48(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x18(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
define i64** @segment_internal(i64* %0, i32 %1) {
%3 = alloca i64*
%4 = alloca i32
%5 = alloca i64**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64*
%10 = alloca i64*
%11 = alloca i64*
%12 = alloca i64
%13 = alloca i64
store i64* %0, i64** %3
store i32 %1, i32* %4
%14 = call i8* @malloc(i64 16)
%15 = bitcast i8* %14 to i64**
store i64** %15, i64*** %5
%16 = load i64*, i64** %3
%17 = getelementptr inbounds i64, i64* %16, i64 0
%18 = load i64, i64* %17
%19 = call i32 @iswlower(i64 %18)
%20 = icmp ne i32 %19, 0
%21 = xor i1 %20, true
%22 = zext i1 %21 to i32
store i32 %22, i32* %6
%23 = load i64*, i64** %3
%24 = call i64 @wcslen(i64* %23)
store i64 %24, i64* %7
%25 = load i64, i64* %7
%26 = load i64*, i64** %3
%27 = load i64, i64* %7
%28 = call i64 @count_double_characters(i64* %26, i64 %27)
%29 = add i64 %25, %28
%30 = add i64 %29, 16
store i64 %30, i64* %8
%31 = load i64, i64* %8
%32 = mul i64 %31, 8
%33 = call i8* @malloc(i64 %32)
%34 = bitcast i8* %33 to i64*
store i64* %34, i64** %9
%35 = load i64, i64* %8
%36 = mul i64 %35, 8
%37 = call i8* @malloc(i64 %36)
%38 = bitcast i8* %37 to i64*
store i64* %38, i64** %10
%39 = load i64, i64* %8
%40 = mul i64 %39, 8
%41 = call i8* @malloc(i64 %40)
%42 = bitcast i8* %41 to i64*
store i64* %42, i64** %11
%43 = load i64*, i64** %3
%44 = load i64, i64* %7
%45 = load i64*, i64** %9
%46 = call i64 @copy_and_normalize(i64* %43, i64 %44, i64* %45, i32 0)
store i64 %46, i64* %12
%47 = load i64*, i64** %9
%48 = load i64, i64* %8
%49 = load i32, i32* %6
%50 = load i32, i32* %4
%51 = call i64 @strip_suffixes(i64* %47, i64 %48, i32 %49, i32 %50)
store i64 %51, i64* %13
%52 = load i64*, i64** %11
%53 = load i64*, i64** %9
%54 = load i64, i64* %13
%55 = getelementptr inbounds i64, i64* %53, i64 %54
%56 = load i64, i64* %12
%57 = load i64, i64* %13
%58 = sub i64 %56, %57
%59 = call i32 @wcsncpy(i64* %52, i64* %55, i64 %58)
%60 = load i64*, i64** %11
%61 = load i64, i64* %12
%62 = load i64, i64* %13
%63 = sub i64 %61, %62
%64 = getelementptr inbounds i64, i64* %60, i64 %63
store i64 0, i64* %64
%65 = load i64*, i64** %9
%66 = load i64, i64* %13
%67 = getelementptr inbounds i64, i64* %65, i64 %66
store i64 0, i64* %67
%68 = load i64*, i64** %9
%69 = load i64, i64* %13
%70 = load i64*, i64** %10
%71 = call i32 @copy_and_denormalize(i64* %68, i64 %69, i64* %70)
%72 = load i64*, i64** %9
%73 = call i32 @free(i64* %72)
%74 = load i64*, i64** %10
%75 = load i64**, i64*** %5
%76 = getelementptr inbounds i64*, i64** %75, i64 0
store i64* %74, i64** %76
%77 = load i64*, i64** %11
%78 = load i64**, i64*** %5
%79 = getelementptr inbounds i64*, i64** %78, i64 1
store i64* %77, i64** %79
%80 = load i64**, i64*** %5
ret i64** %80
}

LLVM IR (-O2):
define noalias i64** @segment_internal(i64* %0, i32 %1) {
%3 = tail call dereferenceable_or_null(16) i8* @malloc(i64 16)
%4 = bitcast i8* %3 to i64**
%5 = load i64, i64* %0
%6 = tail call i32 @iswlower(i64 %5)
%7 = icmp eq i32 %6, 0
%8 = zext i1 %7 to i32
%9 = tail call i64 @wcslen(i64* %0)
%10 = tail call i64 @count_double_characters(i64* %0, i64 %9)
%11 = add i64 %9, 16
%12 = add i64 %11, %10
%13 = shl i64 %12, 3
%14 = tail call i8* @malloc(i64 %13)
%15 = bitcast i8* %14 to i64*
%16 = tail call i8* @malloc(i64 %13)
%17 = bitcast i8* %16 to i64*
%18 = tail call i8* @malloc(i64 %13)
%19 = bitcast i8* %18 to i64*
%20 = tail call i64 @copy_and_normalize(i64* %0, i64 %9, i64* %15, i32 0)
%21 = tail call i64 @strip_suffixes(i64* %15, i64 %12, i32 %8, i32 %1)
%22 = getelementptr inbounds i64, i64* %15, i64 %21
%23 = sub i64 %20, %21
%24 = tail call i32 @wcsncpy(i64* %19, i64* %22, i64 %23)
%25 = getelementptr inbounds i64, i64* %19, i64 %23
store i64 0, i64* %25
store i64 0, i64* %22
%26 = tail call i32 @copy_and_denormalize(i64* %15, i64 %21, i64* %17)
%27 = tail call i32 @free(i64* %15)
%28 = bitcast i8* %3 to i8**
store i8* %16, i8** %28
%29 = getelementptr inbounds i64*, i64** %4, i64 1
%30 = bitcast i64** %29 to i8**
store i8* %18, i8** %30
ret i64** %4
}