#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 matching_char_position(char *string, char c, int i) {
  if (i >= strlen(string))
    return -1;
  while (i < strlen(string)) {
    if ((string[i] != c) && (string[i] != '$'))
      return -1;
    else if (string[i] == c)
      return i;
    i++;
  }
  return -1;
}


x86 assembly (clang, -O0):
<matching_char_position>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jl     114d <matching_char_position+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e4 <matching_char_position+0xd4>
jmp    1152 <matching_char_position+0x42>
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    11dd <matching_char_position+0xcd>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
je     11a7 <matching_char_position+0x97>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x24,%eax
je     11a7 <matching_char_position+0x97>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e4 <matching_char_position+0xd4>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
jne    11ca <matching_char_position+0xba>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e4 <matching_char_position+0xd4>
jmp    11cf <matching_char_position+0xbf>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1152 <matching_char_position+0x42>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matching_char_position>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r15d
mov    %esi,%r12d
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    $0xffffffff,%r14d
cmp    %r15d,%eax
jle    1185 <matching_char_position+0x75>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    %r15d,%eax
jle    1185 <matching_char_position+0x75>
movslq %r15d,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%rbx,%rbp,1),%eax
cmp    %r12b,%al
je     1172 <matching_char_position+0x62>
cmp    $0x24,%al
jne    1172 <matching_char_position+0x62>
add    $0x1,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     1150 <matching_char_position+0x40>
jmp    1185 <matching_char_position+0x75>
cmp    $0x24,%al
mov    $0xffffffff,%r14d
cmove  %ebp,%r14d
cmp    %r12b,%al
cmove  %ebp,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @matching_char_position(i8* %0, i8 signext %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i32
store i8* %0, i8** %5
store i8 %1, i8* %6
store i32 %2, i32* %7
%8 = load i32, i32* %7
%9 = load i8*, i8** %5
%10 = call i32 @strlen(i8* %9)
%11 = icmp sge i32 %8, %10
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 -1, i32* %4
br label %55
13: ; preds = %3
br label %14
14: ; preds = %51, %13
%15 = load i32, i32* %7
%16 = load i8*, i8** %5
%17 = call i32 @strlen(i8* %16)
%18 = icmp slt i32 %15, %17
br i1 %18, label %19, label %54
19: ; preds = %14
%20 = load i8*, i8** %5
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = load i8, i8* %6
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %25, %27
br i1 %28, label %29, label %38
29: ; preds = %19
%30 = load i8*, i8** %5
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 36
br i1 %36, label %37, label %38
37: ; preds = %29
store i32 -1, i32* %4
br label %55
38: ; preds = %29, %19
%39 = load i8*, i8** %5
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = load i8, i8* %6
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %44, %46
br i1 %47, label %48, label %50
48: ; preds = %38
%49 = load i32, i32* %7
store i32 %49, i32* %4
br label %55
50: ; preds = %38
br label %51
51: ; preds = %50
%52 = load i32, i32* %7
%53 = add nsw i32 %52, 1
store i32 %53, i32* %7
br label %14
54: ; preds = %14
store i32 -1, i32* %4
br label %55
55: ; preds = %54, %48, %37, %12
%56 = load i32, i32* %4
ret i32 %56
}

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