#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*/ memcpy(int *, unsigned char *, int);
int matGetNextVariable__read_tag(unsigned int *dtype, unsigned int *dsize,
                                 unsigned char *data_ptr) {
  int tag[2];
  memcpy(tag, data_ptr, 8);
  *dtype = tag[0] & 0x000000ff;
  if (tag[0] & 0xffff0000) {
    *dsize = (tag[0] >> 16);
    return 4;
  } else {
    *dsize = tag[1];
    return 8;
  }
}


x86 assembly (clang, -O0):
<matGetNextVariable__read_tag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1030 <memcpy@plt>
mov    -0x28(%rbp),%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%eax
and    $0xffff0000,%eax
cmp    $0x0,%eax
je     116e <matGetNextVariable__read_tag+0x5e>
mov    -0x28(%rbp),%ecx
sar    $0x10,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x4,-0x4(%rbp)
jmp    117e <matGetNextVariable__read_tag+0x6e>
mov    -0x24(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x8,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matGetNextVariable__read_tag>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%rdi
mov    %rdx,%rsi
mov    $0x8,%edx
call   1030 <memcpy@plt>
mov    (%rsp),%ecx
movzbl %cl,%eax
mov    %eax,(%rbx)
xor    %eax,%eax
cmp    $0x10000,%ecx
setb   %dl
jae    1145 <matGetNextVariable__read_tag+0x35>
mov    0x4(%rsp),%ecx
jmp    1148 <matGetNextVariable__read_tag+0x38>
sar    $0x10,%ecx
mov    %dl,%al
lea    0x4(,%rax,4),%eax
mov    %ecx,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @matGetNextVariable__read_tag(i32* %0, i32* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca [2 x i32]
store i32* %0, i32** %5
store i32* %1, i32** %6
store i8* %2, i8** %7
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%10 = load i8*, i8** %7
%11 = call i32 @memcpy(i32* %9, i8* %10, i32 8)
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%13 = load i32, i32* %12
%14 = and i32 %13, 255
%15 = load i32*, i32** %5
store i32 %14, i32* %15
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%17 = load i32, i32* %16
%18 = and i32 %17, -65536
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %3
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%22 = load i32, i32* %21
%23 = ashr i32 %22, 16
%24 = load i32*, i32** %6
store i32 %23, i32* %24
store i32 4, i32* %4
br label %29
25: ; preds = %3
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%27 = load i32, i32* %26
%28 = load i32*, i32** %6
store i32 %27, i32* %28
store i32 8, i32* %4
br label %29
29: ; preds = %25, %20
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
define i32 @matGetNextVariable__read_tag(i32* nocapture writeonly %0, i32* nocapture writeonly %1, i8* %2) {
%4 = alloca [2 x i32]
%5 = bitcast [2 x i32]* %4 to i8*
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%7 = call i32 @memcpy(i32* %6, i8* %2, i32 8)
%8 = load i32, i32* %6
%9 = and i32 %8, 255
store i32 %9, i32* %0
%10 = icmp ult i32 %8, 65536
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%12 = load i32, i32* %11
%13 = ashr i32 %8, 16
%14 = select i1 %10, i32 %12, i32 %13
%15 = select i1 %10, i32 8, i32 4
store i32 %14, i32* %1
ret i32 %15
}