#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 */
scalar_t__ log2(unsigned long);
int /*<<< orphan*/ pcibios_write_config_byte(int /*<<< orphan*/, scalar_t__,
                                             unsigned int, unsigned int);
int /*<<< orphan*/ print_debug(char *);
int /*<<< orphan*/ print_debug_hex32(unsigned int);
int smbus_read_byte(unsigned int, int);
void spd_set_drb(void) {
  unsigned end_of_memory;
  unsigned device;
  unsigned drb_reg;
  end_of_memory = 0;
  device = 0x50;
  drb_reg = 0x60;
  while (device <= 0x53) {
    unsigned side1_bits, side2_bits;
    int byte, byte2;
    side1_bits = side2_bits = -1;
    byte = smbus_read_byte(device, 3);
    if (byte >= 0) {
      side1_bits += byte & 0xf;
      byte = smbus_read_byte(device, 4);
      side1_bits += byte & 0xf;
      byte = smbus_read_byte(device, 17);
      side1_bits += log2(byte);
      byte = smbus_read_byte(device, 6);
      byte2 = smbus_read_byte(device, 7);
      side1_bits += log2((((unsigned long)byte2 << 8) | byte));
      side1_bits -= 25;
      byte = smbus_read_byte(device, 5);
      if (byte > 1) {
        side2_bits = side1_bits;
      }
    }
    if (side1_bits < 8) {
      end_of_memory += (1 << side1_bits);
    }
    print_debug("end_of_memory: ");
    print_debug_hex32(end_of_memory);
    print_debug("\n");
    pcibios_write_config_byte(0, ((0x00 << 3) + 0), drb_reg, end_of_memory);
    if (side2_bits < 8) {
      end_of_memory += (1 << side2_bits);
    }
    print_debug("end_of_memory: ");
    print_debug_hex32(end_of_memory);
    print_debug("\n");
    pcibios_write_config_byte(0, ((0x00 << 3) + 0), drb_reg + 1, end_of_memory);
    drb_reg += 2;
    device += 1;
  }
}


