#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ clear_memory(char *);
int /*<<< orphan*/ enter_data(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char *firstString;
char getchar();
char *make_char(int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int right_most_occurrence(char *, char);
int main() {
  char *firstString = make_char(firstString, 100);
  char character;
  if (firstString == NULL) {
    printf("Not enough memory!");
    exit(EXIT_FAILURE);
  }
  enter_data(firstString);
  printf("Enter char:");
  character = getchar();
  getchar();
  int index = right_most_occurrence(firstString, character);
  if (index == -1) {
    printf("No such character.");
  } else {
    printf("%d", index);
  }
  clear_memory(firstString);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,%edi
mov    $0x64,%esi
call   1090 <make_char@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ba <main+0x4a>
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1030 <enter_data@plt>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x11(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    -0x10(%rbp),%rdi
movsbl -0x11(%rbp),%esi
call   1070 <right_most_occurrence@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    120f <main+0x9f>
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1220 <main+0xb0>
mov    -0x18(%rbp),%esi
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <clear_memory@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x64,%esi
call   1090 <make_char@plt>
test   %rax,%rax
je     11f5 <main+0x85>
mov    %rax,%r14
mov    %rax,%rdi
call   1030 <enter_data@plt>
lea    0xe7e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getchar@plt>
movsbl %bl,%esi
mov    %r14,%rdi
call   1070 <right_most_occurrence@plt>
cmp    $0xffffffff,%eax
je     11ce <main+0x5e>
lea    0xe6f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11dc <main+0x6c>
lea    0xe4a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
call   1060 <clear_memory@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe04(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"Not enough memory!\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [12 x i8] c"Enter char:\00"
@.str.2 = [19 x i8] c"No such character.\00"
@.str.3 = [3 x i8] c"%d\00"
@EXIT_SUCCESS = global i32 0
@firstString = global i8* null
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i32
store i32 0, i32* %1
%5 = load i8*, i8** %2
%6 = ptrtoint i8* %5 to i32
%7 = call i8* @make_char(i32 %6, i32 100)
store i8* %7, i8** %2
%8 = load i8*, i8** %2
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %14
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %0
%15 = load i8*, i8** %2
%16 = call i32 @enter_data(i8* %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%18 = call signext i8 (...) @getchar()
store i8 %18, i8* %3
%19 = call signext i8 (...) @getchar()
%20 = load i8*, i8** %2
%21 = load i8, i8* %3
%22 = call i32 @right_most_occurrence(i8* %20, i8 signext %21)
store i32 %22, i32* %4
%23 = load i32, i32* %4
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %14
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %30
27: ; preds = %14
%28 = load i32, i32* %4
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %27, %25
%31 = load i8*, i8** %2
%32 = call i32 @clear_memory(i8* %31)
%33 = load i32, i32* @EXIT_SUCCESS
ret i32 %33
}

LLVM IR (-O2):
@.str = [19 x i8] c"Not enough memory!\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [12 x i8] c"Enter char:\00"
@.str.2 = [19 x i8] c"No such character.\00"
@.str.3 = [3 x i8] c"%d\00"
@EXIT_SUCCESS = global i32 0
@firstString = global i8* null
define i32 @main() {
%1 = tail call i8* @make_char(i32 undef, i32 100)
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %7
3: ; preds = %0
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @EXIT_FAILURE
%6 = tail call i32 @exit(i32 %5)
unreachable
7: ; preds = %0
%8 = tail call i32 @enter_data(i8* %1)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call signext i8 (...) @getchar()
%11 = tail call signext i8 (...) @getchar()
%12 = tail call i32 @right_most_occurrence(i8* %1, i8 signext %10)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %7
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %18
16: ; preds = %7
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %12)
br label %18
18: ; preds = %16, %14
%19 = tail call i32 @clear_memory(i8* %1)
%20 = load i32, i32* @EXIT_SUCCESS
ret i32 %20
}