#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*/ label;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int bufToInt32(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ getLabel(int /*<<< orphan*/ **, char *, int);
int getOrdinal(int /*<<< orphan*/ **);
int /*<<< orphan*/ printf(char *);
int readTag(int, char *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ skipStructEntry(int /*<<< orphan*/ **);
int getValueAsInt(int entId, int index) {
  uint8_t buffer[100000];
  uint8_t *pnt = buffer;
  char label[256];
  int bufLen = readTag(entId, "values", buffer, sizeof(buffer));
  if (!bufLen) {
    printf("Error - ENT file does not contain a tag 'values'\n");
    return -1;
  }
  while (index-- > 0)
    skipStructEntry(&pnt);
  int ordinal = getOrdinal(&pnt);
  getLabel(&pnt, label, sizeof(label));
  if (ordinal != 3) {
    printf("Error - requested value is not a normal non-meta block, or some "
           "other error in filestructure.\n");
    exit(0);
  }
  return bufToInt32(pnt);
}


x86 assembly (clang, -O0):
<getValueAsInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x61bb0,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x61a90(%rbp),%rax
mov    %rax,-0x61a98(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x61a90(%rbp),%rdx
lea    0xe60(%rip),%rsi
mov    $0x61a80,%ecx
call   1060 <readTag@plt>
mov    %eax,-0x61ba4(%rbp)
cmpl   $0x0,-0x61ba4(%rbp)
jne    11d5 <getValueAsInt+0x65>
lea    0xe43(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1258 <getValueAsInt+0xe8>
jmp    11da <getValueAsInt+0x6a>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
jle    11ff <getValueAsInt+0x8f>
lea    -0x61a98(%rbp),%rdi
call   1090 <skipStructEntry@plt>
jmp    11da <getValueAsInt+0x6a>
lea    -0x61a98(%rbp),%rdi
call   1040 <getOrdinal@plt>
mov    %eax,-0x61ba8(%rbp)
lea    -0x61ba0(%rbp),%rsi
lea    -0x61a98(%rbp),%rdi
mov    $0x100,%edx
call   1050 <getLabel@plt>
cmpl   $0x3,-0x61ba8(%rbp)
je     1249 <getValueAsInt+0xd9>
lea    0xdfc(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x61a98(%rbp),%rdi
call   1070 <bufToInt32@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x61bb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getValueAsInt>:
push   %rbp
push   %r14
push   %rbx
sub    $0x61b90,%rsp
mov    %esi,%ebx
lea    0x110(%rsp),%rdx
mov    %rdx,0x8(%rsp)
lea    0xe6f(%rip),%rsi
mov    $0x61a80,%ecx
call   1060 <readTag@plt>
test   %eax,%eax
je     11f2 <getValueAsInt+0x82>
test   %ebx,%ebx
jle    11c0 <getValueAsInt+0x50>
add    $0x1,%ebx
lea    0x8(%rsp),%r14
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1090 <skipStructEntry@plt>
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
ja     11b0 <getValueAsInt+0x40>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <getOrdinal@plt>
mov    %eax,%ebp
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x100,%edx
call   1050 <getLabel@plt>
cmp    $0x3,%ebp
jne    120f <getValueAsInt+0x9f>
mov    0x8(%rsp),%rdi
call   1070 <bufToInt32@plt>
jmp    1203 <getValueAsInt+0x93>
lea    0xe0e(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x61b90,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe22(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"values\00"
@.str.1 = [50 x i8] c"Error - ENT file does not contain a tag 'values'\0A\00"
@.str.2 = [95 x i8] c"Error - requested value is not a normal non-meta block, or some other error in filestructure.\0A\00"
define i32 @getValueAsInt(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [100000 x i32]
%7 = alloca i32*
%8 = alloca [256 x i8]
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%11 = getelementptr inbounds [100000 x i32], [100000 x i32]* %6, i64 0, i64 0
store i32* %11, i32** %7
%12 = load i32, i32* %4
%13 = getelementptr inbounds [100000 x i32], [100000 x i32]* %6, i64 0, i64 0
%14 = call i32 @readTag(i32 %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* %13, i32 400000)
store i32 %14, i32* %9
%15 = load i32, i32* %9
%16 = icmp ne i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %2
%18 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %38
19: ; preds = %2
br label %20
20: ; preds = %24, %19
%21 = load i32, i32* %5
%22 = add nsw i32 %21, -1
store i32 %22, i32* %5
%23 = icmp sgt i32 %21, 0
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = call i32 @skipStructEntry(i32** %7)
br label %20
26: ; preds = %20
%27 = call i32 @getOrdinal(i32** %7)
store i32 %27, i32* %10
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%29 = call i32 @getLabel(i32** %7, i8* %28, i32 256)
%30 = load i32, i32* %10
%31 = icmp ne i32 %30, 3
br i1 %31, label %32, label %35
32: ; preds = %26
%33 = call i32 @printf(i8* getelementptr inbounds ([95 x i8], [95 x i8]* @.str.2, i64 0, i64 0))
%34 = call i32 @exit(i32 0)
unreachable
35: ; preds = %26
%36 = load i32*, i32** %7
%37 = call i32 @bufToInt32(i32* %36)
store i32 %37, i32* %3
br label %38
38: ; preds = %35, %17
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@.str = [7 x i8] c"values\00"
@str = [49 x i8] c"Error - ENT file does not contain a tag 'values'\00"
@str.3 = [94 x i8] c"Error - requested value is not a normal non-meta block, or some other error in filestructure.\00"
define i32 @getValueAsInt(i32 %0, i32 %1) {
%3 = alloca [100000 x i32]
%4 = alloca i32*
%5 = alloca [256 x i8]
%6 = bitcast [100000 x i32]* %3 to i8*
%7 = bitcast i32** %4 to i8*
%8 = getelementptr inbounds [100000 x i32], [100000 x i32]* %3, i64 0, i64 0
store i32* %8, i32** %4
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%10 = call i32 @readTag(i32 %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* %8, i32 400000)
%11 = icmp eq i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = icmp sgt i32 %1, 0
br i1 %13, label %16, label %21
14: ; preds = %2
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str, i64 0, i64 0))
br label %31
16: ; preds = %12, %16
%17 = phi i32 [ %18, %16 ], [ %1, %12 ]
%18 = add nsw i32 %17, -1
%19 = call i32 @skipStructEntry(i32** %4)
%20 = icmp ugt i32 %17, 1
br i1 %20, label %16, label %21
21: ; preds = %16, %12
%22 = call i32 @getOrdinal(i32** %4)
%23 = call i32 @getLabel(i32** %4, i8* %9, i32 256)
%24 = icmp eq i32 %22, 3
br i1 %24, label %28, label %25
25: ; preds = %21
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([94 x i8], [94 x i8]* @str.3, i64 0, i64 0))
%27 = call i32 @exit(i32 0)
unreachable
28: ; preds = %21
%29 = load i32*, i32** %4
%30 = call i32 @bufToInt32(i32* %29)
br label %31
31: ; preds = %28, %14
%32 = phi i32 [ %30, %28 ], [ -1, %14 ]
ret i32 %32
}