#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*/ printf(char *, int);
int /*<<< orphan*/ sys_dump(int);
int /*<<< orphan*/ sys_get_char(int);
int /*<<< orphan*/ sys_get_int(int);
int /*<<< orphan*/ sys_halt(int);
int /*<<< orphan*/ sys_put_char(int);
int /*<<< orphan*/ sys_put_int(int);
int /*<<< orphan*/ sys_put_str(int);
void sys_call(int reg, int code) {
  switch (code) {
  case 0x0:
    sys_halt(reg);
    break;
  case 0x1:
    sys_dump(reg);
    break;
  case 0x2:
    sys_put_int(reg);
    break;
  case 0x3:
    sys_put_char(reg);
    break;
  case 0x4:
    sys_put_str(reg);
    break;
  case 0x5:
    sys_get_int(reg);
    break;
  case 0x6:
    sys_get_char(reg);
    break;
  default:
    printf("Error: invalid system call code %#x.\n", reg);
    sys_dump(0x0);
    sys_halt(0x0);
  }
}


x86 assembly (clang, -O0):
<sys_call>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %rax,-0x10(%rbp)
sub    $0x6,%rax
ja     120e <sys_call+0x8e>
mov    -0x10(%rbp),%rax
lea    0xe56(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x4(%rbp),%edi
call   1060 <sys_halt@plt>
jmp    122b <sys_call+0xab>
mov    -0x4(%rbp),%edi
call   1090 <sys_dump@plt>
jmp    122b <sys_call+0xab>
mov    -0x4(%rbp),%edi
call   1030 <sys_put_int@plt>
jmp    122b <sys_call+0xab>
mov    -0x4(%rbp),%edi
call   1080 <sys_put_char@plt>
jmp    122b <sys_call+0xab>
mov    -0x4(%rbp),%edi
call   1040 <sys_put_str@plt>
jmp    122b <sys_call+0xab>
mov    -0x4(%rbp),%edi
call   1070 <sys_get_int@plt>
jmp    122b <sys_call+0xab>
mov    -0x4(%rbp),%edi
call   10a0 <sys_get_char@plt>
jmp    122b <sys_call+0xab>
mov    -0x4(%rbp),%esi
lea    0xe04(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <sys_dump@plt>
xor    %edi,%edi
call   1060 <sys_halt@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sys_call>:
push   %rax
mov    %edi,%eax
cmp    $0x6,%esi
ja     11a2 <sys_call+0x22>
mov    %esi,%ecx
lea    0xe6f(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
mov    %eax,%edi
pop    %rax
jmp    1060 <sys_halt@plt>
lea    0xe73(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <sys_dump@plt>
xor    %edi,%edi
pop    %rax
jmp    1060 <sys_halt@plt>
mov    %eax,%edi
pop    %rax
jmp    1090 <sys_dump@plt>
mov    %eax,%edi
pop    %rax
jmp    1030 <sys_put_int@plt>
mov    %eax,%edi
pop    %rax
jmp    1080 <sys_put_char@plt>
mov    %eax,%edi
pop    %rax
jmp    1040 <sys_put_str@plt>
mov    %eax,%edi
pop    %rax
jmp    1070 <sys_get_int@plt>
mov    %eax,%edi
pop    %rax
jmp    10a0 <sys_get_char@plt>

LLVM IR (-O0):
@.str = [38 x i8] c"Error: invalid system call code %#x.\0A\00"
define void @sys_call(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%5 = load i32, i32* %4
switch i32 %5, label %27 [
i32 0, label %6
i32 1, label %9
i32 2, label %12
i32 3, label %15
i32 4, label %18
i32 5, label %21
i32 6, label %24
]
6: ; preds = %2
%7 = load i32, i32* %3
%8 = call i32 @sys_halt(i32 %7)
br label %32
9: ; preds = %2
%10 = load i32, i32* %3
%11 = call i32 @sys_dump(i32 %10)
br label %32
12: ; preds = %2
%13 = load i32, i32* %3
%14 = call i32 @sys_put_int(i32 %13)
br label %32
15: ; preds = %2
%16 = load i32, i32* %3
%17 = call i32 @sys_put_char(i32 %16)
br label %32
18: ; preds = %2
%19 = load i32, i32* %3
%20 = call i32 @sys_put_str(i32 %19)
br label %32
21: ; preds = %2
%22 = load i32, i32* %3
%23 = call i32 @sys_get_int(i32 %22)
br label %32
24: ; preds = %2
%25 = load i32, i32* %3
%26 = call i32 @sys_get_char(i32 %25)
br label %32
27: ; preds = %2
%28 = load i32, i32* %3
%29 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %28)
%30 = call i32 @sys_dump(i32 0)
%31 = call i32 @sys_halt(i32 0)
br label %32
32: ; preds = %27, %24, %21, %18, %15, %12, %9, %6
ret void
}

LLVM IR (-O2):
@.str = [38 x i8] c"Error: invalid system call code %#x.\0A\00"
define void @sys_call(i32 %0, i32 %1) {
switch i32 %1, label %17 [
i32 0, label %3
i32 1, label %5
i32 2, label %7
i32 3, label %9
i32 4, label %11
i32 5, label %13
i32 6, label %15
]
3: ; preds = %2
%4 = tail call i32 @sys_halt(i32 %0)
br label %21
5: ; preds = %2
%6 = tail call i32 @sys_dump(i32 %0)
br label %21
7: ; preds = %2
%8 = tail call i32 @sys_put_int(i32 %0)
br label %21
9: ; preds = %2
%10 = tail call i32 @sys_put_char(i32 %0)
br label %21
11: ; preds = %2
%12 = tail call i32 @sys_put_str(i32 %0)
br label %21
13: ; preds = %2
%14 = tail call i32 @sys_get_int(i32 %0)
br label %21
15: ; preds = %2
%16 = tail call i32 @sys_get_char(i32 %0)
br label %21
17: ; preds = %2
%18 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %0)
%19 = tail call i32 @sys_dump(i32 0)
%20 = tail call i32 @sys_halt(i32 0)
br label %21
21: ; preds = %17, %15, %13, %11, %9, %7, %5, %3
ret void
}