#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 *, ...);
scalar_t__ strlen(char *);
char *strrchr(char const *, char const);
int main() {
  const char str[] = "https://github.com/zhangrxiang/learn-c";
  const char str2[] =
      "D:\\WorkSpace\\clionProjects\\learn-c\\string\\strrchr.c";
  const char ch = '/';
  const char ch2 = '\\';
  char *ret;
  ret = strrchr(str, ch);
  printf("|%c| ------ |%s|\n", ch, ret);
  printf("%c\n", ret[0]);
  printf("%ld\n", ret - str + 1);
  printf("%ld\n", ret - str);
  ret = strrchr(str2, ch2);
  printf("|%c| ------ |%s|\n", ch2, ret);
  printf("%c\n", ret[0]);
  printf("%c\n", str2[ret - str2]);
  printf("%ld\n", ret - str2 + 1);
  printf("%d\n", (int)strlen(ret));
  printf("%s\n", ret + 1);
  printf("%c\n", *ret);
  printf("%c\n", *(ret + sizeof(char)));
  printf("%c\n", *(ret + sizeof(char) * 2));
  printf("%s\n", &(*ret));
  printf("%s\n", &*(ret + sizeof(char)));
  ret = strrchr(str, 'A');
  if (ret) {
    printf("exists A\n");
  } else {
    printf("no exists A\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xea3(%rip),%rsi
mov    $0x27,%edx
call   1060 <memcpy@plt>
lea    -0x70(%rbp),%rdi
lea    0xebe(%rip),%rsi
mov    $0x34,%edx
call   1060 <memcpy@plt>
movb   $0x2f,-0x71(%rbp)
movb   $0x5c,-0x72(%rbp)
lea    -0x30(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rdx
lea    0xec3(%rip),%rdi
mov    $0x2f,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x80(%rbp),%rax
movsbl (%rax),%esi
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x80(%rbp),%rsi
lea    -0x30(%rbp),%rax
sub    %rax,%rsi
add    $0x1,%rsi
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x80(%rbp),%rsi
lea    -0x30(%rbp),%rax
sub    %rax,%rsi
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x70(%rbp),%rdi
mov    $0x5c,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rdx
lea    0xe4f(%rip),%rdi
mov    $0x5c,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x80(%rbp),%rax
movsbl (%rax),%esi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x80(%rbp),%rax
lea    -0x70(%rbp),%rcx
sub    %rcx,%rax
movsbl -0x70(%rbp,%rax,1),%esi
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x80(%rbp),%rsi
lea    -0x70(%rbp),%rax
sub    %rax,%rsi
add    $0x1,%rsi
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x80(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%esi
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x80(%rbp),%rsi
add    $0x1,%rsi
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x80(%rbp),%rax
movsbl (%rax),%esi
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x80(%rbp),%rax
movsbl 0x1(%rax),%esi
lea    0xdb2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x80(%rbp),%rax
movsbl 0x2(%rax),%esi
lea    0xd9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x80(%rbp),%rsi
lea    0xd97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x80(%rbp),%rsi
add    $0x1,%rsi
lea    0xd81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    $0x41,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x80(%rbp)
cmpq   $0x0,-0x80(%rbp)
je     1339 <main+0x1f9>
lea    0xd5d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1347 <main+0x207>
lea    0xd47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
movaps 0xebb(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe9f(%rip),%xmm0
movaps %xmm0,(%rsp)
movabs $0x632d6e7261656c,%rax
mov    %rax,0x1f(%rsp)
movaps 0xed5(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xeb9(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe9d(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movl   $0x632e72,0x60(%rsp)
mov    %rsp,%rdi
mov    %rdi,%rbp
mov    $0x2f,%esi
call   1060 <strrchr@plt>
mov    %rax,%rbx
lea    0xeaa(%rip),%r13
mov    %r13,%rdi
mov    $0x2f,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
movsbl (%rbx),%esi
lea    0xea0(%rip),%r15
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
sub    %rbp,%rbx
lea    0x1(%rbx),%rsi
lea    0xe8c(%rip),%r12
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x30(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x5c,%esi
call   1060 <strrchr@plt>
mov    %rax,%r14
mov    %r13,%rdi
mov    $0x5c,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
movsbl (%r14),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rbx
sub    %rbp,%rbx
movsbl (%r14),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0xe11(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x1(%r14),%r12
mov    %r12,%rdi
call   1030 <puts@plt>
movsbl (%r14),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movsbl 0x1(%r14),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movsbl 0x2(%r14),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
mov    $0x41,%esi
call   1060 <strrchr@plt>
test   %rax,%rax
lea    0xdad(%rip),%rax
lea    0xda9(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.str = [39 x i8] c"https://github.com/zhangrxiang/learn-c\00"
@__const.main.str2 = [52 x i8] c"D:\\WorkSpace\\clionProjects\\learn-c\\string\\strrchr.c\00"
@.str = [18 x i8] c"|%c| ------ |%s|\0A\00"
@.str.1 = [4 x i8] c"%c\0A\00"
@.str.2 = [5 x i8] c"%ld\0A\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [10 x i8] c"exists A\0A\00"
@.str.6 = [13 x i8] c"no exists A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [39 x i8]
%3 = alloca [52 x i8]
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8*
store i32 0, i32* %1
%7 = bitcast [39 x i8]* %2 to i8*
%8 = bitcast [52 x i8]* %3 to i8*
store i8 47, i8* %4
store i8 92, i8* %5
%9 = getelementptr inbounds [39 x i8], [39 x i8]* %2, i64 0, i64 0
%10 = call i8* @strrchr(i8* %9, i8 signext 47)
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 47, i8* %11)
%13 = load i8*, i8** %6
%14 = getelementptr inbounds i8, i8* %13, i64 0
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = load i8*, i8** %6
%19 = getelementptr inbounds [39 x i8], [39 x i8]* %2, i64 0, i64 0
%20 = ptrtoint i8* %18 to i64
%21 = ptrtoint i8* %19 to i64
%22 = sub i64 %20, %21
%23 = add nsw i64 %22, 1
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %23)
%25 = load i8*, i8** %6
%26 = getelementptr inbounds [39 x i8], [39 x i8]* %2, i64 0, i64 0
%27 = ptrtoint i8* %25 to i64
%28 = ptrtoint i8* %26 to i64
%29 = sub i64 %27, %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %29)
%31 = getelementptr inbounds [52 x i8], [52 x i8]* %3, i64 0, i64 0
%32 = call i8* @strrchr(i8* %31, i8 signext 92)
store i8* %32, i8** %6
%33 = load i8*, i8** %6
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 92, i8* %33)
%35 = load i8*, i8** %6
%36 = getelementptr inbounds i8, i8* %35, i64 0
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %38)
%40 = load i8*, i8** %6
%41 = getelementptr inbounds [52 x i8], [52 x i8]* %3, i64 0, i64 0
%42 = ptrtoint i8* %40 to i64
%43 = ptrtoint i8* %41 to i64
%44 = sub i64 %42, %43
%45 = getelementptr inbounds [52 x i8], [52 x i8]* %3, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %47)
%49 = load i8*, i8** %6
%50 = getelementptr inbounds [52 x i8], [52 x i8]* %3, i64 0, i64 0
%51 = ptrtoint i8* %49 to i64
%52 = ptrtoint i8* %50 to i64
%53 = sub i64 %51, %52
%54 = add nsw i64 %53, 1
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %54)
%56 = load i8*, i8** %6
%57 = call i64 @strlen(i8* %56)
%58 = trunc i64 %57 to i32
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %58)
%60 = load i8*, i8** %6
%61 = getelementptr inbounds i8, i8* %60, i64 1
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %61)
%63 = load i8*, i8** %6
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %65)
%67 = load i8*, i8** %6
%68 = getelementptr inbounds i8, i8* %67, i64 1
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %70)
%72 = load i8*, i8** %6
%73 = getelementptr inbounds i8, i8* %72, i64 2
%74 = load i8, i8* %73
%75 = sext i8 %74 to i32
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %75)
%77 = load i8*, i8** %6
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %77)
%79 = load i8*, i8** %6
%80 = getelementptr inbounds i8, i8* %79, i64 1
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %80)
%82 = getelementptr inbounds [39 x i8], [39 x i8]* %2, i64 0, i64 0
%83 = call i8* @strrchr(i8* %82, i8 signext 65)
store i8* %83, i8** %6
%84 = load i8*, i8** %6
%85 = icmp ne i8* %84, null
br i1 %85, label %86, label %88
86: ; preds = %0
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
br label %90
88: ; preds = %0
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
br label %90
90: ; preds = %88, %86
ret i32 0
}

