#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 /*<<< orphan*/ strcasecmp(char const *, char const *);
int /*<<< orphan*/ string_empty(char const *);
size_t string_length(char const *);
int string_ends_with_ignore_case(const char *string, const char *suffix) {
  if (!string_empty(suffix)) {
    size_t length = string_length(string);
    size_t suffix_length = string_length(suffix);
    if (length < suffix_length)
      return 0;
    return !strcasecmp(string + length - suffix_length, suffix);
  }
  return 1;
}


x86 assembly (clang, -O0):
<string_ends_with_ignore_case>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <string_empty@plt>
cmp    $0x0,%eax
jne    11b5 <string_ends_with_ignore_case+0x85>
mov    -0x10(%rbp),%rdi
call   1050 <string_length@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <string_length@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1186 <string_ends_with_ignore_case+0x56>
movl   $0x0,-0x4(%rbp)
jmp    11bc <string_ends_with_ignore_case+0x8c>
mov    -0x10(%rbp),%rdi
add    -0x20(%rbp),%rdi
xor    %eax,%eax
sub    -0x28(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    11bc <string_ends_with_ignore_case+0x8c>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_ends_with_ignore_case>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <string_empty@plt>
mov    %eax,%ecx
mov    $0x1,%eax
test   %ecx,%ecx
jne    1185 <string_ends_with_ignore_case+0x55>
mov    %r14,%rdi
call   1050 <string_length@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1050 <string_length@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%r15
jb     1185 <string_ends_with_ignore_case+0x55>
add    %r15,%r14
sub    %rcx,%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcasecmp@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
sete   %al
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @string_ends_with_ignore_case(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = call i32 @string_empty(i8* %8)
%10 = icmp ne i32 %9, 0
br i1 %10, label %32, label %11
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = call i64 @string_length(i8* %12)
store i64 %13, i64* %6
%14 = load i8*, i8** %5
%15 = call i64 @string_length(i8* %14)
store i64 %15, i64* %7
%16 = load i64, i64* %6
%17 = load i64, i64* %7
%18 = icmp ult i64 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %11
store i32 0, i32* %3
br label %33
20: ; preds = %11
%21 = load i8*, i8** %4
%22 = load i64, i64* %6
%23 = getelementptr inbounds i8, i8* %21, i64 %22
%24 = load i64, i64* %7
%25 = sub i64 0, %24
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8*, i8** %5
%28 = call i32 @strcasecmp(i8* %26, i8* %27)
%29 = icmp ne i32 %28, 0
%30 = xor i1 %29, true
%31 = zext i1 %30 to i32
store i32 %31, i32* %3
br label %33
32: ; preds = %2
store i32 1, i32* %3
br label %33
33: ; preds = %32, %20, %19
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
define i32 @string_ends_with_ignore_case(i8* %0, i8* %1) {
%3 = tail call i32 @string_empty(i8* %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %16
5: ; preds = %2
%6 = tail call i64 @string_length(i8* %0)
%7 = tail call i64 @string_length(i8* %1)
%8 = icmp ult i64 %6, %7
br i1 %8, label %16, label %9
9: ; preds = %5
%10 = getelementptr inbounds i8, i8* %0, i64 %6
%11 = sub i64 0, %7
%12 = getelementptr inbounds i8, i8* %10, i64 %11
%13 = tail call i32 @strcasecmp(i8* %12, i8* %1)
%14 = icmp eq i32 %13, 0
%15 = zext i1 %14 to i32
br label %16
16: ; preds = %2, %9, %5
%17 = phi i32 [ %15, %9 ], [ 0, %5 ], [ 1, %2 ]
ret i32 %17
}