#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 */

/* Variables and functions */
int LPA_100;
int LPA_1000FULL;
int LPA_1000HALF;
int LPA_10FULL;
int LPA_10HALF;
unsigned int mii_nway_result(unsigned int);
unsigned int gmii_nway_result(unsigned int negotiated) {
  unsigned int other_bits;
  other_bits = negotiated & ~((LPA_10FULL | LPA_10HALF) | LPA_100 |
                              ((LPA_1000FULL << 6) | (LPA_1000HALF << 6)));
  if (negotiated & (LPA_1000FULL << 6))
    return (other_bits | (LPA_1000FULL << 6));
  else if (negotiated & (LPA_1000HALF << 6))
    return (other_bits | (LPA_1000HALF << 6));
  else
    return (other_bits | mii_nway_result(negotiated));
}


x86 assembly (clang, -O0):
<gmii_nway_result>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2eab(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2eaa(%rip),%rdx
or     (%rdx),%ecx
mov    0x2ea9(%rip),%rdx
or     (%rdx),%ecx
mov    0x2eb8(%rip),%rdx
mov    (%rdx),%edx
shl    $0x6,%edx
mov    0x2e7c(%rip),%rsi
mov    (%rsi),%esi
shl    $0x6,%esi
or     %esi,%edx
or     %edx,%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2e91(%rip),%rcx
mov    (%rcx),%ecx
shl    $0x6,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1190 <gmii_nway_result+0x80>
mov    -0xc(%rbp),%eax
mov    0x2e77(%rip),%rcx
mov    (%rcx),%ecx
shl    $0x6,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11db <gmii_nway_result+0xcb>
mov    -0x8(%rbp),%eax
mov    0x2e2e(%rip),%rcx
mov    (%rcx),%ecx
shl    $0x6,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11c3 <gmii_nway_result+0xb3>
mov    -0xc(%rbp),%eax
mov    0x2e14(%rip),%rcx
mov    (%rcx),%ecx
shl    $0x6,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11db <gmii_nway_result+0xcb>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <mii_nway_result@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gmii_nway_result>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r12d
mov    0x2eab(%rip),%rax
mov    (%rax),%r14d
mov    0x2ea9(%rip),%rax
mov    (%rax),%ebp
mov    0x2ea8(%rip),%rax
mov    (%rax),%r15d
mov    0x2eb6(%rip),%rax
mov    (%rax),%ebx
shl    $0x6,%ebx
mov    0x2e7a(%rip),%rax
mov    (%rax),%r13d
shl    $0x6,%r13d
mov    %ebx,%eax
test   %edi,%ebx
jne    116b <gmii_nway_result+0x5b>
mov    %r13d,%eax
test   %r12d,%r13d
jne    116b <gmii_nway_result+0x5b>
mov    %r12d,%edi
call   1030 <mii_nway_result@plt>
or     %r14d,%ebp
or     %r15d,%ebp
or     %ebx,%ebp
or     %r13d,%ebp
not    %ebp
and    %r12d,%ebp
or     %eax,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@LPA_10FULL = global i32 0
@LPA_10HALF = global i32 0
@LPA_100 = global i32 0
@LPA_1000FULL = global i32 0
@LPA_1000HALF = global i32 0
define i32 @gmii_nway_result(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = load i32, i32* @LPA_10FULL
%7 = load i32, i32* @LPA_10HALF
%8 = or i32 %6, %7
%9 = load i32, i32* @LPA_100
%10 = or i32 %8, %9
%11 = load i32, i32* @LPA_1000FULL
%12 = shl i32 %11, 6
%13 = load i32, i32* @LPA_1000HALF
%14 = shl i32 %13, 6
%15 = or i32 %12, %14
%16 = or i32 %10, %15
%17 = xor i32 %16, -1
%18 = and i32 %5, %17
store i32 %18, i32* %4
%19 = load i32, i32* %3
%20 = load i32, i32* @LPA_1000FULL
%21 = shl i32 %20, 6
%22 = and i32 %19, %21
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %1
%25 = load i32, i32* %4
%26 = load i32, i32* @LPA_1000FULL
%27 = shl i32 %26, 6
%28 = or i32 %25, %27
store i32 %28, i32* %2
br label %45
29: ; preds = %1
%30 = load i32, i32* %3
%31 = load i32, i32* @LPA_1000HALF
%32 = shl i32 %31, 6
%33 = and i32 %30, %32
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %29
%36 = load i32, i32* %4
%37 = load i32, i32* @LPA_1000HALF
%38 = shl i32 %37, 6
%39 = or i32 %36, %38
store i32 %39, i32* %2
br label %45
40: ; preds = %29
%41 = load i32, i32* %4
%42 = load i32, i32* %3
%43 = call i32 @mii_nway_result(i32 %42)
%44 = or i32 %41, %43
store i32 %44, i32* %2
br label %45
45: ; preds = %40, %35, %24
%46 = load i32, i32* %2
ret i32 %46
}

LLVM IR (-O2):
@LPA_10FULL = global i32 0
@LPA_10HALF = global i32 0
@LPA_100 = global i32 0
@LPA_1000FULL = global i32 0
@LPA_1000HALF = global i32 0
define i32 @gmii_nway_result(i32 %0) {
%2 = load i32, i32* @LPA_10FULL
%3 = load i32, i32* @LPA_10HALF
%4 = load i32, i32* @LPA_100
%5 = load i32, i32* @LPA_1000FULL
%6 = shl i32 %5, 6
%7 = load i32, i32* @LPA_1000HALF
%8 = shl i32 %7, 6
%9 = and i32 %6, %0
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %1
%12 = and i32 %8, %0
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 @mii_nway_result(i32 %0)
br label %16
16: ; preds = %11, %1, %14
%17 = phi i32 [ %15, %14 ], [ %6, %1 ], [ %8, %11 ]
%18 = or i32 %3, %2
%19 = or i32 %18, %4
%20 = or i32 %19, %6
%21 = or i32 %20, %8
%22 = xor i32 %21, -1
%23 = and i32 %22, %0
%24 = or i32 %17, %23
ret i32 %24
}