#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__ path_ends_with_kmod_ext(char const *, int /*<<< orphan*/);
scalar_t__ stat(char const *, struct stat *);
int /*<<< orphan*/ strlen(char const *);
bool is_module_filename(const char *name) {
  struct stat st;
  if (stat(name, &st) == 0 && S_ISREG(st.st_mode) &&
      path_ends_with_kmod_ext(name, strlen(name)))
    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   1040 <stat@plt>
cmp    $0x0,%rax
jne    11a7 <is_module_filename+0x67>
mov    -0x18(%rbp),%edi
call   1050 <S_ISREG@plt>
cmp    $0x0,%rax
je     11a7 <is_module_filename+0x67>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%esi
call   1060 <path_ends_with_kmod_ext@plt>
cmp    $0x0,%rax
je     11a7 <is_module_filename+0x67>
movl   $0x1,-0x4(%rbp)
jmp    11ae <is_module_filename+0x6e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_module_filename>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1040 <stat@plt>
test   %rax,%rax
je     115f <is_module_filename+0x1f>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x8(%rsp),%edi
call   1050 <S_ISREG@plt>
test   %rax,%rax
je     1157 <is_module_filename+0x17>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <path_ends_with_kmod_ext@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    1159 <is_module_filename+0x19>
jmp    1157 <is_module_filename+0x17>

LLVM IR (-O0):
%struct.stat = type { i32 }
define i32 @is_module_filename(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.stat
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i64 @stat(i8* %5, %struct.stat* %4)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %20
8: ; preds = %1
%9 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%10 = load i32, i32* %9
%11 = call i64 @S_ISREG(i32 %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %8
%14 = load i8*, i8** %3
%15 = load i8*, i8** %3
%16 = call i32 @strlen(i8* %15)
%17 = call i64 @path_ends_with_kmod_ext(i8* %14, i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %13
store i32 1, i32* %2
br label %21
20: ; preds = %13, %8, %1
store i32 0, i32* %2
br label %21
21: ; preds = %20, %19
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
%struct.stat = type { i32 }
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 %15
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 %15, label %11
11: ; preds = %6
%12 = call i32 @strlen(i8* %0)
%13 = call i64 @path_ends_with_kmod_ext(i8* %0, i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %11, %6, %1
br label %16
16: ; preds = %11, %15
%17 = phi i32 [ 0, %15 ], [ 1, %11 ]
ret i32 %17
}