#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 *strchr(char const *, char);
scalar_t__ strncmp(char const *, char *, int);
int filename_is_pem(const char *filename) {
  const char *q, *p = filename;
  if ((q = strchr(p, '\0')) == NULL)
    return (0);
  if ((q - p) < 4)
    return (0);
  if (strncmp((q - 4), ".pem", 4) != 0)
    return (0);
  return (1);
}


x86 assembly (clang, -O0):
<filename_is_pem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1159 <filename_is_pem+0x39>
movl   $0x0,-0x4(%rbp)
jmp    11b0 <filename_is_pem+0x90>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x4,%rax
jge    117a <filename_is_pem+0x5a>
movl   $0x0,-0x4(%rbp)
jmp    11b0 <filename_is_pem+0x90>
mov    -0x18(%rbp),%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xe77(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11a9 <filename_is_pem+0x89>
movl   $0x0,-0x4(%rbp)
jmp    11b0 <filename_is_pem+0x90>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filename_is_pem>:
push   %rbx
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x4,%rcx
jl     115c <filename_is_pem+0x3c>
add    %rcx,%rbx
je     115c <filename_is_pem+0x3c>
add    $0xfffffffffffffffc,%rbx
lea    0xebc(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c".pem\00"
define i32 @filename_is_pem(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
store i8* %6, i8** %5
%7 = load i8*, i8** %5
%8 = call i8* @strchr(i8* %7, i8 signext 0)
store i8* %8, i8** %4
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 0, i32* %2
br label %26
11: ; preds = %1
%12 = load i8*, i8** %4
%13 = load i8*, i8** %5
%14 = ptrtoint i8* %12 to i64
%15 = ptrtoint i8* %13 to i64
%16 = sub i64 %14, %15
%17 = icmp slt i64 %16, 4
br i1 %17, label %18, label %19
18: ; preds = %11
store i32 0, i32* %2
br label %26
19: ; preds = %11
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i64 -4
%22 = call i64 @strncmp(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
store i32 0, i32* %2
br label %26
25: ; preds = %19
store i32 1, i32* %2
br label %26
26: ; preds = %25, %24, %18, %10
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@.str = [5 x i8] c".pem\00"
define i32 @filename_is_pem(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = getelementptr i8, i8* %0, i64 %2
%4 = icmp eq i8* %3, null
%5 = icmp slt i64 %2, 4
%6 = or i1 %5, %4
br i1 %6, label %12, label %7
7: ; preds = %1
%8 = getelementptr inbounds i8, i8* %3, i64 -4
%9 = tail call i64 @strncmp(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%10 = icmp eq i64 %9, 0
%11 = zext i1 %10 to i32
br label %12
12: ; preds = %7, %1
%13 = phi i32 [ 0, %1 ], [ %11, %7 ]
ret i32 %13
}