#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 */
typedef int /*<<< orphan*/ buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ strstr(char *, char *);
int check_module_loaded(char *module, bool *loaded) {
  FILE *fp;
  *loaded = false;
  if ((fp = fopen("/proc/modules", "r")) != NULL) {
    char buffer[1024];
    while (fgets(buffer, sizeof(buffer), fp) != NULL) {
      if (strstr(buffer, module)) {
        *loaded = true;
        break;
      }
    }
    (void)fclose(fp);
    return 0;
  }
  printf(
      "Could not open /proc/modules to check if efi module '%s' is loaded.\n",
      module);
  return -1;
}


x86 assembly (clang, -O0):
<check_module_loaded>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
lea    0xe8c(%rip),%rdi
lea    0xe93(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11f5 <check_module_loaded+0xa5>
jmp    1193 <check_module_loaded+0x43>
lea    -0x420(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11e0 <check_module_loaded+0x90>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     11db <check_module_loaded+0x8b>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
jmp    11e0 <check_module_loaded+0x90>
jmp    1193 <check_module_loaded+0x43>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    120c <check_module_loaded+0xbc>
mov    -0x10(%rbp),%rsi
lea    0xe10(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_module_loaded>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
movl   $0x0,(%rsi)
lea    0xe8f(%rip),%rdi
lea    0xe96(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11c8 <check_module_loaded+0x78>
mov    %rax,%rbx
mov    %rsp,%r12
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11bc <check_module_loaded+0x6c>
mov    %r12,%rdi
mov    %r15,%rsi
call   1070 <strstr@plt>
test   %rax,%rax
je     1190 <check_module_loaded+0x40>
movl   $0x1,(%r14)
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    11dc <check_module_loaded+0x8c>
lea    0xe41(%rip),%rdi
mov    %r15,%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/modules\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [69 x i8] c"Could not open /proc/modules to check if efi module '%s' is loaded.\0A\00"
define i32 @check_module_loaded(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca [1024 x i8]
store i8* %0, i8** %4
store i32* %1, i32** %5
%8 = load i32*, i32** %5
store i32 0, i32* %8
%9 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %6
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %28
11: ; preds = %2
br label %12
12: ; preds = %24, %11
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%14 = load i32*, i32** %6
%15 = call i32* @fgets(i8* %13, i32 1024, i32* %14)
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %25
17: ; preds = %12
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%19 = load i8*, i8** %4
%20 = call i64 @strstr(i8* %18, i8* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = load i32*, i32** %5
store i32 1, i32* %23
br label %25
24: ; preds = %17
br label %12
25: ; preds = %22, %12
%26 = load i32*, i32** %6
%27 = call i32 @fclose(i32* %26)
store i32 0, i32* %3
br label %31
28: ; preds = %2
%29 = load i8*, i8** %4
%30 = call i32 @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.2, i64 0, i64 0), i8* %29)
store i32 -1, i32* %3
br label %31
31: ; preds = %28, %25
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/modules\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [69 x i8] c"Could not open /proc/modules to check if efi module '%s' is loaded.\0A\00"
define i32 @check_module_loaded(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca [1024 x i8]
store i32 0, i32* %1
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %17, label %6
6: ; preds = %2
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
br label %8
8: ; preds = %11, %6
%9 = call i32* @fgets(i8* %7, i32 1024, i32* %4)
%10 = icmp eq i32* %9, null
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = call i64 @strstr(i8* %7, i8* %0)
%13 = icmp eq i64 %12, 0
br i1 %13, label %8, label %14
14: ; preds = %11
store i32 1, i32* %1
br label %15
15: ; preds = %8, %14
%16 = call i32 @fclose(i32* %4)
br label %19
17: ; preds = %2
%18 = tail call i32 @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %19
19: ; preds = %17, %15
%20 = phi i32 [ 0, %15 ], [ -1, %17 ]
ret i32 %20
}