#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*/ haltdump(char *, int);
int /*<<< orphan*/ kccolor(int, int, int);
int /*<<< orphan*/ kclear();
int /*<<< orphan*/ kflip();
int /*<<< orphan*/ kfree(void *);
scalar_t__ kmalloc(size_t);
int /*<<< orphan*/ kmemcpy(void *, void *, size_t);
int /*<<< orphan*/ kmemset(void *, int, size_t);
int /*<<< orphan*/ kprint(int, char *, int);
int /*<<< orphan*/ kprintnum(int, int, int, int);
int /*<<< orphan*/ kputchar(int, int, int);
int /*<<< orphan*/ kputstring(int, char *, int, int);
scalar_t__ krealloc(void *, size_t);
int /*<<< orphan*/ kscroll();
int /*<<< orphan*/ ksleep(int);
int /*<<< orphan*/ ksync();
int process_syscall(int eax, int ebx, int ecx, int edx, int esi) {
  switch (eax) {
  case 0x0:
    ksleep(ebx);
    break;
  case 0x1:
    break;
  case 0x2:
    kclear();
    break;
  case 0x3:
    return (int)kmalloc((size_t)ebx);
  case 0x4:
    return (int)krealloc((void *)ebx, (size_t)ecx);
  case 0x5:
    kfree((void *)ebx);
    break;
  case 0x6:
    kmemcpy((void *)ebx, (void *)ecx, (size_t)edx);
    break;
  case 0x7:
    kmemset((void *)ebx, ecx, (size_t)edx);
    break;
  case 0x8:
    kputchar(ebx, ecx, edx);
    break;
  case 0x9:
    kputstring(ebx, (char *)ecx, edx, esi);
    break;
  case 0xA:
    kprint(ebx, (char *)ecx, edx);
    break;
  case 0xB:
    kprintnum(ebx, ecx, edx, esi);
    break;
  case 0xC:
    kccolor(ebx, ecx, edx);
    break;
  case 0xD:
    kscroll();
    break;
  case 0xE:
    kflip();
    break;
  case 0xF:
    ksync();
    break;
  default:
    haltdump("Unknown or invalid system call.", 13);
  }
  return (int)NULL;
}


