#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*/ printf(char *, ...);
void dump_buffers(uint8_t *write_buf, uint8_t *read_buf, int len) {
  static const int space_per_byte = 5;
  static const int screen_size = 80;
  const int bytes_per_row = screen_size / space_per_byte;
  int cur, wr_cnt = 0, rd_cnt = 0;
  printf("Dump of read and write buffers:\n");
  while (wr_cnt < len) {
    for (cur = 0; (cur < bytes_per_row) && (wr_cnt < len); ++cur, ++wr_cnt) {
      if (!cur)
        printf("Wr: ");
      printf("0x%2x ", write_buf[cur]);
    }
    printf("\n");
    for (cur = 0; (cur < bytes_per_row) && (rd_cnt < len); ++cur, ++rd_cnt) {
      if (!cur)
        printf("Rd: ");
      printf("0x%2x ", read_buf[cur]);
    }
    printf("\n\n");
  }
}


x86 assembly (clang, -O0):
<dump_buffers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x10,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
lea    0xec9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1267 <dump_buffers+0x157>
movl   $0x0,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x10,-0x1c(%rbp)
mov    %al,-0x25(%rbp)
jge    1174 <dump_buffers+0x64>
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
setl   %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    1184 <dump_buffers+0x74>
jmp    11cc <dump_buffers+0xbc>
cmpl   $0x0,-0x1c(%rbp)
jne    119c <dump_buffers+0x8c>
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1159 <dump_buffers+0x49>
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x10,-0x1c(%rbp)
mov    %al,-0x26(%rbp)
jge    11fc <dump_buffers+0xec>
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
setl   %al
mov    %al,-0x26(%rbp)
mov    -0x26(%rbp),%al
test   $0x1,%al
jne    120c <dump_buffers+0xfc>
jmp    1254 <dump_buffers+0x144>
cmpl   $0x0,-0x1c(%rbp)
jne    1224 <dump_buffers+0x114>
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11e1 <dump_buffers+0xd1>
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1146 <dump_buffers+0x36>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_buffers>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,0x10(%rsp)
lea    0xec1(%rip),%rdi
call   1040 <puts@plt>
test   %r15d,%r15d
jle    12b8 <dump_buffers+0x188>
lea    0xea0(%rip),%r13
lea    0xec5(%rip),%rbp
xor    %ebx,%ebx
xor    %eax,%eax
jmp    1195 <dump_buffers+0x65>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
call   1040 <puts@plt>
mov    0x8(%rsp),%eax
cmp    %r15d,%eax
jge    12b8 <dump_buffers+0x188>
mov    %eax,%r12d
cmp    %r15d,%eax
jge    1230 <dump_buffers+0x100>
lea    0xe58(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rsp),%rax
mov    (%rax),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x1(%r12),%eax
cmp    %r15d,%eax
jge    1233 <dump_buffers+0x103>
mov    %rbx,0x8(%rsp)
mov    %r14,%rbx
mov    %r12d,%ebp
mov    $0x1,%r14d
nopl   0x0(%rax,%rax,1)
mov    0x10(%rsp),%rax
mov    (%rax,%r14,4),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x1(%r14),%rax
cmp    $0xe,%r14
ja     120c <dump_buffers+0xdc>
lea    (%r14,%rbp,1),%ecx
add    $0x1,%ecx
mov    %rax,%r14
cmp    %r15d,%ecx
jl     11e0 <dump_buffers+0xb0>
add    %eax,%r12d
mov    %r12d,%eax
mov    %rbx,%r14
lea    0xe15(%rip),%rbp
mov    0x8(%rsp),%rbx
jmp    1233 <dump_buffers+0x103>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12d,%eax
mov    %eax,0x8(%rsp)
mov    $0xa,%edi
call   1030 <putchar@plt>
cmp    %r15d,%ebx
jge    1180 <dump_buffers+0x50>
lea    0xdbb(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r14),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rax
add    $0x1,%ebx
cmp    %r15d,%ebx
jge    1180 <dump_buffers+0x50>
mov    %rax,%r12
mov    %eax,%ebp
mov    $0x1,%ebx
xchg   %ax,%ax
mov    (%r14,%rbx,4),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x1(%rbx),%rax
cmp    $0xe,%rbx
ja     12a6 <dump_buffers+0x176>
lea    (%rbx,%rbp,1),%ecx
add    $0x1,%ecx
mov    %rax,%rbx
cmp    %r15d,%ecx
jl     1280 <dump_buffers+0x150>
add    %eax,%r12d
mov    %r12d,%ebx
lea    0xd7e(%rip),%rbp
jmp    1180 <dump_buffers+0x50>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@dump_buffers.space_per_byte = internal constant i32 5
@dump_buffers.screen_size = internal constant i32 80
@.str = [33 x i8] c"Dump of read and write buffers:\0A\00"
@.str.1 = [5 x i8] c"Wr: \00"
@.str.2 = [7 x i8] c"0x%2x \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [5 x i8] c"Rd: \00"
@.str.5 = [3 x i8] c"\0A\0A\00"
define void @dump_buffers(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** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
store i32 16, i32* %7
store i32 0, i32* %9
store i32 0, i32* %10
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %71, %3
%13 = load i32, i32* %9
%14 = load i32, i32* %6
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %73
16: ; preds = %12
store i32 0, i32* %8
br label %17
17: ; preds = %38, %16
%18 = load i32, i32* %8
%19 = icmp slt i32 %18, 16
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i32, i32* %9
%22 = load i32, i32* %6
%23 = icmp slt i32 %21, %22
br label %24
24: ; preds = %20, %17
%25 = phi i1 [ false, %17 ], [ %23, %20 ]
br i1 %25, label %26, label %43
26: ; preds = %24
%27 = load i32, i32* %8
%28 = icmp ne i32 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %26
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %29, %26
%32 = load i32*, i32** %4
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %32, i64 %34
%36 = load i32, i32* %35
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %36)
br label %38
38: ; preds = %31
%39 = load i32, i32* %8
%40 = add nsw i32 %39, 1
store i32 %40, i32* %8
%41 = load i32, i32* %9
%42 = add nsw i32 %41, 1
store i32 %42, i32* %9
br label %17
43: ; preds = %24
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %8
br label %45
45: ; preds = %66, %43
%46 = load i32, i32* %8
%47 = icmp slt i32 %46, 16
br i1 %47, label %48, label %52
48: ; preds = %45
%49 = load i32, i32* %10
%50 = load i32, i32* %6
%51 = icmp slt i32 %49, %50
br label %52
52: ; preds = %48, %45
%53 = phi i1 [ false, %45 ], [ %51, %48 ]
br i1 %53, label %54, label %71
54: ; preds = %52
%55 = load i32, i32* %8
%56 = icmp ne i32 %55, 0
br i1 %56, label %59, label %57
57: ; preds = %54
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %59
59: ; preds = %57, %54
%60 = load i32*, i32** %5
%61 = load i32, i32* %8
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i32, i32* %60, i64 %62
%64 = load i32, i32* %63
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %64)
br label %66
66: ; preds = %59
%67 = load i32, i32* %8
%68 = add nsw i32 %67, 1
store i32 %68, i32* %8
%69 = load i32, i32* %10
%70 = add nsw i32 %69, 1
store i32 %70, i32* %10
br label %45
71: ; preds = %52
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %12
73: ; preds = %12
ret void
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"Wr: \00"
@.str.2 = [7 x i8] c"0x%2x \00"
@.str.4 = [5 x i8] c"Rd: \00"
@str = [32 x i8] c"Dump of read and write buffers:\00"
@str.6 = [2 x i8] c"\0A\00"
define void @dump_buffers(i32* nocapture %0, i32* nocapture %1, i32 %2) {
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %52
6: ; preds = %3, %48
%7 = phi i32 [ %49, %48 ], [ 0, %3 ]
%8 = phi i32 [ %28, %48 ], [ 0, %3 ]
%9 = icmp slt i32 %8, %2
br i1 %9, label %10, label %27
10: ; preds = %6
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* %0
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = add nsw i32 %8, 1
%15 = icmp slt i32 %14, %2
br i1 %15, label %16, label %27
16: ; preds = %10, %16
%17 = phi i64 [ %22, %16 ], [ 1, %10 ]
%18 = phi i32 [ %23, %16 ], [ %14, %10 ]
%19 = getelementptr inbounds i32, i32* %0, i64 %17
%20 = load i32, i32* %19
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = add nuw nsw i64 %17, 1
%23 = add nsw i32 %18, 1
%24 = icmp ult i64 %17, 15
%25 = icmp slt i32 %23, %2
%26 = select i1 %24, i1 %25, i1 false
br i1 %26, label %16, label %27
27: ; preds = %16, %10, %6
%28 = phi i32 [ %8, %6 ], [ %14, %10 ], [ %23, %16 ]
%29 = tail call i32 @putchar(i32 10)
%30 = icmp slt i32 %7, %2
br i1 %30, label %31, label %48
31: ; preds = %27
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%33 = load i32, i32* %1
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %33)
%35 = add nsw i32 %7, 1
%36 = icmp slt i32 %35, %2
br i1 %36, label %37, label %48
37: ; preds = %31, %37
%38 = phi i64 [ %43, %37 ], [ 1, %31 ]
%39 = phi i32 [ %44, %37 ], [ %35, %31 ]
%40 = getelementptr inbounds i32, i32* %1, i64 %38
%41 = load i32, i32* %40
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %41)
%43 = add nuw nsw i64 %38, 1
%44 = add nsw i32 %39, 1
%45 = icmp ult i64 %38, 15
%46 = icmp slt i32 %44, %2
%47 = select i1 %45, i1 %46, i1 false
br i1 %47, label %37, label %48
48: ; preds = %37, %31, %27
%49 = phi i32 [ %7, %27 ], [ %35, %31 ], [ %44, %37 ]
%50 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.6, i64 0, i64 0))
%51 = icmp slt i32 %28, %2
br i1 %51, label %6, label %52
52: ; preds = %48, %3
ret void
}