#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__ strcasecmp(char const *, char const *);
size_t strlen(char const *);
extern const char *str_casesuffix(const char *str, const char *suffix) {
  const char *start;
  size_t lenstr = strlen(str);
  size_t lensuffix = strlen(suffix);
  if (lenstr < lensuffix) {
    return 0;
  }
  start = str + lenstr - lensuffix;
  if (strcasecmp(start, suffix)) {
    return 0;
  }
  return start;
}


x86 assembly (clang, -O0):
<str_casesuffix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    1165 <str_casesuffix+0x45>
movq   $0x0,-0x8(%rbp)
jmp    11a6 <str_casesuffix+0x86>
mov    -0x10(%rbp),%rax
add    -0x28(%rbp),%rax
xor    %ecx,%ecx
sub    -0x30(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
je     119e <str_casesuffix+0x7e>
movq   $0x0,-0x8(%rbp)
jmp    11a6 <str_casesuffix+0x86>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_casesuffix>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    %rax,%r15
jae    1144 <str_casesuffix+0x24>
xor    %eax,%eax
jmp    1161 <str_casesuffix+0x41>
add    %r15,%rbx
sub    %rax,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcasecmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
cmove  %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @str_casesuffix(i8* %0, i8* nocapture %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = icmp ult i64 %3, %4
br i1 %5, label %13, label %6
6: ; preds = %2
%7 = getelementptr inbounds i8, i8* %0, i64 %3
%8 = sub i64 0, %4
%9 = getelementptr inbounds i8, i8* %7, i64 %8
%10 = tail call i64 @strcasecmp(i8* %9, i8* %1)
%11 = icmp eq i64 %10, 0
%12 = select i1 %11, i8* %9, i8* null
br label %13
13: ; preds = %6, %2
%14 = phi i8* [ null, %2 ], [ %12, %6 ]
ret i8* %14
}