#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 dummy;
};

/* Variables and functions */
int PATH_MAX;
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char const *);
scalar_t__ stat(char *, struct stat *);
int driver_loaded(const char *name) {
  char modpath[PATH_MAX];
  struct stat statbuf;
  snprintf(modpath, PATH_MAX - 1, "%s%s", "/sys/module/", name);
  if (stat(modpath, &statbuf) < 0)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<driver_loaded>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2ebd(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
sub    $0x1,%esi
mov    -0x10(%rbp),%r8
lea    0xe91(%rip),%rdx
lea    0xe8f(%rip),%rcx
call   1030 <snprintf@plt>
mov    -0x38(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
jge    11a5 <driver_loaded+0x85>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    11b3 <driver_loaded+0x93>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<driver_loaded>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
push   %rax
mov    %rdi,%r8
mov    0x2ec0(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
lea    -0x1(%rax),%esi
lea    0xeb0(%rip),%rdx
lea    0xeae(%rip),%rcx
mov    %rbx,%rdi
call   1030 <snprintf@plt>
lea    -0x10(%rbp),%rsi
mov    %rbx,%rdi
call   1040 <stat@plt>
shr    $0x3f,%rax
xor    $0x1,%eax
lea    -0x8(%rbp),%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@PATH_MAX = global i32 0
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [13 x i8] c"/sys/module/\00"
define i32 @driver_loaded(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca %struct.stat
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i32, i32* @PATH_MAX
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %4
%11 = alloca i8, i64 %9
store i64 %9, i64* %5
%12 = load i32, i32* @PATH_MAX
%13 = sub nsw i32 %12, 1
%14 = load i8*, i8** %3
%15 = call i32 @snprintf(i8* %11, i32 %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = call i64 @stat(i8* %11, %struct.stat* %6)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %1
store i32 0, i32* %2
store i32 1, i32* %7
br label %20
19: ; preds = %1
store i32 1, i32* %2
store i32 1, i32* %7
br label %20
20: ; preds = %19, %18
%21 = load i8*, i8** %4
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@PATH_MAX = global i32 0
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [13 x i8] c"/sys/module/\00"
define i32 @driver_loaded(i8* %0) {
%2 = alloca %struct.stat
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = bitcast %struct.stat* %2 to i8*
%7 = add nsw i32 %3, -1
%8 = call i32 @snprintf(i8* %5, i32 %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%9 = call i64 @stat(i8* %5, %struct.stat* %2)
%10 = lshr i64 %9, 63
%11 = trunc i64 %10 to i32
%12 = xor i32 %11, 1
ret i32 %12
}