#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 */
scalar_t__ toupper(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 (toupper(*p) != toupper(*q))
      return 0;
    p++;
    q++;
  }
  *ptr = p;
  return 1;
}


x86 assembly (clang, -O0):
<strcasestart>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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     1199 <strcasestart+0x89>
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
cmp    %rcx,%rax
je     117c <strcasestart+0x6c>
movl   $0x0,-0x4(%rbp)
jmp    11ab <strcasestart+0x9b>
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>
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcasestart>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%rbx
cmpb   $0x0,(%rsi)
je     1158 <strcasestart+0x48>
mov    %rsi,%r15
add    $0x1,%r15
nopw   0x0(%rax,%rax,1)
movsbl (%rbx),%edi
call   1030 <toupper@plt>
mov    %rax,%r12
movsbl -0x1(%r15),%edi
call   1030 <toupper@plt>
cmp    %rax,%r12
jne    1162 <strcasestart+0x52>
add    $0x1,%rbx
cmpb   $0x0,(%r15)
lea    0x1(%r15),%r15
jne    1130 <strcasestart+0x20>
mov    %rbx,(%r14)
mov    $0x1,%eax
jmp    1164 <strcasestart+0x54>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
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 = %26, %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 %31
17: ; preds = %12
%18 = load i8*, i8** %8
%19 = load i8, i8* %18
%20 = call i64 @toupper(i8 signext %19)
%21 = load i8*, i8** %9
%22 = load i8, i8* %21
%23 = call i64 @toupper(i8 signext %22)
%24 = icmp ne i64 %20, %23
br i1 %24, label %25, label %26
25: ; preds = %17
store i32 0, i32* %4
br label %34
26: ; preds = %17
%27 = load i8*, i8** %8
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %8
%29 = load i8*, i8** %9
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %9
br label %12
31: ; preds = %12
%32 = load i8*, i8** %8
%33 = load i8**, i8*** %7
store i8* %32, i8** %33
store i32 1, i32* %4
br label %34
34: ; preds = %31, %25
%35 = load i32, i32* %4
ret i32 %35
}

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