#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int strlen(char *);
int main() {
  char word[30];
  int len;
  printf("\nEnter a word to stem: ");
  scanf("%s", word);
  printf("Initial word: %s\n", word);
  len = strlen(word);
  if (word[len - 4] == 's' && word[len - 3] == 's' && word[len - 2] == 'e' &&
      word[len - 1] == 's') {
    word[len - 2] = '\0';
  } else if (word[len - 1] == 's') {
    word[len - 1] = '\0';
  } else if (word[len - 2] == 'e' && word[len - 1] == 'd') {
    word[len - 2] = '\0';
  }
  printf("Stemmed word: %s\n\n", word);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x30(%rbp),%rsi
lea    0xec0(%rip),%rdi
call   1050 <scanf@plt>
lea    -0x30(%rbp),%rsi
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
sub    $0x4,%eax
cltq
movsbl -0x30(%rbp,%rax,1),%eax
cmp    $0x73,%eax
jne    11e5 <main+0xb5>
mov    -0x34(%rbp),%eax
sub    $0x3,%eax
cltq
movsbl -0x30(%rbp,%rax,1),%eax
cmp    $0x73,%eax
jne    11e5 <main+0xb5>
mov    -0x34(%rbp),%eax
sub    $0x2,%eax
cltq
movsbl -0x30(%rbp,%rax,1),%eax
cmp    $0x65,%eax
jne    11e5 <main+0xb5>
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x30(%rbp,%rax,1),%eax
cmp    $0x73,%eax
jne    11e5 <main+0xb5>
mov    -0x34(%rbp),%eax
sub    $0x2,%eax
cltq
movb   $0x0,-0x30(%rbp,%rax,1)
jmp    1250 <main+0x120>
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x30(%rbp,%rax,1),%eax
cmp    $0x73,%eax
jne    120d <main+0xdd>
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x30(%rbp,%rax,1)
jmp    124b <main+0x11b>
mov    -0x34(%rbp),%eax
sub    $0x2,%eax
cltq
movsbl -0x30(%rbp,%rax,1),%eax
cmp    $0x65,%eax
jne    1246 <main+0x116>
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x30(%rbp,%rax,1),%eax
cmp    $0x64,%eax
jne    1246 <main+0x116>
mov    -0x34(%rbp),%eax
sub    $0x2,%eax
cltq
movb   $0x0,-0x30(%rbp,%rax,1)
jmp    124b <main+0x11b>
jmp    1250 <main+0x120>
lea    -0x30(%rbp),%rsi
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
lea    0xec4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xece(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1050 <scanf@plt>
lea    0xebf(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmpb   $0x73,-0x4(%rax,%rbx,1)
jne    118c <main+0x5c>
cmpb   $0x73,-0x3(%rax,%rbx,1)
jne    118c <main+0x5c>
cmpb   $0x65,-0x2(%rax,%rbx,1)
jne    118c <main+0x5c>
cmpb   $0x73,-0x1(%rax,%rbx,1)
je     11aa <main+0x7a>
mov    -0x1(%rax,%rbx,1),%cl
cmp    $0x73,%cl
jne    119e <main+0x6e>
add    %rbx,%rax
add    $0xffffffffffffffff,%rax
jmp    11b1 <main+0x81>
cmpb   $0x65,-0x2(%rax,%rbx,1)
jne    11b4 <main+0x84>
cmp    $0x64,%cl
jne    11b4 <main+0x84>
add    %rbx,%rax
add    $0xfffffffffffffffe,%rax
movb   $0x0,(%rax)
lea    0xe72(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [24 x i8] c"\0AEnter a word to stem: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [18 x i8] c"Initial word: %s\0A\00"
@.str.3 = [19 x i8] c"Stemmed word: %s\0A\0A\00"
define i32 @main() {
%1 = alloca [30 x i8]
%2 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%6 = call i32 @strlen(i8* %2)
%7 = add nsw i32 %6, -4
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 115
br i1 %11, label %12, label %30
12: ; preds = %0
%13 = add nsw i32 %6, -3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 115
br i1 %17, label %18, label %30
18: ; preds = %12
%19 = add nsw i32 %6, -2
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 101
br i1 %23, label %24, label %30
24: ; preds = %18
%25 = add nsw i32 %6, -1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 115
br i1 %29, label %44, label %30
30: ; preds = %24, %18, %12, %0
%31 = add nsw i32 %6, -1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = icmp eq i8 %34, 115
br i1 %35, label %44, label %36
36: ; preds = %30
%37 = add nsw i32 %6, -2
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = icmp eq i8 %40, 101
%42 = icmp eq i8 %34, 100
%43 = select i1 %41, i1 %42, i1 false
br i1 %43, label %44, label %46
44: ; preds = %36, %30, %24
%45 = phi i8* [ %21, %24 ], [ %33, %30 ], [ %39, %36 ]
store i8 0, i8* %45
br label %46
46: ; preds = %44, %36
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %2)
ret i32 0
}