#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 int32_t;

/* Variables and functions */
int strlen(char const *);
const char *string_array_getter(const void *array_data, size_t index,
                                int32_t *out_length) {
  const char **array = (const char **)array_data;
  *out_length = array[index] ? strlen(array[index]) : -1;
  return array[index];
}


x86 assembly (clang, -O0):
<string_array_getter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1158 <string_array_getter+0x48>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
jmp    1165 <string_array_getter+0x55>
mov    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    1165 <string_array_getter+0x55>
mov    -0x24(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_array_getter>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rdi,%rbx
mov    (%rdi,%rsi,8),%rdi
test   %rdi,%rdi
je     1132 <string_array_getter+0x22>
mov    %rsi,%r15
call   1030 <strlen@plt>
mov    (%rbx,%r15,8),%rcx
jmp    1139 <string_array_getter+0x29>
mov    $0xffffffff,%eax
xor    %ecx,%ecx
mov    %eax,(%r14)
mov    %rcx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @string_array_getter(i8* %0, i64 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32*
%7 = alloca i8**
store i8* %0, i8** %4
store i64 %1, i64* %5
store i32* %2, i32** %6
%8 = load i8*, i8** %4
%9 = bitcast i8* %8 to i8**
store i8** %9, i8*** %7
%10 = load i8**, i8*** %7
%11 = load i64, i64* %5
%12 = getelementptr inbounds i8*, i8** %10, i64 %11
%13 = load i8*, i8** %12
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %21
15: ; preds = %3
%16 = load i8**, i8*** %7
%17 = load i64, i64* %5
%18 = getelementptr inbounds i8*, i8** %16, i64 %17
%19 = load i8*, i8** %18
%20 = call i32 @strlen(i8* %19)
br label %22
21: ; preds = %3
br label %22
22: ; preds = %21, %15
%23 = phi i32 [ %20, %15 ], [ -1, %21 ]
%24 = load i32*, i32** %6
store i32 %23, i32* %24
%25 = load i8**, i8*** %7
%26 = load i64, i64* %5
%27 = getelementptr inbounds i8*, i8** %25, i64 %26
%28 = load i8*, i8** %27
ret i8* %28
}

LLVM IR (-O2):
define i8* @string_array_getter(i8* nocapture %0, i64 %1, i32* nocapture writeonly %2) {
%4 = bitcast i8* %0 to i8**
%5 = getelementptr inbounds i8*, i8** %4, i64 %1
%6 = load i8*, i8** %5
%7 = icmp eq i8* %6, null
br i1 %7, label %11, label %8
8: ; preds = %3
%9 = tail call i32 @strlen(i8* %6)
%10 = load i8*, i8** %5
br label %11
11: ; preds = %3, %8
%12 = phi i8* [ %10, %8 ], [ null, %3 ]
%13 = phi i32 [ %9, %8 ], [ -1, %3 ]
store i32 %13, i32* %2
ret i8* %12
}