#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 */
int get_value_ptr(void *, char const *, void **);
int get_var_nbytes(void *, char const *, int *);
int /*<<< orphan*/ memcpy(void *, void *, int);
int set_value(void *self, const char *name, void *array) {
  void *dest = NULL;
  if (get_value_ptr(self, name, &dest) == (1)) {
    return (1);
  } else {
    int nbytes = 0;
    {
      const int status = (get_var_nbytes(self, name, &nbytes));
      if (status != (0))
        return status;
    };
    memcpy(dest, array, nbytes);
    return (0);
  }
}


x86 assembly (clang, -O0):
<set_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1050 <get_value_ptr@plt>
cmp    $0x1,%eax
jne    1172 <set_value+0x42>
movl   $0x1,-0x4(%rbp)
jmp    11b9 <set_value+0x89>
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   1030 <get_var_nbytes@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
je     11a2 <set_value+0x72>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b9 <set_value+0x89>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1040 <memcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_value>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
movq   $0x0,0x10(%rsp)
lea    0x10(%rsp),%rdx
call   1050 <get_value_ptr@plt>
mov    $0x1,%ebp
cmp    $0x1,%eax
je     118f <set_value+0x5f>
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <get_var_nbytes@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    118f <set_value+0x5f>
mov    0x10(%rsp),%rdi
mov    0xc(%rsp),%edx
mov    %r14,%rsi
call   1040 <memcpy@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @set_value(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* null, i8** %8
%11 = load i8*, i8** %5
%12 = load i8*, i8** %6
%13 = call i32 @get_value_ptr(i8* %11, i8* %12, i8** %8)
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 1, i32* %4
br label %29
16: ; preds = %3
store i32 0, i32* %9
%17 = load i8*, i8** %5
%18 = load i8*, i8** %6
%19 = call i32 @get_var_nbytes(i8* %17, i8* %18, i32* %9)
store i32 %19, i32* %10
%20 = load i32, i32* %10
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = load i32, i32* %10
store i32 %23, i32* %4
br label %29
24: ; preds = %16
%25 = load i8*, i8** %8
%26 = load i8*, i8** %7
%27 = load i32, i32* %9
%28 = call i32 @memcpy(i8* %25, i8* %26, i32 %27)
store i32 0, i32* %4
br label %29
29: ; preds = %24, %22, %15
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
define i32 @set_value(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%7 = call i32 @get_value_ptr(i8* %0, i8* %1, i8** %4)
%8 = icmp eq i32 %7, 1
br i1 %8, label %18, label %9
9: ; preds = %3
%10 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%11 = call i32 @get_var_nbytes(i8* %0, i8* %1, i32* %5)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = load i8*, i8** %4
%15 = load i32, i32* %5
%16 = call i32 @memcpy(i8* %14, i8* %2, i32 %15)
br label %17
17: ; preds = %9, %13
br label %18
18: ; preds = %3, %17
%19 = phi i32 [ %11, %17 ], [ 1, %3 ]
ret i32 %19
}