#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 */
struct user_regs_struct {
  unsigned long long rdi;
  unsigned long long rsi;
  unsigned long long rdx;
  unsigned long long r10;
  unsigned long long r8;
  unsigned long long r9;
};

/* Variables and functions */
unsigned long long int arg_val(struct user_regs_struct *regs, int arg) {
  switch (arg) {
  case 0:
    return regs->rdi;
  case 1:
    return regs->rsi;
  case 2:
    return regs->rdx;
  case 3:
    return regs->r10;
  case 4:
    return regs->r8;
  case 5:
    return regs->r9;
  default:
    return 0;
  }
}


x86 assembly (clang, -O0):
<arg_val>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %rax,-0x20(%rbp)
sub    $0x5,%rax
ja     1195 <arg_val+0x95>
mov    -0x20(%rbp),%rax
lea    0xed9(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    119d <arg_val+0x9d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    119d <arg_val+0x9d>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    119d <arg_val+0x9d>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    119d <arg_val+0x9d>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    119d <arg_val+0x9d>
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    119d <arg_val+0x9d>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<arg_val>:
cmp    $0x5,%esi
ja     111f <arg_val+0x1f>
mov    %esi,%eax
lea    0xef2(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
add    $0x8,%rdi
mov    (%rdi),%rax
ret
xor    %eax,%eax
ret
add    $0x10,%rdi
mov    (%rdi),%rax
ret
add    $0x18,%rdi
mov    (%rdi),%rax
ret
add    $0x20,%rdi
mov    (%rdi),%rax
ret
add    $0x28,%rdi
mov    (%rdi),%rax
ret

LLVM IR (-O0):
%struct.user_regs_struct = type { i64, i64, i64, i64, i64, i64 }
define i64 @arg_val(%struct.user_regs_struct* %0, i32 %1) {
%3 = alloca i64
%4 = alloca %struct.user_regs_struct*
%5 = alloca i32
store %struct.user_regs_struct* %0, %struct.user_regs_struct** %4
store i32 %1, i32* %5
%6 = load i32, i32* %5
switch i32 %6, label %31 [
i32 0, label %7
i32 1, label %11
i32 2, label %15
i32 3, label %19
i32 4, label %23
i32 5, label %27
]
7: ; preds = %2
%8 = load %struct.user_regs_struct*, %struct.user_regs_struct** %4
%9 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %8, i32 0, i32 0
%10 = load i64, i64* %9
store i64 %10, i64* %3
br label %32
11: ; preds = %2
%12 = load %struct.user_regs_struct*, %struct.user_regs_struct** %4
%13 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %12, i32 0, i32 1
%14 = load i64, i64* %13
store i64 %14, i64* %3
br label %32
15: ; preds = %2
%16 = load %struct.user_regs_struct*, %struct.user_regs_struct** %4
%17 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %16, i32 0, i32 2
%18 = load i64, i64* %17
store i64 %18, i64* %3
br label %32
19: ; preds = %2
%20 = load %struct.user_regs_struct*, %struct.user_regs_struct** %4
%21 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %20, i32 0, i32 3
%22 = load i64, i64* %21
store i64 %22, i64* %3
br label %32
23: ; preds = %2
%24 = load %struct.user_regs_struct*, %struct.user_regs_struct** %4
%25 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %24, i32 0, i32 4
%26 = load i64, i64* %25
store i64 %26, i64* %3
br label %32
27: ; preds = %2
%28 = load %struct.user_regs_struct*, %struct.user_regs_struct** %4
%29 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %28, i32 0, i32 5
%30 = load i64, i64* %29
store i64 %30, i64* %3
br label %32
31: ; preds = %2
store i64 0, i64* %3
br label %32
32: ; preds = %31, %27, %23, %19, %15, %11, %7
%33 = load i64, i64* %3
ret i64 %33
}

LLVM IR (-O2):
%struct.user_regs_struct = type { i64, i64, i64, i64, i64, i64 }
define i64 @arg_val(%struct.user_regs_struct* nocapture %0, i32 %1) {
switch i32 %1, label %18 [
i32 0, label %3
i32 1, label %5
i32 2, label %7
i32 3, label %9
i32 4, label %11
i32 5, label %13
]
3: ; preds = %2
%4 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %0, i64 0, i32 0
br label %15
5: ; preds = %2
%6 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %0, i64 0, i32 1
br label %15
7: ; preds = %2
%8 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %0, i64 0, i32 2
br label %15
9: ; preds = %2
%10 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %0, i64 0, i32 3
br label %15
11: ; preds = %2
%12 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %0, i64 0, i32 4
br label %15
13: ; preds = %2
%14 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %0, i64 0, i32 5
br label %15
15: ; preds = %3, %5, %7, %9, %11, %13
%16 = phi i64* [ %14, %13 ], [ %12, %11 ], [ %10, %9 ], [ %8, %7 ], [ %6, %5 ], [ %4, %3 ]
%17 = load i64, i64* %16
br label %18
18: ; preds = %15, %2
%19 = phi i64 [ 0, %2 ], [ %17, %15 ]
ret i64 %19
}