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;
  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
mov    %eax,-0x18(%rbp)
sub    $0x1,%eax
je     1159 <__put_user+0x49>
jmp    1137 <__put_user+0x27>
mov    -0x18(%rbp),%eax
sub    $0x2,%eax
je     116a <__put_user+0x5a>
jmp    1148 <__put_user+0x38>
mov    -0x18(%rbp),%eax
sub    $0x4,%eax
je     117d <__put_user+0x6d>
jmp    118e <__put_user+0x7e>
mov    -0x8(%rbp),%rax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
jmp    1195 <__put_user+0x85>
mov    -0x8(%rbp),%rax
mov    %ax,%cx
mov    -0x10(%rbp),%rax
mov    %cx,(%rax)
jmp    1195 <__put_user+0x85>
mov    -0x8(%rbp),%rax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    1195 <__put_user+0x85>
mov    $0x0,%al
call   1030 <bad_user_access_length@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__put_user>:
push   %rax
cmp    $0x4,%edx
je     1125 <__put_user+0x15>
cmp    $0x2,%edx
je     1129 <__put_user+0x19>
cmp    $0x1,%edx
jne    112e <__put_user+0x1e>
mov    %dil,(%rsi)
jmp    1135 <__put_user+0x25>
mov    %edi,(%rsi)
jmp    1135 <__put_user+0x25>
mov    %di,(%rsi)
jmp    1135 <__put_user+0x25>
xor    %eax,%eax
call   1030 <bad_user_access_length@plt>
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 %22 [
i32 1, label %8
i32 2, label %12
i32 4, label %17
]
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 %24
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 %24
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 %24
22: ; preds = %3
%23 = call i32 (...) @bad_user_access_length()
br label %24
24: ; preds = %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 %12 [
i32 1, label %4
i32 2, label %6
i32 4, label %9
]
4: ; preds = %3
%5 = trunc i64 %0 to i8
store i8 %5, i8* %1
br label %14
6: ; preds = %3
%7 = trunc i64 %0 to i16
%8 = bitcast i8* %1 to i16*
store i16 %7, i16* %8
br label %14
9: ; preds = %3
%10 = trunc i64 %0 to i32
%11 = bitcast i8* %1 to i32*
store i32 %10, i32* %11
br label %14
12: ; preds = %3
%13 = tail call i32 (...) @bad_user_access_length()
br label %14
14: ; preds = %12, %9, %6, %4
tail call void asm sideeffect "", "~{memory},~{dirflag},~{fpsr},~{flags}"()
ret void
}