#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 */
unsigned int strlen(char const *);
scalar_t__ tolower(char const);
int string_ends_with(const char *string, const char *suffix) {
  unsigned string_length = strlen(string), suffix_length = strlen(suffix);
  unsigned i;
  if (string_length < suffix_length)
    return 0;
  string += string_length - suffix_length;
  for (i = 0; i < suffix_length; i++)
    if (tolower(string[i]) != tolower(suffix[i]))
      return 0;
  return 1;
}


x86 assembly (clang, -O0):
<string_ends_with>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jae    1160 <string_ends_with+0x40>
movl   $0x0,-0x4(%rbp)
jmp    11e0 <string_ends_with+0xc0>
mov    -0x1c(%rbp),%ecx
sub    -0x20(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,%ecx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jae    11d9 <string_ends_with+0xb9>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
movsbl (%rax,%rcx,1),%edi
call   1040 <tolower@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
movsbl (%rax,%rcx,1),%edi
call   1040 <tolower@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
je     11c6 <string_ends_with+0xa6>
movl   $0x0,-0x4(%rbp)
jmp    11e0 <string_ends_with+0xc0>
jmp    11cb <string_ends_with+0xab>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    117a <string_ends_with+0x5a>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_ends_with>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r13
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1030 <strlen@plt>
xor    %r15d,%r15d
sub    %eax,%ebp
jb     118b <string_ends_with+0x6b>
mov    $0x1,%r15d
test   %eax,%eax
je     118b <string_ends_with+0x6b>
add    %rbp,%r13
mov    %eax,%r12d
xor    %ebx,%ebx
nopl   0x0(%rax)
movsbl 0x0(%r13,%rbx,1),%edi
call   1040 <tolower@plt>
mov    %rax,%rbp
movsbl (%r14,%rbx,1),%edi
call   1040 <tolower@plt>
cmp    %rax,%rbp
jne    1188 <string_ends_with+0x68>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1160 <string_ends_with+0x40>
jmp    118b <string_ends_with+0x6b>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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