#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
scalar_t__ malloc(unsigned int);
int matGetNextVariable__read_tag(unsigned int *, unsigned int *,
                                 unsigned char *);
int /*<<< orphan*/ memcpy(int *, unsigned char *, int);
int /*<<< orphan*/ stderr;
int matGetNextVariable_int32_array(int *outsz, size_t **out, int dsz,
                                   unsigned char *data_ptr) {
  unsigned int dtype, dsize, nvals;
  int utmp;
  int i, offset;
  size_t *out2;
  offset = matGetNextVariable__read_tag(&dtype, &dsize, data_ptr);
  if (dtype != 5) {
    fprintf(stderr, "Error: array type not miINT32, type %i\n", dtype);
    exit(0);
  }
  nvals = dsize / 4;
  *out = (size_t *)malloc(nvals * sizeof(size_t));
  out2 = *out;
  if (nvals > dsz) {
    fprintf(stderr, "Error: array size mis-match. dsz=%i\n", dsz);
    exit(0);
  }
  for (i = 0; i < nvals; i++) {
    utmp = 0;
    memcpy(&utmp, &data_ptr[offset + 4 * i], 4 * sizeof(char));
    out2[i] = (size_t)utmp;
  }
  *outsz = nvals;
  return offset + dsize;
}


x86 assembly (clang, -O0):
<matGetNextVariable_int32_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rdx
lea    -0x24(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <matGetNextVariable__read_tag@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x5,-0x24(%rbp)
je     11a4 <matGetNextVariable_int32_array+0x54>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
lea    0xe68(%rip),%rsi
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x28(%rbp),%eax
shr    $0x2,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jbe    11fb <matGetNextVariable_int32_array+0xab>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe39(%rip),%rsi
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jae    1255 <matGetNextVariable_int32_array+0x105>
movl   $0x0,-0x30(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x38(%rbp),%eax
mov    -0x34(%rbp),%ecx
shl    $0x2,%ecx
add    %ecx,%eax
cltq
add    %rax,%rsi
lea    -0x30(%rbp),%rdi
mov    $0x4,%edx
call   1050 <memcpy@plt>
movslq -0x30(%rbp),%rdx
mov    -0x40(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1202 <matGetNextVariable_int32_array+0xb2>
mov    -0x2c(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%eax
add    -0x28(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matGetNextVariable_int32_array>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r15
mov    %edx,%r12d
mov    %rsi,%rbx
mov    %rdi,0x10(%rsp)
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    %rcx,%rdx
call   1030 <matGetNextVariable__read_tag@plt>
mov    %eax,(%rsp)
mov    0xc(%rsp),%edx
cmp    $0x5,%edx
jne    122a <matGetNextVariable_int32_array+0xda>
mov    0x8(%rsp),%ebp
mov    %ebp,%r14d
shr    $0x2,%r14d
lea    0x0(,%r14,8),%edi
call   1060 <malloc@plt>
mov    %rax,(%rbx)
cmp    %r12d,%r14d
ja     123c <matGetNextVariable_int32_array+0xec>
cmp    $0x4,%ebp
jb     120c <matGetNextVariable_int32_array+0xbc>
mov    %rax,%r13
movslq (%rsp),%rax
cmp    $0x2,%r14d
mov    $0x1,%ebx
cmovae %r14d,%ebx
add    %rax,%r15
shl    $0x2,%rbx
xor    %ebp,%ebp
lea    0x4(%rsp),%r12
nopl   0x0(%rax)
movl   $0x0,0x4(%rsp)
lea    (%r15,%rbp,1),%rsi
mov    %r12,%rdi
mov    $0x4,%edx
call   1050 <memcpy@plt>
movslq 0x4(%rsp),%rax
mov    %rax,0x0(%r13,%rbp,2)
add    $0x4,%rbp
cmp    %rbp,%rbx
jne    11e0 <matGetNextVariable_int32_array+0x90>
mov    0x10(%rsp),%rax
mov    %r14d,(%rax)
mov    0x8(%rsp),%eax
add    (%rsp),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
lea    0xdc6(%rip),%rsi
jmp    124f <matGetNextVariable_int32_array+0xff>
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
lea    0xddc(%rip),%rsi
mov    %r12d,%edx
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [40 x i8] c"Error: array type not miINT32, type %i\0A\00"
@.str.1 = [37 x i8] c"Error: array size mis-match. dsz=%i\0A\00"
define i32 @matGetNextVariable_int32_array(i32* %0, i64** %1, i32 %2, i8* %3) {
%5 = alloca i32*
%6 = alloca i64**
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i64*
store i32* %0, i32** %5
store i64** %1, i64*** %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%16 = load i8*, i8** %8
%17 = call i32 @matGetNextVariable__read_tag(i32* %9, i32* %10, i8* %16)
store i32 %17, i32* %14
%18 = load i32, i32* %9
%19 = icmp ne i32 %18, 5
br i1 %19, label %20, label %25
20: ; preds = %4
%21 = load i32, i32* @stderr
%22 = load i32, i32* %9
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = call i32 @exit(i32 0)
unreachable
25: ; preds = %4
%26 = load i32, i32* %10
%27 = udiv i32 %26, 4
store i32 %27, i32* %11
%28 = load i32, i32* %11
%29 = zext i32 %28 to i64
%30 = mul i64 %29, 8
%31 = trunc i64 %30 to i32
%32 = call i64 @malloc(i32 %31)
%33 = inttoptr i64 %32 to i64*
%34 = load i64**, i64*** %6
store i64* %33, i64** %34
%35 = load i64**, i64*** %6
%36 = load i64*, i64** %35
store i64* %36, i64** %15
%37 = load i32, i32* %11
%38 = load i32, i32* %7
%39 = icmp ugt i32 %37, %38
br i1 %39, label %40, label %45
40: ; preds = %25
%41 = load i32, i32* @stderr
%42 = load i32, i32* %7
%43 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %42)
%44 = call i32 @exit(i32 0)
unreachable
45: ; preds = %25
store i32 0, i32* %13
br label %46
46: ; preds = %65, %45
%47 = load i32, i32* %13
%48 = load i32, i32* %11
%49 = icmp ult i32 %47, %48
br i1 %49, label %50, label %68
50: ; preds = %46
store i32 0, i32* %12
%51 = load i8*, i8** %8
%52 = load i32, i32* %14
%53 = load i32, i32* %13
%54 = mul nsw i32 4, %53
%55 = add nsw i32 %52, %54
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %51, i64 %56
%58 = call i32 @memcpy(i32* %12, i8* %57, i32 4)
%59 = load i32, i32* %12
%60 = sext i32 %59 to i64
%61 = load i64*, i64** %15
%62 = load i32, i32* %13
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i64, i64* %61, i64 %63
store i64 %60, i64* %64
br label %65
65: ; preds = %50
%66 = load i32, i32* %13
%67 = add nsw i32 %66, 1
store i32 %67, i32* %13
br label %46
68: ; preds = %46
%69 = load i32, i32* %11
%70 = load i32*, i32** %5
store i32 %69, i32* %70
%71 = load i32, i32* %14
%72 = load i32, i32* %10
%73 = add i32 %71, %72
ret i32 %73
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [40 x i8] c"Error: array type not miINT32, type %i\0A\00"
@.str.1 = [37 x i8] c"Error: array size mis-match. dsz=%i\0A\00"
define i32 @matGetNextVariable_int32_array(i32* nocapture writeonly %0, i64** nocapture writeonly %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = bitcast i32* %5 to i8*
%9 = bitcast i32* %6 to i8*
%10 = bitcast i32* %7 to i8*
%11 = call i32 @matGetNextVariable__read_tag(i32* %5, i32* %6, i8* %3)
%12 = load i32, i32* %5
%13 = icmp eq i32 %12, 5
br i1 %13, label %18, label %14
14: ; preds = %4
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %12)
%17 = call i32 @exit(i32 0)
unreachable
18: ; preds = %4
%19 = load i32, i32* %6
%20 = lshr i32 %19, 2
%21 = shl i32 %20, 3
%22 = call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to i64*
store i64* %23, i64** %1
%24 = icmp ugt i32 %20, %2
br i1 %24, label %31, label %25
25: ; preds = %18
%26 = icmp ult i32 %19, 4
br i1 %26, label %46, label %27
27: ; preds = %25
%28 = sext i32 %11 to i64
%29 = call i32 @llvm.umax.i32(i32 %20, i32 1)
%30 = zext i32 %29 to i64
br label %35
31: ; preds = %18
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%34 = call i32 @exit(i32 0)
unreachable
35: ; preds = %27, %35
%36 = phi i64 [ 0, %27 ], [ %44, %35 ]
store i32 0, i32* %7
%37 = shl nsw i64 %36, 2
%38 = add nsw i64 %37, %28
%39 = getelementptr inbounds i8, i8* %3, i64 %38
%40 = call i32 @memcpy(i32* %7, i8* %39, i32 4)
%41 = load i32, i32* %7
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i64, i64* %23, i64 %36
store i64 %42, i64* %43
%44 = add nuw nsw i64 %36, 1
%45 = icmp eq i64 %44, %30
br i1 %45, label %46, label %35
46: ; preds = %35, %25
store i32 %20, i32* %0
%47 = load i32, i32* %6
%48 = add i32 %47, %11
ret i32 %48
}