#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 length(char *);
int lastIndexOf(char *str, char c) {
  int tamanho = length(str);
  int i;
  for (i = tamanho; i > 0; i--) {
    if (*(str + i - 1) == c) {
      return i - 1;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<lastIndexOf>:
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 <length@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    1178 <lastIndexOf+0x68>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl -0x1(%rax,%rcx,1),%eax
movsbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
jne    1165 <lastIndexOf+0x55>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    117f <lastIndexOf+0x6f>
jmp    116a <lastIndexOf+0x5a>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1134 <lastIndexOf+0x24>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lastIndexOf>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <length@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
test   %ecx,%ecx
jle    114b <lastIndexOf+0x3b>
nopl   0x0(%rax,%rax,1)
mov    %ecx,%edx
cmp    %bpl,-0x1(%rbx,%rdx,1)
je     1146 <lastIndexOf+0x36>
add    $0xffffffff,%ecx
lea    0x1(%rcx),%edx
cmp    $0x1,%edx
jg     1130 <lastIndexOf+0x20>
jmp    114b <lastIndexOf+0x3b>
add    $0xffffffff,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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