#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*/ gets(char *);
int primeira(char *, char);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int ultima(char *, char);
int main() {
  char string[10], letra;
  int ult, pri;
  printf("Entre com um string: ");
  gets(string);
  printf("Entre com um letra: ");
  scanf(" %c", &letra);
  ult = ultima(&string[0], letra);
  pri = primeira(&string[0], letra);
  printf(
      "Ultima ocorrencia da letra %c: %d\nPrimeira ocorrencia da letra %c: %d",
      letra, ult, letra, pri);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xe(%rbp),%rdi
call   1050 <gets@plt>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea0(%rip),%rdi
lea    -0xf(%rbp),%rsi
call   1060 <scanf@plt>
lea    -0xe(%rbp),%rdi
movsbl -0xf(%rbp),%esi
call   1070 <ultima@plt>
mov    %eax,-0x14(%rbp)
lea    -0xe(%rbp),%rdi
movsbl -0xf(%rbp),%esi
call   1040 <primeira@plt>
mov    %eax,-0x18(%rbp)
movsbl -0xf(%rbp),%esi
mov    -0x14(%rbp),%edx
movsbl -0xf(%rbp),%ecx
mov    -0x18(%rbp),%r8d
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
lea    0xea3(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <gets@plt>
lea    0xe9e(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xea5(%rip),%rdi
lea    0xd(%rsp),%rsi
call   1060 <scanf@plt>
movsbl 0xd(%rsp),%esi
mov    %rbx,%rdi
call   1070 <ultima@plt>
mov    %eax,%ebp
movsbl 0xd(%rsp),%esi
mov    %rbx,%rdi
call   1040 <primeira@plt>
movsbl 0xd(%rsp),%ecx
lea    0xe77(%rip),%rdi
mov    %ecx,%esi
mov    %ebp,%edx
mov    %eax,%r8d
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Entre com um string: \00"
@.str.1 = [21 x i8] c"Entre com um letra: \00"
@.str.2 = [4 x i8] c" %c\00"
@.str.3 = [70 x i8] c"Ultima ocorrencia da letra %c: %d\0APrimeira ocorrencia da letra %c: %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%8 = call i32 @gets(i8* %7)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%12 = load i8, i8* %3
%13 = call i32 @ultima(i8* %11, i8 signext %12)
store i32 %13, i32* %4
%14 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%15 = load i8, i8* %3
%16 = call i32 @primeira(i8* %14, i8 signext %15)
store i32 %16, i32* %5
%17 = load i8, i8* %3
%18 = sext i8 %17 to i32
%19 = load i32, i32* %4
%20 = load i8, i8* %3
%21 = sext i8 %20 to i32
%22 = load i32, i32* %5
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.3, i64 0, i64 0), i32 %18, i32 %19, i32 %21, i32 %22)
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"Entre com um string: \00"
@.str.1 = [21 x i8] c"Entre com um letra: \00"
@.str.2 = [4 x i8] c" %c\00"
@.str.3 = [70 x i8] c"Ultima ocorrencia da letra %c: %d\0APrimeira ocorrencia da letra %c: %d\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = alloca i8
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @gets(i8* %3)
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%8 = load i8, i8* %2
%9 = call i32 @ultima(i8* %3, i8 signext %8)
%10 = load i8, i8* %2
%11 = call i32 @primeira(i8* %3, i8 signext %10)
%12 = load i8, i8* %2
%13 = sext i8 %12 to i32
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @.str.3, i64 0, i64 0), i32 %13, i32 %9, i32 %13, i32 %11)
ret i32 0
}