#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(unsigned char);
int smbus_read_byte(unsigned int, int);
void dump_spd_registers(void) {
  unsigned device;
  device = (0xa << 3);
  print_debug("\r\n");
  while (device <= ((0xa << 3) + 1)) {
    int i;
    print_debug("dimm: ");
    print_debug_hex8(device);
    for (i = 0; i < 256; i++) {
      int status;
      unsigned char byte;
      if ((i & 0xf) == 0) {
        print_debug("\r\n");
        print_debug_hex8(i);
        print_debug(": ");
      }
      status = smbus_read_byte(device, i);
      if (status < 0) {
        print_debug("bad device\r\n");
        break;
      }
      byte = status & 0xff;
      print_debug_hex8(byte);
      print_debug_char(' ');
    }
    device += 1;
    print_debug("\r\n");
  }
}


x86 assembly (clang, -O0):
<dump_spd_registers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x50,-0x4(%rbp)
lea    0xebb(%rip),%rdi
call   1050 <print_debug@plt>
cmpl   $0x51,-0x4(%rbp)
ja     1231 <dump_spd_registers+0xf1>
lea    0xe94(%rip),%rdi
call   1050 <print_debug@plt>
mov    -0x4(%rbp),%eax
movzbl %al,%edi
call   1030 <print_debug_hex8@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x100,-0x8(%rbp)
jge    1217 <dump_spd_registers+0xd7>
mov    -0x8(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
jne    11c2 <dump_spd_registers+0x82>
lea    0xe6b(%rip),%rdi
call   1050 <print_debug@plt>
mov    -0x8(%rbp),%eax
movzbl %al,%edi
call   1030 <print_debug_hex8@plt>
lea    0xe47(%rip),%rdi
call   1050 <print_debug@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <smbus_read_byte@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11eb <dump_spd_registers+0xab>
lea    0xe26(%rip),%rdi
call   1050 <print_debug@plt>
jmp    1217 <dump_spd_registers+0xd7>
mov    -0xc(%rbp),%eax
and    $0xff,%eax
mov    %al,-0xd(%rbp)
movzbl -0xd(%rbp),%edi
call   1030 <print_debug_hex8@plt>
mov    $0x20,%edi
call   1060 <print_debug_char@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1183 <dump_spd_registers+0x43>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
lea    0xdea(%rip),%rdi
call   1050 <print_debug@plt>
jmp    115b <dump_spd_registers+0x1b>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_spd_registers>:
push   %rbp
push   %r14
push   %rbx
lea    0xec6(%rip),%r14
mov    %r14,%rdi
call   1050 <print_debug@plt>
lea    0xea6(%rip),%rdi
call   1050 <print_debug@plt>
mov    $0x50,%edi
call   1030 <print_debug_hex8@plt>
xor    %ebp,%ebp
lea    0xe92(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
test   $0xf,%bpl
jne    119f <dump_spd_registers+0x5f>
mov    %r14,%rdi
call   1050 <print_debug@plt>
movzbl %bpl,%edi
call   1030 <print_debug_hex8@plt>
mov    %rbx,%rdi
call   1050 <print_debug@plt>
mov    $0x50,%edi
mov    %ebp,%esi
call   1040 <smbus_read_byte@plt>
test   %eax,%eax
js     11ce <dump_spd_registers+0x8e>
movzbl %al,%edi
call   1030 <print_debug_hex8@plt>
mov    $0x20,%edi
call   1060 <print_debug_char@plt>
add    $0x1,%ebp
cmp    $0x100,%ebp
jne    1180 <dump_spd_registers+0x40>
jmp    11da <dump_spd_registers+0x9a>
lea    0xe32(%rip),%rdi
call   1050 <print_debug@plt>
lea    0xe30(%rip),%r14
mov    %r14,%rdi
call   1050 <print_debug@plt>
lea    0xe10(%rip),%rdi
call   1050 <print_debug@plt>
mov    $0x51,%edi
call   1030 <print_debug_hex8@plt>
xor    %ebp,%ebp
lea    0xdfc(%rip),%rbx
nopl   0x0(%rax,%rax,1)
test   $0xf,%bpl
jne    122f <dump_spd_registers+0xef>
mov    %r14,%rdi
call   1050 <print_debug@plt>
movzbl %bpl,%edi
call   1030 <print_debug_hex8@plt>
mov    %rbx,%rdi
call   1050 <print_debug@plt>
mov    $0x51,%edi
mov    %ebp,%esi
call   1040 <smbus_read_byte@plt>
test   %eax,%eax
js     125e <dump_spd_registers+0x11e>
movzbl %al,%edi
call   1030 <print_debug_hex8@plt>
mov    $0x20,%edi
call   1060 <print_debug_char@plt>
add    $0x1,%ebp
cmp    $0x100,%ebp
jne    1210 <dump_spd_registers+0xd0>
jmp    126a <dump_spd_registers+0x12a>
lea    0xda2(%rip),%rdi
call   1050 <print_debug@plt>
lea    0xda0(%rip),%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <print_debug@plt>

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

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