#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*/ FILE;

/* Variables and functions */
unsigned int read_be32(unsigned int);
scalar_t__ read_packet(int /*<<< orphan*/ *, char *);
unsigned int *read_index_packet(FILE *fp, char *expect) {
  unsigned int *rv = (unsigned int *)read_packet(fp, expect);
  int i;
  if (!rv) {
    return NULL;
  }
  for (i = 2; i < rv[0] / 4; i++) {
    rv[i] = read_be32(rv[i]);
  }
  return rv;
}


x86 assembly (clang, -O0):
<read_index_packet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <read_packet@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1159 <read_index_packet+0x39>
movq   $0x0,-0x8(%rbp)
jmp    11a7 <read_index_packet+0x87>
movl   $0x2,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%rcx
mov    (%rcx),%ecx
shr    $0x2,%ecx
cmp    %ecx,%eax
jae    119f <read_index_packet+0x7f>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1040 <read_be32@plt>
mov    %eax,%edx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1160 <read_index_packet+0x40>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_index_packet>:
push   %r14
push   %rbx
push   %rax
call   1030 <read_packet@plt>
test   %rax,%rax
je     115f <read_index_packet+0x3f>
mov    %rax,%r14
cmpl   $0xc,(%rax)
jb     1162 <read_index_packet+0x42>
mov    $0x2,%ebx
nopl   0x0(%rax,%rax,1)
mov    (%r14,%rbx,4),%edi
call   1040 <read_be32@plt>
mov    %eax,(%r14,%rbx,4)
add    $0x1,%rbx
mov    (%r14),%eax
shr    $0x2,%rax
cmp    %rax,%rbx
jb     1140 <read_index_packet+0x20>
jmp    1162 <read_index_packet+0x42>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32* @read_index_packet(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
%8 = load i32*, i32** %4
%9 = load i8*, i8** %5
%10 = call i64 @read_packet(i32* %8, i8* %9)
%11 = inttoptr i64 %10 to i32*
store i32* %11, i32** %6
%12 = load i32*, i32** %6
%13 = icmp ne i32* %12, null
br i1 %13, label %15, label %14
14: ; preds = %2
store i32* null, i32** %3
br label %39
15: ; preds = %2
store i32 2, i32* %7
br label %16
16: ; preds = %34, %15
%17 = load i32, i32* %7
%18 = load i32*, i32** %6
%19 = getelementptr inbounds i32, i32* %18, i64 0
%20 = load i32, i32* %19
%21 = udiv i32 %20, 4
%22 = icmp ult i32 %17, %21
br i1 %22, label %23, label %37
23: ; preds = %16
%24 = load i32*, i32** %6
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
%28 = load i32, i32* %27
%29 = call i32 @read_be32(i32 %28)
%30 = load i32*, i32** %6
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
store i32 %29, i32* %33
br label %34
34: ; preds = %23
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
store i32 %36, i32* %7
br label %16
37: ; preds = %16
%38 = load i32*, i32** %6
store i32* %38, i32** %3
br label %39
39: ; preds = %37, %14
%40 = load i32*, i32** %3
ret i32* %40
}

LLVM IR (-O2):
define i32* @read_index_packet(i32* %0, i8* %1) {
%3 = tail call i64 @read_packet(i32* %0, i8* %1)
%4 = inttoptr i64 %3 to i32*
%5 = icmp eq i64 %3, 0
br i1 %5, label %19, label %6
6: ; preds = %2
%7 = load i32, i32* %4
%8 = icmp ugt i32 %7, 11
br i1 %8, label %9, label %19
9: ; preds = %6, %9
%10 = phi i64 [ %14, %9 ], [ 2, %6 ]
%11 = getelementptr inbounds i32, i32* %4, i64 %10
%12 = load i32, i32* %11
%13 = tail call i32 @read_be32(i32 %12)
store i32 %13, i32* %11
%14 = add nuw nsw i64 %10, 1
%15 = load i32, i32* %4
%16 = lshr i32 %15, 2
%17 = zext i32 %16 to i64
%18 = icmp ult i64 %14, %17
br i1 %18, label %9, label %19
19: ; preds = %9, %6, %2
%20 = phi i32* [ null, %2 ], [ %4, %6 ], [ %4, %9 ]
ret i32* %20
}