#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_32x32_pack(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                       int, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ nios_pkt_32x32_resp_unpack(int /*<<< orphan*/ *,
                                              int /*<<< orphan*/ *,
                                              int /*<<< orphan*/ *,
                                              int /*<<< orphan*/ *,
                                              scalar_t__ *, int *);
int nios_32x32_masked_read(struct bladerf *dev, uint8_t id, uint32_t mask,
                           uint32_t *val) {
  int status;
  bool success;
  uint8_t buf[16];
  nios_pkt_32x32_pack(buf, id, false, mask, 0);
  status = nios_access(dev, buf);
  if (status != 0) {
    return status;
  }
  nios_pkt_32x32_resp_unpack(buf, NULL, NULL, NULL, val, &success);
  if (success) {
    return 0;
  } else {
    *val = 0;
    do {
      do {
      } while (0);
    } while (0);
    return (-16);
  }
}


x86 assembly (clang, -O0):
<nios_32x32_masked_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rcx
xor    %r8d,%r8d
mov    %r8d,%edx
call   1030 <nios_pkt_32x32_pack@plt>
mov    -0x10(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1040 <nios_access@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     1182 <nios_32x32_masked_read+0x52>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d4 <nios_32x32_masked_read+0xa4>
lea    -0x70(%rbp),%rdi
mov    -0x28(%rbp),%r8
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x30(%rbp),%r9
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1050 <nios_pkt_32x32_resp_unpack@plt>
cmpl   $0x0,-0x30(%rbp)
je     11b3 <nios_32x32_masked_read+0x83>
movl   $0x0,-0x4(%rbp)
jmp    11d4 <nios_32x32_masked_read+0xa4>
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
jmp    11c3 <nios_32x32_masked_read+0x93>
jmp    11c8 <nios_32x32_masked_read+0x98>
jmp    11cd <nios_32x32_masked_read+0x9d>
movl   $0xfffffff0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nios_32x32_masked_read>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %rcx,%r14
mov    %rdx,%rcx
mov    %rdi,%rbx
lea    0x10(%rsp),%r15
mov    %r15,%rdi
xor    %edx,%edx
xor    %r8d,%r8d
call   1030 <nios_pkt_32x32_pack@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <nios_access@plt>
test   %eax,%eax
jne    1193 <nios_32x32_masked_read+0x63>
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%r9
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1050 <nios_pkt_32x32_resp_unpack@plt>
cmpl   $0x0,0xc(%rsp)
mov    $0x0,%eax
jne    1193 <nios_32x32_masked_read+0x63>
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_32x32_masked_read(%struct.bladerf* %0, i32 %1, i64 %2, i64* %3) {
%5 = alloca i32
%6 = alloca %struct.bladerf*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64*
%10 = alloca i32
%11 = alloca i32
%12 = alloca [16 x i32]
store %struct.bladerf* %0, %struct.bladerf** %6
store i32 %1, i32* %7
store i64 %2, i64* %8
store i64* %3, i64** %9
%13 = getelementptr inbounds [16 x i32], [16 x i32]* %12, i64 0, i64 0
%14 = load i32, i32* %7
%15 = load i64, i64* %8
%16 = call i32 @nios_pkt_32x32_pack(i32* %13, i32 %14, i32 0, i64 %15, i32 0)
%17 = load %struct.bladerf*, %struct.bladerf** %6
%18 = getelementptr inbounds [16 x i32], [16 x i32]* %12, i64 0, i64 0
%19 = call i32 @nios_access(%struct.bladerf* %17, i32* %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 i32], [16 x i32]* %12, i64 0, i64 0
%26 = load i64*, i64** %9
%27 = call i32 @nios_pkt_32x32_resp_unpack(i32* %25, i32* null, i32* null, i32* null, i64* %26, i32* %11)
%28 = load i32, i32* %11
%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
%32 = load i64*, i64** %9
store i64 0, i64* %32
br label %33
33: ; preds = %31
br label %34
34: ; preds = %33
br label %35
35: ; preds = %34
br label %36
36: ; preds = %35
store i32 -16, i32* %5
br label %37
37: ; preds = %36, %30, %22
%38 = load i32, i32* %5
ret i32 %38
}

LLVM IR (-O2):
%struct.bladerf = type { i32 }
define i32 @nios_32x32_masked_read(%struct.bladerf* %0, i32 %1, i64 %2, i64* %3) {
%5 = alloca i32
%6 = alloca [16 x i32]
%7 = bitcast i32* %5 to i8*
%8 = bitcast [16 x i32]* %6 to i8*
%9 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 0
%10 = call i32 @nios_pkt_32x32_pack(i32* %9, i32 %1, i32 0, i64 %2, 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_32x32_resp_unpack(i32* %9, i32* null, i32* null, i32* null, i64* %3, i32* %5)
%15 = load i32, i32* %5
%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
}