#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 /*<<< orphan*/ print_debug(char *);
int /*<<< orphan*/ print_debug_hex8(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);
  print_debug("spd_set_nbxcfg reg=");
  print_debug_hex8(reg);
  print_debug("\n");
  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);
    print_debug("spd_set_nbxcfg 0x76.b=");
    print_debug_hex8(byte);
    print_debug("\n");
  }
}


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     1205 <spd_set_nbxcfg+0xb5>
mov    -0xc(%rbp),%edi
mov    $0xb,%esi
call   1050 <smbus_read_byte@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1196 <spd_set_nbxcfg+0x46>
jmp    11ee <spd_set_nbxcfg+0x9e>
movl   $0x0,-0x10(%rbp)
cmpl   $0x2,-0x10(%rbp)
je     11ac <spd_set_nbxcfg+0x5c>
jmp    11ee <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   1050 <smbus_read_byte@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x1,-0x10(%rbp)
jg     11db <spd_set_nbxcfg+0x8b>
jmp    11ee <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    116d <spd_set_nbxcfg+0x1d>
mov    -0x4(%rbp),%eax
xor    %edi,%edi
xor    %ecx,%ecx
mov    %ecx,%esi
mov    $0x53,%edx
movzbl %al,%ecx
call   1040 <pcibios_write_config_byte@plt>
lea    0xdde(%rip),%rdi
call   1060 <print_debug@plt>
mov    -0x4(%rbp),%eax
movzbl %al,%edi
call   1030 <print_debug_hex8@plt>
lea    0xddb(%rip),%rdi
call   1060 <print_debug@plt>
cmpl   $0xff,-0x4(%rbp)
je     1301 <spd_set_nbxcfg+0x1b1>
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x50,%edx
call   1070 <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   1040 <pcibios_write_config_byte@plt>
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x51,%edx
call   1070 <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   1040 <pcibios_write_config_byte@plt>
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x76,%edx
call   1070 <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   1040 <pcibios_write_config_byte@plt>
lea    0xd2f(%rip),%rdi
call   1060 <print_debug@plt>
movzbl -0x11(%rbp),%edi
call   1030 <print_debug_hex8@plt>
lea    0xd18(%rip),%rdi
call   1060 <print_debug@plt>
add    $0x20,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
@.str = [20 x i8] c"spd_set_nbxcfg reg=\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [23 x i8] c"spd_set_nbxcfg 0x76.b=\00"
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 = call i32 @print_debug(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%45 = load i32, i32* %1
%46 = trunc i32 %45 to i8
%47 = call i32 @print_debug_hex8(i8 zeroext %46)
%48 = call i32 @print_debug(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%49 = load i32, i32* %1
%50 = icmp ne i32 %49, 255
br i1 %50, label %51, label %77
51: ; preds = %40
%52 = call zeroext i8 @pcibios_read_config_byte(i32 0, i64 0, i32 80)
store i8 %52, i8* %5
%53 = load i8, i8* %5
%54 = zext i8 %53 to i32
%55 = or i32 %54, 128
%56 = trunc i32 %55 to i8
store i8 %56, i8* %5
%57 = load i8, i8* %5
%58 = call i32 @pcibios_write_config_byte(i32 0, i64 0, i32 80, i8 zeroext %57)
%59 = call zeroext i8 @pcibios_read_config_byte(i32 0, i64 0, i32 81)
store i8 %59, i8* %5
%60 = load i8, i8* %5
%61 = zext i8 %60 to i32
%62 = or i32 %61, 1
%63 = trunc i32 %62 to i8
store i8 %63, i8* %5
%64 = load i8, i8* %5
%65 = call i32 @pcibios_write_config_byte(i32 0, i64 0, i32 81, i8 zeroext %64)
%66 = call zeroext i8 @pcibios_read_config_byte(i32 0, i64 0, i32 118)
store i8 %66, i8* %5
%67 = load i8, i8* %5
%68 = zext i8 %67 to i32
%69 = or i32 %68, 4
%70 = trunc i32 %69 to i8
store i8 %70, i8* %5
%71 = load i8, i8* %5
%72 = call i32 @pcibios_write_config_byte(i32 0, i64 0, i32 118, i8 zeroext %71)
%73 = call i32 @print_debug(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%74 = load i8, i8* %5
%75 = call i32 @print_debug_hex8(i8 zeroext %74)
%76 = call i32 @print_debug(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %77
77: ; preds = %51, %40
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"spd_set_nbxcfg reg=\00"
@.str.1 = [2 x i8] c"\0A\00"
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)
%6 = tail call i32 @print_debug(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @print_debug_hex8(i8 zeroext -1)
%8 = tail call i32 @print_debug(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}