LLVM IR (-O2):
@__const.main.str = [39 x i8] c"https://github.com/zhangrxiang/learn-c\00"
@__const.main.str2 = [52 x i8] c"D:\\WorkSpace\\clionProjects\\learn-c\\string\\strrchr.c\00"
@.str = [18 x i8] c"|%c| ------ |%s|\0A\00"
@.str.1 = [4 x i8] c"%c\0A\00"
@.str.2 = [5 x i8] c"%ld\0A\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@str = [12 x i8] c"no exists A\00"
@str.7 = [9 x i8] c"exists A\00"
define i32 @main() {
%1 = alloca [39 x i8]
%2 = alloca [52 x i8]
%3 = getelementptr inbounds [39 x i8], [39 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [52 x i8], [52 x i8]* %2, i64 0, i64 0
%5 = call i8* @strrchr(i8* %3, i8 signext 47)
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 47, i8* %5)
%7 = load i8, i8* %5
%8 = sext i8 %7 to i32
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = ptrtoint i8* %5 to i64
%11 = ptrtoint [39 x i8]* %1 to i64
%12 = sub i64 %10, %11
%13 = add nsw i64 %12, 1
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %13)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %12)
%16 = call i8* @strrchr(i8* %4, i8 signext 92)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 92, i8* %16)
%18 = load i8, i8* %16
%19 = sext i8 %18 to i32
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = ptrtoint i8* %16 to i64
%22 = ptrtoint [52 x i8]* %2 to i64
%23 = sub i64 %21, %22
%24 = getelementptr inbounds [52 x i8], [52 x i8]* %2, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = add nsw i64 %23, 1
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %28)
%30 = call i64 @strlen(i8* %16)
%31 = trunc i64 %30 to i32
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %31)
%33 = getelementptr inbounds i8, i8* %16, i64 1
%34 = call i32 @puts(i8* %33)
%35 = load i8, i8* %16
%36 = sext i8 %35 to i32
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %36)
%38 = load i8, i8* %33
%39 = sext i8 %38 to i32
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %39)
%41 = getelementptr inbounds i8, i8* %16, i64 2
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %43)
%45 = call i32 @puts(i8* %16)
%46 = call i32 @puts(i8* %33)
%47 = call i8* @strrchr(i8* %3, i8 signext 65)
%48 = icmp eq i8* %47, null
%49 = select i1 %48, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @str.7, i64 0, i64 0)
%50 = call i32 @puts(i8* dereferenceable(1) %49)
ret i32 0
}