#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 strlen(char *);
int chindex(char *string, char ch) {
  int count;
  for (count = 0; count < strlen(string); count++)
    if (string[count] == ch)
      break;
  if (count >= strlen(string))
    count = -1;
  return (count);
}


x86 assembly (clang, -O0):
<chindex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%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    1175 <chindex+0x65>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
jne    1162 <chindex+0x52>
jmp    1175 <chindex+0x65>
jmp    1167 <chindex+0x57>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1129 <chindex+0x19>
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jl     1198 <chindex+0x88>
movl   $0xffffffff,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chindex>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
call   1030 <strlen@plt>
xor    %ebp,%ebp
test   %eax,%eax
jle    1149 <chindex+0x39>
cs nopw 0x0(%rax,%rax,1)
nop
cmp    %r14b,(%rbx,%rbp,1)
je     1149 <chindex+0x39>
add    $0x1,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     1130 <chindex+0x20>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    %eax,%ebp
mov    $0xffffffff,%eax
cmovl  %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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