#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*/ memset(unsigned char *, int /*<<< orphan*/, int);
char *cpo_strchr(const char *s, int c) {
  unsigned char char_mask[256];
  int car;
  memset(char_mask, 0, 256);
  char_mask[(unsigned char)c] = 1;
  char_mask[0] = 1;
  car = (unsigned char)*s;
  while (car != 0) {
    if (car == c)
      return (char *)s;
    car = (unsigned char)*++s;
    while (char_mask[car] == 0) {
      car = (unsigned char)*++s;
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<cpo_strchr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1030 <memset@plt>
mov    -0x14(%rbp),%eax
movzbl %al,%eax
movb   $0x1,-0x120(%rbp,%rax,1)
01
movb   $0x1,-0x120(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
mov    %eax,-0x124(%rbp)
cmpl   $0x0,-0x124(%rbp)
je     11d4 <cpo_strchr+0xc4>
mov    -0x124(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1180 <cpo_strchr+0x70>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11dc <cpo_strchr+0xcc>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl 0x1(%rax),%eax
mov    %eax,-0x124(%rbp)
movslq -0x124(%rbp),%rax
movzbl -0x120(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
jne    11cf <cpo_strchr+0xbf>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl 0x1(%rax),%eax
mov    %eax,-0x124(%rbp)
jmp    1199 <cpo_strchr+0x89>
jmp    1157 <cpo_strchr+0x47>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpo_strchr>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1030 <memset@plt>
movzbl %r14b,%eax
movb   $0x1,(%rsp,%rax,1)
movb   $0x1,(%rsp)
mov    (%rbx),%al
nopl   (%rax)
test   %al,%al
je     1160 <cpo_strchr+0x50>
movzbl %al,%eax
cmp    %r14d,%eax
je     1162 <cpo_strchr+0x52>
nopl   0x0(%rax)
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
cmpb   $0x0,(%rsp,%rax,1)
je     1150 <cpo_strchr+0x40>
jmp    1140 <cpo_strchr+0x30>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @cpo_strchr(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [256 x i8]
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%9 = call i32 @memset(i8* %8, i32 0, i32 256)
%10 = load i32, i32* %5
%11 = trunc i32 %10 to i8
%12 = zext i8 %11 to i64
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 %12
store i8 1, i8* %13
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
store i8 1, i8* %14
%15 = load i8*, i8** %4
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
store i32 %17, i32* %7
br label %18
18: ; preds = %44, %2
%19 = load i32, i32* %7
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %45
21: ; preds = %18
%22 = load i32, i32* %7
%23 = load i32, i32* %5
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = load i8*, i8** %4
store i8* %26, i8** %3
br label %46
27: ; preds = %21
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %4
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
store i32 %31, i32* %7
br label %32
32: ; preds = %39, %27
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %32
%40 = load i8*, i8** %4
%41 = getelementptr inbounds i8, i8* %40, i32 1
store i8* %41, i8** %4
%42 = load i8, i8* %41
%43 = zext i8 %42 to i32
store i32 %43, i32* %7
br label %32
44: ; preds = %32
br label %18
45: ; preds = %18
store i8* null, i8** %3
br label %46
46: ; preds = %45, %25
%47 = load i8*, i8** %3
ret i8* %47
}

LLVM IR (-O2):
define i8* @cpo_strchr(i8* %0, i32 %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 256)
%6 = and i32 %1, 255
%7 = zext i32 %6 to i64
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %7
store i8 1, i8* %8
store i8 1, i8* %4
%9 = load i8, i8* %0
%10 = icmp eq i8 %9, 0
br i1 %10, label %26, label %13
11: ; preds = %18
%12 = icmp eq i8 %21, 0
br i1 %12, label %26, label %13
13: ; preds = %2, %11
%14 = phi i8 [ %21, %11 ], [ %9, %2 ]
%15 = phi i8* [ %20, %11 ], [ %0, %2 ]
%16 = zext i8 %14 to i32
%17 = icmp eq i32 %16, %1
br i1 %17, label %26, label %18
18: ; preds = %13, %18
%19 = phi i8* [ %20, %18 ], [ %15, %13 ]
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = load i8, i8* %20
%22 = zext i8 %21 to i64
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 0
br i1 %25, label %18, label %11
26: ; preds = %13, %11, %2
%27 = phi i8* [ null, %2 ], [ null, %11 ], [ %15, %13 ]
ret i8* %27
}