#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 ds1307_test_ram_byte(int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stdout;
int ds1307_test_ram(int file) {
  int res;
  int bit;
  for (bit = 0; bit < 8; bit++) {
    if ((res = ds1307_test_ram_byte(file, 1 << bit)) < 0) {
      return res;
    }
    fprintf(stdout, "Done checking 0x%02x\n", 1 << bit);
  }
  if ((res = ds1307_test_ram_byte(file, 0x55)) < 0) {
    return res;
  }
  fprintf(stdout, "Done checking 0x%02x\n", 0x55);
  if ((res = ds1307_test_ram_byte(file, 0xaa)) < 0) {
    return res;
  }
  fprintf(stdout, "Done checking 0x%02x\n", 0xaa);
  if ((res = ds1307_test_ram_byte(file, 0xff)) < 0) {
    return res;
  }
  fprintf(stdout, "Done checking 0x%02x\n", 0xff);
  if ((res = ds1307_test_ram_byte(file, 0x00)) < 0) {
    return res;
  }
  fprintf(stdout, "Done checking 0x%02x\n", 0x00);
  return 0;
}


x86 assembly (clang, -O0):
<ds1307_test_ram>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x8,-0x10(%rbp)
jge    1192 <ds1307_test_ram+0x72>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%ecx
mov    $0x1,%esi
shl    %cl,%esi
call   1030 <ds1307_test_ram_byte@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    1165 <ds1307_test_ram+0x45>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    128b <ds1307_test_ram+0x16b>
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
lea    0xe81(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1132 <ds1307_test_ram+0x12>
mov    -0x8(%rbp),%edi
mov    $0x55,%esi
call   1030 <ds1307_test_ram_byte@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    11b6 <ds1307_test_ram+0x96>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    128b <ds1307_test_ram+0x16b>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    0xe3a(%rip),%rsi
mov    $0x55,%edx
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%edi
mov    $0xaa,%esi
call   1030 <ds1307_test_ram_byte@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    11f4 <ds1307_test_ram+0xd4>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    128b <ds1307_test_ram+0x16b>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
lea    0xdfc(%rip),%rsi
mov    $0xaa,%edx
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%edi
mov    $0xff,%esi
call   1030 <ds1307_test_ram_byte@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    1232 <ds1307_test_ram+0x112>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    128b <ds1307_test_ram+0x16b>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
lea    0xdbe(%rip),%rsi
mov    $0xff,%edx
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%edi
xor    %esi,%esi
call   1030 <ds1307_test_ram_byte@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    126d <ds1307_test_ram+0x14d>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    128b <ds1307_test_ram+0x16b>
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
lea    0xd83(%rip),%rsi
xor    %edx,%edx
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ds1307_test_ram>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
mov    $0x1,%esi
call   1030 <ds1307_test_ram_byte@plt>
test   %eax,%eax
js     12f9 <ds1307_test_ram+0x1d9>
mov    0x2ea1(%rip),%r14
mov    (%r14),%edi
lea    0xeb7(%rip),%rsi
mov    $0x1,%edx
call   1040 <fprintf@plt>
mov    %ebx,%edi
mov    $0x2,%esi
call   1030 <ds1307_test_ram_byte@plt>
test   %eax,%eax
js     12f9 <ds1307_test_ram+0x1d9>
mov    (%r14),%edi
lea    0xe8f(%rip),%rsi
mov    $0x2,%edx
call   1040 <fprintf@plt>
mov    %ebx,%edi
mov    $0x4,%esi
call   1030 <ds1307_test_ram_byte@plt>
test   %eax,%eax
js     12f9 <ds1307_test_ram+0x1d9>
mov    (%r14),%edi
lea    0xe67(%rip),%rsi
mov    $0x4,%edx
call   1040 <fprintf@plt>
mov    %ebx,%edi
mov    $0x8,%esi
call   1030 <ds1307_test_ram_byte@plt>
test   %eax,%eax
js     12f9 <ds1307_test_ram+0x1d9>
mov    (%r14),%edi
lea    0xe3f(%rip),%rsi
mov    $0x8,%edx
call   1040 <fprintf@plt>
mov    %ebx,%edi
mov    $0x10,%esi
call   1030 <ds1307_test_ram_byte@plt>
test   %eax,%eax
js     12f9 <ds1307_test_ram+0x1d9>
mov    (%r14),%edi
lea    0xe17(%rip),%rsi
mov    $0x10,%edx
call   1040 <fprintf@plt>
mov    %ebx,%edi
mov    $0x20,%esi
call   1030 <ds1307_test_ram_byte@plt>
test   %eax,%eax
js     12f9 <ds1307_test_ram+0x1d9>
mov    (%r14),%edi
lea    0xdef(%rip),%rsi
mov    $0x20,%edx
call   1040 <fprintf@plt>
mov    %ebx,%edi
mov    $0x40,%esi
call   1030 <ds1307_test_ram_byte@plt>
test   %eax,%eax
js     12f9 <ds1307_test_ram+0x1d9>
mov    (%r14),%edi
lea    0xdc7(%rip),%rsi
mov    $0x40,%edx
call   1040 <fprintf@plt>
mov    %ebx,%edi
mov    $0x80,%esi
call   1030 <ds1307_test_ram_byte@plt>
test   %eax,%eax
js     12f9 <ds1307_test_ram+0x1d9>
mov    (%r14),%edi
lea    0xd9f(%rip),%rsi
mov    $0x80,%edx
call   1040 <fprintf@plt>
mov    %ebx,%edi
mov    $0x55,%esi
call   1030 <ds1307_test_ram_byte@plt>
test   %eax,%eax
js     12f9 <ds1307_test_ram+0x1d9>
mov    (%r14),%edi
lea    0xd7b(%rip),%rsi
mov    $0x55,%edx
call   1040 <fprintf@plt>
mov    %ebx,%edi
mov    $0xaa,%esi
call   1030 <ds1307_test_ram_byte@plt>
test   %eax,%eax
js     12f9 <ds1307_test_ram+0x1d9>
mov    (%r14),%edi
lea    0xd57(%rip),%rsi
mov    $0xaa,%edx
call   1040 <fprintf@plt>
mov    %ebx,%edi
mov    $0xff,%esi
call   1030 <ds1307_test_ram_byte@plt>
test   %eax,%eax
js     12f9 <ds1307_test_ram+0x1d9>
mov    (%r14),%edi
lea    0xd33(%rip),%rsi
mov    $0xff,%edx
call   1040 <fprintf@plt>
xor    %ebp,%ebp
mov    %ebx,%edi
xor    %esi,%esi
call   1030 <ds1307_test_ram_byte@plt>
test   %eax,%eax
js     12f9 <ds1307_test_ram+0x1d9>
mov    (%r14),%edi
lea    0xd10(%rip),%rsi
xor    %edx,%edx
call   1040 <fprintf@plt>
jmp    12fb <ds1307_test_ram+0x1db>
mov    %eax,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@stdout = global i32 0
@.str = [22 x i8] c"Done checking 0x%02x\0A\00"
define i32 @ds1307_test_ram(i32 %0) {
%2 = tail call i32 @ds1307_test_ram_byte(i32 %0, i32 1)
%3 = icmp slt i32 %2, 0
br i1 %3, label %62, label %4
4: ; preds = %1
%5 = load i32, i32* @stdout
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 1)
%7 = tail call i32 @ds1307_test_ram_byte(i32 %0, i32 2)
%8 = icmp slt i32 %7, 0
br i1 %8, label %62, label %9
9: ; preds = %4
%10 = load i32, i32* @stdout
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 2)
%12 = tail call i32 @ds1307_test_ram_byte(i32 %0, i32 4)
%13 = icmp slt i32 %12, 0
br i1 %13, label %62, label %14
14: ; preds = %9
%15 = load i32, i32* @stdout
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 4)
%17 = tail call i32 @ds1307_test_ram_byte(i32 %0, i32 8)
%18 = icmp slt i32 %17, 0
br i1 %18, label %62, label %19
19: ; preds = %14
%20 = load i32, i32* @stdout
%21 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 8)
%22 = tail call i32 @ds1307_test_ram_byte(i32 %0, i32 16)
%23 = icmp slt i32 %22, 0
br i1 %23, label %62, label %24
24: ; preds = %19
%25 = load i32, i32* @stdout
%26 = tail call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 16)
%27 = tail call i32 @ds1307_test_ram_byte(i32 %0, i32 32)
%28 = icmp slt i32 %27, 0
br i1 %28, label %62, label %29
29: ; preds = %24
%30 = load i32, i32* @stdout
%31 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 32)
%32 = tail call i32 @ds1307_test_ram_byte(i32 %0, i32 64)
%33 = icmp slt i32 %32, 0
br i1 %33, label %62, label %34
34: ; preds = %29
%35 = load i32, i32* @stdout
%36 = tail call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 64)
%37 = tail call i32 @ds1307_test_ram_byte(i32 %0, i32 128)
%38 = icmp slt i32 %37, 0
br i1 %38, label %62, label %39
39: ; preds = %34
%40 = load i32, i32* @stdout
%41 = tail call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 128)
%42 = tail call i32 @ds1307_test_ram_byte(i32 %0, i32 85)
%43 = icmp slt i32 %42, 0
br i1 %43, label %62, label %44
44: ; preds = %39
%45 = load i32, i32* @stdout
%46 = tail call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 85)
%47 = tail call i32 @ds1307_test_ram_byte(i32 %0, i32 170)
%48 = icmp slt i32 %47, 0
br i1 %48, label %62, label %49
49: ; preds = %44
%50 = load i32, i32* @stdout
%51 = tail call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 170)
%52 = tail call i32 @ds1307_test_ram_byte(i32 %0, i32 255)
%53 = icmp slt i32 %52, 0
br i1 %53, label %62, label %54
54: ; preds = %49
%55 = load i32, i32* @stdout
%56 = tail call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 255)
%57 = tail call i32 @ds1307_test_ram_byte(i32 %0, i32 0)
%58 = icmp slt i32 %57, 0
br i1 %58, label %62, label %59
59: ; preds = %54
%60 = load i32, i32* @stdout
%61 = tail call i32 @fprintf(i32 %60, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 0)
br label %62
62: ; preds = %1, %4, %9, %14, %19, %24, %29, %34, %54, %49, %44, %39, %59
%63 = phi i32 [ 0, %59 ], [ %42, %39 ], [ %47, %44 ], [ %52, %49 ], [ %57, %54 ], [ %2, %1 ], [ %7, %4 ], [ %12, %9 ], [ %17, %14 ], [ %22, %19 ], [ %27, %24 ], [ %32, %29 ], [ %37, %34 ]
ret i32 %63
}