#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 const *strchr(char const *, char);
int test_strrchr(void) {
  const char *str = "hello";
  printf("\tstrrchr");
  if (strchr(str, 'l') != &str[2])
    return 1;
  else
    printf(".");
  if (strchr(str, 'q') != NULL)
    return 1;
  else
    printf(".");
  if (strchr(str, '\0') != NULL)
    return 1;
  else
    printf(".");
  printf(" passed.\n");
  return 0;
}


x86 assembly (clang, -O0):
<test_strrchr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xed1(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xecc(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x6c,%esi
call   1030 <strchr@plt>
mov    -0x10(%rbp),%rcx
add    $0x2,%rcx
cmp    %rcx,%rax
je     116a <test_strrchr+0x4a>
movl   $0x1,-0x4(%rbp)
jmp    11e6 <test_strrchr+0xc6>
lea    0xe9e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x71,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     119a <test_strrchr+0x7a>
movl   $0x1,-0x4(%rbp)
jmp    11e6 <test_strrchr+0xc6>
lea    0xe6e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     11c7 <test_strrchr+0xa7>
movl   $0x1,-0x4(%rbp)
jmp    11e6 <test_strrchr+0xc6>
lea    0xe41(%rip),%rdi
call   1040 <printf@plt>
lea    0xe37(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_strrchr>:
push   %rax
lea    0xed8(%rip),%rdi
call   1040 <printf@plt>
mov    $0x2e,%edi
call   1030 <putchar@plt>
mov    $0x2e,%edi
call   1030 <putchar@plt>
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"hello\00"
@.str.1 = [9 x i8] c"\09strrchr\00"
@.str.2 = [2 x i8] c".\00"
@.str.3 = [10 x i8] c" passed.\0A\00"
define i32 @test_strrchr() {
%1 = alloca i32
%2 = alloca i8*
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %2
%3 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%4 = load i8*, i8** %2
%5 = call i8* @strchr(i8* %4, i8 signext 108)
%6 = load i8*, i8** %2
%7 = getelementptr inbounds i8, i8* %6, i64 2
%8 = icmp ne i8* %5, %7
br i1 %8, label %9, label %10
9: ; preds = %0
store i32 1, i32* %1
br label %28
10: ; preds = %0
%11 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %12
12: ; preds = %10
%13 = load i8*, i8** %2
%14 = call i8* @strchr(i8* %13, i8 signext 113)
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %12
store i32 1, i32* %1
br label %28
17: ; preds = %12
%18 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %17
%20 = load i8*, i8** %2
%21 = call i8* @strchr(i8* %20, i8 signext 0)
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %24
23: ; preds = %19
store i32 1, i32* %1
br label %28
24: ; preds = %19
%25 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %24
%27 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %28
28: ; preds = %26, %23, %16, %9
%29 = load i32, i32* %1
ret i32 %29
}

LLVM IR (-O2):
@.str.1 = [9 x i8] c"\09strrchr\00"
define i32 @test_strrchr() {
%1 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i32 @putchar(i32 46)
%3 = tail call i32 @putchar(i32 46)
ret i32 1
}