#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 */
scalar_t__ ends_in_chr(char, char *);
scalar_t__ ends_in_str(char *, char *);
int strlen(char *);
void flertal(char *ord) {
  int len = strlen(ord);
  if (ends_in_chr('y', ord)) {
    ord[len - 1] = 'i';
    ord[len] = 'e';
    ord[len + 1] = 's';
    ord[len + 2] = '\0';
  } else if (ends_in_str("ch", ord) || ends_in_str("sh", ord) ||
             ends_in_chr('s', ord)) {
    ord[len] = 'e';
    ord[len + 1] = 's';
    ord[len + 2] = '\0';
  } else {
    ord[len] = 's';
    ord[len + 1] = '\0';
  }
}


x86 assembly (clang, -O0):
<flertal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rsi
mov    $0x79,%edi
call   1040 <ends_in_chr@plt>
cmp    $0x0,%rax
je     11a4 <flertal+0x74>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x69,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x65,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x73,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1245 <flertal+0x115>
mov    -0x8(%rbp),%rsi
lea    0xe51(%rip),%rdi
call   1050 <ends_in_str@plt>
cmp    $0x0,%rax
jne    11f0 <flertal+0xc0>
mov    -0x8(%rbp),%rsi
lea    0xe3a(%rip),%rdi
call   1050 <ends_in_str@plt>
cmp    $0x0,%rax
jne    11f0 <flertal+0xc0>
mov    -0x8(%rbp),%rsi
mov    $0x73,%edi
call   1040 <ends_in_chr@plt>
cmp    $0x0,%rax
je     1223 <flertal+0xf3>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x65,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x73,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1240 <flertal+0x110>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x73,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1245 <flertal+0x115>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flertal>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%r14d
mov    $0x79,%edi
mov    %rbx,%rsi
call   1040 <ends_in_chr@plt>
movslq %r14d,%r15
test   %rax,%rax
je     115d <flertal+0x2d>
movb   $0x69,-0x1(%r15,%rbx,1)
jmp    1197 <flertal+0x67>
lea    0xe9c(%rip),%rdi
mov    %rbx,%rsi
call   1050 <ends_in_str@plt>
test   %rax,%rax
jne    1197 <flertal+0x67>
lea    0xe8b(%rip),%rdi
mov    %rbx,%rsi
call   1050 <ends_in_str@plt>
test   %rax,%rax
jne    1197 <flertal+0x67>
mov    $0x73,%edi
mov    %rbx,%rsi
call   1040 <ends_in_chr@plt>
test   %rax,%rax
je     11bc <flertal+0x8c>
movb   $0x65,(%rbx,%r15,1)
lea    0x1(%r14),%ecx
mov    $0x2,%eax
movslq %ecx,%rcx
movb   $0x73,(%rbx,%rcx,1)
add    %eax,%r14d
movslq %r14d,%rax
movb   $0x0,(%rbx,%rax,1)
pop    %rbx
pop    %r14
pop    %r15
ret
mov    $0x1,%eax
mov    %r14d,%ecx
jmp    11a5 <flertal+0x75>

LLVM IR (-O0):
@.str = [3 x i8] c"ch\00"
@.str.1 = [3 x i8] c"sh\00"
define void @flertal(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @strlen(i8* %4)
store i32 %5, i32* %3
%6 = load i8*, i8** %2
%7 = call i64 @ends_in_chr(i8 signext 121, i8* %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %29
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = load i32, i32* %3
%12 = sub nsw i32 %11, 1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %10, i64 %13
store i8 105, i8* %14
%15 = load i8*, i8** %2
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
store i8 101, i8* %18
%19 = load i8*, i8** %2
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
store i8 115, i8* %23
%24 = load i8*, i8** %2
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 2
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %24, i64 %27
store i8 0, i8* %28
br label %67
29: ; preds = %1
%30 = load i8*, i8** %2
%31 = call i64 @ends_in_str(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %41, label %33
33: ; preds = %29
%34 = load i8*, i8** %2
%35 = call i64 @ends_in_str(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %41, label %37
37: ; preds = %33
%38 = load i8*, i8** %2
%39 = call i64 @ends_in_chr(i8 signext 115, i8* %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %56
41: ; preds = %37, %33, %29
%42 = load i8*, i8** %2
%43 = load i32, i32* %3
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
store i8 101, i8* %45
%46 = load i8*, i8** %2
%47 = load i32, i32* %3
%48 = add nsw i32 %47, 1
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %46, i64 %49
store i8 115, i8* %50
%51 = load i8*, i8** %2
%52 = load i32, i32* %3
%53 = add nsw i32 %52, 2
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %51, i64 %54
store i8 0, i8* %55
br label %66
56: ; preds = %37
%57 = load i8*, i8** %2
%58 = load i32, i32* %3
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %57, i64 %59
store i8 115, i8* %60
%61 = load i8*, i8** %2
%62 = load i32, i32* %3
%63 = add nsw i32 %62, 1
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %61, i64 %64
store i8 0, i8* %65
br label %66
66: ; preds = %56, %41
br label %67
67: ; preds = %66, %9
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"ch\00"
@.str.1 = [3 x i8] c"sh\00"
define void @flertal(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i64 @ends_in_chr(i8 signext 121, i8* %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %9, label %5
5: ; preds = %1
%6 = add nsw i32 %2, -1
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
store i8 105, i8* %8
br label %18
9: ; preds = %1
%10 = tail call i64 @ends_in_str(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %9
%13 = tail call i64 @ends_in_str(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = tail call i64 @ends_in_chr(i8 signext 115, i8* %0)
%17 = icmp eq i64 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %9, %12, %15, %5
%19 = sext i32 %2 to i64
%20 = getelementptr inbounds i8, i8* %0, i64 %19
store i8 101, i8* %20
%21 = add nsw i32 %2, 1
br label %22
22: ; preds = %18, %15
%23 = phi i32 [ %2, %15 ], [ %21, %18 ]
%24 = phi i32 [ 1, %15 ], [ 2, %18 ]
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds i8, i8* %0, i64 %25
store i8 115, i8* %26
%27 = add nsw i32 %2, %24
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %0, i64 %28
store i8 0, i8* %29
ret void
}