#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 */
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int main(void) {
  char c, prev;
  int ei = 0;
  prev = 0;
  printf("Please enter something ends with '#'\n");
  while ((c = getchar()) != '#') {
    if ('e' == prev && 'i' == c)
      ei++;
    prev = c;
    putchar(c);
  }
  printf("\nThe sequence \"ei\" occurs %d times.\n", ei);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movb   $0x0,-0x6(%rbp)
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x5(%rbp)
movsbl %al,%eax
cmp    $0x23,%eax
je     11ad <main+0x7d>
movsbl -0x6(%rbp),%ecx
mov    $0x65,%eax
cmp    %ecx,%eax
jne    1199 <main+0x69>
movsbl -0x5(%rbp),%ecx
mov    $0x69,%eax
cmp    %ecx,%eax
jne    1199 <main+0x69>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x5(%rbp),%al
mov    %al,-0x6(%rbp)
movsbl -0x5(%rbp),%edi
call   1030 <putchar@plt>
jmp    1158 <main+0x28>
mov    -0xc(%rbp),%esi
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xedb(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0x23,%al
je     1186 <main+0x46>
xor    %ebx,%ebx
xor    %ecx,%ecx
mov    %eax,%ebp
xor    $0x65,%cl
xor    $0x69,%al
xor    %edx,%edx
or     %cl,%al
sete   %dl
add    %edx,%ebx
movsbl %bpl,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
mov    %ebp,%ecx
cmp    $0x23,%al
jne    1160 <main+0x20>
lea    0xe73(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [38 x i8] c"Please enter something ends with '#'\0A\00"
@.str.1 = [37 x i8] c"\0AThe sequence \22ei\22 occurs %d times.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i8
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
store i8 0, i8* %3
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %21, %0
%7 = call signext i8 (...) @getchar()
store i8 %7, i8* %2
%8 = sext i8 %7 to i32
%9 = icmp ne i32 %8, 35
br i1 %9, label %10, label %25
10: ; preds = %6
%11 = load i8, i8* %3
%12 = sext i8 %11 to i32
%13 = icmp eq i32 101, %12
br i1 %13, label %14, label %21
14: ; preds = %10
%15 = load i8, i8* %2
%16 = sext i8 %15 to i32
%17 = icmp eq i32 105, %16
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
br label %21
21: ; preds = %18, %14, %10
%22 = load i8, i8* %2
store i8 %22, i8* %3
%23 = load i8, i8* %2
%24 = call i32 @putchar(i8 signext %23)
br label %6
25: ; preds = %6
%26 = load i32, i32* %4
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %26)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [37 x i8] c"\0AThe sequence \22ei\22 occurs %d times.\0A\00"
@str = [37 x i8] c"Please enter something ends with '#'\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%2 = tail call signext i8 (...) @getchar()
%3 = icmp eq i8 %2, 35
br i1 %3, label %16, label %4
4: ; preds = %0, %4
%5 = phi i8 [ %14, %4 ], [ %2, %0 ]
%6 = phi i32 [ %12, %4 ], [ 0, %0 ]
%7 = phi i8 [ %5, %4 ], [ 0, %0 ]
%8 = icmp eq i8 %7, 101
%9 = icmp eq i8 %5, 105
%10 = and i1 %8, %9
%11 = zext i1 %10 to i32
%12 = add nuw nsw i32 %6, %11
%13 = tail call i32 @putchar(i8 signext %5)
%14 = tail call signext i8 (...) @getchar()
%15 = icmp eq i8 %14, 35
br i1 %15, label %16, label %4
16: ; preds = %4, %0
%17 = phi i32 [ 0, %0 ], [ %12, %4 ]
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %17)
ret i32 0
}