#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 */
scalar_t__ malloc(int);
scalar_t__ strcmp(char *, char *);
int checkfilename(const char *filename) {
  int i = 0, j = 0, k;
  char c = filename[i];
  while (c != 0) {
    i++;
    j++;
    c = filename[i];
  }
  char *subbuf = (char *)malloc(sizeof(char) * 5);
  for (k = 0; k < 5; k++)
    subbuf[k] = filename[j + k - 5];
  subbuf[5] = 0;
  if (strcmp(subbuf, ".digs") == 0)
    return 1;
  else
    return 0;
}


x86 assembly (clang, -O0):
<checkfilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1d(%rbp)
movsbl -0x1d(%rbp),%eax
cmp    $0x0,%eax
je     117a <checkfilename+0x5a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1d(%rbp)
jmp    1148 <checkfilename+0x28>
mov    $0x5,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x5,-0x1c(%rbp)
jge    11c5 <checkfilename+0xa5>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    -0x1c(%rbp),%ecx
sub    $0x5,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118f <checkfilename+0x6f>
mov    -0x28(%rbp),%rax
movb   $0x0,0x5(%rax)
mov    -0x28(%rbp),%rdi
lea    0xe28(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    11f3 <checkfilename+0xd3>
movl   $0x1,-0x4(%rbp)
jmp    11fa <checkfilename+0xda>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkfilename>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
cmpb   $0x0,(%rdi)
je     1162 <checkfilename+0x42>
lea    0x1(%r14),%rax
movabs $0xfffffffb00000000,%rbx
ff ff ff
movabs $0x100000000,%rcx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    %rcx,%rbx
cmpb   $0x0,(%rax)
lea    0x1(%rax),%rax
jne    1150 <checkfilename+0x30>
sar    $0x20,%rbx
jmp    1169 <checkfilename+0x49>
mov    $0xfffffffffffffffb,%rbx
mov    $0x5,%edi
call   1040 <malloc@plt>
mov    (%r14,%rbx,1),%cl
mov    %cl,(%rax)
mov    0x1(%r14,%rbx,1),%cl
mov    %cl,0x1(%rax)
mov    0x2(%r14,%rbx,1),%cl
mov    %cl,0x2(%rax)
mov    0x3(%r14,%rbx,1),%cl
mov    %cl,0x3(%rax)
mov    0x4(%r14,%rbx,1),%cl
mov    %cl,0x4(%rax)
movb   $0x0,0x5(%rax)
lea    0xe5c(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [6 x i8] c".digs\00"
define i32 @checkfilename(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8*
store i8* %0, i8** %3
store i32 0, i32* %4
store i32 0, i32* %5
%9 = load i8*, i8** %3
%10 = load i32, i32* %4
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = load i8, i8* %12
store i8 %13, i8* %7
br label %14
14: ; preds = %18, %1
%15 = load i8, i8* %7
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %28
18: ; preds = %14
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
%23 = load i8*, i8** %3
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
store i8 %27, i8* %7
br label %14
28: ; preds = %14
%29 = call i64 @malloc(i32 5)
%30 = inttoptr i64 %29 to i8*
store i8* %30, i8** %8
store i32 0, i32* %6
br label %31
31: ; preds = %47, %28
%32 = load i32, i32* %6
%33 = icmp slt i32 %32, 5
br i1 %33, label %34, label %50
34: ; preds = %31
%35 = load i8*, i8** %3
%36 = load i32, i32* %5
%37 = load i32, i32* %6
%38 = add nsw i32 %36, %37
%39 = sub nsw i32 %38, 5
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %35, i64 %40
%42 = load i8, i8* %41
%43 = load i8*, i8** %8
%44 = load i32, i32* %6
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
store i8 %42, i8* %46
br label %47
47: ; preds = %34
%48 = load i32, i32* %6
%49 = add nsw i32 %48, 1
store i32 %49, i32* %6
br label %31
50: ; preds = %31
%51 = load i8*, i8** %8
%52 = getelementptr inbounds i8, i8* %51, i64 5
store i8 0, i8* %52
%53 = load i8*, i8** %8
%54 = call i64 @strcmp(i8* %53, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %50
store i32 1, i32* %2
br label %58
57: ; preds = %50
store i32 0, i32* %2
br label %58
58: ; preds = %57, %56
%59 = load i32, i32* %2
ret i32 %59
}

LLVM IR (-O2):
@.str = [6 x i8] c".digs\00"
define i32 @checkfilename(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %14, label %4
4: ; preds = %1, %4
%5 = phi i64 [ %6, %4 ], [ 0, %1 ]
%6 = add nuw nsw i64 %5, 1
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
br i1 %9, label %10, label %4
10: ; preds = %4
%11 = shl i64 %5, 32
%12 = add i64 %11, -17179869184
%13 = ashr exact i64 %12, 32
br label %14
14: ; preds = %10, %1
%15 = phi i64 [ -5, %1 ], [ %13, %10 ]
%16 = tail call i64 @malloc(i32 5)
%17 = inttoptr i64 %16 to i8*
%18 = getelementptr inbounds i8, i8* %0, i64 %15
%19 = load i8, i8* %18
store i8 %19, i8* %17
%20 = add nsw i64 %15, 1
%21 = getelementptr inbounds i8, i8* %0, i64 %20
%22 = load i8, i8* %21
%23 = getelementptr inbounds i8, i8* %17, i64 1
store i8 %22, i8* %23
%24 = add nsw i64 %15, 2
%25 = getelementptr inbounds i8, i8* %0, i64 %24
%26 = load i8, i8* %25
%27 = getelementptr inbounds i8, i8* %17, i64 2
store i8 %26, i8* %27
%28 = add nsw i64 %15, 3
%29 = getelementptr inbounds i8, i8* %0, i64 %28
%30 = load i8, i8* %29
%31 = getelementptr inbounds i8, i8* %17, i64 3
store i8 %30, i8* %31
%32 = add nsw i64 %15, 4
%33 = getelementptr inbounds i8, i8* %0, i64 %32
%34 = load i8, i8* %33
%35 = getelementptr inbounds i8, i8* %17, i64 4
store i8 %34, i8* %35
%36 = getelementptr inbounds i8, i8* %17, i64 5
store i8 0, i8* %36
%37 = tail call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
%39 = zext i1 %38 to i32
ret i32 %39
}