#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 */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int sscanf(char *, char *, char *, int *, int *);
scalar_t__ strcmp(char *, char *);
int check_driver() {
  FILE *proc;
  char buffer[80];
  proc = fopen("/proc/modules", "r");
  if (proc == NULL)
    return 0;
  while (fgets(buffer, 80, proc) != NULL) {
    char name[80];
    int size;
    int used;
    if (sscanf(buffer, "%s %d %d", name, &size, &used) != 3)
      continue;
    if (strcmp(name, "NVdriver") == 0) {
      fclose(proc);
      if (used)
        return 1;
      return 0;
    }
    if (strcmp(name, "nvidia") == 0) {
      fclose(proc);
      if (used)
        return 2;
      return 0;
    }
  }
  fclose(proc);
  return 0;
}


x86 assembly (clang, -O0):
<check_driver>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
lea    0xe9e(%rip),%rdi
lea    0xeb5(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1189 <check_driver+0x39>
movl   $0x0,-0x4(%rbp)
jmp    1288 <check_driver+0x138>
jmp    118e <check_driver+0x3e>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x50,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     1278 <check_driver+0x128>
lea    -0x60(%rbp),%rdi
lea    -0xb0(%rbp),%rdx
lea    0xe52(%rip),%rsi
lea    -0xb4(%rbp),%rcx
lea    -0xb8(%rbp),%r8
call   1060 <sscanf@plt>
cmp    $0x3,%eax
je     11dd <check_driver+0x8d>
jmp    118e <check_driver+0x3e>
lea    -0xb0(%rbp),%rdi
lea    0xe2c(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1228 <check_driver+0xd8>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x0,-0xb8(%rbp)
je     121c <check_driver+0xcc>
movl   $0x1,-0x4(%rbp)
jmp    1288 <check_driver+0x138>
movl   $0x0,-0x4(%rbp)
jmp    1288 <check_driver+0x138>
lea    -0xb0(%rbp),%rdi
lea    0xdea(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1273 <check_driver+0x123>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x0,-0xb8(%rbp)
je     1267 <check_driver+0x117>
movl   $0x2,-0x4(%rbp)
jmp    1288 <check_driver+0x138>
movl   $0x0,-0x4(%rbp)
jmp    1288 <check_driver+0x138>
jmp    118e <check_driver+0x3e>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_driver>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
lea    0xe98(%rip),%rdi
lea    0xeaf(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
xor    %eax,%eax
test   %rbx,%rbx
je     1236 <check_driver+0xe6>
lea    0x10(%rsp),%rdi
mov    $0x50,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     122c <check_driver+0xdc>
lea    0xe6a(%rip),%r15
lea    0x10(%rsp),%r12
lea    0x60(%rsp),%rbp
lea    0xc(%rsp),%r13
lea    0x8(%rsp),%r14
jmp    11d5 <check_driver+0x85>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x50,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     122c <check_driver+0xdc>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %r13,%rcx
mov    %r14,%r8
call   1060 <sscanf@plt>
cmp    $0x3,%eax
jne    11c0 <check_driver+0x70>
mov    %rbp,%rdi
lea    0xe1f(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1248 <check_driver+0xf8>
mov    %rbp,%rdi
lea    0xe14(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11c0 <check_driver+0x70>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
cmpl   $0x0,0x8(%rsp)
setne  %al
add    %eax,%eax
jmp    1236 <check_driver+0xe6>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
cmpl   $0x0,0x8(%rsp)
setne  %al
jmp    1236 <check_driver+0xe6>

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/modules\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"%s %d %d\00"
@.str.3 = [9 x i8] c"NVdriver\00"
@.str.4 = [7 x i8] c"nvidia\00"
define i32 @check_driver() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [80 x i8]
%4 = alloca [80 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = 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* %7, i32** %2
%8 = load i32*, i32** %2
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %11
10: ; preds = %0
store i32 0, i32* %1
br label %49
11: ; preds = %0
br label %12
12: ; preds = %45, %22, %11
%13 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%14 = load i32*, i32** %2
%15 = call i32* @fgets(i8* %13, i32 80, i32* %14)
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %46
17: ; preds = %12
%18 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%19 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%20 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %19, i32* %5, i32* %6)
%21 = icmp ne i32 %20, 3
br i1 %21, label %22, label %23
22: ; preds = %17
br label %12
23: ; preds = %17
%24 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %34
27: ; preds = %23
%28 = load i32*, i32** %2
%29 = call i32 @fclose(i32* %28)
%30 = load i32, i32* %6
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %27
store i32 1, i32* %1
br label %49
33: ; preds = %27
store i32 0, i32* %1
br label %49
34: ; preds = %23
%35 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%36 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %45
38: ; preds = %34
%39 = load i32*, i32** %2
%40 = call i32 @fclose(i32* %39)
%41 = load i32, i32* %6
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %38
store i32 2, i32* %1
br label %49
44: ; preds = %38
store i32 0, i32* %1
br label %49
45: ; preds = %34
br label %12
46: ; preds = %12
%47 = load i32*, i32** %2
%48 = call i32 @fclose(i32* %47)
store i32 0, i32* %1
br label %49
49: ; preds = %46, %44, %43, %33, %32, %10
%50 = load i32, i32* %1
ret i32 %50
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/modules\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"%s %d %d\00"
@.str.3 = [9 x i8] c"NVdriver\00"
@.str.4 = [7 x i8] c"nvidia\00"
define i32 @check_driver() {
%1 = alloca [80 x i8]
%2 = alloca [80 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%6 = 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))
%7 = icmp eq i32* %6, null
br i1 %7, label %41, label %8
8: ; preds = %0
%9 = call i32* @fgets(i8* %5, i32 80, i32* %6)
%10 = icmp eq i32* %9, null
br i1 %10, label %39, label %11
11: ; preds = %8
%12 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%13 = bitcast i32* %3 to i8*
%14 = bitcast i32* %4 to i8*
br label %15
15: ; preds = %11, %36
%16 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %12, i32* %3, i32* %4)
%17 = icmp eq i32 %16, 3
br i1 %17, label %18, label %36
18: ; preds = %15
%19 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = call i32 @fclose(i32* %6)
%23 = load i32, i32* %4
%24 = icmp ne i32 %23, 0
%25 = zext i1 %24 to i32
br label %34
26: ; preds = %18
%27 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %26
%30 = call i32 @fclose(i32* %6)
%31 = load i32, i32* %4
%32 = icmp eq i32 %31, 0
%33 = select i1 %32, i32 0, i32 2
br label %34
34: ; preds = %21, %29
%35 = phi i32 [ %33, %29 ], [ %25, %21 ]
br label %41
36: ; preds = %26, %15
%37 = call i32* @fgets(i8* %5, i32 80, i32* %6)
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %15
39: ; preds = %36, %8
%40 = call i32 @fclose(i32* %6)
br label %41
41: ; preds = %34, %0, %39
%42 = phi i32 [ 0, %39 ], [ 0, %0 ], [ %35, %34 ]
ret i32 %42
}