#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 getch();
int strlen(char const *);
char waitForSomething(const char *str) {
  int i = 0;
  char ch;
again:
  ch = getch();
  for (i = 0; i < strlen(str); ++i) {
    if (ch == str[i])
      return (ch);
  }
  goto again;
  return 0;
}


x86 assembly (clang, -O0):
<waitForSomething>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1040 <getch@plt>
mov    %al,-0xd(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jge    1195 <waitForSomething+0x75>
movsbl -0xd(%rbp),%eax
mov    -0x8(%rbp),%rcx
movslq -0xc(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    1182 <waitForSomething+0x62>
movsbl -0xd(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret
jmp    1187 <waitForSomething+0x67>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1144 <waitForSomething+0x24>
jmp    1133 <waitForSomething+0x13>

x86 assembly (clang, -O2):
<waitForSomething>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <getch@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    1127 <waitForSomething+0x7>
xor    %ebp,%ebp
nop
cmp    (%rbx,%rbp,1),%r14b
je     115b <waitForSomething+0x3b>
add    $0x1,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     1140 <waitForSomething+0x20>
jmp    1127 <waitForSomething+0x7>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define signext i8 @waitForSomething(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8
store i8* %0, i8** %2
store i32 0, i32* %3
br label %5
5: ; preds = %28, %1
%6 = call signext i8 (...) @getch()
store i8 %6, i8* %4
store i32 0, i32* %3
br label %7
7: ; preds = %25, %5
%8 = load i32, i32* %3
%9 = load i8*, i8** %2
%10 = call i32 @strlen(i8* %9)
%11 = icmp slt i32 %8, %10
br i1 %11, label %12, label %28
12: ; preds = %7
%13 = load i8, i8* %4
%14 = sext i8 %13 to i32
%15 = load i8*, i8** %2
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %14, %20
br i1 %21, label %22, label %24
22: ; preds = %12
%23 = load i8, i8* %4
ret i8 %23
24: ; preds = %12
br label %25
25: ; preds = %24
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
store i32 %27, i32* %3
br label %7
28: ; preds = %7
br label %5
}

LLVM IR (-O2):
define signext i8 @waitForSomething(i8* %0) {
br label %2
2: ; preds = %6, %1
%3 = tail call signext i8 (...) @getch()
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %7, %2
br label %2
7: ; preds = %11
%8 = tail call i32 @strlen(i8* %0)
%9 = sext i32 %8 to i64
%10 = icmp slt i64 %16, %9
br i1 %10, label %11, label %6
11: ; preds = %2, %7
%12 = phi i64 [ %16, %7 ], [ 0, %2 ]
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %3, %14
%16 = add nuw nsw i64 %12, 1
br i1 %15, label %17, label %7
17: ; preds = %11
ret i8 %3
}