#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 */
struct pevent {
  int dummy;
};

/* Variables and functions */
unsigned long long __data2host2(struct pevent *, unsigned short);
unsigned long long __data2host4(struct pevent *, unsigned int);
int /*<<< orphan*/ __data2host8(struct pevent *, unsigned long long);
int /*<<< orphan*/ memcpy(unsigned long long *, void const *, int);
unsigned long long pevent_read_number(struct pevent *pevent, const void *ptr,
                                      int size) {
  switch (size) {
  case 1:
    return *(unsigned char *)ptr;
  case 2:
    return __data2host2(pevent, *(unsigned short *)(ptr));
  case 4:
    return __data2host4(pevent, *(unsigned int *)(ptr));
  case 8:
    return ({
      unsigned long long __val;
      memcpy(&__val, (ptr), sizeof(unsigned long long));
      __data2host8(pevent, __val);
    });
  default:
    return 0;
  }
}


x86 assembly (clang, -O0):
<pevent_read_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x7,%eax
ja     11ec <pevent_read_number+0xac>
mov    -0x38(%rbp),%rax
lea    0xe8d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
mov    %rax,-0x8(%rbp)
jmp    11f4 <pevent_read_number+0xb4>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
movzwl (%rax),%esi
call   1060 <__data2host2@plt>
mov    %rax,-0x8(%rbp)
jmp    11f4 <pevent_read_number+0xb4>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
call   1040 <__data2host4@plt>
mov    %rax,-0x8(%rbp)
jmp    11f4 <pevent_read_number+0xb4>
mov    -0x18(%rbp),%rsi
lea    -0x28(%rbp),%rdi
mov    $0x8,%edx
call   1030 <memcpy@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <__data2host8@plt>
mov    %eax,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11f4 <pevent_read_number+0xb4>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pevent_read_number>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
add    $0xffffffff,%edx
cmp    $0x7,%edx
ja     11a4 <pevent_read_number+0x64>
mov    %rdi,%rbx
lea    0xea7(%rip),%rcx
movslq (%rcx,%rdx,4),%rdx
add    %rcx,%rdx
jmp    *%rdx
movzbl (%rsi),%eax
jmp    11a4 <pevent_read_number+0x64>
movzwl (%rsi),%esi
mov    %rbx,%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1060 <__data2host2@plt>
mov    (%rsi),%esi
mov    %rbx,%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1040 <__data2host4@plt>
lea    0x8(%rsp),%rdi
mov    $0x8,%edx
call   1030 <memcpy@plt>
mov    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <__data2host8@plt>
cltq
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.pevent = type { i32 }
define i64 @pevent_read_number(%struct.pevent* %0, i8* %1, i32 %2) {
%4 = alloca i64
%5 = alloca %struct.pevent*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32
store %struct.pevent* %0, %struct.pevent** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i32, i32* %7
switch i32 %10, label %35 [
i32 1, label %11
i32 2, label %15
i32 4, label %21
i32 8, label %27
]
11: ; preds = %3
%12 = load i8*, i8** %6
%13 = load i8, i8* %12
%14 = zext i8 %13 to i64
store i64 %14, i64* %4
br label %36
15: ; preds = %3
%16 = load %struct.pevent*, %struct.pevent** %5
%17 = load i8*, i8** %6
%18 = bitcast i8* %17 to i16*
%19 = load i16, i16* %18
%20 = call i64 @__data2host2(%struct.pevent* %16, i16 zeroext %19)
store i64 %20, i64* %4
br label %36
21: ; preds = %3
%22 = load %struct.pevent*, %struct.pevent** %5
%23 = load i8*, i8** %6
%24 = bitcast i8* %23 to i32*
%25 = load i32, i32* %24
%26 = call i64 @__data2host4(%struct.pevent* %22, i32 %25)
store i64 %26, i64* %4
br label %36
27: ; preds = %3
%28 = load i8*, i8** %6
%29 = call i32 @memcpy(i64* %8, i8* %28, i32 8)
%30 = load %struct.pevent*, %struct.pevent** %5
%31 = load i64, i64* %8
%32 = call i32 @__data2host8(%struct.pevent* %30, i64 %31)
store i32 %32, i32* %9
%33 = load i32, i32* %9
%34 = sext i32 %33 to i64
store i64 %34, i64* %4
br label %36
35: ; preds = %3
store i64 0, i64* %4
br label %36
36: ; preds = %35, %27, %21, %15, %11
%37 = load i64, i64* %4
ret i64 %37
}

LLVM IR (-O2):
%struct.pevent = type { i32 }
define i64 @pevent_read_number(%struct.pevent* %0, i8* %1, i32 %2) {
%4 = alloca i64
switch i32 %2, label %22 [
i32 1, label %5
i32 2, label %8
i32 4, label %12
i32 8, label %16
]
5: ; preds = %3
%6 = load i8, i8* %1
%7 = zext i8 %6 to i64
br label %22
8: ; preds = %3
%9 = bitcast i8* %1 to i16*
%10 = load i16, i16* %9
%11 = tail call i64 @__data2host2(%struct.pevent* %0, i16 zeroext %10)
br label %22
12: ; preds = %3
%13 = bitcast i8* %1 to i32*
%14 = load i32, i32* %13
%15 = tail call i64 @__data2host4(%struct.pevent* %0, i32 %14)
br label %22
16: ; preds = %3
%17 = bitcast i64* %4 to i8*
%18 = call i32 @memcpy(i64* %4, i8* %1, i32 8)
%19 = load i64, i64* %4
%20 = call i32 @__data2host8(%struct.pevent* %0, i64 %19)
%21 = sext i32 %20 to i64
br label %22
22: ; preds = %3, %16, %12, %8, %5
%23 = phi i64 [ %21, %16 ], [ %15, %12 ], [ %11, %8 ], [ %7, %5 ], [ 0, %3 ]
ret i64 %23
}