#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 */
struct dirent {
  char *d_name;
};

/* Variables and functions */
scalar_t__ strcmp(char const *, char *);
size_t strlen(char const *);
bool is_plugin(struct dirent *ent) {
  const char *name = ent->d_name;
  const size_t name_len = strlen(name);
  return name_len > 3 && strcmp(name + name_len - 3, ".so") == 0;
}


x86 assembly (clang, -O0):
<is_plugin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x3,-0x18(%rbp)
mov    %al,-0x19(%rbp)
jbe    1176 <is_plugin+0x56>
mov    -0x10(%rbp),%rdi
add    -0x18(%rbp),%rdi
add    $0xfffffffffffffffd,%rdi
lea    0xe99(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_plugin>:
push   %rbx
mov    (%rdi),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x4,%rcx
jb     1156 <is_plugin+0x36>
lea    (%rbx,%rcx,1),%rdi
add    $0xfffffffffffffffd,%rdi
lea    0xeba(%rip),%rsi
call   1040 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
pop    %rbx
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [4 x i8] c".so\00"
define i32 @is_plugin(%struct.dirent* %0) {
%2 = alloca %struct.dirent*
%3 = alloca i8*
%4 = alloca i64
store %struct.dirent* %0, %struct.dirent** %2
%5 = load %struct.dirent*, %struct.dirent** %2
%6 = getelementptr inbounds %struct.dirent, %struct.dirent* %5, i32 0, i32 0
%7 = load i8*, i8** %6
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = call i64 @strlen(i8* %8)
store i64 %9, i64* %4
%10 = load i64, i64* %4
%11 = icmp ugt i64 %10, 3
br i1 %11, label %12, label %19
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = load i64, i64* %4
%15 = getelementptr inbounds i8, i8* %13, i64 %14
%16 = getelementptr inbounds i8, i8* %15, i64 -3
%17 = call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br label %19
19: ; preds = %12, %1
%20 = phi i1 [ false, %1 ], [ %18, %12 ]
%21 = zext i1 %20 to i32
ret i32 %21
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [4 x i8] c".so\00"
define i32 @is_plugin(%struct.dirent* nocapture %0) {
%2 = getelementptr inbounds %struct.dirent, %struct.dirent* %0, i64 0, i32 0
%3 = load i8*, i8** %2
%4 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%5 = icmp ugt i64 %4, 3
br i1 %5, label %6, label %12
6: ; preds = %1
%7 = getelementptr inbounds i8, i8* %3, i64 %4
%8 = getelementptr inbounds i8, i8* %7, i64 -3
%9 = tail call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
%11 = zext i1 %10 to i32
br label %12
12: ; preds = %6, %1
%13 = phi i32 [ 0, %1 ], [ %11, %6 ]
ret i32 %13
}