#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 scalar_t__ uint8_t;
struct bladerf {
  int dummy;
};

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


x86 assembly (clang, -O0):
<nios_8x8_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
lea    -0xb0(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rcx
xor    %r8d,%r8d
mov    %r8d,%edx
call   1050 <nios_pkt_8x8_pack@plt>
mov    -0x10(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
call   1030 <nios_access@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     118d <nios_8x8_read+0x5d>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ed <nios_8x8_read+0xbd>
lea    -0xb0(%rbp),%rdi
mov    -0x28(%rbp),%r8
xor    %eax,%eax
mov    %eax,%ecx
lea    -0xb4(%rbp),%r9
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1040 <nios_pkt_8x8_resp_unpack@plt>
cmpl   $0x0,-0xb4(%rbp)
je     11c7 <nios_8x8_read+0x97>
movl   $0x0,-0x4(%rbp)
jmp    11ed <nios_8x8_read+0xbd>
jmp    11cc <nios_8x8_read+0x9c>
jmp    11d1 <nios_8x8_read+0xa1>
jmp    11d6 <nios_8x8_read+0xa6>
jmp    11db <nios_8x8_read+0xab>
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
movl   $0xfffffff0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

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

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

LLVM IR (-O2):
%struct.bladerf = type { i32 }
define i32 @nios_8x8_read(%struct.bladerf* %0, i64 %1, i64 %2, i64* %3) {
%5 = alloca [16 x i64]
%6 = alloca i32
%7 = bitcast [16 x i64]* %5 to i8*
%8 = bitcast i32* %6 to i8*
%9 = getelementptr inbounds [16 x i64], [16 x i64]* %5, i64 0, i64 0
%10 = call i32 @nios_pkt_8x8_pack(i64* %9, i64 %1, i32 0, i64 %2, i32 0)
%11 = call i32 @nios_access(%struct.bladerf* %0, i64* %9)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %4
%14 = call i32 @nios_pkt_8x8_resp_unpack(i64* %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
}