#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 const bf_tolower(char const);
int strcasestart(const char *str, const char *val, const char **ptr) {
  const char *p, *q;
  p = str;
  q = val;
  while (*q != '\0') {
    if (bf_tolower(*p) != *q)
      return 0;
    p++;
    q++;
  }
  if (ptr)
    *ptr = p;
  return 1;
}


x86 assembly (clang, -O0):
<strcasestart>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     118b <strcasestart+0x7b>
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1030 <bf_tolower@plt>
movsbl %al,%eax
mov    -0x30(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     116e <strcasestart+0x5e>
movl   $0x0,-0x4(%rbp)
jmp    11a8 <strcasestart+0x98>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1134 <strcasestart+0x24>
cmpq   $0x0,-0x20(%rbp)
je     11a1 <strcasestart+0x91>
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcasestart>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rdi,%r15
cmpb   $0x0,(%rsi)
je     114b <strcasestart+0x3b>
mov    %rsi,%rbx
add    $0x1,%rbx
nopw   0x0(%rax,%rax,1)
movsbl (%r15),%edi
call   1030 <bf_tolower@plt>
cmp    -0x1(%rbx),%al
jne    115a <strcasestart+0x4a>
add    $0x1,%r15
cmpb   $0x0,(%rbx)
lea    0x1(%rbx),%rbx
jne    1130 <strcasestart+0x20>
mov    $0x1,%eax
test   %r14,%r14
je     115c <strcasestart+0x4c>
mov    %r15,(%r14)
jmp    115c <strcasestart+0x4c>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @strcasestart(i8* %0, i8* %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8** %2, i8*** %7
%10 = load i8*, i8** %5
store i8* %10, i8** %8
%11 = load i8*, i8** %6
store i8* %11, i8** %9
br label %12
12: ; preds = %27, %3
%13 = load i8*, i8** %9
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %32
17: ; preds = %12
%18 = load i8*, i8** %8
%19 = load i8, i8* %18
%20 = call signext i8 @bf_tolower(i8 signext %19)
%21 = sext i8 %20 to i32
%22 = load i8*, i8** %9
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %21, %24
br i1 %25, label %26, label %27
26: ; preds = %17
store i32 0, i32* %4
br label %39
27: ; preds = %17
%28 = load i8*, i8** %8
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %8
%30 = load i8*, i8** %9
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %9
br label %12
32: ; preds = %12
%33 = load i8**, i8*** %7
%34 = icmp ne i8** %33, null
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load i8*, i8** %8
%37 = load i8**, i8*** %7
store i8* %36, i8** %37
br label %38
38: ; preds = %35, %32
store i32 1, i32* %4
br label %39
39: ; preds = %38, %26
%40 = load i32, i32* %4
ret i32 %40
}

LLVM IR (-O2):
define i32 @strcasestart(i8* %0, i8* nocapture %1, i8** writeonly %2) {
%4 = load i8, i8* %1
%5 = icmp eq i8 %4, 0
br i1 %5, label %18, label %6
6: ; preds = %3, %13
%7 = phi i8* [ %15, %13 ], [ %1, %3 ]
%8 = phi i8* [ %14, %13 ], [ %0, %3 ]
%9 = load i8, i8* %8
%10 = tail call signext i8 @bf_tolower(i8 signext %9)
%11 = load i8, i8* %7
%12 = icmp eq i8 %10, %11
br i1 %12, label %13, label %22
13: ; preds = %6
%14 = getelementptr inbounds i8, i8* %8, i64 1
%15 = getelementptr inbounds i8, i8* %7, i64 1
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %6
18: ; preds = %13, %3
%19 = phi i8* [ %0, %3 ], [ %14, %13 ]
%20 = icmp eq i8** %2, null
br i1 %20, label %22, label %21
21: ; preds = %18
store i8* %19, i8** %2
br label %22
22: ; preds = %6, %18, %21
%23 = phi i32 [ 1, %21 ], [ 1, %18 ], [ 0, %6 ]
ret i32 %23
}