int main() {
  char str[] = "I am your God";
  char *position = (char *)memchr(str, 'y', strlen(str));
  if (position) {
    printf("%s\n", position);
    printf("%d\n", (int)(position - str));
    printf("%c\n", str[position - str]);
  } else {
    printf("null\n");
  }
  printf("===================================\n");
  int arr[] = {10, 20, 30, 40, 50, 60, 70, 80, 90};
  int *pInt = (int *)memchr(arr, 50, sizeof(arr));
  printf("%d\n", (int)(pInt - arr));
  printf("%ld\n", (pInt - arr));
  printf("%d\n", *pInt);
  printf("%c\n", *pInt);
  printf("%c\n", (unsigned char)50);
  printf("%c\n", (char)50);
  printf("%c\n", 50);
  printf("%c\n", (unsigned char)51);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeaa(%rip),%rax
mov    %rax,-0x12(%rbp)
mov    0xea8(%rip),%eax
mov    %eax,-0xa(%rbp)
mov    0xea2(%rip),%ax
mov    %ax,-0x6(%rbp)
lea    -0x12(%rbp),%rax
mov    %rax,-0x60(%rbp)
lea    -0x12(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x60(%rbp),%rdi
mov    %rax,%rdx
mov    $0x79,%esi
call   1050 <memchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11ef <main+0xaf>
mov    -0x20(%rbp),%rsi
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
lea    -0x12(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
lea    -0x12(%rbp),%rcx
sub    %rcx,%rax
movsbl -0x12(%rbp,%rax,1),%esi
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11fd <main+0xbd>
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x50(%rbp),%rdi
lea    0xe3a(%rip),%rsi
mov    $0x24,%edx
call   1060 <memcpy@plt>
lea    -0x50(%rbp),%rdi
mov    $0x32,%esi
mov    $0x24,%edx
call   1050 <memchr@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
lea    -0x50(%rbp),%rcx
sub    %rcx,%rax
sar    $0x2,%rax
mov    %eax,%esi
lea    0xdc3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x58(%rbp),%rsi
lea    -0x50(%rbp),%rax
sub    %rax,%rsi
sar    $0x2,%rsi
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x58(%rbp),%rax
mov    (%rax),%esi
lea    0xd92(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x58(%rbp),%rax
mov    (%rax),%esi
lea    0xd82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd74(%rip),%rdi
mov    $0x32,%esi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd61(%rip),%rdi
mov    $0x32,%esi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd4e(%rip),%rdi
mov    $0x32,%esi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd3b(%rip),%rdi
mov    $0x33,%esi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
movabs $0x646f472072756f,%rax
mov    %rax,0x6(%rsp)
movabs $0x756f79206d612049,%rax
79 6f 75
mov    %rax,(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    $0x79,%esi
mov    %rax,%rdx
call   1060 <memchr@plt>
test   %rax,%rax
je     11b9 <main+0x79>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <puts@plt>
mov    %rsp,%rax
mov    %ebx,%esi
sub    %eax,%esi
lea    0xe6f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movsbl (%rbx),%esi
lea    0xe62(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11c5 <main+0x85>
lea    0xe5b(%rip),%rdi
call   1030 <puts@plt>
lea    0xe54(%rip),%rdi
call   1030 <puts@plt>
mov    0xe99(%rip),%eax
mov    %eax,0x30(%rsp)
movaps 0xe7e(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe62(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x10(%rsp),%r14
mov    $0x24,%edx
mov    %r14,%rdi
mov    $0x32,%esi
call   1060 <memchr@plt>
mov    %rax,%r15
mov    %rax,%rbx
sub    %r14,%rbx
sar    $0x2,%rbx
lea    0xdf0(%rip),%r14
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xde5(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r15),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r15),%esi
lea    0xdc0(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x32,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x32,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x32,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x33,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.str = [14 x i8] c"I am your God\00"
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [4 x i8] c"%c\0A\00"
@.str.3 = [6 x i8] c"null\0A\00"
@.str.4 = [37 x i8] c"===================================\0A\00"
@__const.main.arr = [9 x i32] [i32 10, i32 20, i32 30, i32 40, i32 50, i32 60, i32 70, i32 80, i32 90]
@.str.5 = [5 x i8] c"%ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [14 x i8]
%3 = alloca i8*
%4 = alloca [9 x i32]
%5 = alloca i32*
store i32 0, i32* %1
%6 = bitcast [14 x i8]* %2 to i8*
%7 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%8 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%9 = call i64 @strlen(i8* %8)
%10 = call i8* @memchr(i8* %7, i32 121, i64 %9)
store i8* %10, i8** %3
%11 = load i8*, i8** %3
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %32
13: ; preds = %0
%14 = load i8*, i8** %3
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i8*, i8** %3
%17 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%18 = ptrtoint i8* %16 to i64
%19 = ptrtoint i8* %17 to i64
%20 = sub i64 %18, %19
%21 = trunc i64 %20 to i32
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = load i8*, i8** %3
%24 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%25 = ptrtoint i8* %23 to i64
%26 = ptrtoint i8* %24 to i64
%27 = sub i64 %25, %26
%28 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %30)
br label %34
32: ; preds = %0
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %34
34: ; preds = %32, %13
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
%36 = bitcast [9 x i32]* %4 to i8*
%37 = getelementptr inbounds [9 x i32], [9 x i32]* %4, i64 0, i64 0
%38 = bitcast i32* %37 to i8*
%39 = call i8* @memchr(i8* %38, i32 50, i64 36)
%40 = bitcast i8* %39 to i32*
store i32* %40, i32** %5
%41 = load i32*, i32** %5
%42 = getelementptr inbounds [9 x i32], [9 x i32]* %4, i64 0, i64 0
%43 = ptrtoint i32* %41 to i64
%44 = ptrtoint i32* %42 to i64
%45 = sub i64 %43, %44
%46 = sdiv exact i64 %45, 4
%47 = trunc i64 %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 i32*, i32** %5
%50 = getelementptr inbounds [9 x i32], [9 x i32]* %4, i64 0, i64 0
%51 = ptrtoint i32* %49 to i64
%52 = ptrtoint i32* %50 to i64
%53 = sub i64 %51, %52
%54 = sdiv exact i64 %53, 4
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i64 %54)
%56 = load i32*, i32** %5
%57 = load i32, i32* %56
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %57)
%59 = load i32*, i32** %5
%60 = load i32, i32* %59
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %60)
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 50)
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 50)
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 50)
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 51)
ret i32 0
}

