#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 EINVAL;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, ...);
int i2c_read_byte(int, int, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int ds1307_dump(int file, uint8_t start, uint8_t count) {
  int i, res;
  uint8_t reg;
  if ((start + count - 1) > 0x3f) {
    fprintf(stderr, "BUG: end address 0x%02x is out of range!",
            start + count - 1);
    return -EINVAL;
  }
  for (i = 0; i < count; i++) {
    if ((res = i2c_read_byte(file, start + i, &reg)) < 0) {
      return res;
    }
    fprintf(stdout, "Register @ 0x%02x: 0x%02x\n", start + i, reg);
  }
  return 0;
}


x86 assembly (clang, -O0):
<ds1307_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
sub    $0x1,%eax
cmp    $0x3f,%eax
jle    1176 <ds1307_dump+0x56>
mov    0x2e96(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
add    -0x10(%rbp),%edx
sub    $0x1,%edx
lea    0xea4(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
xor    %eax,%eax
mov    0x2e6c(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11e7 <ds1307_dump+0xc7>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11e0 <ds1307_dump+0xc0>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
add    -0x14(%rbp),%esi
lea    -0x1c(%rbp),%rdx
call   1040 <i2c_read_byte@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    11b2 <ds1307_dump+0x92>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e7 <ds1307_dump+0xc7>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
add    -0x14(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xe5e(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117d <ds1307_dump+0x5d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ds1307_dump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%ebx
lea    (%r14,%rbx,1),%edx
cmp    $0x40,%edx
jle    1160 <ds1307_dump+0x40>
add    $0xffffffff,%edx
mov    0x2e9d(%rip),%rax
mov    (%rax),%edi
lea    0xeb4(%rip),%rsi
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x2e7c(%rip),%rax
sub    (%rax),%ebp
jmp    11bd <ds1307_dump+0x9d>
test   %r14d,%r14d
jle    11b7 <ds1307_dump+0x97>
mov    %edi,%r15d
lea    0x4(%rsp),%r12
lea    0xeb5(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15d,%edi
mov    %ebx,%esi
mov    %r12,%rdx
call   1040 <i2c_read_byte@plt>
test   %eax,%eax
js     11bb <ds1307_dump+0x9b>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
mov    0x4(%rsp),%ecx
xor    %ebp,%ebp
mov    %r13,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x1,%ebx
add    $0xffffffff,%r14d
jne    1180 <ds1307_dump+0x60>
jmp    11bd <ds1307_dump+0x9d>
xor    %ebp,%ebp
jmp    11bd <ds1307_dump+0x9d>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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