#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*/ uint8_t;
struct ndarray {
  int dummy;
};
typedef int int8_t;
typedef int /*<<< orphan*/ int64_t;

/* Variables and functions */
int /*<<< orphan*/ *stdlib_ndarray_get_ptr(struct ndarray const *,
                                           int /*<<< orphan*/ const *);
int stdlib_ndarray_set_ptr_value(struct ndarray const *, int /*<<< orphan*/ *,
                                 void const *);
int8_t stdlib_ndarray_set(const struct ndarray *arr, const int64_t *sub,
                          const void *v) {
  uint8_t *idx = stdlib_ndarray_get_ptr(arr, sub);
  if (idx == NULL) {
    return -1;
  }
  return stdlib_ndarray_set_ptr_value(arr, idx, v);
}


x86 assembly (clang, -O0):
<stdlib_ndarray_set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <stdlib_ndarray_get_ptr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    115c <stdlib_ndarray_set+0x3c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1170 <stdlib_ndarray_set+0x50>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <stdlib_ndarray_set_ptr_value@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stdlib_ndarray_set>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%rbx
call   1030 <stdlib_ndarray_get_ptr@plt>
test   %rax,%rax
je     1149 <stdlib_ndarray_set+0x29>
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <stdlib_ndarray_set_ptr_value@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.ndarray = type { i32 }
define i32 @stdlib_ndarray_set(%struct.ndarray* %0, i32* %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.ndarray*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32*
store %struct.ndarray* %0, %struct.ndarray** %5
store i32* %1, i32** %6
store i8* %2, i8** %7
%9 = load %struct.ndarray*, %struct.ndarray** %5
%10 = load i32*, i32** %6
%11 = call i32* @stdlib_ndarray_get_ptr(%struct.ndarray* %9, i32* %10)
store i32* %11, i32** %8
%12 = load i32*, i32** %8
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 -1, i32* %4
br label %20
15: ; preds = %3
%16 = load %struct.ndarray*, %struct.ndarray** %5
%17 = load i32*, i32** %8
%18 = load i8*, i8** %7
%19 = call i32 @stdlib_ndarray_set_ptr_value(%struct.ndarray* %16, i32* %17, i8* %18)
store i32 %19, i32* %4
br label %20
20: ; preds = %15, %14
%21 = load i32, i32* %4
ret i32 %21
}

LLVM IR (-O2):
%struct.ndarray = type { i32 }
define i32 @stdlib_ndarray_set(%struct.ndarray* %0, i32* %1, i8* %2) {
%4 = tail call i32* @stdlib_ndarray_get_ptr(%struct.ndarray* %0, i32* %1)
%5 = icmp eq i32* %4, null
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call i32 @stdlib_ndarray_set_ptr_value(%struct.ndarray* %0, i32* %4, i8* %2)
br label %8
8: ; preds = %3, %6
%9 = phi i32 [ %7, %6 ], [ -1, %3 ]
ret i32 %9
}