#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 int /*<<< orphan*/ uint16_t;
struct bladerf {
  int dummy;
};

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


x86 assembly (clang, -O0):
<nios_8x16_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
mov    -0x18(%rbp),%ecx
xor    %r8d,%r8d
mov    %r8d,%edx
call   1050 <nios_pkt_8x16_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_8x16_read+0x53>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11dd <nios_8x16_read+0xad>
lea    -0x70(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x78(%rbp),%r8
lea    -0x74(%rbp),%r9
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1040 <nios_pkt_8x16_resp_unpack@plt>
cmpl   $0x0,-0x74(%rbp)
je     11bd <nios_8x16_read+0x8d>
mov    -0x78(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11dd <nios_8x16_read+0xad>
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
jmp    11cc <nios_8x16_read+0x9c>
jmp    11d1 <nios_8x16_read+0xa1>
jmp    11d6 <nios_8x16_read+0xa6>
movl   $0xfffffff0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nios_8x16_read>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %rcx,%r14
mov    %edx,%ecx
mov    %rdi,%rbx
lea    0x10(%rsp),%r15
mov    %r15,%rdi
xor    %edx,%edx
xor    %r8d,%r8d
call   1050 <nios_pkt_8x16_pack@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <nios_access@plt>
test   %eax,%eax
jne    1198 <nios_8x16_read+0x68>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%r8
lea    0xc(%rsp),%r9
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <nios_pkt_8x16_resp_unpack@plt>
mov    0xc(%rsp),%ecx
xor    %eax,%eax
test   %ecx,%ecx
setne  %dl
je     118d <nios_8x16_read+0x5d>
mov    0x8(%rsp),%ecx
mov    %dl,%al
shl    $0x4,%eax
add    $0xfffffff0,%eax
mov    %ecx,(%r14)
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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