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

/* Variables and functions */
int nios_legacy_pio_read(struct bladerf *, int, int *);
int nios_legacy_pio_write(struct bladerf *, int, int);
int nios_legacy_expansion_gpio_dir_write(struct bladerf *dev, uint32_t mask,
                                         uint32_t val) {
  int status;
  uint32_t tmp;
  if (mask != 0xffffffff) {
    status = nios_legacy_pio_read(dev, 44, &tmp);
    if (status != 0) {
      return status;
    }
    tmp &= ~mask;
    tmp |= (val & mask);
    val = tmp;
  }
  do {
    do {
    } while (0);
  } while (0);
  return nios_legacy_pio_write(dev, 44, val);
}


x86 assembly (clang, -O0):
<nios_legacy_expansion_gpio_dir_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
je     1184 <nios_legacy_expansion_gpio_dir_write+0x64>
mov    -0x10(%rbp),%rdi
mov    $0x2c,%esi
lea    -0x20(%rbp),%rdx
call   1040 <nios_legacy_pio_read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1166 <nios_legacy_expansion_gpio_dir_write+0x46>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ac <nios_legacy_expansion_gpio_dir_write+0x8c>
mov    -0x14(%rbp),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
and    -0x14(%rbp),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1189 <nios_legacy_expansion_gpio_dir_write+0x69>
jmp    118e <nios_legacy_expansion_gpio_dir_write+0x6e>
jmp    1193 <nios_legacy_expansion_gpio_dir_write+0x73>
jmp    1198 <nios_legacy_expansion_gpio_dir_write+0x78>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%edx
mov    $0x2c,%esi
call   1030 <nios_legacy_pio_write@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nios_legacy_expansion_gpio_dir_write>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebx
mov    %rdi,%r14
cmp    $0xffffffff,%esi
je     1158 <nios_legacy_expansion_gpio_dir_write+0x38>
mov    %esi,%ebp
lea    0xc(%rsp),%rdx
mov    %r14,%rdi
mov    $0x2c,%esi
call   1040 <nios_legacy_pio_read@plt>
test   %eax,%eax
jne    1167 <nios_legacy_expansion_gpio_dir_write+0x47>
mov    0xc(%rsp),%eax
xor    %eax,%ebx
and    %ebp,%ebx
xor    %eax,%ebx
mov    %ebx,0xc(%rsp)
mov    %r14,%rdi
mov    $0x2c,%esi
mov    %ebx,%edx
call   1030 <nios_legacy_pio_write@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.bladerf = type { i32 }
define i32 @nios_legacy_expansion_gpio_dir_write(%struct.bladerf* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.bladerf*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store %struct.bladerf* %0, %struct.bladerf** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = load i32, i32* %6
%11 = icmp ne i32 %10, -1
br i1 %11, label %12, label %30
12: ; preds = %3
%13 = load %struct.bladerf*, %struct.bladerf** %5
%14 = call i32 @nios_legacy_pio_read(%struct.bladerf* %13, i32 44, i32* %9)
store i32 %14, i32* %8
%15 = load i32, i32* %8
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = load i32, i32* %8
store i32 %18, i32* %4
br label %38
19: ; preds = %12
%20 = load i32, i32* %6
%21 = xor i32 %20, -1
%22 = load i32, i32* %9
%23 = and i32 %22, %21
store i32 %23, i32* %9
%24 = load i32, i32* %7
%25 = load i32, i32* %6
%26 = and i32 %24, %25
%27 = load i32, i32* %9
%28 = or i32 %27, %26
store i32 %28, i32* %9
%29 = load i32, i32* %9
store i32 %29, i32* %7
br label %30
30: ; preds = %19, %3
br label %31
31: ; preds = %30
br label %32
32: ; preds = %31
br label %33
33: ; preds = %32
br label %34
34: ; preds = %33
%35 = load %struct.bladerf*, %struct.bladerf** %5
%36 = load i32, i32* %7
%37 = call i32 @nios_legacy_pio_write(%struct.bladerf* %35, i32 44, i32 %36)
store i32 %37, i32* %4
br label %38
38: ; preds = %34, %17
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
%struct.bladerf = type { i32 }
define i32 @nios_legacy_expansion_gpio_dir_write(%struct.bladerf* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = icmp eq i32 %1, -1
br i1 %6, label %16, label %7
7: ; preds = %3
%8 = call i32 @nios_legacy_pio_read(%struct.bladerf* %0, i32 44, i32* %4)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %19
10: ; preds = %7
%11 = xor i32 %1, -1
%12 = load i32, i32* %4
%13 = and i32 %12, %11
%14 = and i32 %2, %1
%15 = or i32 %13, %14
store i32 %15, i32* %4
br label %16
16: ; preds = %10, %3
%17 = phi i32 [ %15, %10 ], [ %2, %3 ]
%18 = call i32 @nios_legacy_pio_write(%struct.bladerf* %0, i32 44, i32 %17)
br label %19
19: ; preds = %7, %16
%20 = phi i32 [ %18, %16 ], [ %8, %7 ]
ret i32 %20
}