#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*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
char *strrchr(char *, char);
char add_ending(char *input, char *output) {
  char a[3] = "ies", b[2] = "es", c[2] = "ch", d[2] = "sh", e[100];
  strcpy(output, input);
  if (*strrchr(input, 'y') == 'y') {
    output[strlen(strrchr(input, 'y'))] = '\0';
    strcat(output, a);
  } else if (*strrchr(input, 's') == 's') {
    output[strlen(strrchr(input, 'y'))] = '\0';
    strcat(output, b);
  } else if (*strrchr(input, 'c') == *c) {
    output[strlen(strrchr(input, 'y'))] = '\0';
    strcat(output, b);
  } else if (*strrchr(input, 's') == *d) {
    output[strlen(strrchr(input, 'y'))] = '\0';
    strcat(output, b);
  } else
    strcat(output, "s");
}


x86 assembly (clang, -O0):
<add_ending>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0xea6(%rip),%ax
mov    %ax,-0x1b(%rbp)
mov    0xe9e(%rip),%al
mov    %al,-0x19(%rbp)
mov    0xe95(%rip),%ax
mov    %ax,-0x1d(%rbp)
mov    0xe8c(%rip),%ax
mov    %ax,-0x1f(%rbp)
mov    0xe83(%rip),%ax
mov    %ax,-0x21(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
mov    $0x79,%esi
call   1050 <strrchr@plt>
movsbl (%rax),%eax
cmp    $0x79,%eax
jne    11f0 <add_ending+0xb0>
mov    -0x18(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x79,%esi
call   1050 <strrchr@plt>
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x98(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
lea    -0x1b(%rbp),%rsi
call   1060 <strcat@plt>
jmp    1326 <add_ending+0x1e6>
mov    -0x10(%rbp),%rdi
mov    $0x73,%esi
call   1050 <strrchr@plt>
movsbl (%rax),%eax
cmp    $0x73,%eax
jne    124b <add_ending+0x10b>
mov    -0x18(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x79,%esi
call   1050 <strrchr@plt>
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0xa0(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
lea    -0x1d(%rbp),%rsi
call   1060 <strcat@plt>
jmp    1321 <add_ending+0x1e1>
mov    -0x10(%rbp),%rdi
mov    $0x63,%esi
call   1050 <strrchr@plt>
movsbl (%rax),%eax
movsbl -0x1f(%rbp),%ecx
cmp    %ecx,%eax
jne    12a9 <add_ending+0x169>
mov    -0x18(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x79,%esi
call   1050 <strrchr@plt>
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0xa8(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
lea    -0x1d(%rbp),%rsi
call   1060 <strcat@plt>
jmp    131c <add_ending+0x1dc>
mov    -0x10(%rbp),%rdi
mov    $0x73,%esi
call   1050 <strrchr@plt>
movsbl (%rax),%eax
movsbl -0x21(%rbp),%ecx
cmp    %ecx,%eax
jne    1307 <add_ending+0x1c7>
mov    -0x18(%rbp),%rax
mov    %rax,-0xb0(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x79,%esi
call   1050 <strrchr@plt>
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0xb0(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
lea    -0x1d(%rbp),%rsi
call   1060 <strcat@plt>
jmp    1317 <add_ending+0x1d7>
mov    -0x18(%rbp),%rdi
lea    0xcf7(%rip),%rsi
call   1060 <strcat@plt>
jmp    131c <add_ending+0x1dc>
jmp    1321 <add_ending+0x1e1>
jmp    1326 <add_ending+0x1e6>
movsbl -0x1(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_ending>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movb   $0x73,0xe(%rsp)
movw   $0x6569,0xc(%rsp)
movw   $0x7365,0xa(%rsp)
mov    %rsi,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    $0x79,%esi
call   1050 <strrchr@plt>
mov    %rax,%r15
cmpb   $0x79,(%rax)
jne    1196 <add_ending+0x56>
mov    %r15,%rdi
call   1040 <strlen@plt>
movb   $0x0,(%r14,%rax,1)
lea    0xc(%rsp),%rsi
jmp    11d5 <add_ending+0x95>
mov    %rbx,%rdi
mov    $0x73,%esi
call   1050 <strrchr@plt>
cmpb   $0x73,(%rax)
je     11ba <add_ending+0x7a>
mov    %rbx,%rdi
mov    $0x63,%esi
call   1050 <strrchr@plt>
cmpb   $0x63,(%rax)
jne    11ce <add_ending+0x8e>
mov    %r15,%rdi
call   1040 <strlen@plt>
movb   $0x0,(%r14,%rax,1)
lea    0xa(%rsp),%rsi
jmp    11d5 <add_ending+0x95>
lea    0xe2e(%rip),%rsi
mov    %r14,%rdi
call   1060 <strcat@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@__const.add_ending.a = [3 x i8] c"ies"
@.str = [2 x i8] c"s\00"
define signext i8 @add_ending(i8* %0, i8* %1) {
%3 = alloca [3 x i8]
%4 = alloca i16
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%6 = bitcast i16* %4 to i8*
store i16 29541, i16* %4
%7 = tail call i32 @strcpy(i8* %1, i8* %0)
%8 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 121)
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 121
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = tail call i64 @strlen(i8* %8)
%13 = getelementptr inbounds i8, i8* %1, i64 %12
store i8 0, i8* %13
%14 = call i32 @strcat(i8* %1, i8* %5)
br label %33
15: ; preds = %2
%16 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 115)
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 115
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = tail call i64 @strlen(i8* %8)
%21 = getelementptr inbounds i8, i8* %1, i64 %20
store i8 0, i8* %21
%22 = call i32 @strcat(i8* %1, i8* %6)
br label %33
23: ; preds = %15
%24 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 99)
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 99
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = tail call i64 @strlen(i8* %8)
%29 = getelementptr inbounds i8, i8* %1, i64 %28
store i8 0, i8* %29
%30 = call i32 @strcat(i8* %1, i8* %6)
br label %33
31: ; preds = %23
%32 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %33
33: ; preds = %19, %31, %27, %11
ret i8 undef
}