#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__ feof(int /*<<< orphan*/);
char getchar();
int /*<<< orphan*/ stdin;
unsigned int strlen(char *);
int waitfor(char *end) {
  unsigned int i = 0;
  char c;
  while (i < strlen(end)) {
    c = getchar();
    if (feof(stdin))
      return 0;
    else if (c == end[i])
      i++;
    else if (c == end[0])
      i = 1;
    else
      i = 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<waitfor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jae    11e7 <waitfor+0xb7>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x15(%rbp)
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
call   1050 <feof@plt>
cmp    $0x0,%rax
je     118d <waitfor+0x5d>
movl   $0x0,-0x4(%rbp)
jmp    11ee <waitfor+0xbe>
movsbl -0x15(%rbp),%eax
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%edx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    11b2 <waitfor+0x82>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11dd <waitfor+0xad>
movsbl -0x15(%rbp),%eax
mov    -0x10(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    11d1 <waitfor+0xa1>
movl   $0x1,-0x14(%rbp)
jmp    11d8 <waitfor+0xa8>
movl   $0x0,-0x14(%rbp)
jmp    11dd <waitfor+0xad>
jmp    11e2 <waitfor+0xb2>
jmp    1143 <waitfor+0x13>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<waitfor>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r12
call   1030 <strlen@plt>
mov    $0x1,%r14d
test   %eax,%eax
je     119c <waitfor+0x6c>
mov    0x2e97(%rip),%r15
xor    %ebp,%ebp
jmp    1176 <waitfor+0x46>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %ebp,%ebp
cmp    (%r12),%bl
sete   %bpl
mov    %r12,%rdi
call   1030 <strlen@plt>
cmp    %eax,%ebp
jae    119c <waitfor+0x6c>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebx
mov    (%r15),%edi
call   1050 <feof@plt>
test   %rax,%rax
jne    1199 <waitfor+0x69>
mov    %ebp,%eax
cmp    (%r12,%rax,1),%bl
jne    1160 <waitfor+0x30>
add    $0x1,%ebp
jmp    116a <waitfor+0x3a>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
define i32 @waitfor(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8
store i8* %0, i8** %3
store i32 0, i32* %4
br label %6
6: ; preds = %42, %1
%7 = load i32, i32* %4
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
%10 = icmp ult i32 %7, %9
br i1 %10, label %11, label %43
11: ; preds = %6
%12 = call signext i8 (...) @getchar()
store i8 %12, i8* %5
%13 = load i32, i32* @stdin
%14 = call i64 @feof(i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %11
store i32 0, i32* %2
br label %44
17: ; preds = %11
%18 = load i8, i8* %5
%19 = sext i8 %18 to i32
%20 = load i8*, i8** %3
%21 = load i32, i32* %4
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %19, %25
br i1 %26, label %27, label %30
27: ; preds = %17
%28 = load i32, i32* %4
%29 = add i32 %28, 1
store i32 %29, i32* %4
br label %41
30: ; preds = %17
%31 = load i8, i8* %5
%32 = sext i8 %31 to i32
%33 = load i8*, i8** %3
%34 = getelementptr inbounds i8, i8* %33, i64 0
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %32, %36
br i1 %37, label %38, label %39
38: ; preds = %30
store i32 1, i32* %4
br label %40
39: ; preds = %30
store i32 0, i32* %4
br label %40
40: ; preds = %39, %38
br label %41
41: ; preds = %40, %27
br label %42
42: ; preds = %41
br label %6
43: ; preds = %6
store i32 1, i32* %2
br label %44
44: ; preds = %43, %16
%45 = load i32, i32* %2
ret i32 %45
}

LLVM IR (-O2):
@stdin = global i32 0
define i32 @waitfor(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %25, label %4
4: ; preds = %1, %21
%5 = phi i32 [ %22, %21 ], [ 0, %1 ]
%6 = tail call signext i8 (...) @getchar()
%7 = load i32, i32* @stdin
%8 = tail call i64 @feof(i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %25
10: ; preds = %4
%11 = zext i32 %5 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %6, %13
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = add nuw i32 %5, 1
br label %21
17: ; preds = %10
%18 = load i8, i8* %0
%19 = icmp eq i8 %6, %18
%20 = zext i1 %19 to i32
br label %21
21: ; preds = %17, %15
%22 = phi i32 [ %16, %15 ], [ %20, %17 ]
%23 = tail call i32 @strlen(i8* %0)
%24 = icmp ult i32 %22, %23
br i1 %24, label %4, label %25
25: ; preds = %4, %21, %1
%26 = phi i32 [ 1, %1 ], [ 1, %21 ], [ 0, %4 ]
ret i32 %26
}