#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 */
unsigned char pcibios_read_config_byte(int /*<<< orphan*/, scalar_t__, int);
int /*<<< orphan*/ pcibios_write_config_byte(int /*<<< orphan*/, scalar_t__,
                                             int, unsigned char);
int smbus_read_byte(unsigned int, int);
void spd_set_nbxcfg(void) {
  unsigned reg;
  unsigned index;
  unsigned device;
  reg = 0xff;
  index = 0;
  device = 0x50;
  for (; device <= 0x53; index += 2, device += 1) {
    int byte;
    byte = smbus_read_byte(device, 11);
    if (byte < 0)
      continue;
    byte = 0;
    if (byte != 2)
      continue;
    reg ^= (1 << index);
    byte = smbus_read_byte(device, 5);
    if (byte <= 1)
      continue;
    reg ^= (1 << (index + 1));
  }
  pcibios_write_config_byte(0, ((0x00 << 3) + 0), 0x53, reg);
  if (reg != 0xff) {
    unsigned char byte;
    byte = pcibios_read_config_byte(0, ((0x00 << 3) + 0), 0x50);
    byte |= 0x80;
    pcibios_write_config_byte(0, ((0x00 << 3) + 0), 0x50, byte);
    byte = pcibios_read_config_byte(0, ((0x00 << 3) + 0), 0x51);
    byte |= 1;
    pcibios_write_config_byte(0, ((0x00 << 3) + 0), 0x51, byte);
    byte = pcibios_read_config_byte(0, ((0x00 << 3) + 0), 0x76);
    byte |= 4;
    pcibios_write_config_byte(0, ((0x00 << 3) + 0), 0x76, byte);
  }
}


