#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*/ assert(int);
scalar_t__ memchr(char const *, int, int);
const char *str_findchr(const char *start, const char *end, int c) {
  const char *it;
  assert(start <= end);
  assert(0 <= c && c <= 127);
  it = (const char *)memchr(start, c, end - start);
  return (it != NULL) ? it : end;
}


x86 assembly (clang, -O0):
<str_findchr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
setbe  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
xor    %eax,%eax
xor    %ecx,%ecx
cmp    -0x14(%rbp),%ecx
mov    %al,-0x21(%rbp)
jg     1162 <str_findchr+0x42>
cmpl   $0x7f,-0x14(%rbp)
setle  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <memchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11a4 <str_findchr+0x84>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    11ac <str_findchr+0x8c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_findchr>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
xor    %edi,%edi
cmp    %rsi,%rbp
setbe  %dil
call   1040 <assert@plt>
xor    %edi,%edi
cmp    $0x80,%r14d
setb   %dil
call   1040 <assert@plt>
mov    %ebx,%edx
sub    %ebp,%edx
mov    %rbp,%rdi
mov    %r14d,%esi
call   1030 <memchr@plt>
test   %rax,%rax
cmove  %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @str_findchr(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i8*, i8** %4
%9 = load i8*, i8** %5
%10 = icmp ule i8* %8, %9
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i32, i32* %6
%14 = icmp sle i32 0, %13
br i1 %14, label %15, label %18
15: ; preds = %3
%16 = load i32, i32* %6
%17 = icmp sle i32 %16, 127
br label %18
18: ; preds = %15, %3
%19 = phi i1 [ false, %3 ], [ %17, %15 ]
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = load i8*, i8** %4
%23 = load i32, i32* %6
%24 = load i8*, i8** %5
%25 = load i8*, i8** %4
%26 = ptrtoint i8* %24 to i64
%27 = ptrtoint i8* %25 to i64
%28 = sub i64 %26, %27
%29 = trunc i64 %28 to i32
%30 = call i64 @memchr(i8* %22, i32 %23, i32 %29)
%31 = inttoptr i64 %30 to i8*
store i8* %31, i8** %7
%32 = load i8*, i8** %7
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %36
34: ; preds = %18
%35 = load i8*, i8** %7
br label %38
36: ; preds = %18
%37 = load i8*, i8** %5
br label %38
38: ; preds = %36, %34
%39 = phi i8* [ %35, %34 ], [ %37, %36 ]
ret i8* %39
}

LLVM IR (-O2):
define i8* @str_findchr(i8* %0, i8* %1, i32 %2) {
%4 = icmp ule i8* %0, %1
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = icmp ult i32 %2, 128
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = ptrtoint i8* %1 to i64
%11 = ptrtoint i8* %0 to i64
%12 = sub i64 %10, %11
%13 = trunc i64 %12 to i32
%14 = tail call i64 @memchr(i8* %0, i32 %2, i32 %13)
%15 = inttoptr i64 %14 to i8*
%16 = icmp eq i64 %14, 0
%17 = select i1 %16, i8* %1, i8* %15
ret i8* %17
}