#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 pevent {
  int dummy;
};

/* Variables and functions */
scalar_t__ errno;
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pevent_register_function(struct pevent *, char *,
                                            unsigned long long, char *);
int /*<<< orphan*/ sscanf(char *, char *, char **, char *, char **, char **);
int strlen(char *);
char *strtok_r(char *, char *, char **);
unsigned long long strtoull(char *, int /*<<< orphan*/ *, int);
void parse_proc_kallsyms(struct pevent *pevent, char *file,
                         unsigned int size __attribute__((unused))) {
  unsigned long long addr;
  char *func;
  char *line;
  char *next = NULL;
  char *addr_str;
  char *mod;
  char ch;
  line = strtok_r(file, "\n", &next);
  while (line) {
    mod = NULL;
    errno = 0;
    sscanf(line, "%ms %c %ms\t[%ms", &addr_str, &ch, &func, &mod);
    if (errno) {
      free(addr_str);
      free(func);
      free(mod);
      perror("sscanf");
      return;
    }
    addr = strtoull(addr_str, NULL, 16);
    free(addr_str);
    if (mod)
      mod[strlen(mod) - 1] = 0;
    if (func[0] != '$')
      pevent_register_function(pevent, func, addr, mod);
    free(func);
    free(mod);
    line = strtok_r(NULL, "\n", &next);
  }
}


