unsigned long __get_user(const void *y, int size) {
  unsigned long result;
  __asm__ __volatile__("" : : : "memory");
  switch (size) {
  case 1:
    result = *(unsigned char *)y;
    break;
  case 2:
    result = *(unsigned short *)y;
    break;
  case 4:
    result = *(unsigned int *)y;
    break;
  default:
    result = bad_user_access_length();
  }
  __asm__ __volatile__("" : : : "memory");
  return result;
}


x86 assembly (clang, -O0):
<__get_user>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x1,%eax
je     1155 <__get_user+0x45>
jmp    1133 <__get_user+0x23>
mov    -0x1c(%rbp),%eax
sub    $0x2,%eax
je     1165 <__get_user+0x55>
jmp    1144 <__get_user+0x34>
mov    -0x1c(%rbp),%eax
sub    $0x4,%eax
je     1175 <__get_user+0x65>
jmp    1184 <__get_user+0x74>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
mov    %rax,-0x18(%rbp)
jmp    1191 <__get_user+0x81>
mov    -0x8(%rbp),%rax
movzwl (%rax),%eax
mov    %rax,-0x18(%rbp)
jmp    1191 <__get_user+0x81>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %rax,-0x18(%rbp)
jmp    1191 <__get_user+0x81>
mov    $0x0,%al
call   1030 <bad_user_access_length@plt>
cltq
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__get_user>:
push   %rax
cmp    $0x4,%esi
je     1125 <__get_user+0x15>
cmp    $0x2,%esi
je     1129 <__get_user+0x19>
cmp    $0x1,%esi
jne    112e <__get_user+0x1e>
movzbl (%rdi),%eax
jmp    1137 <__get_user+0x27>
mov    (%rdi),%eax
jmp    1137 <__get_user+0x27>
movzwl (%rdi),%eax
jmp    1137 <__get_user+0x27>
xor    %eax,%eax
call   1030 <bad_user_access_length@plt>
cltq
pop    %rcx
ret

LLVM IR (-O0):
define i64 @__get_user(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
switch i32 %6, label %21 [
i32 1, label %7
i32 2, label %11
i32 4, label %16
]
7: ; preds = %2
%8 = load i8*, i8** %3
%9 = load i8, i8* %8
%10 = zext i8 %9 to i64
store i64 %10, i64* %5
br label %24
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = bitcast i8* %12 to i16*
%14 = load i16, i16* %13
%15 = zext i16 %14 to i64
store i64 %15, i64* %5
br label %24
16: ; preds = %2
%17 = load i8*, i8** %3
%18 = bitcast i8* %17 to i32*
%19 = load i32, i32* %18
%20 = zext i32 %19 to i64
store i64 %20, i64* %5
br label %24
21: ; preds = %2
%22 = call i32 (...) @bad_user_access_length()
%23 = sext i32 %22 to i64
store i64 %23, i64* %5
br label %24
24: ; preds = %21, %16, %11, %7
%25 = load i64, i64* %5
ret i64 %25
}

LLVM IR (-O2):
define i64 @__get_user(i8* nocapture %0, i32 %1) {
tail call void asm sideeffect "", "~{memory},~{dirflag},~{fpsr},~{flags}"()
switch i32 %1, label %14 [
i32 1, label %3
i32 2, label %6
i32 4, label %10
]
3: ; preds = %2
%4 = load i8, i8* %0
%5 = zext i8 %4 to i64
br label %17
6: ; preds = %2
%7 = bitcast i8* %0 to i16*
%8 = load i16, i16* %7
%9 = zext i16 %8 to i64
br label %17
10: ; preds = %2
%11 = bitcast i8* %0 to i32*
%12 = load i32, i32* %11
%13 = zext i32 %12 to i64
br label %17
14: ; preds = %2
%15 = tail call i32 (...) @bad_user_access_length()
%16 = sext i32 %15 to i64
br label %17
17: ; preds = %14, %10, %6, %3
%18 = phi i64 [ %16, %14 ], [ %13, %10 ], [ %9, %6 ], [ %5, %3 ]
tail call void asm sideeffect "", "~{memory},~{dirflag},~{fpsr},~{flags}"()
ret i64 %18
}