#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 lastindexof(char *, char);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int main() {
  char str[41], ch;
  int pos;
  printf("Informe uma string: \n");
  scanf("%41[^\n]", str);
  printf("Informe um caractere: \n");
  scanf(" %c", &ch);
  pos = lastindexof(str, ch);
  if (pos != -1) {
    printf("Posicao da ultima de %c em \"%s\": %d\n", ch, str, pos);
  } else {
    printf("%c nao ocorre em \"%s\"\n", ch, str);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x30(%rbp),%rsi
lea    0xebe(%rip),%rdi
call   1050 <scanf@plt>
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec4(%rip),%rdi
lea    -0x31(%rbp),%rsi
call   1050 <scanf@plt>
lea    -0x30(%rbp),%rdi
movsbl -0x31(%rbp),%esi
call   1040 <lastindexof@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0xffffffff,-0x38(%rbp)
je     11b3 <main+0x83>
movsbl -0x31(%rbp),%esi
lea    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%ecx
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c9 <main+0x99>
movsbl -0x31(%rbp),%esi
lea    -0x30(%rbp),%rdx
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
lea    0xefc(%rip),%rdi
call   1030 <puts@plt>
lea    0xea8(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   1060 <scanf@plt>
lea    0xef1(%rip),%rdi
call   1030 <puts@plt>
lea    0xe90(%rip),%rdi
lea    0xf(%rsp),%rsi
call   1060 <scanf@plt>
movsbl 0xf(%rsp),%esi
mov    %rbx,%rdi
call   1050 <lastindexof@plt>
movsbl 0xf(%rsp),%esi
cmp    $0xffffffff,%eax
je     11b0 <main+0x70>
lea    0xe6c(%rip),%rdi
lea    0x10(%rsp),%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11c3 <main+0x83>
lea    0xe7a(%rip),%rdi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Informe uma string: \0A\00"
@.str.1 = [8 x i8] c"%41[^\0A]\00"
@.str.2 = [24 x i8] c"Informe um caractere: \0A\00"
@.str.3 = [4 x i8] c" %c\00"
@.str.4 = [37 x i8] c"Posicao da ultima de %c em \22%s\22: %d\0A\00"
@.str.5 = [23 x i8] c"%c nao ocorre em \22%s\22\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [41 x i8]
%3 = alloca i8
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [41 x i8], [41 x i8]* %2, i64 0, i64 0
%7 = call i32 @scanf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %3)
%10 = getelementptr inbounds [41 x i8], [41 x i8]* %2, i64 0, i64 0
%11 = load i8, i8* %3
%12 = call i32 @lastindexof(i8* %10, i8 signext %11)
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %21
15: ; preds = %0
%16 = load i8, i8* %3
%17 = sext i8 %16 to i32
%18 = getelementptr inbounds [41 x i8], [41 x i8]* %2, i64 0, i64 0
%19 = load i32, i32* %4
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i32 %17, i8* %18, i32 %19)
br label %26
21: ; preds = %0
%22 = load i8, i8* %3
%23 = sext i8 %22 to i32
%24 = getelementptr inbounds [41 x i8], [41 x i8]* %2, i64 0, i64 0
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %23, i8* %24)
br label %26
26: ; preds = %21, %15
%27 = load i32, i32* %1
ret i32 %27
}

LLVM IR (-O2):
@.str.1 = [8 x i8] c"%41[^\0A]\00"
@.str.3 = [4 x i8] c" %c\00"
@.str.4 = [37 x i8] c"Posicao da ultima de %c em \22%s\22: %d\0A\00"
@.str.5 = [23 x i8] c"%c nao ocorre em \22%s\22\0A\00"
@str = [21 x i8] c"Informe uma string: \00"
@str.6 = [23 x i8] c"Informe um caractere: \00"
define i32 @main() {
%1 = alloca [41 x i8]
%2 = alloca i8
%3 = getelementptr inbounds [41 x i8], [41 x i8]* %1, i64 0, i64 0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.6, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%8 = load i8, i8* %2
%9 = call i32 @lastindexof(i8* %3, i8 signext %8)
%10 = icmp eq i32 %9, -1
%11 = load i8, i8* %2
%12 = sext i8 %11 to i32
br i1 %10, label %15, label %13
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i32 %12, i8* %3, i32 %9)
br label %17
15: ; preds = %0
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %12, i8* %3)
br label %17
17: ; preds = %15, %13
ret i32 0
}