#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 /*<<< orphan*/ assert(char *);
int /*<<< orphan*/ basename(char *);
scalar_t__ endswith(char *, char *);
scalar_t__ startswith(int /*<<< orphan*/, char *);
bool is_valid_filename(char *filename) {
  assert(filename);
  if (endswith(filename, ".swp") || endswith(filename, "~")) {
    return false;
  }
  if (startswith(basename(filename), ".")) {
    return false;
  }
  return true;
}


x86 assembly (clang, -O0):
<is_valid_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rdi
lea    0xea0(%rip),%rsi
call   1030 <endswith@plt>
cmp    $0x0,%rax
jne    1189 <is_valid_filename+0x49>
mov    -0x10(%rbp),%rdi
lea    0xe8b(%rip),%rsi
call   1030 <endswith@plt>
cmp    $0x0,%rax
je     1195 <is_valid_filename+0x55>
movl   $0x0,-0x4(%rbp)
jmp    11c9 <is_valid_filename+0x89>
mov    -0x10(%rbp),%rdi
call   1060 <basename@plt>
mov    %eax,%edi
lea    0xe60(%rip),%rsi
call   1040 <startswith@plt>
cmp    $0x0,%rax
je     11c2 <is_valid_filename+0x82>
movl   $0x0,-0x4(%rbp)
jmp    11c9 <is_valid_filename+0x89>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_valid_filename>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <assert@plt>
lea    0xeae(%rip),%rsi
mov    %rbx,%rdi
call   1030 <endswith@plt>
xor    %ebp,%ebp
test   %rax,%rax
jne    1194 <is_valid_filename+0x54>
lea    0xe9d(%rip),%rsi
mov    %rbx,%rdi
call   1030 <endswith@plt>
test   %rax,%rax
jne    1194 <is_valid_filename+0x54>
mov    %rbx,%rdi
call   1060 <basename@plt>
lea    0xe83(%rip),%rsi
mov    %eax,%edi
call   1040 <startswith@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c".swp\00"
@.str.1 = [2 x i8] c"~\00"
@.str.2 = [2 x i8] c".\00"
define i32 @is_valid_filename(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = call i32 @assert(i8* %4)
%6 = load i8*, i8** %3
%7 = call i64 @endswith(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = icmp ne i64 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i64 @endswith(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %9, %1
store i32 0, i32* %2
br label %21
14: ; preds = %9
%15 = load i8*, i8** %3
%16 = call i32 @basename(i8* %15)
%17 = call i64 @startswith(i32 %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %14
store i32 0, i32* %2
br label %21
20: ; preds = %14
store i32 1, i32* %2
br label %21
21: ; preds = %20, %19, %13
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@.str = [5 x i8] c".swp\00"
@.str.1 = [2 x i8] c"~\00"
@.str.2 = [2 x i8] c".\00"
define i32 @is_valid_filename(i8* %0) {
%2 = tail call i32 @assert(i8* %0)
%3 = tail call i64 @endswith(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %13
5: ; preds = %1
%6 = tail call i64 @endswith(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %5
%9 = tail call i32 @basename(i8* %0)
%10 = tail call i64 @startswith(i32 %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
%12 = zext i1 %11 to i32
br label %13
13: ; preds = %8, %1, %5
%14 = phi i32 [ 0, %5 ], [ 0, %1 ], [ %12, %8 ]
ret i32 %14
}