#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 /*<<< 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 /*<<< orphan*/ uint32ToBuf(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ writeTagPart(int, char *, int, int /*<<< orphan*/ *, int);
void setValueAsInt(int entId, int index, int value) {
  uint8_t buffer[100000];
  uint8_t *pnt = buffer;
  char label[256];
  int bufLen = readTag(entId, "values", buffer, sizeof(buffer));
  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);
  }
  uint8_t buf[4];
  uint32ToBuf(value, buf);
  writeTagPart(entId, "values", pnt - buffer, buf, 4);
}


x86 assembly (clang, -O0):
<setValueAsInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x61bc0,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
lea    -0x61a90(%rbp),%rax
mov    %rax,-0x61a98(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x61a90(%rbp),%rdx
lea    0xe4d(%rip),%rsi
mov    $0x61a80,%ecx
call   1070 <readTag@plt>
mov    %eax,-0x61ba4(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
jle    11e8 <setValueAsInt+0x68>
lea    -0x61a98(%rbp),%rdi
call   10a0 <skipStructEntry@plt>
jmp    11c3 <setValueAsInt+0x43>
lea    -0x61a98(%rbp),%rdi
call   1050 <getOrdinal@plt>
mov    %eax,-0x61ba8(%rbp)
lea    -0x61ba0(%rbp),%rsi
lea    -0x61a98(%rbp),%rdi
mov    $0x100,%edx
call   1060 <getLabel@plt>
cmpl   $0x3,-0x61ba8(%rbp)
je     1232 <setValueAsInt+0xb2>
lea    0xde1(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0xc(%rbp),%edi
lea    -0x61bc0(%rbp),%rsi
call   1040 <uint32ToBuf@plt>
mov    -0x4(%rbp),%edi
mov    -0x61a98(%rbp),%rax
lea    -0x61a90(%rbp),%rcx
sub    %rcx,%rax
sar    $0x2,%rax
mov    %eax,%edx
lea    -0x61bc0(%rbp),%rcx
lea    0xd97(%rip),%rsi
mov    $0x4,%r8d
call   1090 <writeTagPart@plt>
add    $0x61bc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setValueAsInt>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x61ba0,%rsp
mov    %edx,%r15d
mov    %esi,%ebp
mov    %edi,%r12d
lea    0x120(%rsp),%r14
mov    %r14,0x8(%rsp)
lea    0xe55(%rip),%rsi
mov    %r14,%rdx
mov    $0x61a80,%ecx
call   1070 <readTag@plt>
test   %ebp,%ebp
jle    11e0 <setValueAsInt+0x60>
add    $0x1,%ebp
lea    0x8(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   10a0 <skipStructEntry@plt>
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
ja     11d0 <setValueAsInt+0x50>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <getOrdinal@plt>
mov    %eax,%ebp
lea    0x20(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x100,%edx
call   1060 <getLabel@plt>
cmp    $0x3,%ebp
jne    124a <setValueAsInt+0xca>
lea    0x10(%rsp),%rbx
mov    %r15d,%edi
mov    %rbx,%rsi
call   1040 <uint32ToBuf@plt>
mov    0x8(%rsp),%rdx
sub    %r14,%rdx
shr    $0x2,%rdx
lea    0xdd7(%rip),%rsi
mov    %r12d,%edi
mov    %rbx,%rcx
mov    $0x4,%r8d
call   1090 <writeTagPart@plt>
add    $0x61ba0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdb6(%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 = [95 x i8] c"Error - requested value is not a normal non-meta block, or some other error in filestructure.\0A\00"
define void @setValueAsInt(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [100000 x i32]
%8 = alloca i32*
%9 = alloca [256 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca [4 x i32]
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%13 = getelementptr inbounds [100000 x i32], [100000 x i32]* %7, i64 0, i64 0
store i32* %13, i32** %8
%14 = load i32, i32* %4
%15 = getelementptr inbounds [100000 x i32], [100000 x i32]* %7, i64 0, i64 0
%16 = call i32 @readTag(i32 %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* %15, i32 400000)
store i32 %16, i32* %10
br label %17
17: ; preds = %21, %3
%18 = load i32, i32* %5
%19 = add nsw i32 %18, -1
store i32 %19, i32* %5
%20 = icmp sgt i32 %18, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 @skipStructEntry(i32** %8)
br label %17
23: ; preds = %17
%24 = call i32 @getOrdinal(i32** %8)
store i32 %24, i32* %11
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%26 = call i32 @getLabel(i32** %8, i8* %25, i32 256)
%27 = load i32, i32* %11
%28 = icmp ne i32 %27, 3
br i1 %28, label %29, label %32
29: ; preds = %23
%30 = call i32 @printf(i8* getelementptr inbounds ([95 x i8], [95 x i8]* @.str.1, i64 0, i64 0))
%31 = call i32 @exit(i32 0)
unreachable
32: ; preds = %23
%33 = load i32, i32* %6
%34 = getelementptr inbounds [4 x i32], [4 x i32]* %12, i64 0, i64 0
%35 = call i32 @uint32ToBuf(i32 %33, i32* %34)
%36 = load i32, i32* %4
%37 = load i32*, i32** %8
%38 = getelementptr inbounds [100000 x i32], [100000 x i32]* %7, i64 0, i64 0
%39 = ptrtoint i32* %37 to i64
%40 = ptrtoint i32* %38 to i64
%41 = sub i64 %39, %40
%42 = sdiv exact i64 %41, 4
%43 = trunc i64 %42 to i32
%44 = getelementptr inbounds [4 x i32], [4 x i32]* %12, i64 0, i64 0
%45 = call i32 @writeTagPart(i32 %36, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %43, i32* %44, i32 4)
ret void
}

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