#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 /*<<< orphan*/ print_debug(char *);
int /*<<< orphan*/ print_debug_char(char);
int /*<<< orphan*/ print_debug_hex8(int);
int smbus_read_byte(unsigned int, int);
void dump_spd_registers(void) {
  unsigned device;
  device = 0x50;
  while (device <= 0x57) {
    int status = 0;
    int i;
    print_debug("\n");
    print_debug("dimm ");
    print_debug_hex8(device);
    for (i = 0; (i < 256); i++) {
      if ((i % 16) == 0) {
        print_debug("\n");
        print_debug_hex8(i);
        print_debug(": ");
      }
      status = smbus_read_byte(device, i);
      if (status < 0) {
        print_debug("bad device: ");
        print_debug_hex8(-status);
        print_debug("\n");
        break;
      }
      print_debug_hex8(status);
      print_debug_char(' ');
    }
    device += 1;
    print_debug("\n");
  }
}


x86 assembly (clang, -O0):
<dump_spd_registers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x50,-0x4(%rbp)
cmpl   $0x57,-0x4(%rbp)
ja     1241 <dump_spd_registers+0x101>
movl   $0x0,-0x8(%rbp)
lea    0xe99(%rip),%rdi
call   1050 <print_debug@plt>
lea    0xe8f(%rip),%rdi
call   1050 <print_debug@plt>
mov    -0x4(%rbp),%edi
call   1030 <print_debug_hex8@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x100,-0xc(%rbp)
jge    1227 <dump_spd_registers+0xe7>
mov    -0xc(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11c8 <dump_spd_registers+0x88>
lea    0xe51(%rip),%rdi
call   1050 <print_debug@plt>
mov    -0xc(%rbp),%edi
call   1030 <print_debug_hex8@plt>
lea    0xe4f(%rip),%rdi
call   1050 <print_debug@plt>
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <smbus_read_byte@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1207 <dump_spd_registers+0xc7>
lea    0xe21(%rip),%rdi
call   1050 <print_debug@plt>
xor    %edi,%edi
sub    -0x8(%rbp),%edi
call   1030 <print_debug_hex8@plt>
lea    0xe03(%rip),%rdi
call   1050 <print_debug@plt>
jmp    1227 <dump_spd_registers+0xe7>
mov    -0x8(%rbp),%edi
call   1030 <print_debug_hex8@plt>
mov    $0x20,%edi
call   1060 <print_debug_char@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1187 <dump_spd_registers+0x47>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
lea    0xdc9(%rip),%rdi
call   1050 <print_debug@plt>
jmp    114f <dump_spd_registers+0xf>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_spd_registers>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x50,%ebx
lea    0xea9(%rip),%r14
lea    0xea4(%rip),%r15
lea    0xead(%rip),%r12
jmp    119f <dump_spd_registers+0x5f>
nopw   0x0(%rax,%rax,1)
lea    0xe91(%rip),%rdi
call   1050 <print_debug@plt>
neg    %r13d
mov    %r13d,%edi
call   1030 <print_debug_hex8@plt>
mov    %r14,%rdi
call   1050 <print_debug@plt>
add    $0x1,%ebx
mov    %r14,%rdi
call   1050 <print_debug@plt>
cmp    $0x58,%ebx
je     120c <dump_spd_registers+0xcc>
mov    %r14,%rdi
call   1050 <print_debug@plt>
mov    %r15,%rdi
call   1050 <print_debug@plt>
mov    %ebx,%edi
call   1030 <print_debug_hex8@plt>
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
test   $0xf,%bpl
jne    11dd <dump_spd_registers+0x9d>
mov    %r14,%rdi
call   1050 <print_debug@plt>
mov    %ebp,%edi
call   1030 <print_debug_hex8@plt>
mov    %r12,%rdi
call   1050 <print_debug@plt>
mov    %ebx,%edi
mov    %ebp,%esi
call   1040 <smbus_read_byte@plt>
mov    %eax,%r13d
test   %eax,%eax
js     1170 <dump_spd_registers+0x30>
mov    %r13d,%edi
call   1030 <print_debug_hex8@plt>
mov    $0x20,%edi
call   1060 <print_debug_char@plt>
add    $0x1,%ebp
cmp    $0x100,%ebp
jne    11c0 <dump_spd_registers+0x80>
jmp    118f <dump_spd_registers+0x4f>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [6 x i8] c"dimm \00"
@.str.2 = [3 x i8] c": \00"
@.str.3 = [13 x i8] c"bad device: \00"
define void @dump_spd_registers() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 80, i32* %1
br label %4
4: ; preds = %43, %0
%5 = load i32, i32* %1
%6 = icmp ule i32 %5, 87
br i1 %6, label %7, label %47
7: ; preds = %4
store i32 0, i32* %2
%8 = call i32 @print_debug(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @print_debug(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* %1
%11 = call i32 @print_debug_hex8(i32 %10)
store i32 0, i32* %3
br label %12
12: ; preds = %40, %7
%13 = load i32, i32* %3
%14 = icmp slt i32 %13, 256
br i1 %14, label %15, label %43
15: ; preds = %12
%16 = load i32, i32* %3
%17 = srem i32 %16, 16
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = call i32 @print_debug(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* %3
%22 = call i32 @print_debug_hex8(i32 %21)
%23 = call i32 @print_debug(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %19, %15
%25 = load i32, i32* %1
%26 = load i32, i32* %3
%27 = call i32 @smbus_read_byte(i32 %25, i32 %26)
store i32 %27, i32* %2
%28 = load i32, i32* %2
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %24
%31 = call i32 @print_debug(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%32 = load i32, i32* %2
%33 = sub nsw i32 0, %32
%34 = call i32 @print_debug_hex8(i32 %33)
%35 = call i32 @print_debug(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %43
36: ; preds = %24
%37 = load i32, i32* %2
%38 = call i32 @print_debug_hex8(i32 %37)
%39 = call i32 @print_debug_char(i8 signext 32)
br label %40
40: ; preds = %36
%41 = load i32, i32* %3
%42 = add nsw i32 %41, 1
store i32 %42, i32* %3
br label %12
43: ; preds = %30, %12
%44 = load i32, i32* %1
%45 = add i32 %44, 1
store i32 %45, i32* %1
%46 = call i32 @print_debug(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %4
47: ; preds = %4
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [6 x i8] c"dimm \00"
@.str.2 = [3 x i8] c": \00"
@.str.3 = [13 x i8] c"bad device: \00"
define void @dump_spd_registers() {
br label %1
1: ; preds = %0, %27
%2 = phi i32 [ 80, %0 ], [ %28, %27 ]
%3 = tail call i32 @print_debug(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @print_debug(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @print_debug_hex8(i32 %2)
br label %6
6: ; preds = %1, %22
%7 = phi i32 [ 0, %1 ], [ %25, %22 ]
%8 = and i32 %7, 15
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = tail call i32 @print_debug(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @print_debug_hex8(i32 %7)
%13 = tail call i32 @print_debug(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %10, %6
%15 = tail call i32 @smbus_read_byte(i32 %2, i32 %7)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = tail call i32 @print_debug(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%19 = sub nsw i32 0, %15
%20 = tail call i32 @print_debug_hex8(i32 %19)
%21 = tail call i32 @print_debug(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %27
22: ; preds = %14
%23 = tail call i32 @print_debug_hex8(i32 %15)
%24 = tail call i32 @print_debug_char(i8 signext 32)
%25 = add nuw nsw i32 %7, 1
%26 = icmp eq i32 %25, 256
br i1 %26, label %27, label %6
27: ; preds = %22, %17
%28 = add nuw nsw i32 %2, 1
%29 = tail call i32 @print_debug(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%30 = icmp eq i32 %28, 88
br i1 %30, label %31, label %1
31: ; preds = %27
ret void
}