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

/* Variables and functions */
int t3_mdio_read(struct cphy *, int, int, unsigned int *);
int t3_mdio_write(struct cphy *, int, int, unsigned int);
int t3_mdio_change_bits(struct cphy *phy, int mmd, int reg, unsigned int clear,
                        unsigned int set) {
  int ret;
  unsigned int val;
  ret = t3_mdio_read(phy, mmd, reg, &val);
  if (!ret) {
    val &= ~clear;
    ret = t3_mdio_write(phy, mmd, reg, val | set);
  }
  return ret;
}


x86 assembly (clang, -O0):
<t3_mdio_change_bits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    -0x20(%rbp),%rcx
call   1040 <t3_mdio_read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    117d <t3_mdio_change_bits+0x5d>
mov    -0x14(%rbp),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x20(%rbp),%ecx
or     -0x18(%rbp),%ecx
call   1030 <t3_mdio_write@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<t3_mdio_change_bits>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %r8d,%r15d
mov    %ecx,%ebx
mov    %edx,%r14d
mov    %esi,%r12d
mov    %rdi,%rbp
lea    0xc(%rsp),%rcx
call   1040 <t3_mdio_read@plt>
test   %eax,%eax
jne    1165 <t3_mdio_change_bits+0x45>
not    %ebx
and    0xc(%rsp),%ebx
mov    %ebx,0xc(%rsp)
or     %r15d,%ebx
mov    %rbp,%rdi
mov    %r12d,%esi
mov    %r14d,%edx
mov    %ebx,%ecx
call   1030 <t3_mdio_write@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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