#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 *modprobe_bin = "/sbin/modprobe";
  if (access(modprobe_bin, X_OK)) {
    modprobe_bin = "modprobe";
  }
  char *mod_argv[] = {modprobe_bin, "--dry-run", "--quiet", 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    $0x40,%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,-0x40(%rbp)
lea    0xea2(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xea1(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
lea    -0x40(%rbp),%rdi
mov    $0x1,%esi
call   1030 <bb_run_fork@plt>
mov    0x2e37(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<module_is_available>:
push   %r14
push   %rbx
sub    $0x28,%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)
lea    0xeb4(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0xeb2(%rip),%rax
mov    %rax,0x10(%rsp)
mov    %rbx,0x18(%rsp)
movq   $0x0,0x20(%rsp)
mov    %rsp,%rdi
mov    $0x1,%esi
call   1030 <bb_run_fork@plt>
mov    0x2e4a(%rip),%rdx
xor    %ecx,%ecx
cmp    (%rdx),%rax
sete   %cl
mov    %ecx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

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

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