#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__ strlen(char const *);
char tolower(unsigned char);
int CompareEnd(const char *a, const char *b) {
  if (strlen(a) < strlen(b)) {
    return 0;
  }
  a += strlen(a) - strlen(b);
  while (*a && *b) {
    char c, d;
    c = tolower((unsigned char)*a++);
    d = tolower((unsigned char)*b++);
    if (c != d) {
      return 0;
    }
  }
  return (*b == 0);
}


x86 assembly (clang, -O0):
<CompareEnd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jge    1162 <CompareEnd+0x42>
movl   $0x0,-0x4(%rbp)
jmp    1229 <CompareEnd+0x109>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
sub    %rcx,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x31(%rbp)
je     11af <CompareEnd+0x8f>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    11bf <CompareEnd+0x9f>
jmp    1214 <CompareEnd+0xf4>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl (%rax),%edi
call   1040 <tolower@plt>
mov    %al,-0x19(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movzbl (%rax),%edi
call   1040 <tolower@plt>
mov    %al,-0x1a(%rbp)
movsbl -0x19(%rbp),%eax
movsbl -0x1a(%rbp),%ecx
cmp    %ecx,%eax
je     120f <CompareEnd+0xef>
movl   $0x0,-0x4(%rbp)
jmp    1229 <CompareEnd+0x109>
jmp    118a <CompareEnd+0x6a>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CompareEnd>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r12
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %rax,%r15
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
xor    %eax,%eax
sub    %rcx,%r15
jl     1191 <CompareEnd+0x71>
add    %r15,%r14
xor    %ebx,%ebx
nopl   (%rax)
movzbl (%r14,%rbx,1),%eax
movzbl (%r12,%rbx,1),%ecx
test   %al,%al
je     1183 <CompareEnd+0x63>
test   %cl,%cl
je     118c <CompareEnd+0x6c>
movzbl %al,%edi
call   1040 <tolower@plt>
mov    %eax,%ebp
movzbl (%r12,%rbx,1),%edi
call   1040 <tolower@plt>
add    $0x1,%rbx
cmp    %al,%bpl
je     1150 <CompareEnd+0x30>
xor    %eax,%eax
jmp    1191 <CompareEnd+0x71>
xor    %eax,%eax
test   %cl,%cl
sete   %al
jmp    1191 <CompareEnd+0x71>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @CompareEnd(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = call i64 @strlen(i8* %8)
%10 = load i8*, i8** %5
%11 = call i64 @strlen(i8* %10)
%12 = icmp slt i64 %9, %11
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 0, i32* %3
br label %56
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = call i64 @strlen(i8* %15)
%17 = load i8*, i8** %5
%18 = call i64 @strlen(i8* %17)
%19 = sub nsw i64 %16, %18
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i64 %19
store i8* %21, i8** %4
br label %22
22: ; preds = %49, %14
%23 = load i8*, i8** %4
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %22
%28 = load i8*, i8** %5
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 0
br label %32
32: ; preds = %27, %22
%33 = phi i1 [ false, %22 ], [ %31, %27 ]
br i1 %33, label %34, label %50
34: ; preds = %32
%35 = load i8*, i8** %4
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %4
%37 = load i8, i8* %35
%38 = call signext i8 @tolower(i8 zeroext %37)
store i8 %38, i8* %6
%39 = load i8*, i8** %5
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %5
%41 = load i8, i8* %39
%42 = call signext i8 @tolower(i8 zeroext %41)
store i8 %42, i8* %7
%43 = load i8, i8* %6
%44 = sext i8 %43 to i32
%45 = load i8, i8* %7
%46 = sext i8 %45 to i32
%47 = icmp ne i32 %44, %46
br i1 %47, label %48, label %49
48: ; preds = %34
store i32 0, i32* %3
br label %56
49: ; preds = %34
br label %22
50: ; preds = %32
%51 = load i8*, i8** %5
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 0
%55 = zext i1 %54 to i32
store i32 %55, i32* %3
br label %56
56: ; preds = %50, %48, %13
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
define i32 @CompareEnd(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = icmp slt i64 %3, %4
br i1 %5, label %26, label %6
6: ; preds = %2
%7 = sub nsw i64 %3, %4
%8 = getelementptr inbounds i8, i8* %0, i64 %7
br label %9
9: ; preds = %19, %6
%10 = phi i8* [ %1, %6 ], [ %22, %19 ]
%11 = phi i8* [ %8, %6 ], [ %20, %19 ]
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
%14 = load i8, i8* %10
%15 = icmp eq i8 %14, 0
br i1 %13, label %16, label %18
16: ; preds = %9
%17 = zext i1 %15 to i32
br label %26
18: ; preds = %9
br i1 %15, label %26, label %19
19: ; preds = %18
%20 = getelementptr inbounds i8, i8* %11, i64 1
%21 = tail call signext i8 @tolower(i8 zeroext %12)
%22 = getelementptr inbounds i8, i8* %10, i64 1
%23 = load i8, i8* %10
%24 = tail call signext i8 @tolower(i8 zeroext %23)
%25 = icmp eq i8 %21, %24
br i1 %25, label %9, label %26
26: ; preds = %19, %18, %16, %2
%27 = phi i32 [ 0, %2 ], [ %17, %16 ], [ 0, %19 ], [ 1, %18 ]
ret i32 %27
}