#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 */
int strlen(char const *);
int isTextFile(const char *fileName) {
  int returnVal = 0;
  int i = 0;
  int j = 0;
  char extension[] = ".txt";
  j = strlen(extension) - 1;
  for (i = strlen(fileName) - 1; i >= strlen(fileName) - strlen(extension);
       --i) {
    if (fileName[i] == extension[j--])
      returnVal = 1;
    else {
      returnVal = 0;
      break;
    }
  }
  return returnVal;
}


x86 assembly (clang, -O0):
<isTextFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    0xec9(%rip),%eax
mov    %eax,-0x19(%rbp)
mov    0xec4(%rip),%al
mov    %al,-0x15(%rbp)
lea    -0x19(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
lea    -0x19(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x24(%rbp),%ecx
mov    %eax,%edx
mov    -0x20(%rbp),%eax
sub    %edx,%ecx
cmp    %ecx,%eax
jl     11e0 <isTextFile+0xd0>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x14(%rbp),%ecx
mov    %ecx,%edx
add    $0xffffffff,%edx
mov    %edx,-0x14(%rbp)
movslq %ecx,%rcx
movsbl -0x19(%rbp,%rcx,1),%ecx
cmp    %ecx,%eax
jne    11c1 <isTextFile+0xb1>
movl   $0x1,-0xc(%rbp)
jmp    11cd <isTextFile+0xbd>
movl   $0x0,-0xc(%rbp)
jmp    11e0 <isTextFile+0xd0>
jmp    11d2 <isTextFile+0xc2>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1161 <isTextFile+0x51>
mov    -0xc(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isTextFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
movb   $0x0,0x4(%rsp)
movl   $0x7478742e,(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%r12d
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%r13d
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1030 <strlen@plt>
sub    %eax,%ebp
xor    %eax,%eax
cmp    %ebp,%r13d
jle    11aa <isTextFile+0x9a>
movslq %r13d,%rbx
movslq %r12d,%rax
lea    (%rax,%r14,1),%rbp
add    $0xffffffffffffffff,%rbp
nopl   0x0(%rax)
movzbl -0x1(%r15,%rbx,1),%eax
cmp    0x0(%rbp),%al
jne    11a8 <isTextFile+0x98>
add    $0xffffffffffffffff,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%r12d
mov    %r14,%rdi
call   1030 <strlen@plt>
sub    %eax,%r12d
movslq %r12d,%rax
add    $0xffffffffffffffff,%rbp
cmp    %rax,%rbx
jg     1170 <isTextFile+0x60>
mov    $0x1,%eax
jmp    11aa <isTextFile+0x9a>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.isTextFile.extension = [5 x i8] c".txt\00"
define i32 @isTextFile(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [5 x i8]
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
%7 = bitcast [5 x i8]* %6 to i8*
%8 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%9 = call i32 @strlen(i8* %8)
%10 = sub nsw i32 %9, 1
store i32 %10, i32* %5
%11 = load i8*, i8** %2
%12 = call i32 @strlen(i8* %11)
%13 = sub nsw i32 %12, 1
store i32 %13, i32* %4
br label %14
14: ; preds = %39, %1
%15 = load i32, i32* %4
%16 = load i8*, i8** %2
%17 = call i32 @strlen(i8* %16)
%18 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%19 = call i32 @strlen(i8* %18)
%20 = sub nsw i32 %17, %19
%21 = icmp sge i32 %15, %20
br i1 %21, label %22, label %42
22: ; preds = %14
%23 = load i8*, i8** %2
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = load i32, i32* %5
%30 = add nsw i32 %29, -1
store i32 %30, i32* %5
%31 = sext i32 %29 to i64
%32 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %28, %34
br i1 %35, label %36, label %37
36: ; preds = %22
store i32 1, i32* %3
br label %38
37: ; preds = %22
store i32 0, i32* %3
br label %42
38: ; preds = %36
br label %39
39: ; preds = %38
%40 = load i32, i32* %4
%41 = add nsw i32 %40, -1
store i32 %41, i32* %4
br label %14
42: ; preds = %37, %14
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@__const.isTextFile.extension = [5 x i8] c".txt\00"
define i32 @isTextFile(i8* %0) {
%2 = alloca [5 x i8]
%3 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%4 = call i32 @strlen(i8* %3)
%5 = call i32 @strlen(i8* %0)
%6 = call i32 @strlen(i8* %0)
%7 = call i32 @strlen(i8* %3)
%8 = sub nsw i32 %6, %7
%9 = icmp sgt i32 %5, %8
br i1 %9, label %10, label %29
10: ; preds = %1
%11 = sext i32 %5 to i64
%12 = sext i32 %4 to i64
br label %19
13: ; preds = %19
%14 = call i32 @strlen(i8* %0)
%15 = call i32 @strlen(i8* %3)
%16 = sub nsw i32 %14, %15
%17 = sext i32 %16 to i64
%18 = icmp sgt i64 %23, %17
br i1 %18, label %19, label %29
19: ; preds = %10, %13
%20 = phi i64 [ %12, %10 ], [ %22, %13 ]
%21 = phi i64 [ %11, %10 ], [ %23, %13 ]
%22 = add i64 %20, -1
%23 = add nsw i64 %21, -1
%24 = getelementptr inbounds i8, i8* %0, i64 %23
%25 = load i8, i8* %24
%26 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 %22
%27 = load i8, i8* %26
%28 = icmp eq i8 %25, %27
br i1 %28, label %13, label %29
29: ; preds = %13, %19, %1
%30 = phi i32 [ 0, %1 ], [ 0, %19 ], [ 1, %13 ]
ret i32 %30
}