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

/* Variables and functions */
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
const char *get_pslr_str(const char **array, int length, int value) {
  if (value >= 0 && value < length) {
    return array[value];
  } else {
    char *ret = malloc(128);
    sprintf(ret, "Unknown value: %d", value);
    return ret;
  }
}


x86 assembly (clang, -O0):
<get_pslr_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     115d <get_pslr_str+0x3d>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    115d <get_pslr_str+0x3d>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x8(%rbp)
jmp    1186 <get_pslr_str+0x66>
mov    $0x80,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xe87(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_pslr_str>:
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
test   %edx,%edx
js     1136 <get_pslr_str+0x16>
cmp    %esi,%ebx
jge    1136 <get_pslr_str+0x16>
mov    %ebx,%eax
mov    (%rdi,%rax,8),%r14
jmp    1154 <get_pslr_str+0x34>
mov    $0x80,%edi
call   1030 <malloc@plt>
mov    %rax,%r14
lea    0xeb6(%rip),%rsi
mov    %rax,%rdi
mov    %ebx,%edx
call   1040 <sprintf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Unknown value: %d\00"
define i8* @get_pslr_str(i8** %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8** %0, i8*** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = load i32, i32* %7
%10 = icmp sge i32 %9, 0
br i1 %10, label %11, label %21
11: ; preds = %3
%12 = load i32, i32* %7
%13 = load i32, i32* %6
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %21
15: ; preds = %11
%16 = load i8**, i8*** %5
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %16, i64 %18
%20 = load i8*, i8** %19
store i8* %20, i8** %4
br label %27
21: ; preds = %11, %3
%22 = call i8* @malloc(i32 128)
store i8* %22, i8** %8
%23 = load i8*, i8** %8
%24 = load i32, i32* %7
%25 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = load i8*, i8** %8
store i8* %26, i8** %4
br label %27
27: ; preds = %21, %15
%28 = load i8*, i8** %4
ret i8* %28
}

LLVM IR (-O2):
@.str = [18 x i8] c"Unknown value: %d\00"
define i8* @get_pslr_str(i8** nocapture %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %2, -1
%5 = icmp slt i32 %2, %1
%6 = and i1 %4, %5
br i1 %6, label %7, label %11
7: ; preds = %3
%8 = zext i32 %2 to i64
%9 = getelementptr inbounds i8*, i8** %0, i64 %8
%10 = load i8*, i8** %9
br label %14
11: ; preds = %3
%12 = tail call dereferenceable_or_null(128) i8* @malloc(i32 128)
%13 = tail call i32 @sprintf(i8* dereferenceable(1) %12, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %2)
br label %14
14: ; preds = %11, %7
%15 = phi i8* [ %10, %7 ], [ %12, %11 ]
ret i8* %15
}