#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*/ FILE;

/* Variables and functions */
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
char *strtok(char *, char *);
int module_loaded(void) {
  FILE *fp;
  char line[8192];
  int found = 0;
  fp = fopen("/proc/modules", "ro");
  while (fgets(line, 8192, fp)) {
    char *s;
    s = strtok(line, " ");
    if (!strcmp(s, "flashcache_wt")) {
      found = 1;
      break;
    }
  }
  return found;
}


x86 assembly (clang, -O0):
<module_loaded>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2020,%rsp
movl   $0x0,-0x2014(%rbp)
lea    0xea4(%rip),%rdi
lea    0xeab(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x8(%rbp)
lea    -0x2010(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x2000,%esi
call   1030 <fgets@plt>
cmp    $0x0,%rax
je     11d5 <module_loaded+0x95>
lea    -0x2010(%rbp),%rdi
lea    0xe78(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x2020(%rbp)
mov    -0x2020(%rbp),%rdi
lea    0xe60(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11d0 <module_loaded+0x90>
movl   $0x1,-0x2014(%rbp)
jmp    11d5 <module_loaded+0x95>
jmp    116c <module_loaded+0x2c>
mov    -0x2014(%rbp),%eax
add    $0x2020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<module_loaded>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x2008,%rsp
lea    0xeab(%rip),%rdi
lea    0xeb2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
mov    %rsp,%r14
lea    0xea3(%rip),%r15
lea    0xe9e(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    $0x2000,%esi
mov    %rbx,%rdx
call   1030 <fgets@plt>
test   %rax,%rax
je     11b6 <module_loaded+0x76>
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <strtok@plt>
mov    %rax,%rdi
mov    %r12,%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
jne    1180 <module_loaded+0x40>
mov    $0x1,%eax
jmp    11b8 <module_loaded+0x78>
xor    %eax,%eax
add    $0x2008,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/modules\00"
@.str.1 = [3 x i8] c"ro\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [14 x i8] c"flashcache_wt\00"
define i32 @module_loaded() {
%1 = alloca i32*
%2 = alloca [8192 x i8]
%3 = alloca i32
%4 = alloca i8*
store i32 0, i32* %3
%5 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %1
br label %6
6: ; preds = %18, %0
%7 = getelementptr inbounds [8192 x i8], [8192 x i8]* %2, i64 0, i64 0
%8 = load i32*, i32** %1
%9 = call i64 @fgets(i8* %7, i32 8192, i32* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %6
%12 = getelementptr inbounds [8192 x i8], [8192 x i8]* %2, i64 0, i64 0
%13 = call i8* @strtok(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = call i32 @strcmp(i8* %14, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%16 = icmp ne i32 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %11
store i32 1, i32* %3
br label %19
18: ; preds = %11
br label %6
19: ; preds = %17, %6
%20 = load i32, i32* %3
ret i32 %20
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/modules\00"
@.str.1 = [3 x i8] c"ro\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [14 x i8] c"flashcache_wt\00"
define i32 @module_loaded() {
%1 = alloca [8192 x i8]
%2 = getelementptr inbounds [8192 x i8], [8192 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %4
4: ; preds = %7, %0
%5 = call i64 @fgets(i8* %2, i32 8192, i32* %3)
%6 = icmp eq i64 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %4
%8 = call i8* @strtok(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @strcmp(i8* dereferenceable(1) %8, i8* dereferenceable(14) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %4
11: ; preds = %7, %4
%12 = phi i32 [ 1, %7 ], [ 0, %4 ]
ret i32 %12
}