#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*/ strcpy(char *, char const *);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
void plurize(char *result, const char *noun) {
  int str_len = strlen(noun);
  if (noun[str_len - 1] == 'y') {
    strncpy(result, noun, str_len - 1);
    strcpy(result + str_len - 1, "ies");
  } else if (noun[str_len - 1] == 's' ||
             (noun[str_len - 1] == 'h' &&
              (noun[str_len - 2] == 'c' || noun[str_len - 2] == 's'))) {
    strcpy(result, noun);
    strcpy(result + str_len - 1, "es");
  } else {
    strcpy(result, noun);
    strcpy(result + str_len, "s");
  }
}


x86 assembly (clang, -O0):
<plurize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x79,%eax
jne    1199 <plurize+0x69>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
add    $0xffffffffffffffff,%rdi
lea    0xe71(%rip),%rsi
call   1040 <strcpy@plt>
jmp    1257 <plurize+0x127>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x73,%eax
je     1201 <plurize+0xd1>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x68,%eax
jne    122e <plurize+0xfe>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x63,%eax
je     1201 <plurize+0xd1>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x73,%eax
jne    122e <plurize+0xfe>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
add    $0xffffffffffffffff,%rdi
lea    0xddd(%rip),%rsi
call   1040 <strcpy@plt>
jmp    1252 <plurize+0x122>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
lea    0xdb5(%rip),%rsi
call   1040 <strcpy@plt>
jmp    1257 <plurize+0x127>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<plurize>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1050 <strlen@plt>
movslq %eax,%r15
mov    -0x1(%rbx,%r15,1),%al
cmp    $0x68,%al
je     1177 <plurize+0x47>
cmp    $0x73,%al
je     1182 <plurize+0x52>
cmp    $0x79,%al
jne    119e <plurize+0x6e>
lea    -0x1(%r15),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strncpy@plt>
lea    (%r14,%r15,1),%rdi
add    $0xffffffffffffffff,%rdi
lea    0xe8b(%rip),%rsi
jmp    11b6 <plurize+0x86>
mov    -0x2(%r15,%rbx,1),%al
or     $0x10,%al
cmp    $0x73,%al
jne    119e <plurize+0x6e>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
lea    (%r14,%r15,1),%rdi
add    $0xffffffffffffffff,%rdi
lea    0xe65(%rip),%rsi
jmp    11b6 <plurize+0x86>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
add    %r14,%r15
lea    0xe4f(%rip),%rsi
mov    %r15,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <strcpy@plt>

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

LLVM IR (-O2):
@.str = [4 x i8] c"ies\00"
@.str.1 = [3 x i8] c"es\00"
@.str.2 = [2 x i8] c"s\00"
define void @plurize(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = add nsw i32 %3, -1
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %1, i64 %5
%7 = load i8, i8* %6
switch i8 %7, label %25 [
i8 121, label %8
i8 115, label %19
i8 104, label %14
]
8: ; preds = %2
%9 = tail call i32 @strncpy(i8* %0, i8* %1, i32 %4)
%10 = sext i32 %3 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = getelementptr inbounds i8, i8* %11, i64 -1
%13 = tail call i32 @strcpy(i8* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %30
14: ; preds = %2
%15 = add nsw i32 %3, -2
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %1, i64 %16
%18 = load i8, i8* %17
switch i8 %18, label %25 [
i8 99, label %19
i8 115, label %19
]
19: ; preds = %14, %14, %2
%20 = tail call i32 @strcpy(i8* %0, i8* %1)
%21 = sext i32 %3 to i64
%22 = getelementptr inbounds i8, i8* %0, i64 %21
%23 = getelementptr inbounds i8, i8* %22, i64 -1
%24 = tail call i32 @strcpy(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %30
25: ; preds = %14, %2
%26 = tail call i32 @strcpy(i8* %0, i8* %1)
%27 = sext i32 %3 to i64
%28 = getelementptr inbounds i8, i8* %0, i64 %27
%29 = tail call i32 @strcpy(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %30
30: ; preds = %19, %25, %8
ret void
}