#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*/ cpu_uint16_write(void *, unsigned int);
int /*<<< orphan*/ cpu_uint24_write(void *, unsigned int);
int /*<<< orphan*/ cpu_uint32_write(void *, unsigned int);
int /*<<< orphan*/ cpu_uint8_write(void *, unsigned int);
void cpu_uint_write(void *ptr, unsigned size, unsigned v) {
  switch (size) {
  default:
  case 1:
    cpu_uint8_write(ptr, v);
    break;
  case 2:
    cpu_uint16_write(ptr, v);
    break;
  case 3:
    cpu_uint24_write(ptr, v);
    break;
  case 4:
    cpu_uint32_write(ptr, v);
    break;
  }
}


x86 assembly (clang, -O0):
<cpu_uint_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x3,%eax
ja     117b <cpu_uint_write+0x3b>
mov    -0x18(%rbp),%rax
lea    0xe8e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
jmp    1180 <cpu_uint_write+0x40>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1060 <cpu_uint8_write@plt>
jmp    11bf <cpu_uint_write+0x7f>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1050 <cpu_uint16_write@plt>
jmp    11bf <cpu_uint_write+0x7f>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1040 <cpu_uint24_write@plt>
jmp    11bf <cpu_uint_write+0x7f>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1030 <cpu_uint32_write@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpu_uint_write>:
cmp    $0x2,%esi
je     1156 <cpu_uint_write+0x16>
cmp    $0x3,%esi
je     115d <cpu_uint_write+0x1d>
cmp    $0x4,%esi
jne    1164 <cpu_uint_write+0x24>
mov    %edx,%esi
jmp    1030 <cpu_uint32_write@plt>
mov    %edx,%esi
jmp    1050 <cpu_uint16_write@plt>
mov    %edx,%esi
jmp    1040 <cpu_uint24_write@plt>
mov    %edx,%esi
jmp    1060 <cpu_uint8_write@plt>

LLVM IR (-O0):
define void @cpu_uint_write(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%7 = load i32, i32* %5
switch i32 %7, label %8 [
i32 1, label %9
i32 2, label %13
i32 3, label %17
i32 4, label %21
]
8: ; preds = %3
br label %9
9: ; preds = %3, %8
%10 = load i8*, i8** %4
%11 = load i32, i32* %6
%12 = call i32 @cpu_uint8_write(i8* %10, i32 %11)
br label %25
13: ; preds = %3
%14 = load i8*, i8** %4
%15 = load i32, i32* %6
%16 = call i32 @cpu_uint16_write(i8* %14, i32 %15)
br label %25
17: ; preds = %3
%18 = load i8*, i8** %4
%19 = load i32, i32* %6
%20 = call i32 @cpu_uint24_write(i8* %18, i32 %19)
br label %25
21: ; preds = %3
%22 = load i8*, i8** %4
%23 = load i32, i32* %6
%24 = call i32 @cpu_uint32_write(i8* %22, i32 %23)
br label %25
25: ; preds = %21, %17, %13, %9
ret void
}

LLVM IR (-O2):
define void @cpu_uint_write(i8* %0, i32 %1, i32 %2) {
switch i32 %1, label %4 [
i32 4, label %10
i32 2, label %6
i32 3, label %8
]
4: ; preds = %3
%5 = tail call i32 @cpu_uint8_write(i8* %0, i32 %2)
br label %12
6: ; preds = %3
%7 = tail call i32 @cpu_uint16_write(i8* %0, i32 %2)
br label %12
8: ; preds = %3
%9 = tail call i32 @cpu_uint24_write(i8* %0, i32 %2)
br label %12
10: ; preds = %3
%11 = tail call i32 @cpu_uint32_write(i8* %0, i32 %2)
br label %12
12: ; preds = %10, %8, %6, %4
ret void
}