#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*/ kfree(char *);
char *kmalloc(int);
int /*<<< orphan*/ kprintf(char *, ...);
int /*<<< orphan*/ kread(char *, int, int);
void __kern_shell_load(void) {
  char *header;
  unsigned int a_text;
  unsigned int a_data;
  unsigned int a_tbase;
  unsigned int a_dbase;
  header = kmalloc(88);
  kprintf("Reading header... ");
  kread(header, 88, 1);
  kprintf("done\n");
  a_text = ((unsigned int)((*(header + 8 + 1) << 8) + (*(header + 8))));
  kprintf("Reading %u bytes of code... ", a_text);
  kprintf("done\n");
  a_data = ((unsigned int)((*(header + 16 + 1) << 8) + (*(header + 16))));
  kprintf("Reading %u bytes of code... ", a_data);
  kprintf("done\n");
  kfree(header);
}


x86 assembly (clang, -O0):
<__kern_shell_load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x58,%edi
call   1060 <kmalloc@plt>
mov    %rax,-0x8(%rbp)
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1050 <kprintf@plt>
mov    -0x8(%rbp),%rdi
mov    $0x58,%esi
mov    $0x1,%edx
call   1040 <kread@plt>
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1050 <kprintf@plt>
mov    -0x8(%rbp),%rax
movsbl 0x9(%rax),%eax
shl    $0x8,%eax
mov    -0x8(%rbp),%rcx
movsbl 0x8(%rcx),%ecx
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1050 <kprintf@plt>
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1050 <kprintf@plt>
mov    -0x8(%rbp),%rax
movsbl 0x11(%rax),%eax
shl    $0x8,%eax
mov    -0x8(%rbp),%rcx
movsbl 0x10(%rcx),%ecx
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1050 <kprintf@plt>
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1050 <kprintf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <kfree@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__kern_shell_load>:
push   %r15
push   %r14
push   %rbx
mov    $0x58,%edi
call   1060 <kmalloc@plt>
mov    %rax,%rbx
lea    0xea7(%rip),%rdi
xor    %eax,%eax
call   1050 <kprintf@plt>
mov    %rbx,%rdi
mov    $0x58,%esi
mov    $0x1,%edx
call   1040 <kread@plt>
lea    0xe9a(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <kprintf@plt>
movsbl 0x9(%rbx),%eax
shl    $0x8,%eax
movsbl 0x8(%rbx),%esi
add    %eax,%esi
lea    0xe82(%rip),%r15
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <kprintf@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <kprintf@plt>
movsbl 0x11(%rbx),%eax
shl    $0x8,%eax
movsbl 0x10(%rbx),%esi
add    %eax,%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <kprintf@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <kprintf@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <kfree@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"Reading header... \00"
@.str.1 = [6 x i8] c"done\0A\00"
@.str.2 = [29 x i8] c"Reading %u bytes of code... \00"
define void @__kern_shell_load() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = call i8* @kmalloc(i32 88)
store i8* %6, i8** %1
%7 = call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%8 = load i8*, i8** %1
%9 = call i32 @kread(i8* %8, i32 88, i32 1)
%10 = call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%11 = load i8*, i8** %1
%12 = getelementptr inbounds i8, i8* %11, i64 8
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = shl i32 %15, 8
%17 = load i8*, i8** %1
%18 = getelementptr inbounds i8, i8* %17, i64 8
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = add nsw i32 %16, %20
store i32 %21, i32* %2
%22 = load i32, i32* %2
%23 = call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %22)
%24 = call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%25 = load i8*, i8** %1
%26 = getelementptr inbounds i8, i8* %25, i64 16
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = shl i32 %29, 8
%31 = load i8*, i8** %1
%32 = getelementptr inbounds i8, i8* %31, i64 16
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = add nsw i32 %30, %34
store i32 %35, i32* %3
%36 = load i32, i32* %3
%37 = call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %36)
%38 = call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%39 = load i8*, i8** %1
%40 = call i32 @kfree(i8* %39)
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"Reading header... \00"
@.str.1 = [6 x i8] c"done\0A\00"
@.str.2 = [29 x i8] c"Reading %u bytes of code... \00"
define void @__kern_shell_load() {
%1 = tail call i8* @kmalloc(i32 88)
%2 = tail call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @kread(i8* %1, i32 88, i32 1)
%4 = tail call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%5 = getelementptr inbounds i8, i8* %1, i64 8
%6 = getelementptr inbounds i8, i8* %1, i64 9
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = shl nsw i32 %8, 8
%10 = load i8, i8* %5
%11 = sext i8 %10 to i32
%12 = add nsw i32 %9, %11
%13 = tail call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = tail call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%15 = getelementptr inbounds i8, i8* %1, i64 16
%16 = getelementptr inbounds i8, i8* %1, i64 17
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = shl nsw i32 %18, 8
%20 = load i8, i8* %15
%21 = sext i8 %20 to i32
%22 = add nsw i32 %19, %21
%23 = tail call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %22)
%24 = tail call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%25 = tail call i32 @kfree(i8* %1)
ret void
}