#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 depmod {
  int dummy;
};
typedef int /*<<< orphan*/ line;
typedef int /*<<< orphan*/ ksymstr;
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 *,
                                     int /*<<< orphan*/, int /*<<< orphan*/ *);
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
char *strchr(char *, char);
scalar_t__ strncmp(char *, char const *, size_t const);
int depmod_load_system_map(struct depmod *depmod, const char *filename) {
  const char ksymstr[] = "__ksymtab_";
  const size_t ksymstr_len = sizeof(ksymstr) - 1;
  char line[10240];
  FILE *fp;
  unsigned int linenum = 0;
  fp = fopen(filename, "r");
  if (fp == NULL) {
    int err = -errno;
    _log(LOG_DEBUG, "load System.map: %s: %m\n", filename);
    return err;
  }
  _log(LOG_DEBUG, "load System.map: %s\n", filename);
  while (fgets(line, sizeof(line), fp) != NULL) {
    char *p, *end;
    linenum++;
    p = strchr(line, ' ');
    if (p == NULL)
      goto invalid_syntax;
    p++;
    p = strchr(p, ' ');
    if (p == NULL)
      goto invalid_syntax;
    p++;
    if (strncmp(p, ksymstr, ksymstr_len) != 0)
      continue;
    end = strchr(p, '\n');
    if (end != NULL)
      *end = '\0';
    depmod_symbol_add(depmod, p + ksymstr_len, 0, NULL);
    continue;
  invalid_syntax:
    _log(LOG_ERR, "%s:%u: invalid line: %s\n", filename, linenum, line);
  }
  depmod_add_fake_syms(depmod);
  _log(LOG_DEBUG, "loaded System.map: %s\n", filename);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<depmod_load_system_map>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2850,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0xe66(%rip),%rax
mov    %rax,-0x23(%rbp)
mov    0xe63(%rip),%ax
mov    %ax,-0x1b(%rbp)
mov    0xe5b(%rip),%al
mov    %al,-0x19(%rbp)
movq   $0xa,-0x30(%rbp)
movl   $0x0,-0x283c(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe3c(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x2838(%rbp)
cmpq   $0x0,-0x2838(%rbp)
jne    1223 <depmod_load_system_map+0xa3>
xor    %eax,%eax
mov    0x2dee(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x2840(%rbp)
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdff(%rip),%rsi
mov    $0x0,%al
call   1040 <_log@plt>
mov    -0x2840(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13c0 <depmod_load_system_map+0x240>
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdef(%rip),%rsi
mov    $0x0,%al
call   1040 <_log@plt>
lea    -0x2830(%rbp),%rdi
mov    -0x2838(%rbp),%rdx
mov    $0x2800,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     1389 <depmod_load_system_map+0x209>
mov    -0x283c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x283c(%rbp)
lea    -0x2830(%rbp),%rdi
mov    $0x20,%esi
call   1070 <strchr@plt>
mov    %rax,-0x2848(%rbp)
cmpq   $0x0,-0x2848(%rbp)
jne    129a <depmod_load_system_map+0x11a>
jmp    135c <depmod_load_system_map+0x1dc>
mov    -0x2848(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x2848(%rbp)
mov    -0x2848(%rbp),%rdi
mov    $0x20,%esi
call   1070 <strchr@plt>
mov    %rax,-0x2848(%rbp)
cmpq   $0x0,-0x2848(%rbp)
jne    12d7 <depmod_load_system_map+0x157>
jmp    135c <depmod_load_system_map+0x1dc>
mov    -0x2848(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x2848(%rbp)
mov    -0x2848(%rbp),%rdi
lea    -0x23(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     130d <depmod_load_system_map+0x18d>
jmp    123e <depmod_load_system_map+0xbe>
mov    -0x2848(%rbp),%rdi
mov    $0xa,%esi
call   1070 <strchr@plt>
mov    %rax,-0x2850(%rbp)
cmpq   $0x0,-0x2850(%rbp)
je     133d <depmod_load_system_map+0x1bd>
mov    -0x2850(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x2848(%rbp),%rsi
add    $0xa,%rsi
xor    %edx,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   10a0 <depmod_symbol_add@plt>
jmp    123e <depmod_load_system_map+0xbe>
mov    0x2c65(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x283c(%rbp),%ecx
lea    -0x2830(%rbp),%r8
lea    0xcbe(%rip),%rsi
mov    $0x0,%al
call   1040 <_log@plt>
jmp    123e <depmod_load_system_map+0xbe>
mov    -0x10(%rbp),%rdi
call   1060 <depmod_add_fake_syms@plt>
mov    0x2c3f(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xcae(%rip),%rsi
mov    $0x0,%al
call   1040 <_log@plt>
mov    -0x2838(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2850,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<depmod_load_system_map>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2828,%rsp
mov    %rsi,%r12
mov    %rdi,0x8(%rsp)
movabs $0x61746d79736b5f5f,%rax
6d 74 61
mov    %rax,0x10(%rsp)
movl   $0x5f6261,0x17(%rsp)
lea    0xe54(%rip),%rsi
mov    %r12,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     12ec <depmod_load_system_map+0x16c>
mov    %rax,%r13
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <_log@plt>
lea    0x20(%rsp),%rdi
mov    $0x2800,%esi
mov    %r13,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     12bc <depmod_load_system_map+0x13c>
mov    $0x1,%ebx
lea    0x20(%rsp),%rbp
jmp    1247 <depmod_load_system_map+0xc7>
nopl   0x0(%rax)
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
lea    0xe1b(%rip),%rsi
mov    %r12,%rdx
mov    %ebx,%ecx
mov    %rbp,%r8
xor    %eax,%eax
call   1040 <_log@plt>
mov    %rbp,%rdi
mov    $0x2800,%esi
mov    %r13,%rdx
call   1080 <fgets@plt>
add    $0x1,%ebx
test   %rax,%rax
je     12bc <depmod_load_system_map+0x13c>
mov    %rbp,%rdi
mov    $0x20,%esi
call   1070 <strchr@plt>
test   %rax,%rax
je     1210 <depmod_load_system_map+0x90>
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x20,%esi
call   1070 <strchr@plt>
test   %rax,%rax
je     1210 <depmod_load_system_map+0x90>
mov    %rax,%r15
lea    0x1(%rax),%r14
mov    $0xa,%edx
mov    %r14,%rdi
lea    0x10(%rsp),%rsi
call   1030 <strncmp@plt>
test   %rax,%rax
jne    122f <depmod_load_system_map+0xaf>
mov    %r14,%rdi
mov    $0xa,%esi
call   1070 <strchr@plt>
test   %rax,%rax
je     12a2 <depmod_load_system_map+0x122>
movb   $0x0,(%rax)
add    $0xb,%r15
mov    0x8(%rsp),%rdi
mov    %r15,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   10a0 <depmod_symbol_add@plt>
jmp    122f <depmod_load_system_map+0xaf>
mov    0x8(%rsp),%rdi
call   1060 <depmod_add_fake_syms@plt>
mov    0x2d0b(%rip),%rax
mov    (%rax),%edi
lea    0xd7e(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <_log@plt>
mov    %r13,%rdi
call   1050 <fclose@plt>
xor    %ebx,%ebx
jmp    1311 <depmod_load_system_map+0x191>
mov    0x2ced(%rip),%rax
xor    %ebx,%ebx
sub    (%rax),%ebx
mov    0x2cda(%rip),%rax
mov    (%rax),%edi
lea    0xd06(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <_log@plt>
mov    %ebx,%eax
add    $0x2828,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.depmod = type { i32 }
@__const.depmod_load_system_map.ksymstr = [11 x i8] c"__ksymtab_\00"
@.str = [2 x i8] c"r\00"
@errno = global i32 0
@LOG_DEBUG = global i32 0
@.str.1 = [25 x i8] c"load System.map: %s: %m\0A\00"
@.str.2 = [21 x i8] c"load System.map: %s\0A\00"
@LOG_ERR = global i32 0
@.str.3 = [25 x i8] c"%s:%u: invalid line: %s\0A\00"
@.str.4 = [23 x i8] c"loaded System.map: %s\0A\00"
define i32 @depmod_load_system_map(%struct.depmod* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.depmod*
%5 = alloca i8*
%6 = alloca [11 x i8]
%7 = alloca i64
%8 = alloca [10240 x i8]
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
store %struct.depmod* %0, %struct.depmod** %4
store i8* %1, i8** %5
%14 = bitcast [11 x i8]* %6 to i8*
store i64 10, i64* %7
store i32 0, i32* %10
%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** %9
%17 = load i32*, i32** %9
%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* %11
%22 = load i32, i32* @LOG_DEBUG
%23 = load i8*, i8** %5
%24 = call i32 (i32, i8*, i8*, ...) @_log(i32 %22, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = load i32, i32* %11
store i32 %25, i32* %3
br label %85
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 ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %71, %66, %58, %26
%31 = getelementptr inbounds [10240 x i8], [10240 x i8]* %8, i64 0, i64 0
%32 = load i32*, i32** %9
%33 = call i32* @fgets(i8* %31, i32 10240, i32* %32)
%34 = icmp ne i32* %33, null
br i1 %34, label %35, label %77
35: ; preds = %30
%36 = load i32, i32* %10
%37 = add i32 %36, 1
store i32 %37, i32* %10
%38 = getelementptr inbounds [10240 x i8], [10240 x i8]* %8, i64 0, i64 0
%39 = call i8* @strchr(i8* %38, i8 signext 32)
store i8* %39, i8** %12
%40 = load i8*, i8** %12
%41 = icmp eq i8* %40, null
br i1 %41, label %42, label %43
42: ; preds = %35
br label %71
43: ; preds = %35
%44 = load i8*, i8** %12
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %12
%46 = load i8*, i8** %12
%47 = call i8* @strchr(i8* %46, i8 signext 32)
store i8* %47, i8** %12
%48 = load i8*, i8** %12
%49 = icmp eq i8* %48, null
br i1 %49, label %50, label %51
50: ; preds = %43
br label %71
51: ; preds = %43
%52 = load i8*, i8** %12
%53 = getelementptr inbounds i8, i8* %52, i32 1
store i8* %53, i8** %12
%54 = load i8*, i8** %12
%55 = getelementptr inbounds [11 x i8], [11 x i8]* %6, i64 0, i64 0
%56 = call i64 @strncmp(i8* %54, i8* %55, i64 10)
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %59
58: ; preds = %51
br label %30
59: ; preds = %51
%60 = load i8*, i8** %12
%61 = call i8* @strchr(i8* %60, i8 signext 10)
store i8* %61, i8** %13
%62 = load i8*, i8** %13
%63 = icmp ne i8* %62, null
br i1 %63, label %64, label %66
64: ; preds = %59
%65 = load i8*, i8** %13
store i8 0, i8* %65
br label %66
66: ; preds = %64, %59
%67 = load %struct.depmod*, %struct.depmod** %4
%68 = load i8*, i8** %12
%69 = getelementptr inbounds i8, i8* %68, i64 10
%70 = call i32 @depmod_symbol_add(%struct.depmod* %67, i8* %69, i32 0, i32* null)
br label %30
71: ; preds = %50, %42
%72 = load i32, i32* @LOG_ERR
%73 = load i8*, i8** %5
%74 = load i32, i32* %10
%75 = getelementptr inbounds [10240 x i8], [10240 x i8]* %8, i64 0, i64 0
%76 = call i32 (i32, i8*, i8*, ...) @_log(i32 %72, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %73, i32 %74, i8* %75)
br label %30
77: ; preds = %30
%78 = load %struct.depmod*, %struct.depmod** %4
%79 = call i32 @depmod_add_fake_syms(%struct.depmod* %78)
%80 = load i32, i32* @LOG_DEBUG
%81 = load i8*, i8** %5
%82 = call i32 (i32, i8*, i8*, ...) @_log(i32 %80, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %81)
%83 = load i32*, i32** %9
%84 = call i32 @fclose(i32* %83)
store i32 0, i32* %3
br label %85
85: ; preds = %77, %19
%86 = load i32, i32* %3
ret i32 %86
}

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