#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 strlen(char *);
scalar_t__ toupper(char);
int expect(char *str, char *substr) {
  int len = strlen(substr);
  while (0 < len--) {
    if (toupper(*str) != toupper(*substr))
      return 0;
    str++, substr++;
  }
  return 1;
}


x86 assembly (clang, -O0):
<expect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%ecx
mov    %ecx,%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmp    %ecx,%eax
jge    11a6 <expect+0x86>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
je     1189 <expect+0x69>
movl   $0x0,-0x4(%rbp)
jmp    11ad <expect+0x8d>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    113c <expect+0x1c>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expect>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r15
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    $0x1,%r14d
test   %eax,%eax
jle    117d <expect+0x5d>
mov    %eax,%ebp
add    $0x1,%ebp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movsbl (%r15,%rbx,1),%edi
call   1030 <toupper@plt>
mov    %rax,%r13
movsbl (%r12,%rbx,1),%edi
call   1030 <toupper@plt>
cmp    %rax,%r13
jne    117a <expect+0x5a>
add    $0xffffffff,%ebp
add    $0x1,%rbx
cmp    $0x1,%ebp
jg     1150 <expect+0x30>
jmp    117d <expect+0x5d>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @expect(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %6
br label %9
9: ; preds = %22, %2
%10 = load i32, i32* %6
%11 = add nsw i32 %10, -1
store i32 %11, i32* %6
%12 = icmp slt i32 0, %10
br i1 %12, label %13, label %27
13: ; preds = %9
%14 = load i8*, i8** %4
%15 = load i8, i8* %14
%16 = call i64 @toupper(i8 signext %15)
%17 = load i8*, i8** %5
%18 = load i8, i8* %17
%19 = call i64 @toupper(i8 signext %18)
%20 = icmp ne i64 %16, %19
br i1 %20, label %21, label %22
21: ; preds = %13
store i32 0, i32* %3
br label %28
22: ; preds = %13
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %4
%25 = load i8*, i8** %5
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %5
br label %9
27: ; preds = %9
store i32 1, i32* %3
br label %28
28: ; preds = %27, %21
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
define i32 @expect(i8* nocapture %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %19
5: ; preds = %2, %14
%6 = phi i32 [ %15, %14 ], [ %3, %2 ]
%7 = phi i8* [ %17, %14 ], [ %1, %2 ]
%8 = phi i8* [ %16, %14 ], [ %0, %2 ]
%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 %19
14: ; preds = %5
%15 = add nsw i32 %6, -1
%16 = getelementptr inbounds i8, i8* %8, i64 1
%17 = getelementptr inbounds i8, i8* %7, i64 1
%18 = icmp sgt i32 %6, 1
br i1 %18, label %5, label %19
19: ; preds = %5, %14, %2
%20 = phi i32 [ 1, %2 ], [ 1, %14 ], [ 0, %5 ]
ret i32 %20
}