#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*/ PrintChar(char);
int /*<<< orphan*/ PrintInt(unsigned int);
int /*<<< orphan*/ PrintString(char *);
int /*<<< orphan*/ Read(unsigned short, unsigned short);
int /*<<< orphan*/ ReadChar(char *, unsigned int, unsigned int);
int /*<<< orphan*/ Write(unsigned short, unsigned short);
void Syscall(unsigned int syscall_code, unsigned int a0, unsigned int a1,
             unsigned int a2) {
  switch (syscall_code) {
  case 11:
    PrintChar((char)a0);
    break;
  case 4:
    PrintString((char *)a0);
    break;
  case 1:
    PrintInt(a0);
    break;
  case 12:
    ReadChar((char *)a0, a1, a2);
    break;
  case 14:
    Read((unsigned short)a0, (unsigned short)a1);
    break;
  case 15:
    Write((unsigned short)a0, (unsigned short)a1);
    break;
  default:
    break;
  }
}


x86 assembly (clang, -O0):
<Syscall>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0xe,%eax
ja     1210 <Syscall+0xb0>
mov    -0x18(%rbp),%rax
lea    0xe6c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%eax
movsbl %al,%edi
call   1040 <PrintChar@plt>
jmp    1215 <Syscall+0xb5>
mov    -0x8(%rbp),%eax
mov    %eax,%edi
call   1080 <PrintString@plt>
jmp    1215 <Syscall+0xb5>
mov    -0x8(%rbp),%edi
call   1060 <PrintInt@plt>
jmp    1215 <Syscall+0xb5>
mov    -0x8(%rbp),%eax
mov    %eax,%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1070 <ReadChar@plt>
jmp    1215 <Syscall+0xb5>
mov    -0x8(%rbp),%eax
mov    %ax,%cx
mov    -0xc(%rbp),%eax
movzwl %cx,%edi
movzwl %ax,%esi
call   1030 <Read@plt>
jmp    1215 <Syscall+0xb5>
mov    -0x8(%rbp),%eax
mov    %ax,%cx
mov    -0xc(%rbp),%eax
movzwl %cx,%edi
movzwl %ax,%esi
call   1050 <Write@plt>
jmp    1215 <Syscall+0xb5>
jmp    1215 <Syscall+0xb5>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Syscall>:
add    $0xffffffff,%edi
cmp    $0xe,%edi
ja     117f <Syscall+0x1f>
lea    0xe91(%rip),%rax
movslq (%rax,%rdi,4),%rdi
add    %rax,%rdi
jmp    *%rdi
mov    %esi,%edi
jmp    1060 <PrintInt@plt>
ret
mov    %esi,%edi
jmp    1080 <PrintString@plt>
movsbl %sil,%edi
jmp    1040 <PrintChar@plt>
mov    %esi,%edi
mov    %edx,%esi
mov    %ecx,%edx
jmp    1070 <ReadChar@plt>
movzwl %si,%edi
movzwl %dx,%esi
jmp    1030 <Read@plt>
movzwl %si,%edi
movzwl %dx,%esi
jmp    1050 <Write@plt>

LLVM IR (-O0):
define void @Syscall(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%9 = load i32, i32* %5
switch i32 %9, label %41 [
i32 11, label %10
i32 4, label %14
i32 1, label %19
i32 12, label %22
i32 14, label %29
i32 15, label %35
]
10: ; preds = %4
%11 = load i32, i32* %6
%12 = trunc i32 %11 to i8
%13 = call i32 @PrintChar(i8 signext %12)
br label %42
14: ; preds = %4
%15 = load i32, i32* %6
%16 = zext i32 %15 to i64
%17 = inttoptr i64 %16 to i8*
%18 = call i32 @PrintString(i8* %17)
br label %42
19: ; preds = %4
%20 = load i32, i32* %6
%21 = call i32 @PrintInt(i32 %20)
br label %42
22: ; preds = %4
%23 = load i32, i32* %6
%24 = zext i32 %23 to i64
%25 = inttoptr i64 %24 to i8*
%26 = load i32, i32* %7
%27 = load i32, i32* %8
%28 = call i32 @ReadChar(i8* %25, i32 %26, i32 %27)
br label %42
29: ; preds = %4
%30 = load i32, i32* %6
%31 = trunc i32 %30 to i16
%32 = load i32, i32* %7
%33 = trunc i32 %32 to i16
%34 = call i32 @Read(i16 zeroext %31, i16 zeroext %33)
br label %42
35: ; preds = %4
%36 = load i32, i32* %6
%37 = trunc i32 %36 to i16
%38 = load i32, i32* %7
%39 = trunc i32 %38 to i16
%40 = call i32 @Write(i16 zeroext %37, i16 zeroext %39)
br label %42
41: ; preds = %4
br label %42
42: ; preds = %41, %35, %29, %22, %19, %14, %10
ret void
}

LLVM IR (-O2):
define void @Syscall(i32 %0, i32 %1, i32 %2, i32 %3) {
switch i32 %0, label %26 [
i32 11, label %5
i32 4, label %8
i32 1, label %12
i32 12, label %14
i32 14, label %18
i32 15, label %22
]
5: ; preds = %4
%6 = trunc i32 %1 to i8
%7 = tail call i32 @PrintChar(i8 signext %6)
br label %26
8: ; preds = %4
%9 = zext i32 %1 to i64
%10 = inttoptr i64 %9 to i8*
%11 = tail call i32 @PrintString(i8* %10)
br label %26
12: ; preds = %4
%13 = tail call i32 @PrintInt(i32 %1)
br label %26
14: ; preds = %4
%15 = zext i32 %1 to i64
%16 = inttoptr i64 %15 to i8*
%17 = tail call i32 @ReadChar(i8* %16, i32 %2, i32 %3)
br label %26
18: ; preds = %4
%19 = trunc i32 %1 to i16
%20 = trunc i32 %2 to i16
%21 = tail call i32 @Read(i16 zeroext %19, i16 zeroext %20)
br label %26
22: ; preds = %4
%23 = trunc i32 %1 to i16
%24 = trunc i32 %2 to i16
%25 = tail call i32 @Write(i16 zeroext %23, i16 zeroext %24)
br label %26
26: ; preds = %4, %22, %18, %14, %12, %8, %5
ret void
}