x86 assembly (clang, -O0):
<process_syscall>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %rax,-0x20(%rbp)
sub    $0xf,%rax
ja     1345 <process_syscall+0x145>
mov    -0x20(%rbp),%rax
lea    0xdcc(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0xc(%rbp),%edi
call   1100 <ksleep@plt>
jmp    1356 <process_syscall+0x156>
jmp    1356 <process_syscall+0x156>
mov    $0x0,%al
call   1050 <kclear@plt>
jmp    1356 <process_syscall+0x156>
movslq -0xc(%rbp),%rdi
call   1110 <kmalloc@plt>
mov    %eax,-0x4(%rbp)
jmp    135d <process_syscall+0x15d>
movslq -0xc(%rbp),%rdi
movslq -0x10(%rbp),%rsi
call   10f0 <krealloc@plt>
mov    %eax,-0x4(%rbp)
jmp    135d <process_syscall+0x15d>
movslq -0xc(%rbp),%rdi
call   1070 <kfree@plt>
jmp    1356 <process_syscall+0x156>
movslq -0xc(%rbp),%rdi
movslq -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rdx
call   10d0 <kmemcpy@plt>
jmp    1356 <process_syscall+0x156>
movslq -0xc(%rbp),%rdi
mov    -0x10(%rbp),%esi
movslq -0x14(%rbp),%rdx
call   1120 <kmemset@plt>
jmp    1356 <process_syscall+0x156>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
call   10e0 <kputchar@plt>
jmp    1356 <process_syscall+0x156>
mov    -0xc(%rbp),%edi
movslq -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1060 <kputstring@plt>
jmp    1356 <process_syscall+0x156>
mov    -0xc(%rbp),%edi
movslq -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   10b0 <kprint@plt>
jmp    1356 <process_syscall+0x156>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1090 <kprintnum@plt>
jmp    1356 <process_syscall+0x156>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1030 <kccolor@plt>
jmp    1356 <process_syscall+0x156>
mov    $0x0,%al
call   10a0 <kscroll@plt>
jmp    1356 <process_syscall+0x156>
mov    $0x0,%al
call   1040 <kflip@plt>
jmp    1356 <process_syscall+0x156>
mov    $0x0,%al
call   1080 <ksync@plt>
jmp    1356 <process_syscall+0x156>
lea    0xcf4(%rip),%rdi
mov    $0xd,%esi
call   10c0 <haltdump@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_syscall>:
push   %rbx
xor    %ebx,%ebx
cmp    $0xf,%edi
ja     1226 <process_syscall+0x26>
mov    %edi,%eax
lea    0xdef(%rip),%rdi
movslq (%rdi,%rax,4),%rax
add    %rdi,%rax
jmp    *%rax
mov    %esi,%edi
call   1100 <ksleep@plt>
jmp    130d <process_syscall+0x10d>
lea    0xe13(%rip),%rdi
mov    $0xd,%esi
call   10c0 <haltdump@plt>
jmp    130d <process_syscall+0x10d>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <kclear@plt>
jmp    130d <process_syscall+0x10d>
movslq %esi,%rdi
call   1110 <kmalloc@plt>
mov    %rax,%rbx
jmp    130d <process_syscall+0x10d>
movslq %esi,%rdi
movslq %edx,%rsi
call   10f0 <krealloc@plt>
mov    %rax,%rbx
jmp    130d <process_syscall+0x10d>
movslq %esi,%rdi
call   1070 <kfree@plt>
jmp    130d <process_syscall+0x10d>
movslq %esi,%rdi
movslq %edx,%rsi
movslq %ecx,%rdx
call   10d0 <kmemcpy@plt>
jmp    130d <process_syscall+0x10d>
movslq %esi,%rdi
movslq %ecx,%rax
mov    %edx,%esi
mov    %rax,%rdx
call   1120 <kmemset@plt>
jmp    130d <process_syscall+0x10d>
mov    %esi,%edi
mov    %edx,%esi
mov    %ecx,%edx
call   10e0 <kputchar@plt>
jmp    130d <process_syscall+0x10d>
movslq %edx,%rax
mov    %esi,%edi
mov    %rax,%rsi
mov    %ecx,%edx
mov    %r8d,%ecx
call   1060 <kputstring@plt>
jmp    130d <process_syscall+0x10d>
movslq %edx,%rax
mov    %esi,%edi
mov    %rax,%rsi
mov    %ecx,%edx
call   10b0 <kprint@plt>
jmp    130d <process_syscall+0x10d>
mov    %esi,%edi
mov    %edx,%esi
mov    %ecx,%edx
mov    %r8d,%ecx
call   1090 <kprintnum@plt>
jmp    130d <process_syscall+0x10d>
mov    %esi,%edi
mov    %edx,%esi
mov    %ecx,%edx
call   1030 <kccolor@plt>
jmp    130d <process_syscall+0x10d>
xor    %ebx,%ebx
xor    %eax,%eax
call   10a0 <kscroll@plt>
jmp    130d <process_syscall+0x10d>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <kflip@plt>
jmp    130d <process_syscall+0x10d>
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <ksync@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Unknown or invalid system call.\00"
define i32 @process_syscall(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%12 = load i32, i32* %7
switch i32 %12, label %92 [
i32 0, label %13
i32 1, label %16
i32 2, label %17
i32 3, label %19
i32 4, label %24
i32 5, label %32
i32 6, label %37
i32 7, label %47
i32 8, label %55
i32 9, label %60
i32 10, label %68
i32 11, label %75
i32 12, label %81
i32 13, label %86
i32 14, label %88
i32 15, label %90
]
13: ; preds = %5
%14 = load i32, i32* %8
%15 = call i32 @ksleep(i32 %14)
br label %94
16: ; preds = %5
br label %94
17: ; preds = %5
%18 = call i32 (...) @kclear()
br label %94
19: ; preds = %5
%20 = load i32, i32* %8
%21 = sext i32 %20 to i64
%22 = call i64 @kmalloc(i64 %21)
%23 = trunc i64 %22 to i32
store i32 %23, i32* %6
br label %95
24: ; preds = %5
%25 = load i32, i32* %8
%26 = sext i32 %25 to i64
%27 = inttoptr i64 %26 to i8*
%28 = load i32, i32* %9
%29 = sext i32 %28 to i64
%30 = call i64 @krealloc(i8* %27, i64 %29)
%31 = trunc i64 %30 to i32
store i32 %31, i32* %6
br label %95
32: ; preds = %5
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = inttoptr i64 %34 to i8*
%36 = call i32 @kfree(i8* %35)
br label %94
37: ; preds = %5
%38 = load i32, i32* %8
%39 = sext i32 %38 to i64
%40 = inttoptr i64 %39 to i8*
%41 = load i32, i32* %9
%42 = sext i32 %41 to i64
%43 = inttoptr i64 %42 to i8*
%44 = load i32, i32* %10
%45 = sext i32 %44 to i64
%46 = call i32 @kmemcpy(i8* %40, i8* %43, i64 %45)
br label %94
47: ; preds = %5
%48 = load i32, i32* %8
%49 = sext i32 %48 to i64
%50 = inttoptr i64 %49 to i8*
%51 = load i32, i32* %9
%52 = load i32, i32* %10
%53 = sext i32 %52 to i64
%54 = call i32 @kmemset(i8* %50, i32 %51, i64 %53)
br label %94
55: ; preds = %5
%56 = load i32, i32* %8
%57 = load i32, i32* %9
%58 = load i32, i32* %10
%59 = call i32 @kputchar(i32 %56, i32 %57, i32 %58)
br label %94
60: ; preds = %5
%61 = load i32, i32* %8
%62 = load i32, i32* %9
%63 = sext i32 %62 to i64
%64 = inttoptr i64 %63 to i8*
%65 = load i32, i32* %10
%66 = load i32, i32* %11
%67 = call i32 @kputstring(i32 %61, i8* %64, i32 %65, i32 %66)
br label %94
68: ; preds = %5
%69 = load i32, i32* %8
%70 = load i32, i32* %9
%71 = sext i32 %70 to i64
%72 = inttoptr i64 %71 to i8*
%73 = load i32, i32* %10
%74 = call i32 @kprint(i32 %69, i8* %72, i32 %73)
br label %94
75: ; preds = %5
%76 = load i32, i32* %8
%77 = load i32, i32* %9
%78 = load i32, i32* %10
%79 = load i32, i32* %11
%80 = call i32 @kprintnum(i32 %76, i32 %77, i32 %78, i32 %79)
br label %94
81: ; preds = %5
%82 = load i32, i32* %8
%83 = load i32, i32* %9
%84 = load i32, i32* %10
%85 = call i32 @kccolor(i32 %82, i32 %83, i32 %84)
br label %94
86: ; preds = %5
%87 = call i32 (...) @kscroll()
br label %94
88: ; preds = %5
%89 = call i32 (...) @kflip()
br label %94
90: ; preds = %5
%91 = call i32 (...) @ksync()
br label %94
92: ; preds = %5
%93 = call i32 @haltdump(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 13)
br label %94
94: ; preds = %92, %90, %88, %86, %81, %75, %68, %60, %55, %47, %37, %32, %17, %16, %13
store i32 0, i32* %6
br label %95
95: ; preds = %94, %24, %19
%96 = load i32, i32* %6
ret i32 %96
}

LLVM IR (-O2):
@.str = [32 x i8] c"Unknown or invalid system call.\00"
define i32 @process_syscall(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
switch i32 %0, label %56 [
i32 0, label %6
i32 1, label %58
i32 2, label %8
i32 3, label %10
i32 4, label %14
i32 5, label %20
i32 6, label %24
i32 7, label %31
i32 8, label %36
i32 9, label %38
i32 10, label %42
i32 11, label %46
i32 12, label %48
i32 13, label %50
i32 14, label %52
i32 15, label %54
]
6: ; preds = %5
%7 = tail call i32 @ksleep(i32 %1)
br label %58
8: ; preds = %5
%9 = tail call i32 (...) @kclear()
br label %58
10: ; preds = %5
%11 = sext i32 %1 to i64
%12 = tail call i64 @kmalloc(i64 %11)
%13 = trunc i64 %12 to i32
br label %58
14: ; preds = %5
%15 = sext i32 %1 to i64
%16 = inttoptr i64 %15 to i8*
%17 = sext i32 %2 to i64
%18 = tail call i64 @krealloc(i8* %16, i64 %17)
%19 = trunc i64 %18 to i32
br label %58
20: ; preds = %5
%21 = sext i32 %1 to i64
%22 = inttoptr i64 %21 to i8*
%23 = tail call i32 @kfree(i8* %22)
br label %58
24: ; preds = %5
%25 = sext i32 %1 to i64
%26 = inttoptr i64 %25 to i8*
%27 = sext i32 %2 to i64
%28 = inttoptr i64 %27 to i8*
%29 = sext i32 %3 to i64
%30 = tail call i32 @kmemcpy(i8* %26, i8* %28, i64 %29)
br label %58
31: ; preds = %5
%32 = sext i32 %1 to i64
%33 = inttoptr i64 %32 to i8*
%34 = sext i32 %3 to i64
%35 = tail call i32 @kmemset(i8* %33, i32 %2, i64 %34)
br label %58
36: ; preds = %5
%37 = tail call i32 @kputchar(i32 %1, i32 %2, i32 %3)
br label %58
38: ; preds = %5
%39 = sext i32 %2 to i64
%40 = inttoptr i64 %39 to i8*
%41 = tail call i32 @kputstring(i32 %1, i8* %40, i32 %3, i32 %4)
br label %58
42: ; preds = %5
%43 = sext i32 %2 to i64
%44 = inttoptr i64 %43 to i8*
%45 = tail call i32 @kprint(i32 %1, i8* %44, i32 %3)
br label %58
46: ; preds = %5
%47 = tail call i32 @kprintnum(i32 %1, i32 %2, i32 %3, i32 %4)
br label %58
48: ; preds = %5
%49 = tail call i32 @kccolor(i32 %1, i32 %2, i32 %3)
br label %58
50: ; preds = %5
%51 = tail call i32 (...) @kscroll()
br label %58
52: ; preds = %5
%53 = tail call i32 (...) @kflip()
br label %58
54: ; preds = %5
%55 = tail call i32 (...) @ksync()
br label %58
56: ; preds = %5
%57 = tail call i32 @haltdump(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 13)
br label %58
58: ; preds = %6, %8, %20, %24, %31, %36, %38, %5, %42, %46, %48, %50, %52, %54, %56, %14, %10
%59 = phi i32 [ %19, %14 ], [ %13, %10 ], [ 0, %56 ], [ 0, %54 ], [ 0, %52 ], [ 0, %50 ], [ 0, %48 ], [ 0, %46 ], [ 0, %42 ], [ 0, %5 ], [ 0, %38 ], [ 0, %36 ], [ 0, %31 ], [ 0, %24 ], [ 0, %20 ], [ 0, %8 ], [ 0, %6 ]
ret i32 %59
}