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


x86 assembly (clang, -O0):
<get_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 <get_value+0x42>
movl   $0x1,-0x4(%rbp)
jmp    11b2 <get_value+0x82>
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     119b <get_value+0x6b>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b2 <get_value+0x82>
mov    -0x20(%rbp),%rdi
mov    -0x28(%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):
<get_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     1187 <get_value+0x57>
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <get_var_nbytes@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1187 <get_value+0x57>
mov    0x10(%rsp),%rsi
mov    0xc(%rsp),%edx
mov    %r14,%rdi
call   1040 <memcpy@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @get_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 %30
16: ; preds = %3
%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 %30
24: ; preds = %16
%25 = load i8*, i8** %7
%26 = load i8*, i8** %8
%27 = load i32, i32* %9
%28 = call i32 @memcpy(i8* %25, i8* %26, i32 %27)
br label %29
29: ; preds = %24
store i32 0, i32* %4
br label %30
30: ; preds = %29, %22, %15
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
define i32 @get_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*
%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* %2, i8* %14, i32 %15)
br label %17
17: ; preds = %9, %13
br label %18
18: ; preds = %17, %3
%19 = phi i32 [ 1, %3 ], [ %11, %17 ]
ret i32 %19
}