#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*/ *memchr(char const *, char, int);
int /*<<< orphan*/ printf(char *);
int test_memchr(void) {
  const char *s = "";
  printf("\tmemchr");
  if (*(char *)memchr("", '\0', 1) != '\0')
    return 1;
  if (*(char *)memchr("123", '3', 3) != '3')
    return 1;
  if (memchr(s, 'a', 0) != NULL)
    return 1;
  if (memchr(s, 'a', 1) != NULL)
    return 1;
  printf("\tpassed.\n");
  return 0;
}


x86 assembly (clang, -O0):
<test_memchr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xee6(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xec6(%rip),%rdi
call   1030 <printf@plt>
lea    0xecf(%rip),%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1040 <memchr@plt>
movsbl (%rax),%eax
cmp    $0x0,%eax
je     116a <test_memchr+0x4a>
movl   $0x1,-0x4(%rbp)
jmp    11fa <test_memchr+0xda>
lea    0xe97(%rip),%rdi
mov    $0x33,%esi
mov    $0x3,%edx
call   1040 <memchr@plt>
movsbl (%rax),%eax
cmp    $0x33,%eax
je     1198 <test_memchr+0x78>
movl   $0x1,-0x4(%rbp)
jmp    11fa <test_memchr+0xda>
mov    -0x10(%rbp),%rdi
mov    $0x61,%esi
xor    %edx,%edx
call   1040 <memchr@plt>
cmp    $0x0,%rax
je     11be <test_memchr+0x9e>
movl   $0x1,-0x4(%rbp)
jmp    11fa <test_memchr+0xda>
mov    -0x10(%rbp),%rdi
mov    $0x61,%esi
mov    $0x1,%edx
call   1040 <memchr@plt>
cmp    $0x0,%rax
je     11e7 <test_memchr+0xc7>
movl   $0x1,-0x4(%rbp)
jmp    11fa <test_memchr+0xda>
lea    0xe1e(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_memchr>:
push   %rbx
lea    0xec8(%rip),%rdi
call   1040 <printf@plt>
lea    0xed0(%rip),%rdi
mov    $0x1,%ebx
xor    %esi,%esi
mov    $0x1,%edx
call   1050 <memchr@plt>
cmpb   $0x0,(%rax)
jne    11bb <test_memchr+0x8b>
lea    0xea7(%rip),%rdi
mov    $0x33,%esi
mov    $0x3,%edx
call   1050 <memchr@plt>
cmpb   $0x33,(%rax)
jne    11bb <test_memchr+0x8b>
lea    0xe98(%rip),%rdi
mov    $0x61,%esi
xor    %edx,%edx
call   1050 <memchr@plt>
test   %rax,%rax
jne    11bb <test_memchr+0x8b>
lea    0xe80(%rip),%rdi
mov    $0x1,%ebx
mov    $0x61,%esi
mov    $0x1,%edx
call   1050 <memchr@plt>
test   %rax,%rax
jne    11bb <test_memchr+0x8b>
lea    0xe58(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [8 x i8] c"\09memchr\00"
@.str.2 = [4 x i8] c"123\00"
@.str.3 = [10 x i8] c"\09passed.\0A\00"
define i32 @test_memchr() {
%1 = alloca i32
%2 = alloca i8*
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %2
%3 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32* @memchr(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8 signext 0, i32 1)
%5 = bitcast i32* %4 to i8*
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %0
store i32 1, i32* %1
br label %29
10: ; preds = %0
%11 = call i32* @memchr(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8 signext 51, i32 3)
%12 = bitcast i32* %11 to i8*
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 51
br i1 %15, label %16, label %17
16: ; preds = %10
store i32 1, i32* %1
br label %29
17: ; preds = %10
%18 = load i8*, i8** %2
%19 = call i32* @memchr(i8* %18, i8 signext 97, i32 0)
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 1, i32* %1
br label %29
22: ; preds = %17
%23 = load i8*, i8** %2
%24 = call i32* @memchr(i8* %23, i8 signext 97, i32 1)
%25 = icmp ne i32* %24, null
br i1 %25, label %26, label %27
26: ; preds = %22
store i32 1, i32* %1
br label %29
27: ; preds = %22
%28 = 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 %29
29: ; preds = %27, %26, %21, %16, %9
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [8 x i8] c"\09memchr\00"
@.str.2 = [4 x i8] c"123\00"
@str = [9 x i8] c"\09passed.\00"
define i32 @test_memchr() {
%1 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i32* @memchr(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8 signext 0, i32 1)
%3 = bitcast i32* %2 to i8*
%4 = load i8, i8* %3
%5 = icmp eq i8 %4, 0
br i1 %5, label %6, label %19
6: ; preds = %0
%7 = tail call i32* @memchr(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8 signext 51, i32 3)
%8 = bitcast i32* %7 to i8*
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 51
br i1 %10, label %11, label %19
11: ; preds = %6
%12 = tail call i32* @memchr(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8 signext 97, i32 0)
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = tail call i32* @memchr(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8 signext 97, i32 1)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %19
19: ; preds = %14, %11, %6, %0, %17
%20 = phi i32 [ 0, %17 ], [ 1, %0 ], [ 1, %6 ], [ 1, %11 ], [ 1, %14 ]
ret i32 %20
}