#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 */
char *strdup(char *);
int /*<<< orphan*/ *strstr(char *, char *);
char tolower(char);
int suffix(char *filename, char *suffix) {
  char *s, *c;
  s = strdup(filename);
  if (s == NULL)
    return 0;
  for (c = s; *c; c++)
    *c = tolower(*c);
  return strstr(s, suffix) != NULL;
}


x86 assembly (clang, -O0):
<suffix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strdup@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1164 <suffix+0x34>
movl   $0x0,-0x4(%rbp)
jmp    11ba <suffix+0x8a>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
je     119e <suffix+0x6e>
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1030 <tolower@plt>
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    116c <suffix+0x3c>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strstr@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<suffix>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
call   1040 <strdup@plt>
test   %rax,%rax
je     118e <suffix+0x5e>
mov    %rax,%r15
mov    (%rax),%al
test   %al,%al
je     1176 <suffix+0x46>
mov    %r15,%rbx
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl %al,%edi
call   1030 <tolower@plt>
mov    %al,-0x1(%rbx)
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1160 <suffix+0x30>
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <strstr@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
setne  %al
jmp    1190 <suffix+0x60>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @suffix(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 i8* @strdup(i8* %8)
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 0, i32* %3
br label %33
13: ; preds = %2
%14 = load i8*, i8** %6
store i8* %14, i8** %7
br label %15
15: ; preds = %24, %13
%16 = load i8*, i8** %7
%17 = load i8, i8* %16
%18 = icmp ne i8 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %15
%20 = load i8*, i8** %7
%21 = load i8, i8* %20
%22 = call signext i8 @tolower(i8 signext %21)
%23 = load i8*, i8** %7
store i8 %22, i8* %23
br label %24
24: ; preds = %19
%25 = load i8*, i8** %7
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %7
br label %15
27: ; preds = %15
%28 = load i8*, i8** %6
%29 = load i8*, i8** %5
%30 = call i32* @strstr(i8* %28, i8* %29)
%31 = icmp ne i32* %30, null
%32 = zext i1 %31 to i32
store i32 %32, i32* %3
br label %33
33: ; preds = %27, %12
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
define i32 @suffix(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call i8* @strdup(i8* %0)
%4 = icmp eq i8* %3, null
br i1 %4, label %19, label %5
5: ; preds = %2
%6 = load i8, i8* %3
%7 = icmp eq i8 %6, 0
br i1 %7, label %15, label %8
8: ; preds = %5, %8
%9 = phi i8 [ %13, %8 ], [ %6, %5 ]
%10 = phi i8* [ %12, %8 ], [ %3, %5 ]
%11 = tail call signext i8 @tolower(i8 signext %9)
store i8 %11, i8* %10
%12 = getelementptr inbounds i8, i8* %10, i64 1
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %8
15: ; preds = %8, %5
%16 = tail call i32* @strstr(i8* %3, i8* dereferenceable(1) %1)
%17 = icmp ne i32* %16, null
%18 = zext i1 %17 to i32
br label %19
19: ; preds = %2, %15
%20 = phi i32 [ %18, %15 ], [ 0, %2 ]
ret i32 %20
}