#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 */
typedef int /*<<< orphan*/ ext;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int is_valid_file(char *filename) {
  char ext[260];
  int i;
  i = strlen(filename);
  while (i > 0 && filename[i] != '.') {
    i--;
  }
  if (i > 0) {
    memset(ext, 0, sizeof(ext));
    strncpy(&ext[0], &filename[i], strlen(&filename[i]));
    if ((strncmp(ext, ".c", 2) == 0) || (strncmp(ext, ".C", 2) == 0)) {
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<is_valid_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x124(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x124(%rbp)
mov    %al,-0x125(%rbp)
jle    118e <is_valid_file+0x4e>
mov    -0x10(%rbp),%rax
movslq -0x124(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
setne  %al
mov    %al,-0x125(%rbp)
mov    -0x125(%rbp),%al
test   $0x1,%al
jne    11a1 <is_valid_file+0x61>
jmp    11b5 <is_valid_file+0x75>
mov    -0x124(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x124(%rbp)
jmp    115e <is_valid_file+0x1e>
cmpl   $0x0,-0x124(%rbp)
jle    1275 <is_valid_file+0x135>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x104,%edx
call   1060 <memset@plt>
lea    -0x120(%rbp),%rax
mov    %rax,-0x138(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x124(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x130(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x124(%rbp),%rax
add    %rax,%rdi
call   1050 <strlen@plt>
mov    -0x138(%rbp),%rdi
mov    -0x130(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
lea    -0x120(%rbp),%rdi
lea    0xdd2(%rip),%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     1264 <is_valid_file+0x124>
lea    -0x120(%rbp),%rdi
lea    0xdb3(%rip),%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1270 <is_valid_file+0x130>
movl   $0x1,-0x4(%rbp)
jmp    127c <is_valid_file+0x13c>
jmp    1275 <is_valid_file+0x135>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_valid_file>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%r14
call   1050 <strlen@plt>
test   %eax,%eax
jle    11d7 <is_valid_file+0x97>
mov    %eax,%ebx
add    %r14,%rbx
nop
mov    %eax,%ecx
cmpb   $0x2e,(%r14,%rcx,1)
je     1179 <is_valid_file+0x39>
lea    -0x1(%rax),%ecx
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%eax
mov    %ecx,%eax
jg     1160 <is_valid_file+0x20>
jmp    11d7 <is_valid_file+0x97>
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x104,%edx
call   1060 <memset@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
lea    0xe59(%rip),%rsi
mov    %r14,%rdi
mov    $0x2,%edx
call   1040 <strncmp@plt>
mov    $0x1,%ebx
test   %rax,%rax
je     11d9 <is_valid_file+0x99>
lea    0xe3e(%rip),%rsi
mov    %rsp,%rdi
mov    $0x2,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     11d9 <is_valid_file+0x99>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c".c\00"
@.str.1 = [3 x i8] c".C\00"
define i32 @is_valid_file(i8* %0) {
%2 = alloca [260 x i8]
%3 = getelementptr inbounds [260 x i8], [260 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %26
6: ; preds = %1, %12
%7 = phi i32 [ %13, %12 ], [ %4, %1 ]
%8 = zext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 46
br i1 %11, label %15, label %12
12: ; preds = %6
%13 = add nsw i32 %7, -1
%14 = icmp sgt i32 %7, 1
br i1 %14, label %6, label %26
15: ; preds = %6
%16 = zext i32 %7 to i64
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = call i32 @memset(i8* %3, i32 0, i32 260)
%19 = call i32 @strlen(i8* %17)
%20 = call i32 @strncpy(i8* %3, i8* %17, i32 %19)
%21 = call i64 @strncmp(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%22 = icmp eq i64 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %15
%24 = call i64 @strncmp(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%25 = icmp eq i64 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %12, %1, %23
br label %27
27: ; preds = %15, %23, %26
%28 = phi i32 [ 0, %26 ], [ 1, %23 ], [ 1, %15 ]
ret i32 %28
}