#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 char uint8_t;

/* Variables and functions */
int get_int32_be(char *);
int /*<<< orphan*/ printf(char *, int, ...);
scalar_t__ strlen(char *);
int imports_ar_read_lookup_table(uint8_t *buffer, int size) {
  int entry_count;
  int ptr_offset;
  int ptr_name;
  int n;
  entry_count = get_int32_be(buffer);
  printf("entry_count=%d\n", entry_count);
  ptr_offset = 4;
  ptr_name = ptr_offset + (entry_count * 4);
  for (n = 0; n < entry_count; n++) {
    int offset = get_int32_be(buffer + ptr_offset);
    printf("%d) 0x%04x %s\n", n, offset, buffer + ptr_name);
    ptr_offset += 4;
    ptr_name += strlen((char *)(buffer + ptr_name)) + 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<imports_ar_read_lookup_table>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <get_int32_be@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x4,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%ecx
shl    $0x2,%ecx
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11ee <imports_ar_read_lookup_table+0xbe>
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
call   1050 <get_int32_be@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x8(%rbp),%rcx
movslq -0x18(%rbp),%rax
add    %rax,%rcx
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
add    $0x1,%rcx
movslq -0x18(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1178 <imports_ar_read_lookup_table+0x48>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<imports_ar_read_lookup_table>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <get_int32_be@plt>
mov    %eax,%r15d
lea    0xeb3(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r15d,%r15d
jle    11b0 <imports_ar_read_lookup_table+0x80>
lea    0x4(,%r15,4),%r13d
lea    0x4(%r14),%rbx
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1050 <get_int32_be@plt>
movslq %r13d,%r12
lea    (%r14,%r12,1),%r13
lea    0xe8a(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
mov    %r13,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13,%rdi
call   1030 <strlen@plt>
lea    (%r12,%rax,1),%r13d
add    $0x1,%r13d
add    $0x1,%ebp
add    $0x4,%rbx
cmp    %ebp,%r15d
jne    1170 <imports_ar_read_lookup_table+0x40>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"entry_count=%d\0A\00"
@.str.1 = [15 x i8] c"%d) 0x%04x %s\0A\00"
define i32 @imports_ar_read_lookup_table(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%10 = load i8*, i8** %3
%11 = call i32 @get_int32_be(i8* %10)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 4, i32* %6
%14 = load i32, i32* %6
%15 = load i32, i32* %5
%16 = mul nsw i32 %15, 4
%17 = add nsw i32 %14, %16
store i32 %17, i32* %7
store i32 0, i32* %8
br label %18
18: ; preds = %47, %2
%19 = load i32, i32* %8
%20 = load i32, i32* %5
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %50
22: ; preds = %18
%23 = load i8*, i8** %3
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = call i32 @get_int32_be(i8* %26)
store i32 %27, i32* %9
%28 = load i32, i32* %8
%29 = load i32, i32* %9
%30 = load i8*, i8** %3
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %28, i32 %29, i8* %33)
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 4
store i32 %36, i32* %6
%37 = load i8*, i8** %3
%38 = load i32, i32* %7
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = call i64 @strlen(i8* %40)
%42 = add nsw i64 %41, 1
%43 = load i32, i32* %7
%44 = sext i32 %43 to i64
%45 = add nsw i64 %44, %42
%46 = trunc i64 %45 to i32
store i32 %46, i32* %7
br label %47
47: ; preds = %22
%48 = load i32, i32* %8
%49 = add nsw i32 %48, 1
store i32 %49, i32* %8
br label %18
50: ; preds = %18
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"entry_count=%d\0A\00"
@.str.1 = [15 x i8] c"%d) 0x%04x %s\0A\00"
define i32 @imports_ar_read_lookup_table(i8* %0, i32 %1) {
%3 = tail call i32 @get_int32_be(i8* %0)
%4 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp sgt i32 %3, 0
br i1 %5, label %6, label %25
6: ; preds = %2
%7 = shl nsw i32 %3, 2
%8 = add nsw i32 %7, 4
br label %9
9: ; preds = %6, %9
%10 = phi i64 [ 4, %6 ], [ %18, %9 ]
%11 = phi i32 [ 0, %6 ], [ %23, %9 ]
%12 = phi i32 [ %8, %6 ], [ %22, %9 ]
%13 = getelementptr inbounds i8, i8* %0, i64 %10
%14 = tail call i32 @get_int32_be(i8* %13)
%15 = sext i32 %12 to i64
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 %14, i8* %16)
%18 = add nuw nsw i64 %10, 4
%19 = tail call i64 @strlen(i8* dereferenceable(1) %16)
%20 = trunc i64 %19 to i32
%21 = add i32 %12, 1
%22 = add i32 %21, %20
%23 = add nuw nsw i32 %11, 1
%24 = icmp eq i32 %23, %3
br i1 %24, label %25, label %9
25: ; preds = %9, %2
ret i32 0
}