#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*/ types;
typedef int /*<<< orphan*/ sizes;

/* Variables and functions */
int /*<<< orphan*/ blosc_compress(int, int, int, int, char *, char *, int);
int /*<<< orphan*/ blosc_getitem(char *, int /*<<< orphan*/, int, char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
char rand();
char *test_getitem() {
  int sizes[] = {7, 64 * 3, 7 * 256, 500, 8000, 100000, 702713};
  int types[] = {1, 2, 3, 4, 5, 6, 7, 8, 16};
  int i, j, k;
  int ok;
  for (i = 0; i < sizeof(sizes) / sizeof(sizes[0]); i++) {
    for (j = 0; j < sizeof(types) / sizeof(types[0]); j++) {
      int n = sizes[i];
      int t = types[j];
      char *d = malloc(t * n);
      char *d2 = malloc(t * n);
      char *o = malloc(t * n + 16);
      for (k = 0; k < n; k++) {
        d[k] = rand();
      }
      blosc_compress(5, 1, t, t * n, d, o, t * n + 16);
      blosc_getitem(o, 0, n, d2);
      ok = 1;
      for (k = 0; ok && k < n; k++) {
        ok = (d[k] == d2[k]);
      }
      free(d);
      free(d2);
      free(o);
      do {
        if (!(ok))
          return "ERROR: getitem test failed";
      } while (0);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_getitem>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    0xe8e(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe8b(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe88(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe86(%rip),%eax
mov    %eax,-0x18(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xe80(%rip),%rsi
mov    $0x24,%edx
call   1060 <memcpy@plt>
movl   $0x0,-0x64(%rbp)
movslq -0x64(%rbp),%rax
cmp    $0x7,%rax
jae    137f <test_getitem+0x21f>
movl   $0x0,-0x68(%rbp)
movslq -0x68(%rbp),%rax
cmp    $0x9,%rax
jae    136c <test_getitem+0x20c>
movslq -0x64(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
mov    %eax,-0x74(%rbp)
movslq -0x68(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%eax
mov    %eax,-0x78(%rbp)
mov    -0x78(%rbp),%edi
imul   -0x74(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x80(%rbp)
mov    -0x78(%rbp),%edi
imul   -0x74(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x88(%rbp)
mov    -0x78(%rbp),%edi
imul   -0x74(%rbp),%edi
add    $0x10,%edi
call   1070 <malloc@plt>
mov    %rax,-0x90(%rbp)
movl   $0x0,-0x6c(%rbp)
mov    -0x6c(%rbp),%eax
cmp    -0x74(%rbp),%eax
jge    1258 <test_getitem+0xf8>
mov    $0x0,%al
call   1080 <rand@plt>
mov    %al,%dl
mov    -0x80(%rbp),%rax
movslq -0x6c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    122a <test_getitem+0xca>
mov    -0x78(%rbp),%edx
mov    -0x78(%rbp),%ecx
imul   -0x74(%rbp),%ecx
mov    -0x80(%rbp),%r8
mov    -0x90(%rbp),%r9
mov    -0x78(%rbp),%eax
imul   -0x74(%rbp),%eax
add    $0x10,%eax
mov    $0x5,%edi
mov    $0x1,%esi
mov    %eax,(%rsp)
call   1040 <blosc_compress@plt>
mov    -0x90(%rbp),%rdi
mov    -0x74(%rbp),%edx
mov    -0x88(%rbp),%rcx
xor    %esi,%esi
call   1050 <blosc_getitem@plt>
movl   $0x1,-0x70(%rbp)
movl   $0x0,-0x6c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x70(%rbp)
mov    %al,-0x91(%rbp)
je     12d0 <test_getitem+0x170>
mov    -0x6c(%rbp),%eax
cmp    -0x74(%rbp),%eax
setl   %al
mov    %al,-0x91(%rbp)
mov    -0x91(%rbp),%al
test   $0x1,%al
jne    12e3 <test_getitem+0x183>
jmp    1319 <test_getitem+0x1b9>
mov    -0x80(%rbp),%rax
movslq -0x6c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x88(%rbp),%rcx
movslq -0x6c(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x70(%rbp)
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    12af <test_getitem+0x14f>
mov    -0x80(%rbp),%rdi
call   1030 <free@plt>
mov    -0x88(%rbp),%rdi
call   1030 <free@plt>
mov    -0x90(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x70(%rbp)
jne    1354 <test_getitem+0x1f4>
lea    0xcf9(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1387 <test_getitem+0x227>
jmp    1359 <test_getitem+0x1f9>
jmp    135e <test_getitem+0x1fe>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    11c6 <test_getitem+0x66>
jmp    1371 <test_getitem+0x211>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    11b1 <test_getitem+0x51>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_getitem>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xe9b(%rip),%rax
xor    %ecx,%ecx
mov    %rcx,0x18(%rsp)
movslq (%rax,%rcx,4),%r15
cmp    $0x2,%r15d
mov    $0x1,%r13d
cmovge %r15d,%r13d
xor    %ecx,%ecx
lea    0xe99(%rip),%rax
mov    %rcx,0x20(%rsp)
mov    (%rax,%rcx,4),%eax
mov    %eax,0xc(%rsp)
mov    %eax,%r14d
imul   %r15d,%r14d
mov    %r14d,%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
mov    %r14d,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
lea    0x10(%r14),%edi
mov    %edi,0x8(%rsp)
call   1060 <malloc@plt>
mov    %rax,0x10(%rsp)
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1070 <rand@plt>
mov    %al,0x0(%rbp,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r13
jne    11d0 <test_getitem+0x80>
mov    0x8(%rsp),%eax
mov    %eax,(%rsp)
mov    $0x5,%edi
mov    $0x1,%esi
mov    0xc(%rsp),%edx
mov    %r14d,%ecx
mov    %rbp,%r8
mov    0x10(%rsp),%rbx
mov    %rbx,%r9
call   1040 <blosc_compress@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r15d,%edx
mov    %r12,%rcx
call   1050 <blosc_getitem@plt>
mov    $0x1,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl -0x1(%rbp,%rax,1),%r14d
movzbl -0x1(%r12,%rax,1),%ebx
cmp    %bl,%r14b
jne    124d <test_getitem+0xfd>
lea    0x1(%rax),%rcx
cmp    %r15,%rax
mov    %rcx,%rax
jl     1230 <test_getitem+0xe0>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
cmp    %bl,%r14b
jne    129d <test_getitem+0x14d>
mov    0x20(%rsp),%rcx
add    $0x1,%rcx
cmp    $0x9,%rcx
jne    1180 <test_getitem+0x30>
mov    0x18(%rsp),%rcx
add    $0x1,%rcx
cmp    $0x7,%rcx
lea    0xd6d(%rip),%rax
jne    1167 <test_getitem+0x17>
xor    %eax,%eax
jmp    12a4 <test_getitem+0x154>
lea    0xda0(%rip),%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.test_getitem.sizes = [7 x i32] [i32 7, i32 192, i32 1792, i32 500, i32 8000, i32 100000, i32 702713]
@__const.test_getitem.types = [9 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 16]
@.str = [27 x i8] c"ERROR: getitem test failed\00"
define i8* @test_getitem() {
%1 = alloca i8*
%2 = alloca [7 x i32]
%3 = alloca [9 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = bitcast [7 x i32]* %2 to i8*
%14 = bitcast [9 x i32]* %3 to i8*
store i32 0, i32* %4
br label %15
15: ; preds = %119, %0
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = icmp ult i64 %17, 7
br i1 %18, label %19, label %122
19: ; preds = %15
store i32 0, i32* %5
br label %20
20: ; preds = %115, %19
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = icmp ult i64 %22, 9
br i1 %23, label %24, label %118
24: ; preds = %20
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [7 x i32], [7 x i32]* %2, i64 0, i64 %26
%28 = load i32, i32* %27
store i32 %28, i32* %8
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [9 x i32], [9 x i32]* %3, i64 0, i64 %30
%32 = load i32, i32* %31
store i32 %32, i32* %9
%33 = load i32, i32* %9
%34 = load i32, i32* %8
%35 = mul nsw i32 %33, %34
%36 = call i8* @malloc(i32 %35)
store i8* %36, i8** %10
%37 = load i32, i32* %9
%38 = load i32, i32* %8
%39 = mul nsw i32 %37, %38
%40 = call i8* @malloc(i32 %39)
store i8* %40, i8** %11
%41 = load i32, i32* %9
%42 = load i32, i32* %8
%43 = mul nsw i32 %41, %42
%44 = add nsw i32 %43, 16
%45 = call i8* @malloc(i32 %44)
store i8* %45, i8** %12
store i32 0, i32* %6
br label %46
46: ; preds = %56, %24
%47 = load i32, i32* %6
%48 = load i32, i32* %8
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %59
50: ; preds = %46
%51 = call signext i8 (...) @rand()
%52 = load i8*, i8** %10
%53 = load i32, i32* %6
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
store i8 %51, i8* %55
br label %56
56: ; preds = %50
%57 = load i32, i32* %6
%58 = add nsw i32 %57, 1
store i32 %58, i32* %6
br label %46
59: ; preds = %46
%60 = load i32, i32* %9
%61 = load i32, i32* %9
%62 = load i32, i32* %8
%63 = mul nsw i32 %61, %62
%64 = load i8*, i8** %10
%65 = load i8*, i8** %12
%66 = load i32, i32* %9
%67 = load i32, i32* %8
%68 = mul nsw i32 %66, %67
%69 = add nsw i32 %68, 16
%70 = call i32 @blosc_compress(i32 5, i32 1, i32 %60, i32 %63, i8* %64, i8* %65, i32 %69)
%71 = load i8*, i8** %12
%72 = load i32, i32* %8
%73 = load i8*, i8** %11
%74 = call i32 @blosc_getitem(i8* %71, i32 0, i32 %72, i8* %73)
store i32 1, i32* %7
store i32 0, i32* %6
br label %75
75: ; preds = %99, %59
%76 = load i32, i32* %7
%77 = icmp ne i32 %76, 0
br i1 %77, label %78, label %82
78: ; preds = %75
%79 = load i32, i32* %6
%80 = load i32, i32* %8
%81 = icmp slt i32 %79, %80
br label %82
82: ; preds = %78, %75
%83 = phi i1 [ false, %75 ], [ %81, %78 ]
br i1 %83, label %84, label %102
84: ; preds = %82
%85 = load i8*, i8** %10
%86 = load i32, i32* %6
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds i8, i8* %85, i64 %87
%89 = load i8, i8* %88
%90 = sext i8 %89 to i32
%91 = load i8*, i8** %11
%92 = load i32, i32* %6
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds i8, i8* %91, i64 %93
%95 = load i8, i8* %94
%96 = sext i8 %95 to i32
%97 = icmp eq i32 %90, %96
%98 = zext i1 %97 to i32
store i32 %98, i32* %7
br label %99
99: ; preds = %84
%100 = load i32, i32* %6
%101 = add nsw i32 %100, 1
store i32 %101, i32* %6
br label %75
102: ; preds = %82
%103 = load i8*, i8** %10
%104 = call i32 @free(i8* %103)
%105 = load i8*, i8** %11
%106 = call i32 @free(i8* %105)
%107 = load i8*, i8** %12
%108 = call i32 @free(i8* %107)
br label %109
109: ; preds = %102
%110 = load i32, i32* %7
%111 = icmp ne i32 %110, 0
br i1 %111, label %113, label %112
112: ; preds = %109
store i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8** %1
br label %123
113: ; preds = %109
br label %114
114: ; preds = %113
br label %115
115: ; preds = %114
%116 = load i32, i32* %5
%117 = add nsw i32 %116, 1
store i32 %117, i32* %5
br label %20
118: ; preds = %20
br label %119
119: ; preds = %118
%120 = load i32, i32* %4
%121 = add nsw i32 %120, 1
store i32 %121, i32* %4
br label %15
122: ; preds = %15
store i8* null, i8** %1
br label %123
123: ; preds = %122, %112
%124 = load i8*, i8** %1
ret i8* %124
}

LLVM IR (-O2):
@__const.test_getitem.sizes = [7 x i32] [i32 7, i32 192, i32 1792, i32 500, i32 8000, i32 100000, i32 702713]
@__const.test_getitem.types = [9 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 16]
@.str = [27 x i8] c"ERROR: getitem test failed\00"
define i8* @test_getitem() {
br label %1
1: ; preds = %0, %43
%2 = phi i64 [ 0, %0 ], [ %44, %43 ]
%3 = getelementptr inbounds [7 x i32], [7 x i32]* @__const.test_getitem.sizes, i64 0, i64 %2
%4 = load i32, i32* %3
%5 = call i32 @llvm.smax.i32(i32 %4, i32 1)
%6 = sext i32 %4 to i64
%7 = zext i32 %5 to i64
br label %11
8: ; preds = %39
%9 = add nuw nsw i64 %12, 1
%10 = icmp eq i64 %9, 9
br i1 %10, label %43, label %11
11: ; preds = %8, %1
%12 = phi i64 [ 0, %1 ], [ %9, %8 ]
%13 = getelementptr inbounds [9 x i32], [9 x i32]* @__const.test_getitem.types, i64 0, i64 %12
%14 = load i32, i32* %13
%15 = mul nsw i32 %14, %4
%16 = tail call i8* @malloc(i32 %15)
%17 = tail call i8* @malloc(i32 %15)
%18 = add nsw i32 %15, 16
%19 = tail call i8* @malloc(i32 %18)
br label %20
20: ; preds = %11, %20
%21 = phi i64 [ 0, %11 ], [ %24, %20 ]
%22 = tail call signext i8 (...) @rand()
%23 = getelementptr inbounds i8, i8* %16, i64 %21
store i8 %22, i8* %23
%24 = add nuw nsw i64 %21, 1
%25 = icmp eq i64 %24, %7
br i1 %25, label %26, label %20
26: ; preds = %20
%27 = tail call i32 @blosc_compress(i32 5, i32 1, i32 %14, i32 %15, i8* %16, i8* %19, i32 %18)
%28 = tail call i32 @blosc_getitem(i8* %19, i32 0, i32 %4, i8* %17)
br label %29
29: ; preds = %26, %29
%30 = phi i64 [ 0, %26 ], [ %36, %29 ]
%31 = getelementptr inbounds i8, i8* %16, i64 %30
%32 = load i8, i8* %31
%33 = getelementptr inbounds i8, i8* %17, i64 %30
%34 = load i8, i8* %33
%35 = icmp eq i8 %32, %34
%36 = add nuw nsw i64 %30, 1
%37 = icmp slt i64 %36, %6
%38 = select i1 %35, i1 %37, i1 false
br i1 %38, label %29, label %39
39: ; preds = %29
%40 = tail call i32 @free(i8* %16)
%41 = tail call i32 @free(i8* %17)
%42 = tail call i32 @free(i8* %19)
br i1 %35, label %8, label %46
43: ; preds = %8
%44 = add nuw nsw i64 %2, 1
%45 = icmp eq i64 %44, 7
br i1 %45, label %46, label %1
46: ; preds = %43, %39
%47 = phi i8* [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), %39 ], [ null, %43 ]
ret i8* %47
}