#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*/ goodchar(int);
int strlen(char const *);
int check_filename_chars(const char *filename) {
  int fnlen, ch, i;
  fnlen = strlen(filename);
  for (i = 0; i < fnlen; i++) {
    ch = filename[i];
    if (!goodchar(ch)) {
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<check_filename_chars>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    118a <check_filename_chars+0x6a>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <goodchar@plt>
cmp    $0x0,%eax
jne    1177 <check_filename_chars+0x57>
movl   $0x0,-0x4(%rbp)
jmp    1191 <check_filename_chars+0x71>
jmp    117c <check_filename_chars+0x5c>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113f <check_filename_chars+0x1f>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_filename_chars>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    $0x1,%r14d
test   %eax,%eax
jle    115c <check_filename_chars+0x3c>
mov    %eax,%ebp
xor    %ebx,%ebx
nopl   (%rax)
movsbl (%r15,%rbx,1),%edi
call   1030 <goodchar@plt>
test   %eax,%eax
je     1159 <check_filename_chars+0x39>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1140 <check_filename_chars+0x20>
jmp    115c <check_filename_chars+0x3c>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @check_filename_chars(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %4
store i32 0, i32* %6
br label %9
9: ; preds = %25, %1
%10 = load i32, i32* %6
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %28
13: ; preds = %9
%14 = load i8*, i8** %3
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = call i32 @goodchar(i32 %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %24, label %23
23: ; preds = %13
store i32 0, i32* %2
br label %29
24: ; preds = %13
br label %25
25: ; preds = %24
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
br label %9
28: ; preds = %9
store i32 1, i32* %2
br label %29
29: ; preds = %28, %23
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
define i32 @check_filename_chars(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %16
4: ; preds = %1
%5 = zext i32 %2 to i64
br label %8
6: ; preds = %8
%7 = icmp eq i64 %15, %5
br i1 %7, label %16, label %8
8: ; preds = %4, %6
%9 = phi i64 [ 0, %4 ], [ %15, %6 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = tail call i32 @goodchar(i32 %12)
%14 = icmp eq i32 %13, 0
%15 = add nuw nsw i64 %9, 1
br i1 %14, label %16, label %6
16: ; preds = %8, %6, %1
%17 = phi i32 [ 1, %1 ], [ 1, %6 ], [ 0, %8 ]
ret i32 %17
}