LLVM IR (-O2):
@__const.main.str = [14 x i8] c"I am your God\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [4 x i8] c"%c\0A\00"
@__const.main.arr = [9 x i32] [i32 10, i32 20, i32 30, i32 40, i32 50, i32 60, i32 70, i32 80, i32 90]
@.str.5 = [5 x i8] c"%ld\0A\00"
@str = [5 x i8] c"null\00"
@str.6 = [36 x i8] c"===================================\00"
define i32 @main() {
%1 = alloca [14 x i8]
%2 = alloca [9 x i32]
%3 = getelementptr inbounds [14 x i8], [14 x i8]* %1, i64 0, i64 0
%4 = call i64 @strlen(i8* %3)
%5 = call i8* @memchr(i8* %3, i32 121, i64 %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %18, label %7
7: ; preds = %0
%8 = call i32 @puts(i8* %5)
%9 = ptrtoint i8* %5 to i64
%10 = ptrtoint [14 x i8]* %1 to i64
%11 = sub i64 %9, %10
%12 = trunc i64 %11 to i32
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = getelementptr inbounds [14 x i8], [14 x i8]* %1, i64 0, i64 %11
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %16)
br label %20
18: ; preds = %0
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
br label %20
20: ; preds = %18, %7
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.6, i64 0, i64 0))
%22 = bitcast [9 x i32]* %2 to i8*
%23 = call i8* @memchr(i8* dereferenceable(36) %22, i32 50, i64 36)
%24 = bitcast i8* %23 to i32*
%25 = ptrtoint i8* %23 to i64
%26 = ptrtoint [9 x i32]* %2 to i64
%27 = sub i64 %25, %26
%28 = ashr exact i64 %27, 2
%29 = trunc i64 %28 to i32
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %29)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i64 %28)
%32 = load i32, i32* %24
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %32)
%34 = load i32, i32* %24
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 50)
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 50)
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 50)
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 51)
ret i32 0
}