void functionStrchr() {
  char *s1 = "fenglin";
  char c1 = 'e';
  printf("ret->%c\n", *strchr(s1, c1));
  printf("c1->%p\n", strchr(s1, c1));
  printf("c1->%s\n", strchr(s1, c1));
  printf("c1->%p\n", &s1[1]);
  char c3 = 'A';
  printf("ret->%p\n", strchr(s1, c3));
}


x86 assembly (clang, -O0):
<functionStrchr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xed1(%rip),%rax
mov    %rax,-0x8(%rbp)
movb   $0x65,-0x9(%rbp)
mov    -0x8(%rbp),%rdi
movsbl -0x9(%rbp),%esi
call   1030 <strchr@plt>
movsbl (%rax),%esi
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
movsbl -0x9(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,%rsi
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
movsbl -0x9(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,%rsi
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rsi
add    $0x1,%rsi
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movb   $0x41,-0xa(%rbp)
mov    -0x8(%rbp),%rdi
movsbl -0xa(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,%rsi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<functionStrchr>:
push   %r14
push   %rbx
push   %rax
lea    0xeed(%rip),%rdi
mov    $0x65,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xee3(%rip),%r14
lea    0xecc(%rip),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xed0(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeba(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"fenglin\00"
@.str.1 = [9 x i8] c"ret->%c\0A\00"
@.str.2 = [8 x i8] c"c1->%p\0A\00"
@.str.3 = [8 x i8] c"c1->%s\0A\00"
@.str.4 = [9 x i8] c"ret->%p\0A\00"
define void @functionStrchr() {
%1 = alloca i8*
%2 = alloca i8
%3 = alloca i8
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %1
store i8 101, i8* %2
%4 = load i8*, i8** %1
%5 = load i8, i8* %2
%6 = sext i8 %5 to i32
%7 = call i8* @strchr(i8* %4, i32 %6)
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = load i8*, i8** %1
%12 = load i8, i8* %2
%13 = sext i8 %12 to i32
%14 = call i8* @strchr(i8* %11, i32 %13)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%16 = load i8*, i8** %1
%17 = load i8, i8* %2
%18 = sext i8 %17 to i32
%19 = call i8* @strchr(i8* %16, i32 %18)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %19)
%21 = load i8*, i8** %1
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %22)
store i8 65, i8* %3
%24 = load i8*, i8** %1
%25 = load i8, i8* %3
%26 = sext i8 %25 to i32
%27 = call i8* @strchr(i8* %24, i32 %26)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %27)
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"fenglin\00"
@.str.1 = [9 x i8] c"ret->%c\0A\00"
@.str.2 = [8 x i8] c"c1->%p\0A\00"
@.str.3 = [8 x i8] c"c1->%s\0A\00"
@.str.4 = [9 x i8] c"ret->%p\0A\00"
define void @functionStrchr() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 101)
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 1))
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 1))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 1))
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* null)
ret void
}