#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 */
struct emu_value {
  int dummy;
};
struct emu_property {
  int dummy;
};
struct emu_df {
  int dummy;
};

/* Variables and functions */
struct emu_property *emu_df_get_property(struct emu_df const *, char const *);
struct emu_value *emu_property_get_value(struct emu_property const *);
unsigned char *emu_value_get(struct emu_value const *, unsigned int, size_t *);
const unsigned char *emu_df_get_value(const struct emu_df *df, const char *name,
                                      unsigned n, size_t *plen) {
  const struct emu_property *prop = emu_df_get_property(df, name);
  if (!prop) {
    *plen = 0;
    return NULL;
  }
  const struct emu_value *value = emu_property_get_value(prop);
  if (!value) {
    *plen = 0;
    return NULL;
  }
  const unsigned char *buf = emu_value_get(value, n, plen);
  return buf;
}


x86 assembly (clang, -O0):
<emu_df_get_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <emu_df_get_property@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    117b <emu_df_get_value+0x4b>
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    11c7 <emu_df_get_value+0x97>
mov    -0x30(%rbp),%rdi
call   1040 <emu_property_get_value@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11ab <emu_df_get_value+0x7b>
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    11c7 <emu_df_get_value+0x97>
mov    -0x38(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x28(%rbp),%rdx
call   1050 <emu_value_get@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<emu_df_get_value>:
push   %rbp
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %edx,%ebp
call   1030 <emu_df_get_property@plt>
test   %rax,%rax
je     1162 <emu_df_get_value+0x32>
mov    %rax,%rdi
call   1040 <emu_property_get_value@plt>
test   %rax,%rax
je     1162 <emu_df_get_value+0x32>
mov    %rax,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <emu_value_get@plt>
movq   $0x0,(%rbx)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.emu_df = type { i32 }
%struct.emu_property = type { i32 }
%struct.emu_value = type { i32 }
define i8* @emu_df_get_value(%struct.emu_df* %0, i8* %1, i32 %2, i64* %3) {
%5 = alloca i8*
%6 = alloca %struct.emu_df*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i64*
%10 = alloca %struct.emu_property*
%11 = alloca %struct.emu_value*
%12 = alloca i8*
store %struct.emu_df* %0, %struct.emu_df** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i64* %3, i64** %9
%13 = load %struct.emu_df*, %struct.emu_df** %6
%14 = load i8*, i8** %7
%15 = call %struct.emu_property* @emu_df_get_property(%struct.emu_df* %13, i8* %14)
store %struct.emu_property* %15, %struct.emu_property** %10
%16 = load %struct.emu_property*, %struct.emu_property** %10
%17 = icmp ne %struct.emu_property* %16, null
br i1 %17, label %20, label %18
18: ; preds = %4
%19 = load i64*, i64** %9
store i64 0, i64* %19
store i8* null, i8** %5
br label %33
20: ; preds = %4
%21 = load %struct.emu_property*, %struct.emu_property** %10
%22 = call %struct.emu_value* @emu_property_get_value(%struct.emu_property* %21)
store %struct.emu_value* %22, %struct.emu_value** %11
%23 = load %struct.emu_value*, %struct.emu_value** %11
%24 = icmp ne %struct.emu_value* %23, null
br i1 %24, label %27, label %25
25: ; preds = %20
%26 = load i64*, i64** %9
store i64 0, i64* %26
store i8* null, i8** %5
br label %33
27: ; preds = %20
%28 = load %struct.emu_value*, %struct.emu_value** %11
%29 = load i32, i32* %8
%30 = load i64*, i64** %9
%31 = call i8* @emu_value_get(%struct.emu_value* %28, i32 %29, i64* %30)
store i8* %31, i8** %12
%32 = load i8*, i8** %12
store i8* %32, i8** %5
br label %33
33: ; preds = %27, %25, %18
%34 = load i8*, i8** %5
ret i8* %34
}

LLVM IR (-O2):
%struct.emu_df = type { i32 }
%struct.emu_property = type { i32 }
%struct.emu_value = type { i32 }
define i8* @emu_df_get_value(%struct.emu_df* %0, i8* %1, i32 %2, i64* %3) {
%5 = tail call %struct.emu_property* @emu_df_get_property(%struct.emu_df* %0, i8* %1)
%6 = icmp eq %struct.emu_property* %5, null
br i1 %6, label %7, label %8
7: ; preds = %4
store i64 0, i64* %3
br label %14
8: ; preds = %4
%9 = tail call %struct.emu_value* @emu_property_get_value(%struct.emu_property* %5)
%10 = icmp eq %struct.emu_value* %9, null
br i1 %10, label %11, label %12
11: ; preds = %8
store i64 0, i64* %3
br label %14
12: ; preds = %8
%13 = tail call i8* @emu_value_get(%struct.emu_value* %9, i32 %2, i64* %3)
br label %14
14: ; preds = %11, %12, %7
%15 = phi i8* [ null, %7 ], [ %13, %12 ], [ null, %11 ]
ret i8* %15
}