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

/* Variables and functions */
int /*<<< orphan*/ add_symbol(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fatal(char *, char const *, int /*<<< orphan*/);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
char *strchr(char *, char);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
void load_system_map(const char *filename) {
  FILE *system_map;
  char line[10240];
  system_map = fopen(filename, "r");
  if (!system_map)
    fatal("Could not open '%s': %s\n", filename, strerror(errno));
  while (fgets(line, sizeof(line) - 1, system_map)) {
    char *ptr;
    ptr = strchr(line, '\n');
    *ptr = '\0';
    ptr = strchr(line, ' ');
    if (!ptr || !(ptr = strchr(ptr + 1, ' ')))
      continue;
    if (strncmp(ptr + 1, "__ksymtab_", strlen("__ksymtab_")) == 0)
      add_symbol(ptr + 1 + strlen("__ksymtab_"), NULL);
  }
  add_symbol("__this_module", NULL);
  add_symbol("_GLOBAL_OFFSET_TABLE_", NULL);
}


x86 assembly (clang, -O0):
<load_system_map>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2830,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe66(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11dc <load_system_map+0x5c>
mov    -0x8(%rbp),%rax
mov    %rax,-0x2820(%rbp)
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x2820(%rbp),%rsi
mov    %eax,%edx
lea    0xe2b(%rip),%rdi
call   10a0 <fatal@plt>
jmp    11e1 <load_system_map+0x61>
lea    -0x2810(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x27ff,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     12e8 <load_system_map+0x168>
lea    -0x2810(%rbp),%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
mov    %rax,-0x2818(%rbp)
mov    -0x2818(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x2810(%rbp),%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
mov    %rax,-0x2818(%rbp)
cmpq   $0x0,-0x2818(%rbp)
je     126e <load_system_map+0xee>
mov    -0x2818(%rbp),%rdi
add    $0x1,%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
mov    %rax,-0x2818(%rbp)
cmp    $0x0,%rax
jne    1273 <load_system_map+0xf3>
jmp    11e1 <load_system_map+0x61>
mov    -0x2818(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x2828(%rbp)
lea    0xd8f(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x2828(%rbp),%rdi
mov    %eax,%edx
lea    0xd7a(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12e3 <load_system_map+0x163>
mov    -0x2818(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x2830(%rbp)
lea    0xd52(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x2830(%rbp),%rdi
cltq
add    %rax,%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <add_symbol@plt>
jmp    11e1 <load_system_map+0x61>
lea    0xd37(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <add_symbol@plt>
lea    0xd35(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <add_symbol@plt>
add    $0x2830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_system_map>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x2808,%rsp
mov    %rdi,%rbx
lea    0xe68(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11c4 <load_system_map+0x44>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe48(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   10a0 <fatal@plt>
mov    %rsp,%rdi
mov    $0x27ff,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     127a <load_system_map+0xfa>
mov    %rsp,%r12
lea    0xe34(%rip),%r15
jmp    1205 <load_system_map+0x85>
nopl   0x0(%rax)
mov    %r12,%rdi
mov    $0x27ff,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     127a <load_system_map+0xfa>
mov    %r12,%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
movb   $0x0,(%rax)
mov    %r12,%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11f0 <load_system_map+0x70>
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11f0 <load_system_map+0x70>
mov    %rax,%rbx
add    $0x1,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11f0 <load_system_map+0x70>
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
add    %rax,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <add_symbol@plt>
jmp    11f0 <load_system_map+0x70>
lea    0xda5(%rip),%rdi
xor    %esi,%esi
call   1060 <add_symbol@plt>
lea    0xda5(%rip),%rdi
xor    %esi,%esi
call   1060 <add_symbol@plt>
add    $0x2808,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [25 x i8] c"Could not open '%s': %s\0A\00"
@errno = global i32 0
@.str.2 = [11 x i8] c"__ksymtab_\00"
@.str.3 = [14 x i8] c"__this_module\00"
@.str.4 = [22 x i8] c"_GLOBAL_OFFSET_TABLE_\00"
define void @load_system_map(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [10240 x i8]
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %3
%8 = load i32*, i32** %3
%9 = icmp ne i32* %8, null
br i1 %9, label %15, label %10
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = load i32, i32* @errno
%13 = call i32 @strerror(i32 %12)
%14 = call i32 @fatal(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %11, i32 %13)
br label %15
15: ; preds = %10, %1
br label %16
16: ; preds = %48, %34, %15
%17 = getelementptr inbounds [10240 x i8], [10240 x i8]* %4, i64 0, i64 0
%18 = load i32*, i32** %3
%19 = call i64 @fgets(i8* %17, i32 10239, i32* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %49
21: ; preds = %16
%22 = getelementptr inbounds [10240 x i8], [10240 x i8]* %4, i64 0, i64 0
%23 = call i8* @strchr(i8* %22, i8 signext 10)
store i8* %23, i8** %5
%24 = load i8*, i8** %5
store i8 0, i8* %24
%25 = getelementptr inbounds [10240 x i8], [10240 x i8]* %4, i64 0, i64 0
%26 = call i8* @strchr(i8* %25, i8 signext 32)
store i8* %26, i8** %5
%27 = load i8*, i8** %5
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %34
29: ; preds = %21
%30 = load i8*, i8** %5
%31 = getelementptr inbounds i8, i8* %30, i64 1
%32 = call i8* @strchr(i8* %31, i8 signext 32)
store i8* %32, i8** %5
%33 = icmp ne i8* %32, null
br i1 %33, label %35, label %34
34: ; preds = %29, %21
br label %16
35: ; preds = %29
%36 = load i8*, i8** %5
%37 = getelementptr inbounds i8, i8* %36, i64 1
%38 = call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%39 = call i64 @strncmp(i8* %37, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %38)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %48
41: ; preds = %35
%42 = load i8*, i8** %5
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = call i32 @add_symbol(i8* %46, i32* null)
br label %48
48: ; preds = %41, %35
br label %16
49: ; preds = %16
%50 = call i32 @add_symbol(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32* null)
%51 = call i32 @add_symbol(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32* null)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [25 x i8] c"Could not open '%s': %s\0A\00"
@errno = global i32 0
@.str.2 = [11 x i8] c"__ksymtab_\00"
@.str.3 = [14 x i8] c"__this_module\00"
@.str.4 = [22 x i8] c"_GLOBAL_OFFSET_TABLE_\00"
define void @load_system_map(i8* %0) {
%2 = alloca [10240 x i8]
%3 = getelementptr inbounds [10240 x i8], [10240 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load i32, i32* @errno
%8 = tail call i32 @strerror(i32 %7)
%9 = tail call i32 @fatal(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %8)
br label %10
10: ; preds = %6, %1
%11 = call i64 @fgets(i8* %3, i32 10239, i32* %4)
%12 = icmp eq i64 %11, 0
br i1 %12, label %34, label %13
13: ; preds = %10, %31
%14 = call i8* @strchr(i8* %3, i8 signext 10)
store i8 0, i8* %14
%15 = call i8* @strchr(i8* %3, i8 signext 32)
%16 = icmp eq i8* %15, null
br i1 %16, label %31, label %17
17: ; preds = %13
%18 = getelementptr inbounds i8, i8* %15, i64 1
%19 = call i8* @strchr(i8* %18, i8 signext 32)
%20 = icmp eq i8* %19, null
br i1 %20, label %31, label %21
21: ; preds = %17
%22 = getelementptr inbounds i8, i8* %19, i64 1
%23 = call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%24 = call i64 @strncmp(i8* %22, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %21
%27 = call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %22, i64 %28
%30 = call i32 @add_symbol(i8* %29, i32* null)
br label %31
31: ; preds = %21, %26, %13, %17
%32 = call i64 @fgets(i8* %3, i32 10239, i32* %4)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %13
34: ; preds = %31, %10
%35 = call i32 @add_symbol(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32* null)
%36 = call i32 @add_symbol(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32* null)
ret void
}