#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 */
typedef int uint8_t;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int, int);
int i2c_read_byte(int, int, int *);
int i2c_write_byte(int, int, int);
int /*<<< orphan*/ stdout;
int ds1307_test_ram_byte(int file, uint8_t byte) {
  int ad;
  int res;
  for (ad = (0x08); ad < (0x40); ad++) {
    if ((res = i2c_write_byte(file, ad, byte)) < 0) {
      return res;
    }
  }
  uint8_t reg;
  for (ad = (0x08); ad < (0x40); ad++) {
    if ((res = i2c_read_byte(file, ad, &reg)) < 0) {
      return res;
    }
    if (reg != byte) {
      fprintf(stdout, "Register @ 0x%02x is bad: expect 0x%02x, got 0x%02x\n",
              ad, byte, reg);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<ds1307_test_ram_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x8,-0x10(%rbp)
cmpl   $0x40,-0x10(%rbp)
jge    1187 <ds1307_test_ram_byte+0x57>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1050 <i2c_write_byte@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1174 <ds1307_test_ram_byte+0x44>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1203 <ds1307_test_ram_byte+0xd3>
jmp    1179 <ds1307_test_ram_byte+0x49>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1145 <ds1307_test_ram_byte+0x15>
movl   $0x8,-0x10(%rbp)
cmpl   $0x40,-0x10(%rbp)
jge    11fc <ds1307_test_ram_byte+0xcc>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%esi
lea    -0x18(%rbp),%rdx
call   1040 <i2c_read_byte@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11be <ds1307_test_ram_byte+0x8e>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1203 <ds1307_test_ram_byte+0xd3>
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     11e9 <ds1307_test_ram_byte+0xb9>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x18(%rbp),%r8d
lea    0xe1c(%rip),%rsi
call   1030 <fprintf@plt>
jmp    11ee <ds1307_test_ram_byte+0xbe>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    118e <ds1307_test_ram_byte+0x5e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ds1307_test_ram_byte>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%r14d
mov    $0x8,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14d,%edi
mov    %ebp,%esi
mov    %ebx,%edx
call   1050 <i2c_write_byte@plt>
test   %eax,%eax
js     11c7 <ds1307_test_ram_byte+0x97>
add    $0x1,%ebp
cmp    $0x40,%ebp
jne    1150 <ds1307_test_ram_byte+0x20>
mov    $0x8,%ebp
lea    0x4(%rsp),%r15
mov    0x2e67(%rip),%r13
lea    0xe80(%rip),%r12
jmp    1198 <ds1307_test_ram_byte+0x68>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%ebp
cmp    $0x40,%ebp
je     11c5 <ds1307_test_ram_byte+0x95>
mov    %r14d,%edi
mov    %ebp,%esi
mov    %r15,%rdx
call   1040 <i2c_read_byte@plt>
test   %eax,%eax
js     11c7 <ds1307_test_ram_byte+0x97>
mov    0x4(%rsp),%r8d
cmp    %ebx,%r8d
je     1190 <ds1307_test_ram_byte+0x60>
mov    0x0(%r13),%edi
mov    %r12,%rsi
mov    %ebp,%edx
mov    %ebx,%ecx
call   1030 <fprintf@plt>
jmp    1190 <ds1307_test_ram_byte+0x60>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [53 x i8] c"Register @ 0x%02x is bad: expect 0x%02x, got 0x%02x\0A\00"
define i32 @ds1307_test_ram_byte(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 8, i32* %6
br label %9
9: ; preds = %21, %2
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 64
br i1 %11, label %12, label %24
12: ; preds = %9
%13 = load i32, i32* %4
%14 = load i32, i32* %6
%15 = load i32, i32* %5
%16 = call i32 @i2c_write_byte(i32 %13, i32 %14, i32 %15)
store i32 %16, i32* %7
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = load i32, i32* %7
store i32 %19, i32* %3
br label %50
20: ; preds = %12
br label %21
21: ; preds = %20
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
store i32 %23, i32* %6
br label %9
24: ; preds = %9
store i32 8, i32* %6
br label %25
25: ; preds = %46, %24
%26 = load i32, i32* %6
%27 = icmp slt i32 %26, 64
br i1 %27, label %28, label %49
28: ; preds = %25
%29 = load i32, i32* %4
%30 = load i32, i32* %6
%31 = call i32 @i2c_read_byte(i32 %29, i32 %30, i32* %8)
store i32 %31, i32* %7
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %28
%34 = load i32, i32* %7
store i32 %34, i32* %3
br label %50
35: ; preds = %28
%36 = load i32, i32* %8
%37 = load i32, i32* %5
%38 = icmp ne i32 %36, %37
br i1 %38, label %39, label %45
39: ; preds = %35
%40 = load i32, i32* @stdout
%41 = load i32, i32* %6
%42 = load i32, i32* %5
%43 = load i32, i32* %8
%44 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i32 %41, i32 %42, i32 %43)
br label %45
45: ; preds = %39, %35
br label %46
46: ; preds = %45
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 1
store i32 %48, i32* %6
br label %25
49: ; preds = %25
store i32 0, i32* %3
br label %50
50: ; preds = %49, %33, %18
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [53 x i8] c"Register @ 0x%02x is bad: expect 0x%02x, got 0x%02x\0A\00"
define i32 @ds1307_test_ram_byte(i32 %0, i32 %1) {
%3 = alloca i32
br label %7
4: ; preds = %7
%5 = add nuw nsw i32 %8, 1
%6 = icmp eq i32 %5, 64
br i1 %6, label %11, label %7
7: ; preds = %2, %4
%8 = phi i32 [ 8, %2 ], [ %5, %4 ]
%9 = tail call i32 @i2c_write_byte(i32 %0, i32 %8, i32 %1)
%10 = icmp slt i32 %9, 0
br i1 %10, label %28, label %4
11: ; preds = %4
%12 = bitcast i32* %3 to i8*
br label %13
13: ; preds = %11, %23
%14 = phi i32 [ 8, %11 ], [ %24, %23 ]
%15 = call i32 @i2c_read_byte(i32 %0, i32 %14, i32* %3)
%16 = icmp slt i32 %15, 0
br i1 %16, label %26, label %17
17: ; preds = %13
%18 = load i32, i32* %3
%19 = icmp eq i32 %18, %1
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = load i32, i32* @stdout
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %1, i32 %18)
br label %23
23: ; preds = %17, %20
%24 = add nuw nsw i32 %14, 1
%25 = icmp eq i32 %24, 64
br i1 %25, label %26, label %13
26: ; preds = %23, %13
%27 = phi i32 [ %15, %13 ], [ 0, %23 ]
br label %28
28: ; preds = %7, %26
%29 = phi i32 [ %27, %26 ], [ %9, %7 ]
ret i32 %29
}