#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 m_len(int);
scalar_t__ mls(int, int);
int s_index(int m, int p, char ch) {
  while (p < m_len(m))
    if (ch == (*(char *)mls((m), (p))))
      return p;
    else
      p++;
  return -1;
}


x86 assembly (clang, -O0):
<s_index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %al,-0xd(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <m_len@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jge    118a <s_index+0x6a>
movsbl -0xd(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <mls@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%eax
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    117c <s_index+0x5c>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1191 <s_index+0x71>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1133 <s_index+0x13>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<s_index>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%ebp
mov    %edi,%ebx
call   1030 <m_len@plt>
mov    $0xffffffff,%r14d
cmp    %ebp,%eax
jle    1161 <s_index+0x41>
nopl   (%rax)
mov    %ebx,%edi
mov    %ebp,%esi
call   1040 <mls@plt>
cmp    %r15b,(%rax)
je     115e <s_index+0x3e>
add    $0x1,%ebp
mov    %ebx,%edi
call   1030 <m_len@plt>
cmp    %eax,%ebp
jl     1140 <s_index+0x20>
jmp    1161 <s_index+0x41>
mov    %ebp,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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