#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 */
typedef int /*<<< orphan*/ uint8_t;
typedef scalar_t__ uint32_t;
struct bladerf {
  int dummy;
};

/* Variables and functions */
int nios_access(struct bladerf *, int /*<<< orphan*/ *);
int /*<<< orphan*/ nios_pkt_8x32_pack(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                      int, int /*<<< orphan*/,
                                      int /*<<< orphan*/);
int /*<<< orphan*/ nios_pkt_8x32_resp_unpack(int /*<<< orphan*/ *,
                                             int /*<<< orphan*/ *,
                                             int /*<<< orphan*/ *,
                                             int /*<<< orphan*/ *, scalar_t__ *,
                                             int *);
int nios_8x32_read(struct bladerf *dev, uint8_t id, uint8_t addr,
                   uint32_t *data) {
  int status;
  uint8_t buf[16];
  bool success;
  nios_pkt_8x32_pack(buf, id, false, 0, 0);
  status = nios_access(dev, buf);
  if (status != 0) {
    return status;
  }
  nios_pkt_8x32_resp_unpack(buf, NULL, NULL, NULL, data, &success);
  if (success) {
    return 0;
  } else {
    *data = 0;
    do {
      do {
      } while (0);
    } while (0);
    return (-16);
  }
}


x86 assembly (clang, -O0):
<nios_8x32_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x14(%rbp),%esi
xor    %r8d,%r8d
mov    %r8d,%edx
mov    %r8d,%ecx
call   1040 <nios_pkt_8x32_pack@plt>
mov    -0x10(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1030 <nios_access@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1183 <nios_8x32_read+0x53>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d5 <nios_8x32_read+0xa5>
lea    -0x70(%rbp),%rdi
mov    -0x20(%rbp),%r8
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x74(%rbp),%r9
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1050 <nios_pkt_8x32_resp_unpack@plt>
cmpl   $0x0,-0x74(%rbp)
je     11b4 <nios_8x32_read+0x84>
movl   $0x0,-0x4(%rbp)
jmp    11d5 <nios_8x32_read+0xa5>
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
jmp    11c4 <nios_8x32_read+0x94>
jmp    11c9 <nios_8x32_read+0x99>
jmp    11ce <nios_8x32_read+0x9e>
movl   $0xfffffff0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nios_8x32_read>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %rcx,%r14
mov    %rdi,%rbx
lea    0x10(%rsp),%r15
mov    %r15,%rdi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <nios_pkt_8x32_pack@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <nios_access@plt>
test   %eax,%eax
jne    1192 <nios_8x32_read+0x62>
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%r9
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1050 <nios_pkt_8x32_resp_unpack@plt>
cmpl   $0x0,0xc(%rsp)
mov    $0x0,%eax
jne    1192 <nios_8x32_read+0x62>
movq   $0x0,(%r14)
mov    $0xfffffff0,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.bladerf = type { i32 }
define i32 @nios_8x32_read(%struct.bladerf* %0, i32 %1, i32 %2, i64* %3) {
%5 = alloca i32
%6 = alloca %struct.bladerf*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64*
%10 = alloca i32
%11 = alloca [16 x i32]
%12 = alloca i32
store %struct.bladerf* %0, %struct.bladerf** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i64* %3, i64** %9
%13 = getelementptr inbounds [16 x i32], [16 x i32]* %11, i64 0, i64 0
%14 = load i32, i32* %7
%15 = call i32 @nios_pkt_8x32_pack(i32* %13, i32 %14, i32 0, i32 0, i32 0)
%16 = load %struct.bladerf*, %struct.bladerf** %6
%17 = getelementptr inbounds [16 x i32], [16 x i32]* %11, i64 0, i64 0
%18 = call i32 @nios_access(%struct.bladerf* %16, i32* %17)
store i32 %18, i32* %10
%19 = load i32, i32* %10
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %4
%22 = load i32, i32* %10
store i32 %22, i32* %5
br label %36
23: ; preds = %4
%24 = getelementptr inbounds [16 x i32], [16 x i32]* %11, i64 0, i64 0
%25 = load i64*, i64** %9
%26 = call i32 @nios_pkt_8x32_resp_unpack(i32* %24, i32* null, i32* null, i32* null, i64* %25, i32* %12)
%27 = load i32, i32* %12
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %23
store i32 0, i32* %5
br label %36
30: ; preds = %23
%31 = load i64*, i64** %9
store i64 0, i64* %31
br label %32
32: ; preds = %30
br label %33
33: ; preds = %32
br label %34
34: ; preds = %33
br label %35
35: ; preds = %34
store i32 -16, i32* %5
br label %36
36: ; preds = %35, %29, %21
%37 = load i32, i32* %5
ret i32 %37
}

LLVM IR (-O2):
%struct.bladerf = type { i32 }
define i32 @nios_8x32_read(%struct.bladerf* %0, i32 %1, i32 %2, i64* %3) {
%5 = alloca [16 x i32]
%6 = alloca i32
%7 = bitcast [16 x i32]* %5 to i8*
%8 = bitcast i32* %6 to i8*
%9 = getelementptr inbounds [16 x i32], [16 x i32]* %5, i64 0, i64 0
%10 = call i32 @nios_pkt_8x32_pack(i32* %9, i32 %1, i32 0, i32 0, i32 0)
%11 = call i32 @nios_access(%struct.bladerf* %0, i32* %9)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %4
%14 = call i32 @nios_pkt_8x32_resp_unpack(i32* %9, i32* null, i32* null, i32* null, i64* %3, i32* %6)
%15 = load i32, i32* %6
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
store i64 0, i64* %3
br label %18
18: ; preds = %13, %4, %17
%19 = phi i32 [ -16, %17 ], [ %11, %4 ], [ 0, %13 ]
ret i32 %19
}