#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 *getenv(char *);
int /*<<< orphan*/ strcmp(char const *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int property_get(const char *key, char *value, const char *default_value) {
  const char *prop = NULL;
  if (!strcmp(key, "persist.sys.bluetooth.mode"))
    prop = getenv("BLUETOOTH_MODE");
  if (!prop)
    prop = default_value;
  if (prop) {
    strncpy(value, prop, 32);
    value[32 - 1] = '\0';
    return strlen(value);
  }
  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
lea    0xe99(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1185 <property_get+0x45>
lea    0xe9f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1198 <property_get+0x58>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11ce <property_get+0x8e>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x20,%edx
call   1040 <strncpy@plt>
mov    -0x18(%rbp),%rax
movb   $0x0,0x1f(%rax)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x4(%rbp)
jmp    11d5 <property_get+0x95>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<property_get>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
lea    0xeaf(%rip),%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     115e <property_get+0x1e>
xor    %eax,%eax
jmp    116a <property_get+0x2a>
lea    0xeb6(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
cmovne %rax,%rbx
test   %rbx,%rbx
je     119a <property_get+0x5a>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x20,%edx
call   1040 <strncpy@plt>
movb   $0x0,0x1f(%r14)
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <strlen@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [27 x i8] c"persist.sys.bluetooth.mode\00"
@.str.1 = [15 x i8] c"BLUETOOTH_MODE\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 i32 @strcmp(i8* %9, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%11 = icmp ne i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %3
%13 = call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i8* %13, i8** %8
br label %14
14: ; preds = %12, %3
%15 = load i8*, i8** %8
%16 = icmp ne i8* %15, null
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = load i8*, i8** %7
store i8* %18, i8** %8
br label %19
19: ; preds = %17, %14
%20 = load i8*, i8** %8
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %30
22: ; preds = %19
%23 = load i8*, i8** %6
%24 = load i8*, i8** %8
%25 = call i32 @strncpy(i8* %23, i8* %24, i32 32)
%26 = load i8*, i8** %6
%27 = getelementptr inbounds i8, i8* %26, i64 31
store i8 0, i8* %27
%28 = load i8*, i8** %6
%29 = call i32 @strlen(i8* %28)
store i32 %29, i32* %4
br label %31
30: ; preds = %19
store i32 0, i32* %4
br label %31
31: ; preds = %30, %22
%32 = load i32, i32* %4
ret i32 %32
}

LLVM IR (-O2):
@.str = [27 x i8] c"persist.sys.bluetooth.mode\00"
@.str.1 = [15 x i8] c"BLUETOOTH_MODE\00"
define i32 @property_get(i8* nocapture %0, i8* %1, i8* %2) {
%4 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(27) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %3
%9 = phi i8* [ null, %3 ], [ %7, %6 ]
%10 = icmp eq i8* %9, null
%11 = select i1 %10, i8* %2, i8* %9
%12 = icmp eq i8* %11, null
br i1 %12, label %17, label %13
13: ; preds = %8
%14 = tail call i32 @strncpy(i8* %1, i8* %11, i32 32)
%15 = getelementptr inbounds i8, i8* %1, i64 31
store i8 0, i8* %15
%16 = tail call i32 @strlen(i8* %1)
br label %17
17: ; preds = %8, %13
%18 = phi i32 [ %16, %13 ], [ 0, %8 ]
ret i32 %18
}