x86 assembly (clang, -O0):
<parse_proc_kallsyms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe6a(%rip),%rsi
lea    -0x38(%rbp),%rdx
call   1050 <strtok_r@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     12c0 <parse_proc_kallsyms+0x150>
movq   $0x0,-0x48(%rbp)
mov    0x2e23(%rip),%rax
movq   $0x0,(%rax)
mov    -0x30(%rbp),%rdi
lea    0xe33(%rip),%rsi
lea    -0x40(%rbp),%rdx
lea    -0x49(%rbp),%rcx
lea    -0x28(%rbp),%r8
lea    -0x48(%rbp),%r9
call   1080 <sscanf@plt>
mov    0x2df5(%rip),%rax
cmpq   $0x0,(%rax)
je     1221 <parse_proc_kallsyms+0xb1>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
lea    0xdfb(%rip),%rdi
call   1090 <perror@plt>
jmp    12c0 <parse_proc_kallsyms+0x150>
mov    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1060 <strtoull@plt>
mov    %rax,-0x20(%rbp)
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x48(%rbp)
je     126c <parse_proc_kallsyms+0xfc>
mov    -0x48(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x48(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x58(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x24,%eax
je     1291 <parse_proc_kallsyms+0x121>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x48(%rbp),%rcx
call   1070 <pevent_register_function@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd52(%rip),%rsi
lea    -0x38(%rbp),%rdx
call   1050 <strtok_r@plt>
mov    %rax,-0x30(%rbp)
jmp    11a3 <parse_proc_kallsyms+0x33>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_proc_kallsyms>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%rax
mov    %rdi,0x30(%rsp)
movq   $0x0,0x28(%rsp)
lea    0xe6a(%rip),%rsi
lea    0x28(%rsp),%rdx
mov    %rax,%rdi
call   1050 <strtok_r@plt>
test   %rax,%rax
je     12b6 <parse_proc_kallsyms+0x146>
mov    0x2e2d(%rip),%rbx
lea    0x10(%rsp),%rbp
lea    0xe41(%rip),%r14
lea    0x28(%rsp),%r15
jmp    11f8 <parse_proc_kallsyms+0x88>
cs nopw 0x0(%rax,%rax,1)
mov    %rsi,%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
xor    %edi,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <strtok_r@plt>
test   %rax,%rax
je     12b6 <parse_proc_kallsyms+0x146>
movq   $0x0,0x10(%rsp)
movq   $0x0,(%rbx)
mov    %rax,%rdi
lea    0xdf0(%rip),%rsi
lea    0x20(%rsp),%rdx
lea    0xf(%rsp),%rcx
lea    0x18(%rsp),%r8
mov    %rbp,%r9
call   1080 <sscanf@plt>
cmpq   $0x0,(%rbx)
mov    0x20(%rsp),%rdi
jne    1291 <parse_proc_kallsyms+0x121>
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <strtoull@plt>
mov    %rax,%r12
mov    0x20(%rsp),%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%r13
test   %r13,%r13
je     1267 <parse_proc_kallsyms+0xf7>
mov    %r13,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r13,1)
mov    0x18(%rsp),%rsi
cmpb   $0x24,(%rsi)
je     11d0 <parse_proc_kallsyms+0x60>
mov    0x10(%rsp),%rcx
mov    0x30(%rsp),%rdi
mov    %r12,%rdx
call   1070 <pevent_register_function@plt>
mov    0x18(%rsp),%rsi
jmp    11d0 <parse_proc_kallsyms+0x60>
call   1030 <free@plt>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
lea    0xd61(%rip),%rdi
call   1090 <perror@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.pevent = type { i32 }
@.str = [2 x i8] c"\0A\00"
@errno = global i64 0
@.str.1 = [16 x i8] c"%ms %c %ms\09[%ms\00"
@.str.2 = [7 x i8] c"sscanf\00"
define void @parse_proc_kallsyms(%struct.pevent* %0, i8* %1, i32 %2) {
%4 = alloca %struct.pevent*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8
store %struct.pevent* %0, %struct.pevent** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i8* null, i8** %10
%14 = load i8*, i8** %5
%15 = call i8* @strtok_r(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %10)
store i8* %15, i8** %9
br label %16
16: ; preds = %58, %3
%17 = load i8*, i8** %9
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %64
19: ; preds = %16
store i8* null, i8** %12
store i64 0, i64* @errno
%20 = load i8*, i8** %9
%21 = call i32 @sscanf(i8* %20, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8** %11, i8* %13, i8** %8, i8** %12)
%22 = load i64, i64* @errno
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %32
24: ; preds = %19
%25 = load i8*, i8** %11
%26 = call i32 @free(i8* %25)
%27 = load i8*, i8** %8
%28 = call i32 @free(i8* %27)
%29 = load i8*, i8** %12
%30 = call i32 @free(i8* %29)
%31 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %64
32: ; preds = %19
%33 = load i8*, i8** %11
%34 = call i64 @strtoull(i8* %33, i32* null, i32 16)
store i64 %34, i64* %7
%35 = load i8*, i8** %11
%36 = call i32 @free(i8* %35)
%37 = load i8*, i8** %12
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %46
39: ; preds = %32
%40 = load i8*, i8** %12
%41 = load i8*, i8** %12
%42 = call i32 @strlen(i8* %41)
%43 = sub nsw i32 %42, 1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %40, i64 %44
store i8 0, i8* %45
br label %46
46: ; preds = %39, %32
%47 = load i8*, i8** %8
%48 = getelementptr inbounds i8, i8* %47, i64 0
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp ne i32 %50, 36
br i1 %51, label %52, label %58
52: ; preds = %46
%53 = load %struct.pevent*, %struct.pevent** %4
%54 = load i8*, i8** %8
%55 = load i64, i64* %7
%56 = load i8*, i8** %12
%57 = call i32 @pevent_register_function(%struct.pevent* %53, i8* %54, i64 %55, i8* %56)
br label %58
58: ; preds = %52, %46
%59 = load i8*, i8** %8
%60 = call i32 @free(i8* %59)
%61 = load i8*, i8** %12
%62 = call i32 @free(i8* %61)
%63 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %10)
store i8* %63, i8** %9
br label %16
64: ; preds = %24, %16
ret void
}

LLVM IR (-O2):
%struct.pevent = type { i32 }
@.str = [2 x i8] c"\0A\00"
@errno = global i64 0
@.str.1 = [16 x i8] c"%ms %c %ms\09[%ms\00"
@.str.2 = [7 x i8] c"sscanf\00"
define void @parse_proc_kallsyms(%struct.pevent* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8
%9 = bitcast i8** %4 to i8*
%10 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%11 = bitcast i8** %6 to i8*
%12 = bitcast i8** %7 to i8*
%13 = call i8* @strtok_r(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %5)
%14 = icmp eq i8* %13, null
br i1 %14, label %54, label %15
15: ; preds = %3, %47
%16 = phi i8* [ %52, %47 ], [ %13, %3 ]
store i8* null, i8** %7
store i64 0, i64* @errno
%17 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8** %6, i8* %8, i8** %4, i8** %7)
%18 = load i64, i64* @errno
%19 = icmp eq i64 %18, 0
%20 = load i8*, i8** %6
br i1 %19, label %28, label %21
21: ; preds = %15
%22 = call i32 @free(i8* %20)
%23 = load i8*, i8** %4
%24 = call i32 @free(i8* %23)
%25 = load i8*, i8** %7
%26 = call i32 @free(i8* %25)
%27 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %54
28: ; preds = %15
%29 = call i64 @strtoull(i8* nocapture %20, i32* null, i32 16)
%30 = load i8*, i8** %6
%31 = call i32 @free(i8* %30)
%32 = load i8*, i8** %7
%33 = icmp eq i8* %32, null
br i1 %33, label %39, label %34
34: ; preds = %28
%35 = call i32 @strlen(i8* %32)
%36 = add nsw i32 %35, -1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %32, i64 %37
store i8 0, i8* %38
br label %39
39: ; preds = %34, %28
%40 = load i8*, i8** %4
%41 = load i8, i8* %40
%42 = icmp eq i8 %41, 36
br i1 %42, label %47, label %43
43: ; preds = %39
%44 = load i8*, i8** %7
%45 = call i32 @pevent_register_function(%struct.pevent* %0, i8* %40, i64 %29, i8* %44)
%46 = load i8*, i8** %4
br label %47
47: ; preds = %43, %39
%48 = phi i8* [ %46, %43 ], [ %40, %39 ]
%49 = call i32 @free(i8* %48)
%50 = load i8*, i8** %7
%51 = call i32 @free(i8* %50)
%52 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %5)
%53 = icmp eq i8* %52, null
br i1 %53, label %54, label %15
54: ; preds = %47, %3, %21
ret void
}