#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 */
typedef int /*<<< orphan*/ uint8_t;
typedef int /*<<< orphan*/ uint64_t;
typedef int /*<<< orphan*/ uint32_t;
typedef int /*<<< orphan*/ uint16_t;

/* Variables and functions */
int /*<<< orphan*/ memcpy(void *, int /*<<< orphan*/ *, size_t);
int /*<<< orphan*/ mvhd_from_be16(int /*<<< orphan*/);
int /*<<< orphan*/ mvhd_from_be32(int /*<<< orphan*/);
int /*<<< orphan*/ mvhd_from_be64(int /*<<< orphan*/);
void mvhd_next_buffer_to_struct(void *struct_memb, size_t memb_size,
                                bool req_endian, uint8_t **buffer) {
  memcpy(struct_memb, *buffer, memb_size);
  if (req_endian) {
    switch (memb_size) {
    case 2:
      *(uint16_t *)(struct_memb) = mvhd_from_be16(*(uint16_t *)(struct_memb));
      break;
    case 4:
      *(uint32_t *)(struct_memb) = mvhd_from_be32(*(uint32_t *)(struct_memb));
      break;
    case 8:
      *(uint64_t *)(struct_memb) = mvhd_from_be64(*(uint64_t *)(struct_memb));
      break;
    }
  }
  *buffer += memb_size;
}


x86 assembly (clang, -O0):
<mvhd_next_buffer_to_struct>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <memcpy@plt>
cmpl   $0x0,-0x14(%rbp)
je     11fa <mvhd_next_buffer_to_struct+0xba>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
sub    $0x2,%rax
je     11b2 <mvhd_next_buffer_to_struct+0x72>
jmp    118c <mvhd_next_buffer_to_struct+0x4c>
mov    -0x28(%rbp),%rax
sub    $0x4,%rax
je     11ca <mvhd_next_buffer_to_struct+0x8a>
jmp    119f <mvhd_next_buffer_to_struct+0x5f>
mov    -0x28(%rbp),%rax
sub    $0x8,%rax
je     11e2 <mvhd_next_buffer_to_struct+0xa2>
jmp    11f5 <mvhd_next_buffer_to_struct+0xb5>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1050 <mvhd_from_be16@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    11f5 <mvhd_next_buffer_to_struct+0xb5>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1030 <mvhd_from_be32@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    11f5 <mvhd_next_buffer_to_struct+0xb5>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1060 <mvhd_from_be64@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    11fa <mvhd_next_buffer_to_struct+0xba>
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%rax
shl    $0x2,%rcx
add    (%rax),%rcx
mov    %rcx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mvhd_next_buffer_to_struct>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r15
mov    (%rcx),%rsi
mov    %rbx,%rdx
call   1040 <memcpy@plt>
test   %ebp,%ebp
je     1192 <mvhd_next_buffer_to_struct+0x52>
cmp    $0x8,%rbx
je     117d <mvhd_next_buffer_to_struct+0x3d>
cmp    $0x4,%rbx
je     1187 <mvhd_next_buffer_to_struct+0x47>
cmp    $0x2,%rbx
jne    1192 <mvhd_next_buffer_to_struct+0x52>
mov    (%r15),%edi
call   1050 <mvhd_from_be16@plt>
jmp    118f <mvhd_next_buffer_to_struct+0x4f>
mov    (%r15),%edi
call   1060 <mvhd_from_be64@plt>
jmp    118f <mvhd_next_buffer_to_struct+0x4f>
mov    (%r15),%edi
call   1030 <mvhd_from_be32@plt>
mov    %eax,(%r15)
shl    $0x2,%rbx
add    %rbx,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @mvhd_next_buffer_to_struct(i8* %0, i64 %1, i32 %2, i32** %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32**
store i8* %0, i8** %5
store i64 %1, i64* %6
store i32 %2, i32* %7
store i32** %3, i32*** %8
%9 = load i8*, i8** %5
%10 = load i32**, i32*** %8
%11 = load i32*, i32** %10
%12 = load i64, i64* %6
%13 = call i32 @memcpy(i8* %9, i32* %11, i64 %12)
%14 = load i32, i32* %7
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %40
16: ; preds = %4
%17 = load i64, i64* %6
switch i64 %17, label %39 [
i64 2, label %18
i64 4, label %25
i64 8, label %32
]
18: ; preds = %16
%19 = load i8*, i8** %5
%20 = bitcast i8* %19 to i32*
%21 = load i32, i32* %20
%22 = call i32 @mvhd_from_be16(i32 %21)
%23 = load i8*, i8** %5
%24 = bitcast i8* %23 to i32*
store i32 %22, i32* %24
br label %39
25: ; preds = %16
%26 = load i8*, i8** %5
%27 = bitcast i8* %26 to i32*
%28 = load i32, i32* %27
%29 = call i32 @mvhd_from_be32(i32 %28)
%30 = load i8*, i8** %5
%31 = bitcast i8* %30 to i32*
store i32 %29, i32* %31
br label %39
32: ; preds = %16
%33 = load i8*, i8** %5
%34 = bitcast i8* %33 to i32*
%35 = load i32, i32* %34
%36 = call i32 @mvhd_from_be64(i32 %35)
%37 = load i8*, i8** %5
%38 = bitcast i8* %37 to i32*
store i32 %36, i32* %38
br label %39
39: ; preds = %16, %32, %25, %18
br label %40
40: ; preds = %39, %4
%41 = load i64, i64* %6
%42 = load i32**, i32*** %8
%43 = load i32*, i32** %42
%44 = getelementptr inbounds i32, i32* %43, i64 %41
store i32* %44, i32** %42
ret void
}

LLVM IR (-O2):
define void @mvhd_next_buffer_to_struct(i8* %0, i64 %1, i32 %2, i32** nocapture %3) {
%5 = load i32*, i32** %3
%6 = tail call i32 @memcpy(i8* %0, i32* %5, i64 %1)
%7 = icmp eq i32 %2, 0
br i1 %7, label %21, label %8
8: ; preds = %4
switch i64 %1, label %21 [
i64 2, label %9
i64 4, label %13
i64 8, label %17
]
9: ; preds = %8
%10 = bitcast i8* %0 to i32*
%11 = load i32, i32* %10
%12 = tail call i32 @mvhd_from_be16(i32 %11)
store i32 %12, i32* %10
br label %21
13: ; preds = %8
%14 = bitcast i8* %0 to i32*
%15 = load i32, i32* %14
%16 = tail call i32 @mvhd_from_be32(i32 %15)
store i32 %16, i32* %14
br label %21
17: ; preds = %8
%18 = bitcast i8* %0 to i32*
%19 = load i32, i32* %18
%20 = tail call i32 @mvhd_from_be64(i32 %19)
store i32 %20, i32* %18
br label %21
21: ; preds = %9, %13, %17, %8, %4
%22 = load i32*, i32** %3
%23 = getelementptr inbounds i32, i32* %22, i64 %1
store i32* %23, i32** %3
ret void
}