#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_write(struct bladerf *dev, uint8_t id, uint8_t addr,
                    uint16_t data) {
  int status;
  uint8_t buf[16];
  bool success;
  nios_pkt_8x16_pack(buf, id, true, addr, data);
  status = nios_access(dev, buf);
  if (status != 0) {
    return status;
  }
  nios_pkt_8x16_resp_unpack(buf, NULL, NULL, NULL, NULL, &success);
  if (success) {
    return 0;
  } else {
    do {
      do {
      } while (0);
    } while (0);
    return (-16);
  }
}


x86 assembly (clang, -O0):
<nios_8x16_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
mov    $0x1,%edx
call   1050 <nios_pkt_8x16_pack@plt>
mov    -0x10(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1030 <nios_access@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1182 <nios_8x16_write+0x52>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ce <nios_8x16_write+0x9e>
lea    -0x60(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%r8d
lea    -0x64(%rbp),%r9
mov    %r8,%rsi
mov    %r8,%rdx
mov    %r8,%rcx
call   1040 <nios_pkt_8x16_resp_unpack@plt>
cmpl   $0x0,-0x64(%rbp)
je     11b3 <nios_8x16_write+0x83>
movl   $0x0,-0x4(%rbp)
jmp    11ce <nios_8x16_write+0x9e>
jmp    11b8 <nios_8x16_write+0x88>
jmp    11bd <nios_8x16_write+0x8d>
jmp    11c2 <nios_8x16_write+0x92>
jmp    11c7 <nios_8x16_write+0x97>
movl   $0xfffffff0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nios_8x16_write>:
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    %ecx,%r8d
mov    %edx,%ecx
mov    %rdi,%rbx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x1,%edx
call   1050 <nios_pkt_8x16_pack@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <nios_access@plt>
test   %eax,%eax
jne    1188 <nios_8x16_write+0x58>
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%r9
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <nios_pkt_8x16_resp_unpack@plt>
xor    %eax,%eax
cmpl   $0x0,0xc(%rsp)
setne  %al
shl    $0x4,%eax
add    $0xfffffff0,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.bladerf = type { i32 }
define i32 @nios_8x16_write(%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
store %struct.bladerf* %0, %struct.bladerf** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%13 = getelementptr inbounds [16 x i32], [16 x i32]* %11, i64 0, i64 0
%14 = load i32, i32* %7
%15 = load i32, i32* %8
%16 = load i32, i32* %9
%17 = call i32 @nios_pkt_8x16_pack(i32* %13, i32 %14, i32 1, i32 %15, i32 %16)
%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 %36
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* null, i32* %12)
%28 = load i32, i32* %12
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %25
store i32 0, i32* %5
br label %36
31: ; preds = %25
br label %32
32: ; preds = %31
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, %30, %23
%37 = load i32, i32* %5
ret i32 %37
}

LLVM IR (-O2):
%struct.bladerf = type { i32 }
define i32 @nios_8x16_write(%struct.bladerf* %0, i32 %1, i32 %2, i32 %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_8x16_pack(i32* %9, i32 %1, i32 1, i32 %2, i32 %3)
%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_8x16_resp_unpack(i32* %9, i32* null, i32* null, i32* null, i32* null, i32* %6)
%15 = load i32, i32* %6
%16 = icmp eq i32 %15, 0
%17 = select i1 %16, i32 -16, i32 0
br label %18
18: ; preds = %13, %4
%19 = phi i32 [ %11, %4 ], [ %17, %13 ]
ret i32 %19
}