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

/* Variables and functions */
scalar_t__ malloc(int);
long peek_data(int /*<<< orphan*/, long);
char *peek_string(int /*<<< orphan*/, long);
char **peek_array(pid_t pid, long addr) {
  long data;
  char **array;
  unsigned i;
  int next;
  array = (char **)malloc(sizeof(char *) * 256);
  i = 0;
  do {
    data = peek_data(pid, addr + i * sizeof(long));
    array[i] = data ? peek_string(pid, data) : NULL;
    ++i;
    next = (data != 0);
    next &= (i < 256);
  } while (next);
  return (array);
}


x86 assembly (clang, -O0):
<peek_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x800,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x24(%rbp),%eax
shl    $0x3,%rax
add    %rax,%rsi
call   1040 <peek_data@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     118e <peek_array+0x5e>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1050 <peek_string@plt>
mov    %rax,-0x30(%rbp)
jmp    1199 <peek_array+0x69>
xor    %eax,%eax
mov    %rax,-0x30(%rbp)
jmp    1199 <peek_array+0x69>
mov    -0x30(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %rdx,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x100,-0x24(%rbp)
setb   %al
and    $0x1,%al
movzbl %al,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    1154 <peek_array+0x24>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<peek_array>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%r15d
mov    $0x800,%edi
call   1030 <malloc@plt>
mov    %rax,%r14
mov    $0xffffffffffffffff,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %rbx,%rsi
call   1040 <peek_data@plt>
test   %rax,%rax
je     1193 <peek_array+0x63>
mov    %r15d,%edi
mov    %rax,%rsi
call   1050 <peek_string@plt>
mov    %rax,0x8(%r14,%rbp,8)
add    $0x1,%rbp
add    $0x8,%rbx
cmp    $0xff,%rbp
jb     1160 <peek_array+0x30>
jmp    119c <peek_array+0x6c>
movq   $0x0,0x8(%r14,%rbp,8)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8** @peek_array(i32 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i64 %1, i64* %4
%9 = call i64 @malloc(i32 2048)
%10 = inttoptr i64 %9 to i8**
store i8** %10, i8*** %6
store i32 0, i32* %7
br label %11
11: ; preds = %42, %2
%12 = load i32, i32* %3
%13 = load i64, i64* %4
%14 = load i32, i32* %7
%15 = zext i32 %14 to i64
%16 = mul i64 %15, 8
%17 = add i64 %13, %16
%18 = call i64 @peek_data(i32 %12, i64 %17)
store i64 %18, i64* %5
%19 = load i64, i64* %5
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %11
%22 = load i32, i32* %3
%23 = load i64, i64* %5
%24 = call i8* @peek_string(i32 %22, i64 %23)
br label %26
25: ; preds = %11
br label %26
26: ; preds = %25, %21
%27 = phi i8* [ %24, %21 ], [ null, %25 ]
%28 = load i8**, i8*** %6
%29 = load i32, i32* %7
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %28, i64 %30
store i8* %27, i8** %31
%32 = load i32, i32* %7
%33 = add i32 %32, 1
store i32 %33, i32* %7
%34 = load i64, i64* %5
%35 = icmp ne i64 %34, 0
%36 = zext i1 %35 to i32
store i32 %36, i32* %8
%37 = load i32, i32* %7
%38 = icmp ult i32 %37, 256
%39 = zext i1 %38 to i32
%40 = load i32, i32* %8
%41 = and i32 %40, %39
store i32 %41, i32* %8
br label %42
42: ; preds = %26
%43 = load i32, i32* %8
%44 = icmp ne i32 %43, 0
br i1 %44, label %11, label %45
45: ; preds = %42
%46 = load i8**, i8*** %6
ret i8** %46
}

LLVM IR (-O2):
define i8** @peek_array(i32 %0, i64 %1) {
%3 = tail call i64 @malloc(i32 2048)
%4 = inttoptr i64 %3 to i8**
br label %5
5: ; preds = %13, %2
%6 = phi i64 [ %16, %13 ], [ 0, %2 ]
%7 = shl nuw nsw i64 %6, 3
%8 = add i64 %7, %1
%9 = tail call i64 @peek_data(i32 %0, i64 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %5
%12 = getelementptr inbounds i8*, i8** %4, i64 %6
store i8* null, i8** %12
br label %18
13: ; preds = %5
%14 = tail call i8* @peek_string(i32 %0, i64 %9)
%15 = getelementptr inbounds i8*, i8** %4, i64 %6
store i8* %14, i8** %15
%16 = add nuw nsw i64 %6, 1
%17 = icmp ult i64 %6, 255
br i1 %17, label %5, label %18
18: ; preds = %13, %11
ret i8** %4
}