#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*/ u_int32_t;
struct arreader {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ die(struct arreader *, char *);
int ntohl(int /*<<< orphan*/);
void parseIndex(struct arreader *a, void *arIndex, int size) {
  int num = ntohl(*((u_int32_t *)arIndex));
  int *positions = arIndex + sizeof(u_int32_t);
  char *names = arIndex + (sizeof(u_int32_t) * (num + 1));
  int nstring;
  for (nstring = 0; nstring < num; nstring++) {
    char *name = names;
    while (*names) {
      names++;
      if ((void *)names >= arIndex + size)
        die(a, "ar index is broken");
    }
    names++;
  }
}


x86 assembly (clang, -O0):
<parseIndex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1040 <ntohl@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11e0 <parseIndex+0xc0>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
je     11c6 <parseIndex+0xa6>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x14(%rbp),%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
jb     11c1 <parseIndex+0xa1>
mov    -0x8(%rbp),%rdi
lea    0xe44(%rip),%rsi
call   1030 <die@plt>
jmp    1180 <parseIndex+0x60>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    116c <parseIndex+0x4c>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseIndex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%r12
mov    %rdi,%r13
mov    (%rsi),%edi
call   1040 <ntohl@plt>
test   %eax,%eax
jle    119e <parseIndex+0x7e>
mov    %eax,%r14d
mov    %eax,%eax
lea    (%r12,%rax,4),%rbx
add    $0x4,%rbx
movslq %r15d,%rbp
add    %r12,%rbp
xor    %r12d,%r12d
lea    0xea4(%rip),%r15
jmp    1174 <parseIndex+0x54>
xchg   %ax,%ax
add    $0xffffffffffffffff,%rax
mov    %rax,%rbx
add    $0x1,%rbx
add    $0x1,%r12d
cmp    %r14d,%r12d
je     119e <parseIndex+0x7e>
cmpb   $0x0,(%rbx)
je     1167 <parseIndex+0x47>
add    $0x1,%rbx
jmp    118c <parseIndex+0x6c>
nop
lea    0x1(%rbx),%rax
cmpb   $0x0,(%rbx)
mov    %rax,%rbx
je     1160 <parseIndex+0x40>
cmp    %rbp,%rbx
jb     1180 <parseIndex+0x60>
mov    %r13,%rdi
mov    %r15,%rsi
call   1030 <die@plt>
jmp    1180 <parseIndex+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.arreader = type { i32 }
@.str = [19 x i8] c"ar index is broken\00"
define void @parseIndex(%struct.arreader* %0, i8* %1, i32 %2) {
%4 = alloca %struct.arreader*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
store %struct.arreader* %0, %struct.arreader** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%12 = load i8*, i8** %5
%13 = bitcast i8* %12 to i32*
%14 = load i32, i32* %13
%15 = call i32 @ntohl(i32 %14)
store i32 %15, i32* %7
%16 = load i8*, i8** %5
%17 = getelementptr i8, i8* %16, i64 4
%18 = bitcast i8* %17 to i32*
store i32* %18, i32** %8
%19 = load i8*, i8** %5
%20 = load i32, i32* %7
%21 = add nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = mul i64 4, %22
%24 = getelementptr i8, i8* %19, i64 %23
store i8* %24, i8** %9
store i32 0, i32* %10
br label %25
25: ; preds = %51, %3
%26 = load i32, i32* %10
%27 = load i32, i32* %7
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %54
29: ; preds = %25
%30 = load i8*, i8** %9
store i8* %30, i8** %11
br label %31
31: ; preds = %47, %29
%32 = load i8*, i8** %9
%33 = load i8, i8* %32
%34 = icmp ne i8 %33, 0
br i1 %34, label %35, label %48
35: ; preds = %31
%36 = load i8*, i8** %9
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %9
%38 = load i8*, i8** %9
%39 = load i8*, i8** %5
%40 = load i32, i32* %6
%41 = sext i32 %40 to i64
%42 = getelementptr i8, i8* %39, i64 %41
%43 = icmp uge i8* %38, %42
br i1 %43, label %44, label %47
44: ; preds = %35
%45 = load %struct.arreader*, %struct.arreader** %4
%46 = call i32 @die(%struct.arreader* %45, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %47
47: ; preds = %44, %35
br label %31
48: ; preds = %31
%49 = load i8*, i8** %9
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %9
br label %51
51: ; preds = %48
%52 = load i32, i32* %10
%53 = add nsw i32 %52, 1
store i32 %53, i32* %10
br label %25
54: ; preds = %25
ret void
}

LLVM IR (-O2):
%struct.arreader = type { i32 }
@.str = [19 x i8] c"ar index is broken\00"
define void @parseIndex(%struct.arreader* %0, i8* %1, i32 %2) {
%4 = bitcast i8* %1 to i32*
%5 = load i32, i32* %4
%6 = tail call i32 @ntohl(i32 %5)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %34
8: ; preds = %3
%9 = add nuw nsw i32 %6, 1
%10 = zext i32 %9 to i64
%11 = shl nuw nsw i64 %10, 2
%12 = getelementptr i8, i8* %1, i64 %11
%13 = sext i32 %2 to i64
%14 = getelementptr i8, i8* %1, i64 %13
br label %15
15: ; preds = %8, %29
%16 = phi i8* [ %12, %8 ], [ %31, %29 ]
%17 = phi i32 [ 0, %8 ], [ %32, %29 ]
%18 = load i8, i8* %16
%19 = icmp eq i8 %18, 0
br i1 %19, label %29, label %20
20: ; preds = %15, %26
%21 = phi i8* [ %22, %26 ], [ %16, %15 ]
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = icmp ult i8* %22, %14
br i1 %23, label %26, label %24
24: ; preds = %20
%25 = tail call i32 @die(%struct.arreader* %0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %24, %20
%27 = load i8, i8* %22
%28 = icmp eq i8 %27, 0
br i1 %28, label %29, label %20
29: ; preds = %26, %15
%30 = phi i8* [ %16, %15 ], [ %22, %26 ]
%31 = getelementptr inbounds i8, i8* %30, i64 1
%32 = add nuw nsw i32 %17, 1
%33 = icmp eq i32 %32, %6
br i1 %33, label %34, label %15
34: ; preds = %29, %3
ret void
}