#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 mstring_get_length(char *);
int mstring_find(char *in, char find) {
  int size = mstring_get_length(in);
  int curr;
  for (curr = 0; curr != size; curr++) {
    char c = in[curr];
    if (c == find) {
      return curr;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<mstring_find>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <mstring_get_length@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     117d <mstring_find+0x6d>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1d(%rbp)
movsbl -0x1d(%rbp),%eax
movsbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
jne    116a <mstring_find+0x5a>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1184 <mstring_find+0x74>
jmp    116f <mstring_find+0x5f>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1135 <mstring_find+0x25>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mstring_find>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <mstring_get_length@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
test   %ecx,%ecx
je     1143 <mstring_find+0x33>
mov    %ecx,%edx
xor    %ecx,%ecx
nopl   0x0(%rax)
cmp    %bpl,(%rbx,%rcx,1)
je     1141 <mstring_find+0x31>
add    $0x1,%rcx
cmp    %rcx,%rdx
jne    1130 <mstring_find+0x20>
jmp    1143 <mstring_find+0x33>
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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