#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 cpu_uint16_read(void const *);
int cpu_uint24_read(void const *);
int cpu_uint32_read(void const *);
int cpu_uint8_read(void const *);
unsigned cpu_uint_read(const void *ptr, unsigned size) {
  switch (size) {
  default:
  case 1:
    return cpu_uint8_read(ptr);
  case 2:
    return cpu_uint16_read(ptr);
  case 3:
    return cpu_uint24_read(ptr);
  case 4:
    return cpu_uint32_read(ptr);
  }
}


x86 assembly (clang, -O0):
<cpu_uint_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x3,%eax
ja     1178 <cpu_uint_read+0x38>
mov    -0x20(%rbp),%rax
lea    0xe91(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
jmp    117d <cpu_uint_read+0x3d>
mov    -0x10(%rbp),%rdi
call   1050 <cpu_uint8_read@plt>
mov    %eax,-0x4(%rbp)
jmp    11bc <cpu_uint_read+0x7c>
mov    -0x10(%rbp),%rdi
call   1060 <cpu_uint16_read@plt>
mov    %eax,-0x4(%rbp)
jmp    11bc <cpu_uint_read+0x7c>
mov    -0x10(%rbp),%rdi
call   1040 <cpu_uint24_read@plt>
mov    %eax,-0x4(%rbp)
jmp    11bc <cpu_uint_read+0x7c>
mov    -0x10(%rbp),%rdi
call   1030 <cpu_uint32_read@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpu_uint_read>:
cmp    $0x2,%esi
je     1154 <cpu_uint_read+0x14>
cmp    $0x3,%esi
je     1159 <cpu_uint_read+0x19>
cmp    $0x4,%esi
jne    115e <cpu_uint_read+0x1e>
jmp    1030 <cpu_uint32_read@plt>
jmp    1060 <cpu_uint16_read@plt>
jmp    1040 <cpu_uint24_read@plt>
jmp    1050 <cpu_uint8_read@plt>

LLVM IR (-O0):
define i32 @cpu_uint_read(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%6 = load i32, i32* %5
switch i32 %6, label %7 [
i32 1, label %8
i32 2, label %11
i32 3, label %14
i32 4, label %17
]
7: ; preds = %2
br label %8
8: ; preds = %2, %7
%9 = load i8*, i8** %4
%10 = call i32 @cpu_uint8_read(i8* %9)
store i32 %10, i32* %3
br label %20
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = call i32 @cpu_uint16_read(i8* %12)
store i32 %13, i32* %3
br label %20
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = call i32 @cpu_uint24_read(i8* %15)
store i32 %16, i32* %3
br label %20
17: ; preds = %2
%18 = load i8*, i8** %4
%19 = call i32 @cpu_uint32_read(i8* %18)
store i32 %19, i32* %3
br label %20
20: ; preds = %17, %14, %11, %8
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
define i32 @cpu_uint_read(i8* %0, i32 %1) {
switch i32 %1, label %3 [
i32 4, label %9
i32 2, label %5
i32 3, label %7
]
3: ; preds = %2
%4 = tail call i32 @cpu_uint8_read(i8* %0)
br label %11
5: ; preds = %2
%6 = tail call i32 @cpu_uint16_read(i8* %0)
br label %11
7: ; preds = %2
%8 = tail call i32 @cpu_uint24_read(i8* %0)
br label %11
9: ; preds = %2
%10 = tail call i32 @cpu_uint32_read(i8* %0)
br label %11
11: ; preds = %9, %7, %5, %3
%12 = phi i32 [ %4, %3 ], [ %8, %7 ], [ %6, %5 ], [ %10, %9 ]
ret i32 %12
}