#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 */
char *memchr(char *, char, int);
int /*<<< orphan*/ printf(char *, char *, int);
int test_memchr(void) {
  char data[] = "xyz\0abc";
  do {
    if (!(&data[2] == memchr(data, 'z', sizeof data))) {
      printf("expression '%s' untrue at %d\n",
             "&data[2] == memchr(data, 'z', sizeof data)", 213);
      return 0;
    }
  } while (0);
  do {
    if (!(&data[3] == memchr(data, '\0', sizeof data))) {
      printf("expression '%s' untrue at %d\n",
             "&data[3] == memchr(data, '\\0', sizeof data)", 214);
      return 0;
    }
  } while (0);
  do {
    if (!(NULL == memchr(data, 'd', sizeof data))) {
      printf("expression '%s' untrue at %d\n",
             "NULL == memchr(data, 'd', sizeof data)", 215);
      return 0;
    }
  } while (0);
  return 1;
}


x86 assembly (clang, -O0):
<test_memchr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0xed1(%rip),%rax
mov    %rax,-0xc(%rbp)
lea    -0xc(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
lea    -0xc(%rbp),%rdi
mov    $0x7a,%esi
mov    $0x8,%edx
call   1040 <memchr@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
cmp    %rcx,%rax
je     1186 <test_memchr+0x66>
lea    0xe9f(%rip),%rdi
lea    0xeb6(%rip),%rsi
mov    $0xd5,%edx
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    123b <test_memchr+0x11b>
jmp    118b <test_memchr+0x6b>
jmp    1190 <test_memchr+0x70>
lea    -0xc(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x20(%rbp)
lea    -0xc(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memchr@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
je     11e0 <test_memchr+0xc0>
lea    0xe45(%rip),%rdi
lea    0xe87(%rip),%rsi
mov    $0xd6,%edx
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    123b <test_memchr+0x11b>
jmp    11e5 <test_memchr+0xc5>
jmp    11ea <test_memchr+0xca>
lea    -0xc(%rbp),%rdi
mov    $0x64,%esi
mov    $0x8,%edx
call   1040 <memchr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     122f <test_memchr+0x10f>
lea    0xdf6(%rip),%rdi
lea    0xe64(%rip),%rsi
mov    $0xd7,%edx
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    123b <test_memchr+0x11b>
jmp    1234 <test_memchr+0x114>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_memchr>:
push   %r14
push   %rbx
push   %rax
movabs $0x636261007a7978,%rax
mov    %rax,(%rsp)
lea    0x2(%rsp),%rbx
mov    %rsp,%rdi
mov    $0x7a,%esi
mov    $0x8,%edx
call   1040 <memchr@plt>
cmp    %rax,%rbx
je     116a <test_memchr+0x4a>
lea    0xeab(%rip),%rdi
lea    0xec2(%rip),%rsi
mov    $0xd5,%edx
call   1030 <printf@plt>
xor    %ebx,%ebx
jmp    11c9 <test_memchr+0xa9>
lea    0x3(%rsp),%r14
mov    %rsp,%rdi
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memchr@plt>
cmp    %rax,%r14
je     119a <test_memchr+0x7a>
lea    0xe74(%rip),%rdi
lea    0xeb6(%rip),%rsi
mov    $0xd6,%edx
jmp    11c4 <test_memchr+0xa4>
mov    %rsp,%rdi
mov    $0x64,%esi
mov    $0x8,%edx
call   1040 <memchr@plt>
test   %rax,%rax
je     11d3 <test_memchr+0xb3>
lea    0xe48(%rip),%rdi
lea    0xeb6(%rip),%rsi
mov    $0xd7,%edx
call   1030 <printf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    $0x1,%ebx
jmp    11c9 <test_memchr+0xa9>

LLVM IR (-O0):
@__const.test_memchr.data = [8 x i8] c"xyz\00abc\00"
@.str = [30 x i8] c"expression '%s' untrue at %d\0A\00"
@.str.1 = [43 x i8] c"&data[2] == memchr(data, 'z', sizeof data)\00"
@.str.2 = [44 x i8] c"&data[3] == memchr(data, '\\0', sizeof data)\00"
@.str.3 = [39 x i8] c"NULL == memchr(data, 'd', sizeof data)\00"
define i32 @test_memchr() {
%1 = alloca i32
%2 = alloca [8 x i8]
%3 = bitcast [8 x i8]* %2 to i8*
br label %4
4: ; preds = %0
%5 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 2
%6 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%7 = call i8* @memchr(i8* %6, i8 signext 122, i32 8)
%8 = icmp eq i8* %5, %7
br i1 %8, label %11, label %9
9: ; preds = %4
%10 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 213)
store i32 0, i32* %1
br label %30
11: ; preds = %4
br label %12
12: ; preds = %11
br label %13
13: ; preds = %12
%14 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 3
%15 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%16 = call i8* @memchr(i8* %15, i8 signext 0, i32 8)
%17 = icmp eq i8* %14, %16
br i1 %17, label %20, label %18
18: ; preds = %13
%19 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i32 214)
store i32 0, i32* %1
br label %30
20: ; preds = %13
br label %21
21: ; preds = %20
br label %22
22: ; preds = %21
%23 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%24 = call i8* @memchr(i8* %23, i8 signext 100, i32 8)
%25 = icmp eq i8* null, %24
br i1 %25, label %28, label %26
26: ; preds = %22
%27 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i32 215)
store i32 0, i32* %1
br label %30
28: ; preds = %22
br label %29
29: ; preds = %28
store i32 1, i32* %1
br label %30
30: ; preds = %29, %26, %18, %9
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
@.str = [30 x i8] c"expression '%s' untrue at %d\0A\00"
@.str.1 = [43 x i8] c"&data[2] == memchr(data, 'z', sizeof data)\00"
@.str.2 = [44 x i8] c"&data[3] == memchr(data, '\\0', sizeof data)\00"
@.str.3 = [39 x i8] c"NULL == memchr(data, 'd', sizeof data)\00"
define i32 @test_memchr() {
%1 = alloca i64
%2 = bitcast i64* %1 to [8 x i8]*
%3 = bitcast i64* %1 to i8*
store i64 27974191453731192, i64* %1
%4 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 2
%5 = call i8* @memchr(i8* %3, i8 signext 122, i32 8)
%6 = icmp eq i8* %4, %5
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 213)
br label %20
9: ; preds = %0
%10 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 3
%11 = call i8* @memchr(i8* %3, i8 signext 0, i32 8)
%12 = icmp eq i8* %10, %11
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i32 214)
br label %20
15: ; preds = %9
%16 = call i8* @memchr(i8* %3, i8 signext 100, i32 8)
%17 = icmp eq i8* %16, null
br i1 %17, label %20, label %18
18: ; preds = %15
%19 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i32 215)
br label %20
20: ; preds = %15, %18, %13, %7
%21 = phi i32 [ 0, %18 ], [ 0, %13 ], [ 0, %7 ], [ 1, %15 ]
ret i32 %21
}