#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 stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ S_ISREG(int /*<<< orphan*/);
scalar_t__ stat(char const *, struct stat *);
char *strstr(char const *, char *);
bool is_module_filename(const char *name) {
  struct stat st;
  const char *ptr;
  if (stat(name, &st) == 0 && S_ISREG(st.st_mode) &&
      (ptr = strstr(name, ".ko")) != NULL) {
    if (ptr[3] == '\0' || ptr[3] == '.')
      return true;
  }
  return false;
}


x86 assembly (clang, -O0):
<is_module_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <stat@plt>
cmp    $0x0,%rax
jne    11b6 <is_module_filename+0x86>
mov    -0x18(%rbp),%edi
call   1040 <S_ISREG@plt>
cmp    $0x0,%rax
je     11b6 <is_module_filename+0x86>
mov    -0x10(%rbp),%rdi
lea    0xe90(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11b6 <is_module_filename+0x86>
mov    -0x20(%rbp),%rax
movsbl 0x3(%rax),%eax
cmp    $0x0,%eax
je     11a5 <is_module_filename+0x75>
mov    -0x20(%rbp),%rax
movsbl 0x3(%rax),%eax
cmp    $0x2e,%eax
jne    11b1 <is_module_filename+0x81>
movl   $0x1,-0x4(%rbp)
jmp    11bd <is_module_filename+0x8d>
jmp    11b6 <is_module_filename+0x86>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_module_filename>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %rsp,%rsi
call   1030 <stat@plt>
xor    %ebp,%ebp
test   %rax,%rax
jne    1178 <is_module_filename+0x48>
mov    (%rsp),%edi
call   1040 <S_ISREG@plt>
test   %rax,%rax
je     1178 <is_module_filename+0x48>
lea    0xea7(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strstr@plt>
test   %rax,%rax
je     1178 <is_module_filename+0x48>
mov    0x3(%rax),%al
test   %al,%al
sete   %cl
cmp    $0x2e,%al
sete   %al
or     %cl,%al
movzbl %al,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [4 x i8] c".ko\00"
define i32 @is_module_filename(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.stat
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @stat(i8* %6, %struct.stat* %4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %32
9: ; preds = %1
%10 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%11 = load i32, i32* %10
%12 = call i64 @S_ISREG(i32 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %32
14: ; preds = %9
%15 = load i8*, i8** %3
%16 = call i8* @strstr(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %16, i8** %5
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %32
18: ; preds = %14
%19 = load i8*, i8** %5
%20 = getelementptr inbounds i8, i8* %19, i64 3
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 0
br i1 %23, label %30, label %24
24: ; preds = %18
%25 = load i8*, i8** %5
%26 = getelementptr inbounds i8, i8* %25, i64 3
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 46
br i1 %29, label %30, label %31
30: ; preds = %24, %18
store i32 1, i32* %2
br label %33
31: ; preds = %24
br label %32
32: ; preds = %31, %14, %9, %1
store i32 0, i32* %2
br label %33
33: ; preds = %32, %30
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [4 x i8] c".ko\00"
define i32 @is_module_filename(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i64 @stat(i8* %0, %struct.stat* %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %21
6: ; preds = %1
%7 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%8 = load i32, i32* %7
%9 = call i64 @S_ISREG(i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %21, label %11
11: ; preds = %6
%12 = call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i8* %12, null
br i1 %13, label %21, label %14
14: ; preds = %11
%15 = getelementptr inbounds i8, i8* %12, i64 3
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
%18 = icmp eq i8 %16, 46
%19 = or i1 %17, %18
%20 = zext i1 %19 to i32
br label %21
21: ; preds = %1, %6, %11, %14
%22 = phi i32 [ %20, %14 ], [ 0, %11 ], [ 0, %6 ], [ 0, %1 ]
ret i32 %22
}