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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ hexdump(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int,
                           int);
int /*<<< orphan*/ indent(int, int /*<<< orphan*/ *);
int read_record(int /*<<< orphan*/ *, int);
void dump_records(FILE *log, int level, int size, int entries) {
  int rec, res;
  for (rec = 1; rec <= 256; rec++) {
    uint8_t rbuf[256];
    res = read_record(rbuf, size);
    if (res > 0) {
      indent(level + 1, log);
      fprintf(log, "%3d: ", rec);
      hexdump(log, rbuf, res, 1);
      fprintf(log, "\n");
    }
    if (entries && (rec >= entries))
      break;
  }
}


x86 assembly (clang, -O0):
<dump_records>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
cmpl   $0x100,-0x18(%rbp)
jg     1204 <dump_records+0xc4>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1030 <read_record@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    11d6 <dump_records+0x96>
mov    -0xc(%rbp),%edi
add    $0x1,%edi
mov    -0x8(%rbp),%rsi
call   1040 <indent@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xe5b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x420(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    $0x1,%ecx
call   1060 <hexdump@plt>
mov    -0x8(%rbp),%rdi
lea    0xe37(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
cmpl   $0x0,-0x14(%rbp)
je     11f1 <dump_records+0xb1>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     11f1 <dump_records+0xb1>
jmp    1204 <dump_records+0xc4>
jmp    11f6 <dump_records+0xb6>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    115f <dump_records+0x1f>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_records>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %ecx,%r13d
mov    %edx,%r15d
mov    %rdi,%rbp
add    $0x1,%esi
mov    %esi,0xc(%rsp)
mov    $0x1,%ebx
lea    0x10(%rsp),%r12
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r15d,%esi
call   1030 <read_record@plt>
test   %eax,%eax
jle    11d1 <dump_records+0x81>
mov    %eax,%r14d
mov    0xc(%rsp),%edi
mov    %rbp,%rsi
call   1050 <indent@plt>
mov    %rbp,%rdi
lea    0xe58(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r14d,%edx
mov    $0x1,%ecx
call   1070 <hexdump@plt>
mov    $0xa,%edi
mov    %rbp,%rsi
call   1040 <fputc@plt>
test   %r13d,%r13d
setne  %al
cmp    %r13d,%ebx
setge  %cl
test   %cl,%al
jne    11ee <dump_records+0x9e>
lea    0x1(%rbx),%eax
cmp    $0x100,%ebx
mov    %eax,%ebx
jne    1180 <dump_records+0x30>
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%3d: \00"
@.str.1 = [2 x i8] c"\0A\00"
define void @dump_records(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [256 x i32]
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 1, i32* %9
br label %12
12: ; preds = %44, %4
%13 = load i32, i32* %9
%14 = icmp sle i32 %13, 256
br i1 %14, label %15, label %47
15: ; preds = %12
%16 = getelementptr inbounds [256 x i32], [256 x i32]* %11, i64 0, i64 0
%17 = load i32, i32* %7
%18 = call i32 @read_record(i32* %16, i32 %17)
store i32 %18, i32* %10
%19 = load i32, i32* %10
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %35
21: ; preds = %15
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
%24 = load i32*, i32** %5
%25 = call i32 @indent(i32 %23, i32* %24)
%26 = load i32*, i32** %5
%27 = load i32, i32* %9
%28 = call i32 (i32*, i8*, ...) @fprintf(i32* %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = load i32*, i32** %5
%30 = getelementptr inbounds [256 x i32], [256 x i32]* %11, i64 0, i64 0
%31 = load i32, i32* %10
%32 = call i32 @hexdump(i32* %29, i32* %30, i32 %31, i32 1)
%33 = load i32*, i32** %5
%34 = call i32 (i32*, i8*, ...) @fprintf(i32* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %35
35: ; preds = %21, %15
%36 = load i32, i32* %8
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %35
%39 = load i32, i32* %9
%40 = load i32, i32* %8
%41 = icmp sge i32 %39, %40
br i1 %41, label %42, label %43
42: ; preds = %38
br label %47
43: ; preds = %38, %35
br label %44
44: ; preds = %43
%45 = load i32, i32* %9
%46 = add nsw i32 %45, 1
store i32 %46, i32* %9
br label %12
47: ; preds = %42, %12
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"%3d: \00"
define void @dump_records(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca [256 x i32]
%6 = bitcast [256 x i32]* %5 to i8*
%7 = getelementptr inbounds [256 x i32], [256 x i32]* %5, i64 0, i64 0
%8 = add nsw i32 %1, 1
%9 = icmp ne i32 %3, 0
br label %10
10: ; preds = %19, %4
%11 = phi i32 [ 1, %4 ], [ %22, %19 ]
%12 = call i32 @read_record(i32* %7, i32 %2)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = call i32 @indent(i32 %8, i32* %0)
%16 = call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %11)
%17 = call i32 @hexdump(i32* %0, i32* %7, i32 %12, i32 1)
%18 = call i32 @fputc(i32 10, i32* %0)
br label %19
19: ; preds = %14, %10
%20 = icmp sge i32 %11, %3
%21 = select i1 %9, i1 %20, i1 false
%22 = add nuw nsw i32 %11, 1
%23 = icmp eq i32 %22, 257
%24 = select i1 %21, i1 true, i1 %23
br i1 %24, label %25, label %10
25: ; preds = %19
ret void
}