#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 */

/* Variables and functions */
int /*<<< orphan*/ bad_user_access_length();
void __put_user(unsigned long x, void *y, int size) {
  switch (size) {
  case 1:
    *(unsigned char *)y = x;
    break;
  case 2:
    *(unsigned short *)y = x;
    break;
  case 4:
    *(unsigned long *)y = x;
    break;
  default:
    bad_user_access_length();
  }
}


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    118d <__put_user+0x7d>
mov    -0x8(%rbp),%rax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
jmp    1194 <__put_user+0x84>
mov    -0x8(%rbp),%rax
mov    %ax,%cx
mov    -0x10(%rbp),%rax
mov    %cx,(%rax)
jmp    1194 <__put_user+0x84>
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    1194 <__put_user+0x84>
mov    $0x0,%al
call   1030 <bad_user_access_length@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__put_user>:
cmp    $0x4,%edx
je     1123 <__put_user+0x13>
cmp    $0x2,%edx
je     1127 <__put_user+0x17>
cmp    $0x1,%edx
jne    112b <__put_user+0x1b>
mov    %dil,(%rsi)
ret
mov    %rdi,(%rsi)
ret
mov    %di,(%rsi)
ret
xor    %eax,%eax
jmp    1030 <bad_user_access_length@plt>

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 %21 [
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 %23
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 %23
17: ; preds = %3
%18 = load i64, i64* %4
%19 = load i8*, i8** %5
%20 = bitcast i8* %19 to i64*
store i64 %18, i64* %20
br label %23
21: ; preds = %3
%22 = call i32 (...) @bad_user_access_length()
br label %23
23: ; preds = %21, %17, %12, %8
ret void
}

LLVM IR (-O2):
define void @__put_user(i64 %0, i8* nocapture writeonly %1, i32 %2) {
switch i32 %2, label %11 [
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 %13
6: ; preds = %3
%7 = trunc i64 %0 to i16
%8 = bitcast i8* %1 to i16*
store i16 %7, i16* %8
br label %13
9: ; preds = %3
%10 = bitcast i8* %1 to i64*
store i64 %0, i64* %10
br label %13
11: ; preds = %3
%12 = tail call i32 (...) @bad_user_access_length()
br label %13
13: ; preds = %11, %9, %6, %4
ret void
}