#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 *find_key(char const *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, char const *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char *);
int property_get(const char *key, char *value, const char *default_value) {
  char *ret = NULL;
  ret = find_key(key);
  if (ret) {
    printf("found %s for %s\n", key, ret);
  }
  if (ret == NULL) {
    if (default_value != NULL) {
      strcpy(value, default_value);
      return strlen(value);
    } else {
      return 0;
    }
  }
  if (ret) {
    strcpy(value, ret);
    free(ret);
    return strlen(value);
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<property_get>:
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
call   1070 <find_key@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1198 <property_get+0x48>
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xe6d(%rip),%rdi
call   1060 <printf@plt>
cmpq   $0x0,-0x28(%rbp)
jne    11d8 <property_get+0x88>
cmpq   $0x0,-0x20(%rbp)
je     11cc <property_get+0x7c>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x4(%rbp)
jmp    1211 <property_get+0xc1>
movl   $0x0,-0x4(%rbp)
jmp    1211 <property_get+0xc1>
cmpq   $0x0,-0x28(%rbp)
je     120a <property_get+0xba>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x4(%rbp)
jmp    1211 <property_get+0xc1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<property_get>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
call   1070 <find_key@plt>
test   %rax,%rax
je     1195 <property_get+0x45>
mov    %rax,%rbx
lea    0xe8b(%rip),%rdi
mov    %r12,%rsi
mov    %rax,%rdx
call   1060 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    11a5 <property_get+0x55>
test   %r15,%r15
je     11b8 <property_get+0x68>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <strlen@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [17 x i8] c"found %s for %s\0A\00"
define i32 @property_get(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* null, i8** %8
%9 = load i8*, i8** %5
%10 = call i8* @find_key(i8* %9)
store i8* %10, i8** %8
%11 = load i8*, i8** %8
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %17
13: ; preds = %3
%14 = load i8*, i8** %5
%15 = load i8*, i8** %8
%16 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %14, i8* %15)
br label %17
17: ; preds = %13, %3
%18 = load i8*, i8** %8
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %30
20: ; preds = %17
%21 = load i8*, i8** %7
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %29
23: ; preds = %20
%24 = load i8*, i8** %6
%25 = load i8*, i8** %7
%26 = call i32 @strcpy(i8* %24, i8* %25)
%27 = load i8*, i8** %6
%28 = call i32 @strlen(i8* %27)
store i32 %28, i32* %4
br label %42
29: ; preds = %20
store i32 0, i32* %4
br label %42
30: ; preds = %17
%31 = load i8*, i8** %8
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %41
33: ; preds = %30
%34 = load i8*, i8** %6
%35 = load i8*, i8** %8
%36 = call i32 @strcpy(i8* %34, i8* %35)
%37 = load i8*, i8** %8
%38 = call i32 @free(i8* %37)
%39 = load i8*, i8** %6
%40 = call i32 @strlen(i8* %39)
store i32 %40, i32* %4
br label %42
41: ; preds = %30
store i32 0, i32* %4
br label %42
42: ; preds = %41, %33, %29, %23
%43 = load i32, i32* %4
ret i32 %43
}

LLVM IR (-O2):
@.str = [17 x i8] c"found %s for %s\0A\00"
define i32 @property_get(i8* %0, i8* %1, i8* %2) {
%4 = tail call i8* @find_key(i8* %0)
%5 = icmp eq i8* %4, null
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %4)
%8 = tail call i32 @strcpy(i8* %1, i8* %4)
%9 = tail call i32 @free(i8* %4)
br label %14
10: ; preds = %3
%11 = icmp eq i8* %2, null
br i1 %11, label %16, label %12
12: ; preds = %10
%13 = tail call i32 @strcpy(i8* %1, i8* %2)
br label %14
14: ; preds = %12, %6
%15 = tail call i32 @strlen(i8* %1)
br label %16
16: ; preds = %14, %10
%17 = phi i32 [ 0, %10 ], [ %15, %14 ]
ret i32 %17
}