#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*/ printf(char *, ...);
char *strrchr(char *, char);
int main(void) {
  char text[] = "I learn through IndiaBIX.com";
  char *ptr, c = 'i';
  ptr = strrchr(text, c);
  if (ptr)
    printf("The position of '%c' is: %d\n", c, ptr - text);
  else
    printf("The character was not found\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeca(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xec7(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xec4(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xec2(%rip),%eax
mov    %eax,-0x18(%rbp)
mov    0xebd(%rip),%al
mov    %al,-0x14(%rbp)
movb   $0x69,-0x39(%rbp)
lea    -0x30(%rbp),%rdi
movsbl -0x39(%rbp),%esi
call   1040 <strrchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11a4 <main+0x84>
movsbl -0x39(%rbp),%esi
mov    -0x38(%rbp),%rdx
lea    -0x30(%rbp),%rax
sub    %rax,%rdx
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b2 <main+0x92>
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
movups 0xed1(%rip),%xmm0
movups %xmm0,0xd(%rsp)
movaps 0xeb8(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x69,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     117c <main+0x4c>
sub    %rbx,%rax
lea    0xeb2(%rip),%rdi
mov    $0x69,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1188 <main+0x58>
lea    0xeb7(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.text = [29 x i8] c"I learn through IndiaBIX.com\00"
@.str = [29 x i8] c"The position of '%c' is: %d\0A\00"
@.str.1 = [29 x i8] c"The character was not found\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [29 x i8]
%3 = alloca i8*
%4 = alloca i8
store i32 0, i32* %1
%5 = bitcast [29 x i8]* %2 to i8*
store i8 105, i8* %4
%6 = getelementptr inbounds [29 x i8], [29 x i8]* %2, i64 0, i64 0
%7 = load i8, i8* %4
%8 = call i8* @strrchr(i8* %6, i8 signext %7)
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %20
11: ; preds = %0
%12 = load i8, i8* %4
%13 = sext i8 %12 to i32
%14 = load i8*, i8** %3
%15 = getelementptr inbounds [29 x i8], [29 x i8]* %2, i64 0, i64 0
%16 = ptrtoint i8* %14 to i64
%17 = ptrtoint i8* %15 to i64
%18 = sub i64 %16, %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %13, i64 %18)
br label %22
20: ; preds = %0
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %11
ret i32 0
}

LLVM IR (-O2):
@__const.main.text = [29 x i8] c"I learn through IndiaBIX.com\00"
@.str = [29 x i8] c"The position of '%c' is: %d\0A\00"
@str = [28 x i8] c"The character was not found\00"
define i32 @main() {
%1 = alloca [29 x i8]
%2 = getelementptr inbounds [29 x i8], [29 x i8]* %1, i64 0, i64 0
%3 = call i8* @strrchr(i8* %2, i8 signext 105)
%4 = icmp eq i8* %3, null
br i1 %4, label %10, label %5
5: ; preds = %0
%6 = ptrtoint i8* %3 to i64
%7 = ptrtoint [29 x i8]* %1 to i64
%8 = sub i64 %6, %7
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 105, i64 %8)
br label %12
10: ; preds = %0
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %12
12: ; preds = %10, %5
ret i32 0
}