#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 *);
int strlen(char *);
char *plural(char *arg) {
  static char buf[4096];
  int len;
  strcpy(buf, arg);
  len = strlen(arg);
  buf[len] = '\0';
  if (buf[len - 1] == 's') {
    if (buf[len - 2] == 'u') {
      buf[len - 2] = 'i';
      buf[len - 1] = '\0';
    } else
      return arg;
  } else if (buf[len - 1] == 'h')
    strcat(buf, "es");
  else
    strcat(buf, "s");
  return buf;
}


x86 assembly (clang, -O0):
<plural>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0x2f09(%rip),%rdi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rcx
lea    0x2eed(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2ed9(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0x73,%eax
jne    11e0 <plural+0xb0>
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
movslq %eax,%rcx
lea    0x2ebc(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0x75,%eax
jne    11ce <plural+0x9e>
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
movslq %eax,%rcx
lea    0x2e9f(%rip),%rax
movb   $0x69,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2e8b(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
jmp    11db <plural+0xab>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1238 <plural+0x108>
jmp    122d <plural+0xfd>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2e60(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0x68,%eax
jne    1215 <plural+0xe5>
lea    0x2e4c(%rip),%rdi
lea    0xdf5(%rip),%rsi
call   1050 <strcat@plt>
jmp    1228 <plural+0xf8>
lea    0x2e34(%rip),%rdi
lea    0xdde(%rip),%rsi
call   1050 <strcat@plt>
jmp    122d <plural+0xfd>
lea    0x2e1c(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<plural>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0x2f12(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,(%rax,%r14,1)
mov    -0x1(%rax,%r14,1),%cl
cmp    $0x68,%cl
je     1184 <plural+0x54>
cmp    $0x73,%cl
jne    119c <plural+0x6c>
lea    0x2ee2(%rip),%rcx
cmpb   $0x75,-0x2(%rax,%rcx,1)
jne    11ae <plural+0x7e>
movb   $0x69,-0x2(%rax,%rcx,1)
movb   $0x0,-0x1(%rax,%rcx,1)
mov    %rcx,%rbx
jmp    11ae <plural+0x7e>
lea    0x2ec5(%rip),%rbx
lea    0xe6e(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcat@plt>
jmp    11ae <plural+0x7e>
lea    0xe5e(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcat@plt>
mov    %r14,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@plural.buf = internal global [4096 x i8] zeroinitializer
@.str = [3 x i8] c"es\00"
@.str.1 = [2 x i8] c"s\00"
define i8* @plural(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @strcpy(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @plural.buf, i64 0, i64 0), i8* %5)
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [4096 x i8], [4096 x i8]* @plural.buf, i64 0, i64 %10
store i8 0, i8* %11
%12 = load i32, i32* %4
%13 = sub nsw i32 %12, 1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [4096 x i8], [4096 x i8]* @plural.buf, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 115
br i1 %18, label %19, label %39
19: ; preds = %1
%20 = load i32, i32* %4
%21 = sub nsw i32 %20, 2
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [4096 x i8], [4096 x i8]* @plural.buf, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 117
br i1 %26, label %27, label %36
27: ; preds = %19
%28 = load i32, i32* %4
%29 = sub nsw i32 %28, 2
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [4096 x i8], [4096 x i8]* @plural.buf, i64 0, i64 %30
store i8 105, i8* %31
%32 = load i32, i32* %4
%33 = sub nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [4096 x i8], [4096 x i8]* @plural.buf, i64 0, i64 %34
store i8 0, i8* %35
br label %38
36: ; preds = %19
%37 = load i8*, i8** %3
store i8* %37, i8** %2
br label %53
38: ; preds = %27
br label %52
39: ; preds = %1
%40 = load i32, i32* %4
%41 = sub nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [4096 x i8], [4096 x i8]* @plural.buf, i64 0, i64 %42
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %45, 104
br i1 %46, label %47, label %49
47: ; preds = %39
%48 = call i32 @strcat(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @plural.buf, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %51
49: ; preds = %39
%50 = call i32 @strcat(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @plural.buf, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %51
51: ; preds = %49, %47
br label %52
52: ; preds = %51, %38
store i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @plural.buf, i64 0, i64 0), i8** %2
br label %53
53: ; preds = %52, %36
%54 = load i8*, i8** %2
ret i8* %54
}

LLVM IR (-O2):
@plural.buf = internal global [4096 x i8] zeroinitializer
@.str = [3 x i8] c"es\00"
@.str.1 = [2 x i8] c"s\00"
define i8* @plural(i8* %0) {
%2 = tail call i32 @strcpy(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @plural.buf, i64 0, i64 0), i8* %0)
%3 = tail call i32 @strlen(i8* %0)
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* @plural.buf, i64 0, i64 %4
store i8 0, i8* %5
%6 = add nsw i32 %3, -1
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* @plural.buf, i64 0, i64 %7
%9 = load i8, i8* %8
switch i8 %9, label %19 [
i8 115, label %10
i8 104, label %17
]
10: ; preds = %1
%11 = add nsw i32 %3, -2
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* @plural.buf, i64 0, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 117
br i1 %15, label %16, label %21
16: ; preds = %10
store i8 105, i8* %13
store i8 0, i8* %8
br label %21
17: ; preds = %1
%18 = tail call i32 @strcat(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @plural.buf, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %21
19: ; preds = %1
%20 = tail call i32 @strcat(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @plural.buf, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %16, %19, %17, %10
%22 = phi i8* [ %0, %10 ], [ getelementptr inbounds ([4096 x i8], [4096 x i8]* @plural.buf, i64 0, i64 0), %17 ], [ getelementptr inbounds ([4096 x i8], [4096 x i8]* @plural.buf, i64 0, i64 0), %19 ], [ getelementptr inbounds ([4096 x i8], [4096 x i8]* @plural.buf, i64 0, i64 0), %16 ]
ret i8* %22
}