#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__ EXIT_SUCCESS;
int /*<<< orphan*/ X_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
scalar_t__ bb_run_fork(char **, int);
int module_is_available(char *module_name) {
  char *modinfo_bin = "/sbin/modinfo";
  if (access(modinfo_bin, X_OK)) {
    modinfo_bin = "modinfo";
  }
  char *mod_argv[] = {modinfo_bin, module_name, NULL};
  return bb_run_fork(mod_argv, 1) == EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<module_is_available>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xecd(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2ea6(%rip),%rax
mov    (%rax),%esi
call   1040 <access@plt>
cmp    $0x0,%rax
je     115e <module_is_available+0x3e>
lea    0xeac(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
lea    -0x30(%rbp),%rdi
mov    $0x1,%esi
call   1030 <bb_run_fork@plt>
mov    0x2e4d(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<module_is_available>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
mov    0x2eb7(%rip),%rax
mov    (%rax),%esi
lea    0xec6(%rip),%r14
mov    %r14,%rdi
call   1040 <access@plt>
test   %rax,%rax
lea    0xeba(%rip),%rax
cmove  %r14,%rax
mov    %rax,(%rsp)
mov    %rbx,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    %rsp,%rdi
mov    $0x1,%esi
call   1030 <bb_run_fork@plt>
mov    0x2e62(%rip),%rdx
xor    %ecx,%ecx
cmp    (%rdx),%rax
sete   %cl
mov    %ecx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/sbin/modinfo\00"
@X_OK = global i32 0
@.str.1 = [8 x i8] c"modinfo\00"
@EXIT_SUCCESS = global i64 0
define i32 @module_is_available(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [3 x i8*]
store i8* %0, i8** %2
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %3
%5 = load i8*, i8** %3
%6 = load i32, i32* @X_OK
%7 = call i64 @access(i8* %5, i32 %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %3
br label %10
10: ; preds = %9, %1
%11 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 0
%12 = load i8*, i8** %3
store i8* %12, i8** %11
%13 = getelementptr inbounds i8*, i8** %11, i64 1
%14 = load i8*, i8** %2
store i8* %14, i8** %13
%15 = getelementptr inbounds i8*, i8** %13, i64 1
store i8* null, i8** %15
%16 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 0
%17 = call i64 @bb_run_fork(i8** %16, i32 1)
%18 = load i64, i64* @EXIT_SUCCESS
%19 = icmp eq i64 %17, %18
%20 = zext i1 %19 to i32
ret i32 %20
}

LLVM IR (-O2):
@.str = [14 x i8] c"/sbin/modinfo\00"
@X_OK = global i32 0
@.str.1 = [8 x i8] c"modinfo\00"
@EXIT_SUCCESS = global i64 0
define i32 @module_is_available(i8* %0) {
%2 = alloca [3 x i8*]
%3 = load i32, i32* @X_OK
%4 = tail call i64 @access(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i64 %4, 0
%6 = select i1 %5, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0)
%7 = bitcast [3 x i8*]* %2 to i8*
%8 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 0
store i8* %6, i8** %8
%9 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 1
store i8* %0, i8** %9
%10 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 2
store i8* null, i8** %10
%11 = call i64 @bb_run_fork(i8** %8, i32 1)
%12 = load i64, i64* @EXIT_SUCCESS
%13 = icmp eq i64 %11, %12
%14 = zext i1 %13 to i32
ret i32 %14
}