#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_ptr(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 NULL;
  }
}


x86 assembly (clang, -O0):
<arg_ptr>:
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     1192 <arg_ptr+0x92>
mov    -0x20(%rbp),%rax
lea    0xed9(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    119a <arg_ptr+0x9a>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
jmp    119a <arg_ptr+0x9a>
mov    -0x10(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x8(%rbp)
jmp    119a <arg_ptr+0x9a>
mov    -0x10(%rbp),%rax
add    $0x18,%rax
mov    %rax,-0x8(%rbp)
jmp    119a <arg_ptr+0x9a>
mov    -0x10(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x8(%rbp)
jmp    119a <arg_ptr+0x9a>
mov    -0x10(%rbp),%rax
add    $0x28,%rax
mov    %rax,-0x8(%rbp)
jmp    119a <arg_ptr+0x9a>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

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

LLVM IR (-O0):
%struct.user_regs_struct = type { i64, i64, i64, i64, i64, i64 }
define i64* @arg_ptr(%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 %25 [
i32 0, label %7
i32 1, label %10
i32 2, label %13
i32 3, label %16
i32 4, label %19
i32 5, label %22
]
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
store i64* %9, i64** %3
br label %26
10: ; preds = %2
%11 = load %struct.user_regs_struct*, %struct.user_regs_struct** %4
%12 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %11, i32 0, i32 1
store i64* %12, i64** %3
br label %26
13: ; preds = %2
%14 = load %struct.user_regs_struct*, %struct.user_regs_struct** %4
%15 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %14, i32 0, i32 2
store i64* %15, i64** %3
br label %26
16: ; preds = %2
%17 = load %struct.user_regs_struct*, %struct.user_regs_struct** %4
%18 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %17, i32 0, i32 3
store i64* %18, i64** %3
br label %26
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 4
store i64* %21, i64** %3
br label %26
22: ; preds = %2
%23 = load %struct.user_regs_struct*, %struct.user_regs_struct** %4
%24 = getelementptr inbounds %struct.user_regs_struct, %struct.user_regs_struct* %23, i32 0, i32 5
store i64* %24, i64** %3
br label %26
25: ; preds = %2
store i64* null, i64** %3
br label %26
26: ; preds = %25, %22, %19, %16, %13, %10, %7
%27 = load i64*, i64** %3
ret i64* %27
}

LLVM IR (-O2):
%struct.user_regs_struct = type { i64, i64, i64, i64, i64, i64 }
define i64* @arg_ptr(%struct.user_regs_struct* readnone %0, i32 %1) {
switch i32 %1, label %15 [
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 = %2, %13, %11, %9, %7, %5, %3
%16 = phi i64* [ %14, %13 ], [ %12, %11 ], [ %10, %9 ], [ %8, %7 ], [ %6, %5 ], [ %4, %3 ], [ null, %2 ]
ret i64* %16
}