#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 */
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
scalar_t__ strstr(char *, char *);
int isCfg(const struct dirent *dent) {
  int len = strlen(dent->d_name);
  if (strncmp(dent->d_name, "ifcfg-", 6))
    return 0;
  if (strstr(dent->d_name, "rpmnew") || strstr(dent->d_name, "rpmsave") ||
      strstr(dent->d_name, "rpmorig"))
    return 0;
  if (dent->d_name[len - 1] == '~')
    return 0;
  if (!strncmp(dent->d_name + len - 5, ".bak", 4))
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<isCfg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xea7(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1179 <isCfg+0x49>
movl   $0x0,-0x4(%rbp)
jmp    1245 <isCfg+0x115>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe80(%rip),%rsi
call   1050 <strstr@plt>
cmp    $0x0,%rax
jne    11d0 <isCfg+0xa0>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe6a(%rip),%rsi
call   1050 <strstr@plt>
cmp    $0x0,%rax
jne    11d0 <isCfg+0xa0>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe55(%rip),%rsi
call   1050 <strstr@plt>
cmp    $0x0,%rax
je     11dc <isCfg+0xac>
movl   $0x0,-0x4(%rbp)
jmp    1245 <isCfg+0x115>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x7e,%eax
jne    1205 <isCfg+0xd5>
movl   $0x0,-0x4(%rbp)
jmp    1245 <isCfg+0x115>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
add    $0xfffffffffffffffb,%rdi
lea    0xe00(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    123e <isCfg+0x10e>
movl   $0x0,-0x4(%rbp)
jmp    1245 <isCfg+0x115>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isCfg>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    (%rdi),%rdi
call   1040 <strlen@plt>
mov    %eax,%r14d
mov    (%rbx),%rdi
lea    0xeb4(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
jne    11c8 <isCfg+0x98>
mov    (%rbx),%rdi
lea    0xea0(%rip),%rsi
call   1050 <strstr@plt>
test   %rax,%rax
jne    11c8 <isCfg+0x98>
mov    (%rbx),%rdi
lea    0xe93(%rip),%rsi
call   1050 <strstr@plt>
test   %rax,%rax
jne    11c8 <isCfg+0x98>
mov    (%rbx),%rdi
lea    0xe87(%rip),%rsi
call   1050 <strstr@plt>
test   %rax,%rax
jne    11c8 <isCfg+0x98>
mov    (%rbx),%rax
movslq %r14d,%rcx
cmpb   $0x7e,-0x1(%rcx,%rax,1)
je     11c8 <isCfg+0x98>
lea    (%rax,%rcx,1),%rdi
add    $0xfffffffffffffffb,%rdi
lea    0xe69(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [7 x i8] c"ifcfg-\00"
@.str.1 = [7 x i8] c"rpmnew\00"
@.str.2 = [8 x i8] c"rpmsave\00"
@.str.3 = [8 x i8] c"rpmorig\00"
@.str.4 = [5 x i8] c".bak\00"
define i32 @isCfg(%struct.dirent* nocapture %0) {
%2 = getelementptr inbounds %struct.dirent, %struct.dirent* %0, i64 0, i32 0
%3 = load i8*, i8** %2
%4 = tail call i32 @strlen(i8* %3)
%5 = load i8*, i8** %2
%6 = tail call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %34
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = tail call i64 @strstr(i8* %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %34
12: ; preds = %8
%13 = load i8*, i8** %2
%14 = tail call i64 @strstr(i8* %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %34
16: ; preds = %12
%17 = load i8*, i8** %2
%18 = tail call i64 @strstr(i8* %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %34
20: ; preds = %16
%21 = load i8*, i8** %2
%22 = add nsw i32 %4, -1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 126
br i1 %26, label %34, label %27
27: ; preds = %20
%28 = sext i32 %4 to i64
%29 = getelementptr inbounds i8, i8* %21, i64 %28
%30 = getelementptr inbounds i8, i8* %29, i64 -5
%31 = tail call i64 @strncmp(i8* %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%32 = icmp ne i64 %31, 0
%33 = zext i1 %32 to i32
br label %34
34: ; preds = %27, %20, %8, %12, %16, %1
%35 = phi i32 [ 0, %1 ], [ 0, %16 ], [ 0, %12 ], [ 0, %8 ], [ 0, %20 ], [ %33, %27 ]
ret i32 %35
}