x86 assembly (clang, -O0):
<spd_set_drb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x50,-0x8(%rbp)
movl   $0x60,-0xc(%rbp)
cmpl   $0x53,-0x8(%rbp)
ja     130a <spd_set_drb+0x1ba>
movl   $0xffffffff,-0x14(%rbp)
movl   $0xffffffff,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x3,%esi
call   1060 <smbus_read_byte@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     125a <spd_set_drb+0x10a>
mov    -0x18(%rbp),%eax
and    $0xf,%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x4,%esi
call   1060 <smbus_read_byte@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
and    $0xf,%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x11,%esi
call   1060 <smbus_read_byte@plt>
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rdi
call   1030 <log2@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x6,%esi
call   1060 <smbus_read_byte@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x7,%esi
call   1060 <smbus_read_byte@plt>
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rdi
shl    $0x8,%rdi
movslq -0x18(%rbp),%rax
or     %rax,%rdi
call   1030 <log2@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
sub    $0x19,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x5,%esi
call   1060 <smbus_read_byte@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
jle    1255 <spd_set_drb+0x105>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    125a <spd_set_drb+0x10a>
cmpl   $0x8,-0x10(%rbp)
jae    1274 <spd_set_drb+0x124>
mov    -0x10(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
add    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
lea    0xd85(%rip),%rdi
call   1070 <print_debug@plt>
mov    -0x4(%rbp),%edi
call   1050 <print_debug_hex32@plt>
lea    0xd81(%rip),%rdi
call   1070 <print_debug@plt>
mov    -0xc(%rbp),%edx
mov    -0x4(%rbp),%ecx
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <pcibios_write_config_byte@plt>
cmpl   $0x8,-0x14(%rbp)
jae    12bf <spd_set_drb+0x16f>
mov    -0x14(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
add    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
lea    0xd3a(%rip),%rdi
call   1070 <print_debug@plt>
mov    -0x4(%rbp),%edi
call   1050 <print_debug_hex32@plt>
lea    0xd36(%rip),%rdi
call   1070 <print_debug@plt>
mov    -0xc(%rbp),%edx
add    $0x1,%edx
mov    -0x4(%rbp),%ecx
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <pcibios_write_config_byte@plt>
mov    -0xc(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    116d <spd_set_drb+0x1d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spd_set_drb>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x50,%r13d
mov    $0x60,%r14d
xor    %ebp,%ebp
lea    0xe90(%rip),%r12
jmp    11bd <spd_set_drb+0x6d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    %eax,%ebp
mov    %r12,%rdi
call   1070 <print_debug@plt>
mov    %ebp,%edi
call   1050 <print_debug_hex32@plt>
mov    %r15,%rdi
call   1070 <print_debug@plt>
lea    0x1(%r14),%edx
xor    %edi,%edi
xor    %esi,%esi
mov    %ebp,%ecx
call   1040 <pcibios_write_config_byte@plt>
add    $0x1,%r13d
lea    0x2(%r14),%eax
cmp    $0x66,%r14d
mov    %eax,%r14d
je     12ca <spd_set_drb+0x17a>
mov    %r13d,%edi
mov    $0x3,%esi
call   1060 <smbus_read_byte@plt>
test   %eax,%eax
js     1280 <spd_set_drb+0x130>
mov    %eax,%r15d
and    $0xf,%r15d
mov    %r13d,%edi
mov    $0x4,%esi
call   1060 <smbus_read_byte@plt>
mov    %eax,%ebx
and    $0xf,%ebx
add    %r15d,%ebx
mov    %r13d,%edi
mov    $0x11,%esi
call   1060 <smbus_read_byte@plt>
movslq %eax,%rdi
call   1030 <log2@plt>
mov    %rax,%r15
mov    %r13d,%edi
mov    $0x6,%esi
call   1060 <smbus_read_byte@plt>
mov    %eax,%r12d
mov    %r13d,%edi
mov    $0x7,%esi
call   1060 <smbus_read_byte@plt>
cltq
shl    $0x8,%rax
movslq %r12d,%rdi
or     %rax,%rdi
call   1030 <log2@plt>
add    %ebx,%r15d
lea    (%rax,%r15,1),%ebx
add    $0xffffffe6,%ebx
mov    %r13d,%edi
mov    $0x5,%esi
call   1060 <smbus_read_byte@plt>
mov    $0x1,%edx
mov    %ebx,%ecx
shl    %cl,%edx
cmp    $0x8,%ebx
jb     125b <spd_set_drb+0x10b>
xor    %edx,%edx
cmp    $0x2,%eax
lea    0xd9b(%rip),%r12
lea    0xda4(%rip),%r15
jge    1273 <spd_set_drb+0x123>
mov    $0xffffffff,%ebx
add    %edx,%ebp
jmp    128c <spd_set_drb+0x13c>
nopw   0x0(%rax,%rax,1)
mov    $0xffffffff,%ebx
lea    0xd84(%rip),%r15
mov    %r12,%rdi
call   1070 <print_debug@plt>
mov    %ebp,%edi
call   1050 <print_debug_hex32@plt>
mov    %r15,%rdi
call   1070 <print_debug@plt>
xor    %edi,%edi
xor    %esi,%esi
mov    %r14d,%edx
mov    %ebp,%ecx
call   1040 <pcibios_write_config_byte@plt>
mov    $0x1,%eax
mov    %ebx,%ecx
shl    %cl,%eax
cmp    $0x8,%ebx
jb     1180 <spd_set_drb+0x30>
xor    %eax,%eax
jmp    1180 <spd_set_drb+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"end_of_memory: \00"
@.str.1 = [2 x i8] c"\0A\00"
define void @spd_set_drb() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 80, i32* %2
store i32 96, i32* %3
br label %8
8: ; preds = %83, %0
%9 = load i32, i32* %2
%10 = icmp ule i32 %9, 83
br i1 %10, label %11, label %96
11: ; preds = %8
store i32 -1, i32* %5
store i32 -1, i32* %4
%12 = load i32, i32* %2
%13 = call i32 @smbus_read_byte(i32 %12, i32 3)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp sge i32 %14, 0
br i1 %15, label %16, label %60
16: ; preds = %11
%17 = load i32, i32* %6
%18 = and i32 %17, 15
%19 = load i32, i32* %4
%20 = add i32 %19, %18
store i32 %20, i32* %4
%21 = load i32, i32* %2
%22 = call i32 @smbus_read_byte(i32 %21, i32 4)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = and i32 %23, 15
%25 = load i32, i32* %4
%26 = add i32 %25, %24
store i32 %26, i32* %4
%27 = load i32, i32* %2
%28 = call i32 @smbus_read_byte(i32 %27, i32 17)
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = call i64 @log2(i64 %30)
%32 = load i32, i32* %4
%33 = zext i32 %32 to i64
%34 = add nsw i64 %33, %31
%35 = trunc i64 %34 to i32
store i32 %35, i32* %4
%36 = load i32, i32* %2
%37 = call i32 @smbus_read_byte(i32 %36, i32 6)
store i32 %37, i32* %6
%38 = load i32, i32* %2
%39 = call i32 @smbus_read_byte(i32 %38, i32 7)
store i32 %39, i32* %7
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = shl i64 %41, 8
%43 = load i32, i32* %6
%44 = sext i32 %43 to i64
%45 = or i64 %42, %44
%46 = call i64 @log2(i64 %45)
%47 = load i32, i32* %4
%48 = zext i32 %47 to i64
%49 = add nsw i64 %48, %46
%50 = trunc i64 %49 to i32
store i32 %50, i32* %4
%51 = load i32, i32* %4
%52 = sub i32 %51, 25
store i32 %52, i32* %4
%53 = load i32, i32* %2
%54 = call i32 @smbus_read_byte(i32 %53, i32 5)
store i32 %54, i32* %6
%55 = load i32, i32* %6
%56 = icmp sgt i32 %55, 1
br i1 %56, label %57, label %59
57: ; preds = %16
%58 = load i32, i32* %4
store i32 %58, i32* %5
br label %59
59: ; preds = %57, %16
br label %60
60: ; preds = %59, %11
%61 = load i32, i32* %4
%62 = icmp ult i32 %61, 8
br i1 %62, label %63, label %68
63: ; preds = %60
%64 = load i32, i32* %4
%65 = shl i32 1, %64
%66 = load i32, i32* %1
%67 = add i32 %66, %65
store i32 %67, i32* %1
br label %68
68: ; preds = %63, %60
%69 = call i32 @print_debug(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%70 = load i32, i32* %1
%71 = call i32 @print_debug_hex32(i32 %70)
%72 = call i32 @print_debug(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%73 = load i32, i32* %3
%74 = load i32, i32* %1
%75 = call i32 @pcibios_write_config_byte(i32 0, i64 0, i32 %73, i32 %74)
%76 = load i32, i32* %5
%77 = icmp ult i32 %76, 8
br i1 %77, label %78, label %83
78: ; preds = %68
%79 = load i32, i32* %5
%80 = shl i32 1, %79
%81 = load i32, i32* %1
%82 = add i32 %81, %80
store i32 %82, i32* %1
br label %83
83: ; preds = %78, %68
%84 = call i32 @print_debug(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%85 = load i32, i32* %1
%86 = call i32 @print_debug_hex32(i32 %85)
%87 = call i32 @print_debug(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%88 = load i32, i32* %3
%89 = add i32 %88, 1
%90 = load i32, i32* %1
%91 = call i32 @pcibios_write_config_byte(i32 0, i64 0, i32 %89, i32 %90)
%92 = load i32, i32* %3
%93 = add i32 %92, 2
store i32 %93, i32* %3
%94 = load i32, i32* %2
%95 = add i32 %94, 1
store i32 %95, i32* %2
br label %8
96: ; preds = %8
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"end_of_memory: \00"
@.str.1 = [2 x i8] c"\0A\00"
define void @spd_set_drb() {
br label %1
1: ; preds = %0, %34
%2 = phi i32 [ 0, %0 ], [ %44, %34 ]
%3 = phi i32 [ 96, %0 ], [ %50, %34 ]
%4 = phi i32 [ 80, %0 ], [ %51, %34 ]
%5 = tail call i32 @smbus_read_byte(i32 %4, i32 3)
%6 = icmp sgt i32 %5, -1
br i1 %6, label %7, label %34
7: ; preds = %1
%8 = and i32 %5, 15
%9 = tail call i32 @smbus_read_byte(i32 %4, i32 4)
%10 = and i32 %9, 15
%11 = tail call i32 @smbus_read_byte(i32 %4, i32 17)
%12 = sext i32 %11 to i64
%13 = tail call i64 @log2(i64 %12)
%14 = trunc i64 %13 to i32
%15 = tail call i32 @smbus_read_byte(i32 %4, i32 6)
%16 = tail call i32 @smbus_read_byte(i32 %4, i32 7)
%17 = sext i32 %16 to i64
%18 = shl nsw i64 %17, 8
%19 = sext i32 %15 to i64
%20 = or i64 %18, %19
%21 = tail call i64 @log2(i64 %20)
%22 = trunc i64 %21 to i32
%23 = add nuw nsw i32 %8, -26
%24 = add nsw i32 %23, %10
%25 = add i32 %24, %14
%26 = add i32 %25, %22
%27 = tail call i32 @smbus_read_byte(i32 %4, i32 5)
%28 = icmp sgt i32 %27, 1
%29 = icmp ult i32 %26, 8
%30 = shl nuw i32 1, %26
%31 = select i1 %29, i32 %30, i32 0
%32 = add i32 %31, %2
%33 = select i1 %28, i32 %26, i32 -1
br label %34
34: ; preds = %7, %1
%35 = phi i32 [ -1, %1 ], [ %33, %7 ]
%36 = phi i32 [ %2, %1 ], [ %32, %7 ]
%37 = tail call i32 @print_debug(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%38 = tail call i32 @print_debug_hex32(i32 %36)
%39 = tail call i32 @print_debug(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%40 = tail call i32 @pcibios_write_config_byte(i32 0, i64 0, i32 %3, i32 %36)
%41 = icmp ult i32 %35, 8
%42 = shl nuw i32 1, %35
%43 = select i1 %41, i32 %42, i32 0
%44 = add i32 %43, %36
%45 = tail call i32 @print_debug(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%46 = tail call i32 @print_debug_hex32(i32 %44)
%47 = tail call i32 @print_debug(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%48 = or i32 %3, 1
%49 = tail call i32 @pcibios_write_config_byte(i32 0, i64 0, i32 %48, i32 %44)
%50 = add nuw nsw i32 %3, 2
%51 = add nuw nsw i32 %4, 1
%52 = icmp eq i32 %51, 84
br i1 %52, label %53, label %1
53: ; preds = %34
ret void
}