#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 */
typedef int /*<<< orphan*/ wchar_t;

/* Variables and functions */
int skipescseq(char const *);
scalar_t__ wcsncasecmp(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int xmbtowc(int /*<<< orphan*/ *, char const *);
const char *strcasechr(const char *s1, const char *s2) {
  wchar_t wc1, wc2;
  size_t i;
  int nbytes;
  if (xmbtowc(&wc2, s2) == 0)
    return NULL;
  for (i = 0; s1[i] != '\0';) {
    if ((nbytes = skipescseq(s1 + i)) > 0)
      ;
    else if ((nbytes = xmbtowc(&wc1, s1 + i)) == 0)
      nbytes = 1;
    else if (wcsncasecmp(&wc1, &wc2, 1) == 0)
      return s1 + i;
    i += nbytes;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<strcasechr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdi
call   1050 <xmbtowc@plt>
cmp    $0x0,%eax
jne    1163 <strcasechr+0x33>
movq   $0x0,-0x8(%rbp)
jmp    1217 <strcasechr+0xe7>
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     120f <strcasechr+0xdf>
mov    -0x10(%rbp),%rdi
add    -0x28(%rbp),%rdi
call   1040 <skipescseq@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jle    119e <strcasechr+0x6e>
jmp    11fe <strcasechr+0xce>
mov    -0x10(%rbp),%rsi
add    -0x28(%rbp),%rsi
lea    -0x1c(%rbp),%rdi
call   1050 <xmbtowc@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jne    11c7 <strcasechr+0x97>
movl   $0x1,-0x2c(%rbp)
jmp    11f9 <strcasechr+0xc9>
lea    -0x1c(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x1,%edx
call   1030 <wcsncasecmp@plt>
cmp    $0x0,%rax
jne    11f4 <strcasechr+0xc4>
mov    -0x10(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1217 <strcasechr+0xe7>
jmp    11f9 <strcasechr+0xc9>
jmp    11fe <strcasechr+0xce>
movslq -0x2c(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    116b <strcasechr+0x3b>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcasechr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
mov    %rsp,%rdi
call   1050 <xmbtowc@plt>
test   %eax,%eax
je     11b7 <strcasechr+0x87>
cmpb   $0x0,(%r12)
je     11b7 <strcasechr+0x87>
lea    0x4(%rsp),%r14
mov    %rsp,%r15
mov    %r12,%r13
xor    %ebx,%ebx
jmp    1181 <strcasechr+0x51>
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
movslq %ebp,%rax
add    %rax,%rbx
lea    (%r12,%rbx,1),%r13
cmpb   $0x0,(%r12,%rbx,1)
je     11b7 <strcasechr+0x87>
mov    %r13,%rdi
call   1040 <skipescseq@plt>
mov    %eax,%ebp
test   %eax,%eax
jg     1170 <strcasechr+0x40>
mov    %r14,%rdi
mov    %r13,%rsi
call   1050 <xmbtowc@plt>
test   %eax,%eax
je     1160 <strcasechr+0x30>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
call   1030 <wcsncasecmp@plt>
test   %rax,%rax
jne    1170 <strcasechr+0x40>
jmp    11ba <strcasechr+0x8a>
xor    %r13d,%r13d
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @strcasechr(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = call i32 @xmbtowc(i32* %4, i8* %1)
%8 = icmp eq i32 %7, 0
br i1 %8, label %30, label %9
9: ; preds = %2
%10 = load i8, i8* %0
%11 = icmp eq i8 %10, 0
br i1 %11, label %30, label %12
12: ; preds = %9, %23
%13 = phi i8* [ %27, %23 ], [ %0, %9 ]
%14 = phi i64 [ %26, %23 ], [ 0, %9 ]
%15 = call i32 @skipescseq(i8* %13)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %23, label %17
17: ; preds = %12
%18 = call i32 @xmbtowc(i32* %3, i8* %13)
%19 = icmp eq i32 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = call i64 @wcsncasecmp(i32* %3, i32* %4, i32 1)
%22 = icmp eq i64 %21, 0
br i1 %22, label %30, label %23
23: ; preds = %17, %20, %12
%24 = phi i32 [ %15, %12 ], [ %18, %20 ], [ 1, %17 ]
%25 = sext i32 %24 to i64
%26 = add i64 %14, %25
%27 = getelementptr inbounds i8, i8* %0, i64 %26
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 0
br i1 %29, label %30, label %12
30: ; preds = %20, %23, %9, %2
%31 = phi i8* [ null, %2 ], [ null, %9 ], [ %13, %20 ], [ null, %23 ]
ret i8* %31
}