#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 (!strcmp(key, "persist.sys.bluetooth.handsfree"))
    prop = getenv("BLUETOOTH_HANDSFREE_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)
mov    -0x10(%rbp),%rdi
lea    0xe9a(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    11ae <property_get+0x6e>
lea    0xea5(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11c1 <property_get+0x81>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11f7 <property_get+0xb7>
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    11fe <property_get+0xbe>
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
lea    0xea8(%rip),%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     1165 <property_get+0x25>
xor    %ebx,%ebx
jmp    1174 <property_get+0x34>
lea    0xeaf(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
lea    0xeaf(%rip),%rsi
mov    %r12,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
jne    1196 <property_get+0x56>
lea    0xebc(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
test   %rbx,%rbx
cmovne %rbx,%r15
test   %r15,%r15
je     11ca <property_get+0x8a>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x20,%edx
call   1040 <strncpy@plt>
movb   $0x0,0x1f(%r14)
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 = [27 x i8] c"persist.sys.bluetooth.mode\00"
@.str.1 = [15 x i8] c"BLUETOOTH_MODE\00"
@.str.2 = [32 x i8] c"persist.sys.bluetooth.handsfree\00"
@.str.3 = [25 x i8] c"BLUETOOTH_HANDSFREE_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** %5
%16 = call i32 @strcmp(i8* %15, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp ne i32 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %14
%19 = call i8* @getenv(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
store i8* %19, i8** %8
br label %20
20: ; preds = %18, %14
%21 = load i8*, i8** %8
%22 = icmp ne i8* %21, null
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = load i8*, i8** %7
store i8* %24, i8** %8
br label %25
25: ; preds = %23, %20
%26 = load i8*, i8** %8
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %36
28: ; preds = %25
%29 = load i8*, i8** %6
%30 = load i8*, i8** %8
%31 = call i32 @strncpy(i8* %29, i8* %30, i32 32)
%32 = load i8*, i8** %6
%33 = getelementptr inbounds i8, i8* %32, i64 31
store i8 0, i8* %33
%34 = load i8*, i8** %6
%35 = call i32 @strlen(i8* %34)
store i32 %35, i32* %4
br label %37
36: ; preds = %25
store i32 0, i32* %4
br label %37
37: ; preds = %36, %28
%38 = load i32, i32* %4
ret i32 %38
}

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