#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 */

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *malloc_or_die(unsigned int);
int /*<<< orphan*/ parse_proc_kallsyms(char *, unsigned int);
unsigned int read4();
int /*<<< orphan*/ read_or_die(char *, unsigned int);
void read_proc_kallsyms(void) {
  unsigned int size;
  char *buf;
  size = read4();
  if (!size)
    return;
  buf = malloc_or_die(size + 1);
  read_or_die(buf, size);
  buf[size] = '\0';
  parse_proc_kallsyms(buf, size);
  free(buf);
}


x86 assembly (clang, -O0):
<read_proc_kallsyms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1040 <read4@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1171 <read_proc_kallsyms+0x21>
jmp    11ac <read_proc_kallsyms+0x5c>
mov    -0x4(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc_or_die@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1060 <read_or_die@plt>
mov    -0x10(%rbp),%rax
mov    -0x4(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1070 <parse_proc_kallsyms@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_proc_kallsyms>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <read4@plt>
test   %eax,%eax
je     1196 <read_proc_kallsyms+0x46>
mov    %eax,%ebx
lea    0x1(%rbx),%edi
call   1050 <malloc_or_die@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %ebx,%esi
call   1060 <read_or_die@plt>
mov    %ebx,%eax
movb   $0x0,(%r14,%rax,1)
mov    %r14,%rdi
mov    %ebx,%esi
call   1070 <parse_proc_kallsyms@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <free@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @read_proc_kallsyms() {
%1 = alloca i32
%2 = alloca i8*
%3 = call i32 (...) @read4()
store i32 %3, i32* %1
%4 = load i32, i32* %1
%5 = icmp ne i32 %4, 0
br i1 %5, label %7, label %6
6: ; preds = %0
br label %23
7: ; preds = %0
%8 = load i32, i32* %1
%9 = add i32 %8, 1
%10 = call i8* @malloc_or_die(i32 %9)
store i8* %10, i8** %2
%11 = load i8*, i8** %2
%12 = load i32, i32* %1
%13 = call i32 @read_or_die(i8* %11, i32 %12)
%14 = load i8*, i8** %2
%15 = load i32, i32* %1
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
store i8 0, i8* %17
%18 = load i8*, i8** %2
%19 = load i32, i32* %1
%20 = call i32 @parse_proc_kallsyms(i8* %18, i32 %19)
%21 = load i8*, i8** %2
%22 = call i32 @free(i8* %21)
br label %23
23: ; preds = %7, %6
ret void
}

LLVM IR (-O2):
define void @read_proc_kallsyms() {
%1 = tail call i32 (...) @read4()
%2 = icmp eq i32 %1, 0
br i1 %2, label %11, label %3
3: ; preds = %0
%4 = add i32 %1, 1
%5 = tail call i8* @malloc_or_die(i32 %4)
%6 = tail call i32 @read_or_die(i8* %5, i32 %1)
%7 = zext i32 %1 to i64
%8 = getelementptr inbounds i8, i8* %5, i64 %7
store i8 0, i8* %8
%9 = tail call i32 @parse_proc_kallsyms(i8* %5, i32 %1)
%10 = tail call i32 @free(i8* %5)
br label %11
11: ; preds = %0, %3
ret void
}