#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__ strcasecmp(char const *, char *);
scalar_t__ strchr(char *, char const);
int file_seems_valid(const char *fname) {
  const char *s;
  const char *ldot = 0;
  if (!fname || !*fname || *fname == ' ')
    return 0;
  for (s = fname; *s; s++) {
    if (*s < 32 || *s == 127)
      return 0;
    if (strchr("*?\"<>|", *s))
      return 0;
    if (*s == '.')
      ldot = s;
  }
  if (!ldot)
    return 0;
  if (strcasecmp(ldot, ".png") == 0)
    return 1;
  else if (strcasecmp(ldot, ".jpeg") == 0)
    return 2;
  else if (strcasecmp(ldot, ".jpg") == 0)
    return 2;
  return 0;
}


x86 assembly (clang, -O0):
<file_seems_valid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     115c <file_seems_valid+0x3c>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     115c <file_seems_valid+0x3c>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    1168 <file_seems_valid+0x48>
movl   $0x0,-0x4(%rbp)
jmp    129a <file_seems_valid+0x17a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     1200 <file_seems_valid+0xe0>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jl     119d <file_seems_valid+0x7d>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7f,%eax
jne    11a9 <file_seems_valid+0x89>
movl   $0x0,-0x4(%rbp)
jmp    129a <file_seems_valid+0x17a>
mov    -0x18(%rbp),%rax
lea    0xe4c(%rip),%rdi
movsbl (%rax),%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     11d2 <file_seems_valid+0xb2>
movl   $0x0,-0x4(%rbp)
jmp    129a <file_seems_valid+0x17a>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11ea <file_seems_valid+0xca>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    11ef <file_seems_valid+0xcf>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1170 <file_seems_valid+0x50>
cmpq   $0x0,-0x20(%rbp)
jne    1217 <file_seems_valid+0xf7>
movl   $0x0,-0x4(%rbp)
jmp    129a <file_seems_valid+0x17a>
mov    -0x20(%rbp),%rdi
lea    0xde5(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    123d <file_seems_valid+0x11d>
movl   $0x1,-0x4(%rbp)
jmp    129a <file_seems_valid+0x17a>
mov    -0x20(%rbp),%rdi
lea    0xdc4(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1263 <file_seems_valid+0x143>
movl   $0x2,-0x4(%rbp)
jmp    129a <file_seems_valid+0x17a>
mov    -0x20(%rbp),%rdi
lea    0xda4(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1289 <file_seems_valid+0x169>
movl   $0x2,-0x4(%rbp)
jmp    129a <file_seems_valid+0x17a>
jmp    128e <file_seems_valid+0x16e>
jmp    1293 <file_seems_valid+0x173>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_seems_valid>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %r14d,%r14d
test   %rdi,%rdi
je     1139 <file_seems_valid+0x19>
mov    %rdi,%rbx
mov    (%rdi),%al
test   $0xdf,%al
jne    1148 <file_seems_valid+0x28>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
xor    %r14d,%r14d
lea    0xeae(%rip),%r12
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nop
lea    -0x7f(%rax),%ecx
cmp    $0xa1,%cl
jb     1139 <file_seems_valid+0x19>
movsbl %al,%esi
mov    %r12,%rdi
call   1040 <strchr@plt>
test   %rax,%rax
jne    1139 <file_seems_valid+0x19>
movzbl 0x1(%rbx),%eax
cmpb   $0x2e,(%rbx)
cmove  %rbx,%r15
add    $0x1,%rbx
test   %al,%al
jne    1160 <file_seems_valid+0x40>
test   %r15,%r15
je     1139 <file_seems_valid+0x19>
lea    0xe70(%rip),%rsi
mov    %r15,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     11d9 <file_seems_valid+0xb9>
lea    0xe61(%rip),%rsi
mov    %r15,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     11e4 <file_seems_valid+0xc4>
lea    0xe53(%rip),%rsi
mov    %r15,%rdi
call   1030 <strcasecmp@plt>
xor    %r14d,%r14d
test   %rax,%rax
sete   %r14b
add    %r14d,%r14d
jmp    1139 <file_seems_valid+0x19>
mov    $0x1,%r14d
jmp    1139 <file_seems_valid+0x19>
mov    $0x2,%r14d
jmp    1139 <file_seems_valid+0x19>

LLVM IR (-O0):
@.str = [7 x i8] c"*?\22<>|\00"
@.str.1 = [5 x i8] c".png\00"
@.str.2 = [6 x i8] c".jpeg\00"
@.str.3 = [5 x i8] c".jpg\00"
define i32 @file_seems_valid(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* null, i8** %5
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %17
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = load i8*, i8** %3
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 32
br i1 %16, label %17, label %18
17: ; preds = %12, %8, %1
store i32 0, i32* %2
br label %74
18: ; preds = %12
%19 = load i8*, i8** %3
store i8* %19, i8** %4
br label %20
20: ; preds = %49, %18
%21 = load i8*, i8** %4
%22 = load i8, i8* %21
%23 = icmp ne i8 %22, 0
br i1 %23, label %24, label %52
24: ; preds = %20
%25 = load i8*, i8** %4
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp slt i32 %27, 32
br i1 %28, label %34, label %29
29: ; preds = %24
%30 = load i8*, i8** %4
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 127
br i1 %33, label %34, label %35
34: ; preds = %29, %24
store i32 0, i32* %2
br label %74
35: ; preds = %29
%36 = load i8*, i8** %4
%37 = load i8, i8* %36
%38 = call i64 @strchr(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 signext %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %35
store i32 0, i32* %2
br label %74
41: ; preds = %35
%42 = load i8*, i8** %4
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 46
br i1 %45, label %46, label %48
46: ; preds = %41
%47 = load i8*, i8** %4
store i8* %47, i8** %5
br label %48
48: ; preds = %46, %41
br label %49
49: ; preds = %48
%50 = load i8*, i8** %4
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %4
br label %20
52: ; preds = %20
%53 = load i8*, i8** %5
%54 = icmp ne i8* %53, null
br i1 %54, label %56, label %55
55: ; preds = %52
store i32 0, i32* %2
br label %74
56: ; preds = %52
%57 = load i8*, i8** %5
%58 = call i64 @strcasecmp(i8* %57, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %61
60: ; preds = %56
store i32 1, i32* %2
br label %74
61: ; preds = %56
%62 = load i8*, i8** %5
%63 = call i64 @strcasecmp(i8* %62, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%64 = icmp eq i64 %63, 0
br i1 %64, label %65, label %66
65: ; preds = %61
store i32 2, i32* %2
br label %74
66: ; preds = %61
%67 = load i8*, i8** %5
%68 = call i64 @strcasecmp(i8* %67, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%69 = icmp eq i64 %68, 0
br i1 %69, label %70, label %71
70: ; preds = %66
store i32 2, i32* %2
br label %74
71: ; preds = %66
br label %72
72: ; preds = %71
br label %73
73: ; preds = %72
store i32 0, i32* %2
br label %74
74: ; preds = %73, %70, %65, %60, %55, %40, %34, %17
%75 = load i32, i32* %2
ret i32 %75
}

LLVM IR (-O2):
@.str = [7 x i8] c"*?\22<>|\00"
@.str.1 = [5 x i8] c".png\00"
@.str.2 = [6 x i8] c".jpeg\00"
@.str.3 = [5 x i8] c".jpg\00"
define i32 @file_seems_valid(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %33, label %3
3: ; preds = %1
%4 = load i8, i8* %0
switch i8 %4, label %5 [
i8 0, label %33
i8 32, label %33
]
5: ; preds = %3, %14
%6 = phi i8* [ %17, %14 ], [ null, %3 ]
%7 = phi i8* [ %18, %14 ], [ %0, %3 ]
%8 = phi i8 [ %19, %14 ], [ %4, %3 ]
%9 = add i8 %8, -127
%10 = icmp ult i8 %9, -95
br i1 %10, label %33, label %11
11: ; preds = %5
%12 = tail call i64 @strchr(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 signext %8)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %33
14: ; preds = %11
%15 = load i8, i8* %7
%16 = icmp eq i8 %15, 46
%17 = select i1 %16, i8* %7, i8* %6
%18 = getelementptr inbounds i8, i8* %7, i64 1
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
br i1 %20, label %21, label %5
21: ; preds = %14
%22 = icmp eq i8* %17, null
br i1 %22, label %33, label %23
23: ; preds = %21
%24 = tail call i64 @strcasecmp(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %33, label %26
26: ; preds = %23
%27 = tail call i64 @strcasecmp(i8* %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %26
%30 = tail call i64 @strcasecmp(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
%32 = select i1 %31, i32 2, i32 0
br label %33
33: ; preds = %11, %5, %29, %26, %23, %21, %1, %3, %3
%34 = phi i32 [ 0, %3 ], [ 0, %3 ], [ 0, %1 ], [ 0, %21 ], [ 1, %23 ], [ 2, %26 ], [ %32, %29 ], [ 0, %5 ], [ 0, %11 ]
ret i32 %34
}