#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 */
typedef struct TYPE_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
typedef int uint8_t;
typedef int uint32_t;
struct TYPE_3__ {
  int /*<<< orphan*/ *data;
  int /*<<< orphan*/ len;
};
struct TYPE_4__ {
  TYPE_1__ buffer;
};
struct dtv_property {
  int cmd;
  TYPE_2__ u;
};
struct dtv_properties {
  int num;
  struct dtv_property *props;
};

/* Variables and functions */
int /*<<< orphan*/ FE_GET_PROPERTY;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int ioctl(int, int /*<<< orphan*/, struct dtv_properties *);
int /*<<< orphan*/ memcpy(int *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ stderr;
int get_property(int fd, uint32_t pcmd, uint32_t *len, uint8_t *data) {
  struct dtv_property p, *b;
  struct dtv_properties cmd;
  int ret;
  p.cmd = pcmd;
  cmd.num = 1;
  cmd.props = &p;
  b = &p;
  ret = ioctl(fd, FE_GET_PROPERTY, &cmd);
  if (ret < 0) {
    fprintf(stderr, "FE_SET_PROPERTY returned %d\n", ret);
    return -1;
  }
  memcpy(len, &b->u.buffer.len, sizeof(uint32_t));
  memcpy(data, b->u.buffer.data, *len);
  return 0;
}


x86 assembly (clang, -O0):
<get_property>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x38(%rbp)
movl   $0x1,-0x50(%rbp)
lea    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
lea    -0x50(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jge    11a9 <get_property+0x79>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
mov    -0x54(%rbp),%edx
lea    0xe68(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e1 <get_property+0xb1>
mov    -0x18(%rbp),%rdi
mov    -0x40(%rbp),%rsi
add    $0x8,%rsi
add    $0x8,%rsi
mov    $0x4,%edx
call   1050 <memcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
call   1050 <memcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_property>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %esi,0x10(%rsp)
movl   $0x1,(%rsp)
lea    0x10(%rsp),%rax
mov    %rax,0x8(%rsp)
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1030 <ioctl@plt>
test   %eax,%eax
js     118c <get_property+0x5c>
lea    0x20(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1050 <memcpy@plt>
mov    0x18(%rsp),%rsi
mov    (%rbx),%edx
mov    %r14,%rdi
call   1050 <memcpy@plt>
xor    %eax,%eax
jmp    11a8 <get_property+0x78>
mov    0x2e4d(%rip),%rcx
mov    (%rcx),%edi
lea    0xe64(%rip),%rsi
mov    %eax,%edx
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.dtv_property = type { i32, %struct.TYPE_4__ }
%struct.TYPE_4__ = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32*, i32 }
%struct.dtv_properties = type { i32, %struct.dtv_property* }
@FE_GET_PROPERTY = global i32 0
@stderr = global i32 0
@.str = [29 x i8] c"FE_SET_PROPERTY returned %d\0A\00"
define i32 @get_property(i32 %0, i32 %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca %struct.dtv_property
%11 = alloca %struct.dtv_property*
%12 = alloca %struct.dtv_properties
%13 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32* %2, i32** %8
store i32* %3, i32** %9
%14 = load i32, i32* %7
%15 = getelementptr inbounds %struct.dtv_property, %struct.dtv_property* %10, i32 0, i32 0
store i32 %14, i32* %15
%16 = getelementptr inbounds %struct.dtv_properties, %struct.dtv_properties* %12, i32 0, i32 0
store i32 1, i32* %16
%17 = getelementptr inbounds %struct.dtv_properties, %struct.dtv_properties* %12, i32 0, i32 1
store %struct.dtv_property* %10, %struct.dtv_property** %17
store %struct.dtv_property* %10, %struct.dtv_property** %11
%18 = load i32, i32* %6
%19 = load i32, i32* @FE_GET_PROPERTY
%20 = call i32 @ioctl(i32 %18, i32 %19, %struct.dtv_properties* %12)
store i32 %20, i32* %13
%21 = load i32, i32* %13
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %4
%24 = load i32, i32* @stderr
%25 = load i32, i32* %13
%26 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %25)
store i32 -1, i32* %5
br label %43
27: ; preds = %4
%28 = load i32*, i32** %8
%29 = load %struct.dtv_property*, %struct.dtv_property** %11
%30 = getelementptr inbounds %struct.dtv_property, %struct.dtv_property* %29, i32 0, i32 1
%31 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %30, i32 0, i32 0
%32 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %31, i32 0, i32 1
%33 = call i32 @memcpy(i32* %28, i32* %32, i32 4)
%34 = load i32*, i32** %9
%35 = load %struct.dtv_property*, %struct.dtv_property** %11
%36 = getelementptr inbounds %struct.dtv_property, %struct.dtv_property* %35, i32 0, i32 1
%37 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %36, i32 0, i32 0
%38 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %37, i32 0, i32 0
%39 = load i32*, i32** %38
%40 = load i32*, i32** %8
%41 = load i32, i32* %40
%42 = call i32 @memcpy(i32* %34, i32* %39, i32 %41)
store i32 0, i32* %5
br label %43
43: ; preds = %27, %23
%44 = load i32, i32* %5
ret i32 %44
}

LLVM IR (-O2):
%struct.dtv_property = type { i32, %struct.TYPE_4__ }
%struct.TYPE_4__ = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32*, i32 }
%struct.dtv_properties = type { i32, %struct.dtv_property* }
@FE_GET_PROPERTY = global i32 0
@stderr = global i32 0
@.str = [29 x i8] c"FE_SET_PROPERTY returned %d\0A\00"
define i32 @get_property(i32 %0, i32 %1, i32* %2, i32* %3) {
%5 = alloca %struct.dtv_property
%6 = alloca %struct.dtv_properties
%7 = bitcast %struct.dtv_property* %5 to i8*
%8 = bitcast %struct.dtv_properties* %6 to i8*
%9 = getelementptr inbounds %struct.dtv_property, %struct.dtv_property* %5, i64 0, i32 0
store i32 %1, i32* %9
%10 = getelementptr inbounds %struct.dtv_properties, %struct.dtv_properties* %6, i64 0, i32 0
store i32 1, i32* %10
%11 = getelementptr inbounds %struct.dtv_properties, %struct.dtv_properties* %6, i64 0, i32 1
store %struct.dtv_property* %5, %struct.dtv_property** %11
%12 = load i32, i32* @FE_GET_PROPERTY
%13 = call i32 @ioctl(i32 %0, i32 %12, %struct.dtv_properties* %6)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %4
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %25
18: ; preds = %4
%19 = getelementptr inbounds %struct.dtv_property, %struct.dtv_property* %5, i64 0, i32 1, i32 0, i32 1
%20 = call i32 @memcpy(i32* %2, i32* %19, i32 4)
%21 = getelementptr inbounds %struct.dtv_property, %struct.dtv_property* %5, i64 0, i32 1, i32 0, i32 0
%22 = load i32*, i32** %21
%23 = load i32, i32* %2
%24 = call i32 @memcpy(i32* %3, i32* %22, i32 %23)
br label %25
25: ; preds = %18, %15
%26 = phi i32 [ -1, %15 ], [ 0, %18 ]
ret i32 %26
}