char *getDeviceNameFromJoystickNr(int joystick_nr) {
  static char *joystick_device_name[4] = {"/dev/js0", "/dev/js1", "/dev/js2",
                                          "/dev/js3"};
  return (joystick_nr >= 0 && joystick_nr <= 3
              ? joystick_device_name[joystick_nr]
              : "");
}


x86 assembly (clang, -O0):
<getDeviceNameFromJoystickNr>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jl     1133 <getDeviceNameFromJoystickNr+0x33>
cmpl   $0x3,-0x4(%rbp)
jg     1133 <getDeviceNameFromJoystickNr+0x33>
movslq -0x4(%rbp),%rcx
lea    0x2f0a(%rip),%rax
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x10(%rbp)
jmp    1143 <getDeviceNameFromJoystickNr+0x43>
lea    0xece(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    1143 <getDeviceNameFromJoystickNr+0x43>
mov    -0x10(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<getDeviceNameFromJoystickNr>:
cmp    $0x3,%edi
ja     1116 <getDeviceNameFromJoystickNr+0x16>
mov    %edi,%eax
lea    0xef2(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
ret
lea    0xefb(%rip),%rax
ret

LLVM IR (-O0):
@getDeviceNameFromJoystickNr.joystick_device_name = internal global [4 x i8*] [i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i32 0, i32 0)]
@.str = [9 x i8] c"/dev/js0\00"
@.str.1 = [9 x i8] c"/dev/js1\00"
@.str.2 = [9 x i8] c"/dev/js2\00"
@.str.3 = [9 x i8] c"/dev/js3\00"
@.str.4 = [1 x i8] zeroinitializer
define i8* @getDeviceNameFromJoystickNr(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = icmp sge i32 %3, 0
br i1 %4, label %5, label %13
5: ; preds = %1
%6 = load i32, i32* %2
%7 = icmp sle i32 %6, 3
br i1 %7, label %8, label %13
8: ; preds = %5
%9 = load i32, i32* %2
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [4 x i8*], [4 x i8*]* @getDeviceNameFromJoystickNr.joystick_device_name, i64 0, i64 %10
%12 = load i8*, i8** %11
br label %14
13: ; preds = %5, %1
br label %14
14: ; preds = %13, %8
%15 = phi i8* [ %12, %8 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), %13 ]
ret i8* %15
}

LLVM IR (-O2):
@reltable.getDeviceNameFromJoystickNr = internal unnamed_addr constant [4 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str to i64), i64 ptrtoint ([4 x i32]* @reltable.getDeviceNameFromJoystickNr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str.1 to i64), i64 ptrtoint ([4 x i32]* @reltable.getDeviceNameFromJoystickNr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str.2 to i64), i64 ptrtoint ([4 x i32]* @reltable.getDeviceNameFromJoystickNr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str.3 to i64), i64 ptrtoint ([4 x i32]* @reltable.getDeviceNameFromJoystickNr to i64)) to i32)]
@.str = [9 x i8] c"/dev/js0\00"
@.str.1 = [9 x i8] c"/dev/js1\00"
@.str.2 = [9 x i8] c"/dev/js2\00"
@.str.3 = [9 x i8] c"/dev/js3\00"
@.str.4 = [1 x i8] zeroinitializer
define i8* @getDeviceNameFromJoystickNr(i32 %0) {
%2 = icmp ult i32 %0, 4
br i1 %2, label %3, label %7
3: ; preds = %1
%4 = zext i32 %0 to i64
%5 = shl i64 %4, 2
%6 = call i8* @llvm.load.relative.i64(i8* bitcast ([4 x i32]* @reltable.getDeviceNameFromJoystickNr to i8*), i64 %5)
br label %7
7: ; preds = %1, %3
%8 = phi i8* [ %6, %3 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), %1 ]
ret i8* %8
}