#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*/ uint64_t;
struct depmod {
  int dummy;
};
typedef int /*<<< orphan*/ line;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ LOG_DEBUG;
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ _log(int /*<<< orphan*/, char *, char const *, ...);
int /*<<< orphan*/ depmod_add_fake_syms(struct depmod *);
int /*<<< orphan*/ depmod_symbol_add(struct depmod *, char const *,
                                     int /*<<< orphan*/, int /*<<< orphan*/ *);
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ strcmp(char const *, char *);
char *strtok(char *, char *);
int /*<<< orphan*/ strtoull(char const *, char **, int);
int depmod_load_symvers(struct depmod *depmod, const char *filename) {
  char line[10240];
  FILE *fp;
  unsigned int linenum = 0;
  fp = fopen(filename, "r");
  if (fp == NULL) {
    int err = -errno;
    _log(LOG_DEBUG, "load symvers: %s: %m\n", filename);
    return err;
  }
  _log(LOG_DEBUG, "load symvers: %s\n", filename);
  while (fgets(line, sizeof(line), fp) != NULL) {
    const char *ver, *sym, *where;
    char *verend;
    uint64_t crc;
    linenum++;
    ver = strtok(line, " \t");
    sym = strtok(NULL, " \t");
    where = strtok(NULL, " \t");
    if (!ver || !sym || !where)
      continue;
    if (!(strcmp((where), ("vmlinux")) == 0))
      continue;
    crc = strtoull(ver, &verend, 16);
    if (verend[0] != '\0') {
      _log(LOG_ERR, "%s:%u Invalid symbol version %s: %m\n", filename, linenum,
           ver);
      continue;
    }
    depmod_symbol_add(depmod, sym, crc, NULL);
  }
  depmod_add_fake_syms(depmod);
  _log(LOG_DEBUG, "loaded symvers: %s\n", filename);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<depmod_load_symvers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2860,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x282c(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe48(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x2828(%rbp)
cmpq   $0x0,-0x2828(%rbp)
jne    120c <depmod_load_symvers+0x7c>
xor    %eax,%eax
mov    0x2e05(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x2830(%rbp)
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe0b(%rip),%rsi
mov    $0x0,%al
call   1030 <_log@plt>
mov    -0x2830(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13a5 <depmod_load_symvers+0x215>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdf8(%rip),%rsi
mov    $0x0,%al
call   1030 <_log@plt>
lea    -0x2820(%rbp),%rdi
mov    -0x2828(%rbp),%rdx
mov    $0x2800,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     136e <depmod_load_symvers+0x1de>
mov    -0x282c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x282c(%rbp)
lea    -0x2820(%rbp),%rdi
lea    0xdc4(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x2838(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdad(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x2840(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd96(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x2848(%rbp)
cmpq   $0x0,-0x2838(%rbp)
je     12ca <depmod_load_symvers+0x13a>
cmpq   $0x0,-0x2840(%rbp)
je     12ca <depmod_load_symvers+0x13a>
cmpq   $0x0,-0x2848(%rbp)
jne    12cf <depmod_load_symvers+0x13f>
jmp    1227 <depmod_load_symvers+0x97>
mov    -0x2848(%rbp),%rdi
lea    0xd50(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     12f1 <depmod_load_symvers+0x161>
jmp    1227 <depmod_load_symvers+0x97>
mov    -0x2838(%rbp),%rdi
lea    -0x2850(%rbp),%rsi
mov    $0x10,%edx
call   1070 <strtoull@plt>
mov    %eax,-0x2854(%rbp)
mov    -0x2850(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     134f <depmod_load_symvers+0x1bf>
mov    0x2c9f(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x282c(%rbp),%ecx
mov    -0x2838(%rbp),%r8
lea    0xcf2(%rip),%rsi
mov    $0x0,%al
call   1030 <_log@plt>
jmp    1227 <depmod_load_symvers+0x97>
mov    -0x10(%rbp),%rdi
mov    -0x2840(%rbp),%rsi
mov    -0x2854(%rbp),%edx
xor    %eax,%eax
mov    %eax,%ecx
call   10b0 <depmod_symbol_add@plt>
jmp    1227 <depmod_load_symvers+0x97>
mov    -0x10(%rbp),%rdi
call   1050 <depmod_add_fake_syms@plt>
mov    0x2c5a(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xccf(%rip),%rsi
mov    $0x0,%al
call   1030 <_log@plt>
mov    -0x2828(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2860,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<depmod_load_symvers>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2828,%rsp
mov    %rsi,%rbx
mov    %rdi,0x8(%rsp)
lea    0xe50(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1308 <depmod_load_symvers+0x178>
mov    %rax,%r13
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
lea    0xe44(%rip),%rsi
mov    %rbx,0x10(%rsp)
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <_log@plt>
lea    0x20(%rsp),%rdi
mov    $0x2800,%esi
mov    %r13,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     12d6 <depmod_load_symvers+0x146>
mov    $0x1,%ebx
lea    0xe20(%rip),%rbp
lea    0x20(%rsp),%r15
jmp    1258 <depmod_load_symvers+0xc8>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
lea    0xe14(%rip),%rsi
mov    0x10(%rsp),%rdx
mov    %ebx,%ecx
mov    %r12,%r8
xor    %eax,%eax
call   1030 <_log@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    $0x2800,%esi
mov    %r13,%rdx
call   1060 <fgets@plt>
add    $0x1,%ebx
test   %rax,%rax
je     12d6 <depmod_load_symvers+0x146>
mov    %r15,%rdi
mov    %rbp,%rsi
call   10a0 <strtok@plt>
mov    %rax,%r12
xor    %edi,%edi
mov    %rbp,%rsi
call   10a0 <strtok@plt>
mov    %rax,%r14
xor    %edi,%edi
mov    %rbp,%rsi
call   10a0 <strtok@plt>
test   %r12,%r12
je     1240 <depmod_load_symvers+0xb0>
test   %r14,%r14
je     1240 <depmod_load_symvers+0xb0>
test   %rax,%rax
je     1240 <depmod_load_symvers+0xb0>
mov    %rax,%rdi
lea    0xd97(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    1240 <depmod_load_symvers+0xb0>
mov    %r12,%rdi
lea    0x18(%rsp),%rsi
mov    $0x10,%edx
call   1070 <strtoull@plt>
mov    0x18(%rsp),%rcx
cmpb   $0x0,(%rcx)
jne    1211 <depmod_load_symvers+0x81>
mov    0x8(%rsp),%rdi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   10b0 <depmod_symbol_add@plt>
jmp    1240 <depmod_load_symvers+0xb0>
mov    0x8(%rsp),%rdi
call   1050 <depmod_add_fake_syms@plt>
mov    0x2cf1(%rip),%rax
mov    (%rax),%edi
lea    0xd6a(%rip),%rsi
mov    0x10(%rsp),%rdx
xor    %eax,%eax
call   1030 <_log@plt>
mov    %r13,%rdi
call   1040 <fclose@plt>
xor    %ebp,%ebp
jmp    132d <depmod_load_symvers+0x19d>
mov    0x2cd1(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
mov    0x2cbe(%rip),%rax
mov    (%rax),%edi
lea    0xcdf(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <_log@plt>
mov    %ebp,%eax
add    $0x2828,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.depmod = type { i32 }
@.str = [2 x i8] c"r\00"
@errno = global i32 0
@LOG_DEBUG = global i32 0
@.str.1 = [22 x i8] c"load symvers: %s: %m\0A\00"
@.str.2 = [18 x i8] c"load symvers: %s\0A\00"
@.str.3 = [3 x i8] c" \09\00"
@.str.4 = [8 x i8] c"vmlinux\00"
@LOG_ERR = global i32 0
@.str.5 = [37 x i8] c"%s:%u Invalid symbol version %s: %m\0A\00"
@.str.6 = [20 x i8] c"loaded symvers: %s\0A\00"
define i32 @depmod_load_symvers(%struct.depmod* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.depmod*
%5 = alloca i8*
%6 = alloca [10240 x i8]
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32
store %struct.depmod* %0, %struct.depmod** %4
store i8* %1, i8** %5
store i32 0, i32* %8
%15 = load i8*, i8** %5
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %7
%17 = load i32*, i32** %7
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %26
19: ; preds = %2
%20 = load i32, i32* @errno
%21 = sub nsw i32 0, %20
store i32 %21, i32* %9
%22 = load i32, i32* @LOG_DEBUG
%23 = load i8*, i8** %5
%24 = call i32 (i32, i8*, i8*, ...) @_log(i32 %22, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = load i32, i32* %9
store i32 %25, i32* %3
br label %83
26: ; preds = %2
%27 = load i32, i32* @LOG_DEBUG
%28 = load i8*, i8** %5
%29 = call i32 (i32, i8*, i8*, ...) @_log(i32 %27, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %70, %64, %55, %50, %26
%31 = getelementptr inbounds [10240 x i8], [10240 x i8]* %6, i64 0, i64 0
%32 = load i32*, i32** %7
%33 = call i32* @fgets(i8* %31, i32 10240, i32* %32)
%34 = icmp ne i32* %33, null
br i1 %34, label %35, label %75
35: ; preds = %30
%36 = load i32, i32* %8
%37 = add i32 %36, 1
store i32 %37, i32* %8
%38 = getelementptr inbounds [10240 x i8], [10240 x i8]* %6, i64 0, i64 0
%39 = call i8* @strtok(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i8* %39, i8** %10
%40 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i8* %40, i8** %11
%41 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i8* %41, i8** %12
%42 = load i8*, i8** %10
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %50
44: ; preds = %35
%45 = load i8*, i8** %11
%46 = icmp ne i8* %45, null
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = load i8*, i8** %12
%49 = icmp ne i8* %48, null
br i1 %49, label %51, label %50
50: ; preds = %47, %44, %35
br label %30
51: ; preds = %47
%52 = load i8*, i8** %12
%53 = call i64 @strcmp(i8* %52, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%54 = icmp eq i64 %53, 0
br i1 %54, label %56, label %55
55: ; preds = %51
br label %30
56: ; preds = %51
%57 = load i8*, i8** %10
%58 = call i32 @strtoull(i8* %57, i8** %13, i32 16)
store i32 %58, i32* %14
%59 = load i8*, i8** %13
%60 = getelementptr inbounds i8, i8* %59, i64 0
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %70
64: ; preds = %56
%65 = load i32, i32* @LOG_ERR
%66 = load i8*, i8** %5
%67 = load i32, i32* %8
%68 = load i8*, i8** %10
%69 = call i32 (i32, i8*, i8*, ...) @_log(i32 %65, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i8* %66, i32 %67, i8* %68)
br label %30
70: ; preds = %56
%71 = load %struct.depmod*, %struct.depmod** %4
%72 = load i8*, i8** %11
%73 = load i32, i32* %14
%74 = call i32 @depmod_symbol_add(%struct.depmod* %71, i8* %72, i32 %73, i32* null)
br label %30
75: ; preds = %30
%76 = load %struct.depmod*, %struct.depmod** %4
%77 = call i32 @depmod_add_fake_syms(%struct.depmod* %76)
%78 = load i32, i32* @LOG_DEBUG
%79 = load i8*, i8** %5
%80 = call i32 (i32, i8*, i8*, ...) @_log(i32 %78, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i8* %79)
%81 = load i32*, i32** %7
%82 = call i32 @fclose(i32* %81)
store i32 0, i32* %3
br label %83
83: ; preds = %75, %19
%84 = load i32, i32* %3
ret i32 %84
}

LLVM IR (-O2):
%struct.depmod = type { i32 }
@.str = [2 x i8] c"r\00"
@errno = global i32 0
@LOG_DEBUG = global i32 0
@.str.1 = [22 x i8] c"load symvers: %s: %m\0A\00"
@.str.2 = [18 x i8] c"load symvers: %s\0A\00"
@.str.3 = [3 x i8] c" \09\00"
@.str.4 = [8 x i8] c"vmlinux\00"
@LOG_ERR = global i32 0
@.str.5 = [37 x i8] c"%s:%u Invalid symbol version %s: %m\0A\00"
@.str.6 = [20 x i8] c"loaded symvers: %s\0A\00"
define i32 @depmod_load_symvers(%struct.depmod* %0, i8* %1) {
%3 = alloca [10240 x i8]
%4 = alloca i8*
%5 = getelementptr inbounds [10240 x i8], [10240 x i8]* %3, i64 0, i64 0
%6 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i32, i32* @errno
%10 = sub nsw i32 0, %9
%11 = load i32, i32* @LOG_DEBUG
%12 = tail call i32 (i32, i8*, i8*, ...) @_log(i32 %11, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %52
13: ; preds = %2
%14 = load i32, i32* @LOG_DEBUG
%15 = tail call i32 (i32, i8*, i8*, ...) @_log(i32 %14, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%16 = call i32* @fgets(i8* %5, i32 10240, i32* %6)
%17 = icmp eq i32* %16, null
br i1 %17, label %47, label %18
18: ; preds = %13
%19 = bitcast i8** %4 to i8*
br label %20
20: ; preds = %18, %44
%21 = phi i32 [ 0, %18 ], [ %22, %44 ]
%22 = add i32 %21, 1
%23 = call i8* @strtok(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%24 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%25 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp ne i8* %23, null
%27 = icmp ne i8* %24, null
%28 = select i1 %26, i1 %27, i1 false
%29 = icmp ne i8* %25, null
%30 = select i1 %28, i1 %29, i1 false
br i1 %30, label %31, label %44
31: ; preds = %20
%32 = call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %44
34: ; preds = %31
%35 = call i32 @strtoull(i8* %23, i8** %4, i32 16)
%36 = load i8*, i8** %4
%37 = load i8, i8* %36
%38 = icmp eq i8 %37, 0
br i1 %38, label %42, label %39
39: ; preds = %34
%40 = load i32, i32* @LOG_ERR
%41 = call i32 (i32, i8*, i8*, ...) @_log(i32 %40, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i8* %1, i32 %22, i8* %23)
br label %44
42: ; preds = %34
%43 = call i32 @depmod_symbol_add(%struct.depmod* %0, i8* %24, i32 %35, i32* null)
br label %44
44: ; preds = %31, %20, %42, %39
%45 = call i32* @fgets(i8* %5, i32 10240, i32* %6)
%46 = icmp eq i32* %45, null
br i1 %46, label %47, label %20
47: ; preds = %44, %13
%48 = call i32 @depmod_add_fake_syms(%struct.depmod* %0)
%49 = load i32, i32* @LOG_DEBUG
%50 = call i32 (i32, i8*, i8*, ...) @_log(i32 %49, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i8* %1)
%51 = call i32 @fclose(i32* %6)
br label %52
52: ; preds = %47, %8
%53 = phi i32 [ %10, %8 ], [ 0, %47 ]
ret i32 %53
}