#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 {
  scalar_t__ d_type;
  char *d_name;
};

/* Variables and functions */
scalar_t__ DT_REG;
size_t strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int isTextFile(struct dirent *dir) {
  if (dir->d_type == DT_REG) {
    char *name = dir->d_name;
    size_t str_len = strlen(name);
    if (4 > str_len)
      return 0;
    return 0 == strncmp(name + str_len - 4, ".txt", 4);
  }
  return 0;
}


x86 assembly (clang, -O0):
<isTextFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2ea6(%rip),%rcx
cmp    (%rcx),%rax
jne    11ac <isTextFile+0x8c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    $0x4,%eax
cmp    -0x20(%rbp),%rax
jbe    1177 <isTextFile+0x57>
movl   $0x0,-0x4(%rbp)
jmp    11b3 <isTextFile+0x93>
mov    -0x18(%rbp),%rdi
add    -0x20(%rbp),%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xe76(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    11b3 <isTextFile+0x93>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isTextFile>:
push   %r14
push   %rbx
push   %rax
mov    (%rdi),%rax
mov    0x2eb2(%rip),%rcx
xor    %ebx,%ebx
cmp    (%rcx),%rax
jne    1168 <isTextFile+0x48>
mov    0x8(%rdi),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    $0x4,%rax
jb     1168 <isTextFile+0x48>
lea    (%r14,%rax,1),%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xeaa(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
xor    %ebx,%ebx
test   %rax,%rax
sete   %bl
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.dirent = type { i64, i8* }
@DT_REG = global i64 0
@.str = [5 x i8] c".txt\00"
define i32 @isTextFile(%struct.dirent* %0) {
%2 = alloca i32
%3 = alloca %struct.dirent*
%4 = alloca i8*
%5 = alloca i64
store %struct.dirent* %0, %struct.dirent** %3
%6 = load %struct.dirent*, %struct.dirent** %3
%7 = getelementptr inbounds %struct.dirent, %struct.dirent* %6, i32 0, i32 0
%8 = load i64, i64* %7
%9 = load i64, i64* @DT_REG
%10 = icmp eq i64 %8, %9
br i1 %10, label %11, label %28
11: ; preds = %1
%12 = load %struct.dirent*, %struct.dirent** %3
%13 = getelementptr inbounds %struct.dirent, %struct.dirent* %12, i32 0, i32 1
%14 = load i8*, i8** %13
store i8* %14, i8** %4
%15 = load i8*, i8** %4
%16 = call i64 @strlen(i8* %15)
store i64 %16, i64* %5
%17 = load i64, i64* %5
%18 = icmp ugt i64 4, %17
br i1 %18, label %19, label %20
19: ; preds = %11
store i32 0, i32* %2
br label %29
20: ; preds = %11
%21 = load i8*, i8** %4
%22 = load i64, i64* %5
%23 = getelementptr inbounds i8, i8* %21, i64 %22
%24 = getelementptr inbounds i8, i8* %23, i64 -4
%25 = call i64 @strncmp(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%26 = icmp eq i64 0, %25
%27 = zext i1 %26 to i32
store i32 %27, i32* %2
br label %29
28: ; preds = %1
store i32 0, i32* %2
br label %29
29: ; preds = %28, %20, %19
%30 = load i32, i32* %2
ret i32 %30
}

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