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


x86 assembly (clang, -O0):
<__put_user>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x7,%eax
ja     1191 <__put_user+0x81>
mov    -0x20(%rbp),%rax
lea    0xebd(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%rax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
jmp    1198 <__put_user+0x88>
mov    -0x8(%rbp),%rax
mov    %ax,%cx
mov    -0x10(%rbp),%rax
mov    %cx,(%rax)
jmp    1198 <__put_user+0x88>
mov    -0x8(%rbp),%rax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    1198 <__put_user+0x88>
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    1198 <__put_user+0x88>
mov    $0x0,%al
call   1030 <bad_user_access_length@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__put_user>:
push   %rax
add    $0xffffffff,%edx
cmp    $0x7,%edx
ja     1133 <__put_user+0x23>
lea    0xee0(%rip),%rax
movslq (%rax,%rdx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
mov    %dil,(%rsi)
jmp    1143 <__put_user+0x33>
mov    %di,(%rsi)
jmp    1143 <__put_user+0x33>
xor    %eax,%eax
call   1030 <bad_user_access_length@plt>
jmp    1143 <__put_user+0x33>
mov    %edi,(%rsi)
jmp    1143 <__put_user+0x33>
mov    %rdi,(%rsi)
pop    %rax
ret

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

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