x86 assembly (clang, -O0):
<spd_set_nbxcfg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0xff,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x50,-0xc(%rbp)
cmpl   $0x53,-0xc(%rbp)
ja     11e5 <spd_set_nbxcfg+0xb5>
mov    -0xc(%rbp),%edi
mov    $0xb,%esi
call   1040 <smbus_read_byte@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1176 <spd_set_nbxcfg+0x46>
jmp    11ce <spd_set_nbxcfg+0x9e>
movl   $0x0,-0x10(%rbp)
cmpl   $0x2,-0x10(%rbp)
je     118c <spd_set_nbxcfg+0x5c>
jmp    11ce <spd_set_nbxcfg+0x9e>
mov    -0x8(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
xor    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x5,%esi
call   1040 <smbus_read_byte@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x1,-0x10(%rbp)
jg     11bb <spd_set_nbxcfg+0x8b>
jmp    11ce <spd_set_nbxcfg+0x9e>
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
mov    $0x1,%eax
shl    %cl,%eax
xor    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114d <spd_set_nbxcfg+0x1d>
mov    -0x4(%rbp),%eax
xor    %edi,%edi
xor    %ecx,%ecx
mov    %ecx,%esi
mov    $0x53,%edx
movzbl %al,%ecx
call   1030 <pcibios_write_config_byte@plt>
cmpl   $0xff,-0x4(%rbp)
je     129d <spd_set_nbxcfg+0x16d>
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x50,%edx
call   1050 <pcibios_read_config_byte@plt>
mov    %al,-0x11(%rbp)
movzbl -0x11(%rbp),%eax
or     $0x80,%eax
mov    %al,-0x11(%rbp)
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x50,%edx
movzbl -0x11(%rbp),%ecx
call   1030 <pcibios_write_config_byte@plt>
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x51,%edx
call   1050 <pcibios_read_config_byte@plt>
mov    %al,-0x11(%rbp)
movzbl -0x11(%rbp),%eax
or     $0x1,%eax
mov    %al,-0x11(%rbp)
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x51,%edx
movzbl -0x11(%rbp),%ecx
call   1030 <pcibios_write_config_byte@plt>
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x76,%edx
call   1050 <pcibios_read_config_byte@plt>
mov    %al,-0x11(%rbp)
movzbl -0x11(%rbp),%eax
or     $0x4,%eax
mov    %al,-0x11(%rbp)
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x76,%edx
movzbl -0x11(%rbp),%ecx
call   1030 <pcibios_write_config_byte@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spd_set_nbxcfg>:
push   %rax
mov    $0x50,%edi
mov    $0xb,%esi
call   1040 <smbus_read_byte@plt>
mov    $0x51,%edi
mov    $0xb,%esi
call   1040 <smbus_read_byte@plt>
mov    $0x52,%edi
mov    $0xb,%esi
call   1040 <smbus_read_byte@plt>
mov    $0x53,%edi
mov    $0xb,%esi
call   1040 <smbus_read_byte@plt>
xor    %edi,%edi
xor    %esi,%esi
mov    $0x53,%edx
mov    $0xff,%ecx
pop    %rax
jmp    1030 <pcibios_write_config_byte@plt>

LLVM IR (-O0):
define void @spd_set_nbxcfg() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
store i32 255, i32* %1
store i32 0, i32* %2
store i32 80, i32* %3
br label %6
6: ; preds = %35, %0
%7 = load i32, i32* %3
%8 = icmp ule i32 %7, 83
br i1 %8, label %9, label %40
9: ; preds = %6
%10 = load i32, i32* %3
%11 = call i32 @smbus_read_byte(i32 %10, i32 11)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %9
br label %35
15: ; preds = %9
store i32 0, i32* %4
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 2
br i1 %17, label %18, label %19
18: ; preds = %15
br label %35
19: ; preds = %15
%20 = load i32, i32* %2
%21 = shl i32 1, %20
%22 = load i32, i32* %1
%23 = xor i32 %22, %21
store i32 %23, i32* %1
%24 = load i32, i32* %3
%25 = call i32 @smbus_read_byte(i32 %24, i32 5)
store i32 %25, i32* %4
%26 = load i32, i32* %4
%27 = icmp sle i32 %26, 1
br i1 %27, label %28, label %29
28: ; preds = %19
br label %35
29: ; preds = %19
%30 = load i32, i32* %2
%31 = add i32 %30, 1
%32 = shl i32 1, %31
%33 = load i32, i32* %1
%34 = xor i32 %33, %32
store i32 %34, i32* %1
br label %35
35: ; preds = %29, %28, %18, %14
%36 = load i32, i32* %2
%37 = add i32 %36, 2
store i32 %37, i32* %2
%38 = load i32, i32* %3
%39 = add i32 %38, 1
store i32 %39, i32* %3
br label %6
40: ; preds = %6
%41 = load i32, i32* %1
%42 = trunc i32 %41 to i8
%43 = call i32 @pcibios_write_config_byte(i32 0, i64 0, i32 83, i8 zeroext %42)
%44 = load i32, i32* %1
%45 = icmp ne i32 %44, 255
br i1 %45, label %46, label %68
46: ; preds = %40
%47 = call zeroext i8 @pcibios_read_config_byte(i32 0, i64 0, i32 80)
store i8 %47, i8* %5
%48 = load i8, i8* %5
%49 = zext i8 %48 to i32
%50 = or i32 %49, 128
%51 = trunc i32 %50 to i8
store i8 %51, i8* %5
%52 = load i8, i8* %5
%53 = call i32 @pcibios_write_config_byte(i32 0, i64 0, i32 80, i8 zeroext %52)
%54 = call zeroext i8 @pcibios_read_config_byte(i32 0, i64 0, i32 81)
store i8 %54, i8* %5
%55 = load i8, i8* %5
%56 = zext i8 %55 to i32
%57 = or i32 %56, 1
%58 = trunc i32 %57 to i8
store i8 %58, i8* %5
%59 = load i8, i8* %5
%60 = call i32 @pcibios_write_config_byte(i32 0, i64 0, i32 81, i8 zeroext %59)
%61 = call zeroext i8 @pcibios_read_config_byte(i32 0, i64 0, i32 118)
store i8 %61, i8* %5
%62 = load i8, i8* %5
%63 = zext i8 %62 to i32
%64 = or i32 %63, 4
%65 = trunc i32 %64 to i8
store i8 %65, i8* %5
%66 = load i8, i8* %5
%67 = call i32 @pcibios_write_config_byte(i32 0, i64 0, i32 118, i8 zeroext %66)
br label %68
68: ; preds = %46, %40
ret void
}

LLVM IR (-O2):
define void @spd_set_nbxcfg() {
%1 = tail call i32 @smbus_read_byte(i32 80, i32 11)
%2 = tail call i32 @smbus_read_byte(i32 81, i32 11)
%3 = tail call i32 @smbus_read_byte(i32 82, i32 11)
%4 = tail call i32 @smbus_read_byte(i32 83, i32 11)
%5 = tail call i32 @pcibios_write_config_byte(i32 0, i64 0, i32 83, i8 zeroext -1)
ret void
}