#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 */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ pevent_register_function(struct pevent *, char *,
                                            unsigned long long, char *);
int sscanf(char *, char *, float *, char *, float *, float *);
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;
  int ret;
  line = strtok_r(file, "\n", &next);
  while (line) {
    mod = NULL;
    ret = sscanf(line, "%as %c %as\t[%as", (float *)(void *)&addr_str, &ch,
                 (float *)(void *)&func, (float *)(void *)&mod);
    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    0xe7a(%rip),%rsi
lea    -0x38(%rbp),%rdx
call   1050 <strtok_r@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1268 <parse_proc_kallsyms+0x108>
movq   $0x0,-0x48(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x40(%rbp),%rdx
lea    -0x28(%rbp),%r8
lea    -0x48(%rbp),%r9
lea    0xe45(%rip),%rsi
lea    -0x49(%rbp),%rcx
call   1080 <sscanf@plt>
mov    %eax,-0x50(%rbp)
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     1214 <parse_proc_kallsyms+0xb4>
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     1239 <parse_proc_kallsyms+0xd9>
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    0xdaa(%rip),%rsi
lea    -0x38(%rbp),%rdx
call   1050 <strtok_r@plt>
mov    %rax,-0x30(%rbp)
jmp    1193 <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,0x20(%rsp)
lea    0xe7a(%rip),%rsi
lea    0x20(%rsp),%rdx
mov    %rax,%rdi
call   1050 <strtok_r@plt>
test   %rax,%rax
je     1272 <parse_proc_kallsyms+0x112>
lea    0x28(%rsp),%rbx
lea    0x10(%rsp),%rbp
lea    0xe53(%rip),%r14
lea    0x20(%rsp),%r15
jmp    11e8 <parse_proc_kallsyms+0x88>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
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     1272 <parse_proc_kallsyms+0x112>
movq   $0x0,0x10(%rsp)
mov    %rax,%rdi
lea    0xe07(%rip),%rsi
lea    0x18(%rsp),%rdx
lea    0xf(%rsp),%rcx
mov    %rbx,%r8
mov    %rbp,%r9
call   1080 <sscanf@plt>
mov    0x18(%rsp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <strtoull@plt>
mov    %rax,%r12
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%r13
test   %r13,%r13
je     1248 <parse_proc_kallsyms+0xe8>
mov    %r13,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r13,1)
mov    0x28(%rsp),%rsi
cmpb   $0x24,(%rsi)
je     11c0 <parse_proc_kallsyms+0x60>
mov    0x10(%rsp),%rcx
mov    0x30(%rsp),%rdi
mov    %r12,%rdx
call   1070 <pevent_register_function@plt>
mov    0x28(%rsp),%rsi
jmp    11c0 <parse_proc_kallsyms+0x60>
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"
@.str.1 = [16 x i8] c"%as %c %as\09[%as\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
%14 = alloca i32
store %struct.pevent* %0, %struct.pevent** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i8* null, i8** %10
%15 = load i8*, i8** %5
%16 = call i8* @strtok_r(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %10)
store i8* %16, i8** %9
br label %17
17: ; preds = %54, %3
%18 = load i8*, i8** %9
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %60
20: ; preds = %17
store i8* null, i8** %12
%21 = load i8*, i8** %9
%22 = bitcast i8** %11 to i8*
%23 = bitcast i8* %22 to float*
%24 = bitcast i8** %8 to i8*
%25 = bitcast i8* %24 to float*
%26 = bitcast i8** %12 to i8*
%27 = bitcast i8* %26 to float*
%28 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), float* %23, i8* %13, float* %25, float* %27)
store i32 %28, i32* %14
%29 = load i8*, i8** %11
%30 = call i64 @strtoull(i8* %29, i32* null, i32 16)
store i64 %30, i64* %7
%31 = load i8*, i8** %11
%32 = call i32 @free(i8* %31)
%33 = load i8*, i8** %12
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %42
35: ; preds = %20
%36 = load i8*, i8** %12
%37 = load i8*, i8** %12
%38 = call i32 @strlen(i8* %37)
%39 = sub nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %36, i64 %40
store i8 0, i8* %41
br label %42
42: ; preds = %35, %20
%43 = load i8*, i8** %8
%44 = getelementptr inbounds i8, i8* %43, i64 0
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp ne i32 %46, 36
br i1 %47, label %48, label %54
48: ; preds = %42
%49 = load %struct.pevent*, %struct.pevent** %4
%50 = load i8*, i8** %8
%51 = load i64, i64* %7
%52 = load i8*, i8** %12
%53 = call i32 @pevent_register_function(%struct.pevent* %49, i8* %50, i64 %51, i8* %52)
br label %54
54: ; preds = %48, %42
%55 = load i8*, i8** %8
%56 = call i32 @free(i8* %55)
%57 = load i8*, i8** %12
%58 = call i32 @free(i8* %57)
%59 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %10)
store i8* %59, i8** %9
br label %17
60: ; preds = %17
ret void
}

LLVM IR (-O2):
%struct.pevent = type { i32 }
@.str = [2 x i8] c"\0A\00"
@.str.1 = [16 x i8] c"%as %c %as\09[%as\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 %48, label %15
15: ; preds = %3
%16 = bitcast i8** %6 to float*
%17 = bitcast i8** %4 to float*
%18 = bitcast i8** %7 to float*
br label %19
19: ; preds = %15, %41
%20 = phi i8* [ %13, %15 ], [ %46, %41 ]
store i8* null, i8** %7
%21 = call i32 @sscanf(i8* %20, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), float* %16, i8* %8, float* %17, float* %18)
%22 = load i8*, i8** %6
%23 = call i64 @strtoull(i8* nocapture %22, i32* null, i32 16)
%24 = load i8*, i8** %6
%25 = call i32 @free(i8* %24)
%26 = load i8*, i8** %7
%27 = icmp eq i8* %26, null
br i1 %27, label %33, label %28
28: ; preds = %19
%29 = call i32 @strlen(i8* %26)
%30 = add nsw i32 %29, -1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %26, i64 %31
store i8 0, i8* %32
br label %33
33: ; preds = %28, %19
%34 = load i8*, i8** %4
%35 = load i8, i8* %34
%36 = icmp eq i8 %35, 36
br i1 %36, label %41, label %37
37: ; preds = %33
%38 = load i8*, i8** %7
%39 = call i32 @pevent_register_function(%struct.pevent* %0, i8* %34, i64 %23, i8* %38)
%40 = load i8*, i8** %4
br label %41
41: ; preds = %37, %33
%42 = phi i8* [ %40, %37 ], [ %34, %33 ]
%43 = call i32 @free(i8* %42)
%44 = load i8*, i8** %7
%45 = call i32 @free(i8* %44)
%46 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %5)
%47 = icmp eq i8* %46, null
br i1 %47, label %48, label %19
48: ; preds = %41, %3
ret void
}