#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 /*<<< orphan*/ printArgs(char **, int);
int /*<<< orphan*/ printf(char *, ...);
int rightMostIndex(char *, char *);
int main(int argc, char **argv) {
  printArgs(argv, argc);
  if (argc < 3) {
    printf("Usage: ./rightMostIndex source target\n");
    return 0;
  }
  int index = rightMostIndex(argv[1], argv[2]);
  printf("right most index is %d\n", index);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <printArgs@plt>
cmpl   $0x3,-0x8(%rbp)
jge    1176 <main+0x46>
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11a6 <main+0x76>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1040 <rightMostIndex@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsi,%rdi
mov    %ebp,%esi
call   1060 <printArgs@plt>
cmp    $0x2,%ebp
jg     1165 <main+0x25>
lea    0xeba(%rip),%rdi
call   1030 <puts@plt>
jmp    1182 <main+0x42>
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rsi
call   1050 <rightMostIndex@plt>
lea    0xe87(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"Usage: ./rightMostIndex source target\0A\00"
@.str.1 = [24 x i8] c"right most index is %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i8**, i8*** %5
%8 = load i32, i32* %4
%9 = call i32 @printArgs(i8** %7, i32 %8)
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %24
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
%21 = call i32 @rightMostIndex(i8* %17, i8* %20)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %22)
store i32 0, i32* %3
br label %24
24: ; preds = %14, %12
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@.str.1 = [24 x i8] c"right most index is %d\0A\00"
@str = [38 x i8] c"Usage: ./rightMostIndex source target\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 @printArgs(i8** %1, i32 %0)
%4 = icmp slt i32 %0, 3
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
br label %14
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i32 @rightMostIndex(i8* %9, i8* %11)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %7, %5
ret i32 0
}