#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 /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(char *, int, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
void dump(char *b, size_t r) {
  size_t i;
  for (i = 0; i + 1023 < r; i += 1024)
    fwrite(b + i, 1, 1024, stdout);
  i = r % 1024;
  if (i)
    fwrite(b + r - i, 1, i, stdout);
  fflush(stdout);
}


x86 assembly (clang, -O0):
<dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x3ff,%rax
cmp    -0x10(%rbp),%rax
jae    117f <dump+0x5f>
mov    -0x8(%rbp),%rdi
add    -0x18(%rbp),%rdi
mov    0x2e85(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
mov    $0x400,%edx
call   1040 <fwrite@plt>
mov    -0x18(%rbp),%rax
add    $0x400,%rax
mov    %rax,-0x18(%rbp)
jmp    1138 <dump+0x18>
mov    -0x10(%rbp),%rax
and    $0x3ff,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11c0 <dump+0xa0>
mov    -0x8(%rbp),%rdi
add    -0x10(%rbp),%rdi
xor    %eax,%eax
sub    -0x18(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rdx
mov    0x2e2c(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1040 <fwrite@plt>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
call   1030 <fflush@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
cmp    $0x400,%rsi
jb     1179 <dump+0x59>
mov    $0x3ff,%r12d
mov    0x2e9b(%rip),%r13
mov    %r14,%rbx
nopl   0x0(%rax,%rax,1)
mov    0x0(%r13),%ecx
mov    $0x400,%edx
mov    %rbx,%rdi
mov    $0x1,%esi
call   1040 <fwrite@plt>
add    $0x400,%rbx
add    $0x400,%r12
cmp    %r15,%r12
jb     1150 <dump+0x30>
mov    %r15,%rdx
and    $0x3ff,%rdx
je     11a1 <dump+0x81>
add    %r15,%r14
sub    %rdx,%r14
mov    0x2e4e(%rip),%rax
mov    (%rax),%ecx
mov    %r14,%rdi
mov    $0x1,%esi
call   1040 <fwrite@plt>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <fflush@plt>

LLVM IR (-O0):
@stdout = global i32 0
define void @dump(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
store i64 0, i64* %5
br label %6
6: ; preds = %17, %2
%7 = load i64, i64* %5
%8 = add i64 %7, 1023
%9 = load i64, i64* %4
%10 = icmp ult i64 %8, %9
br i1 %10, label %11, label %20
11: ; preds = %6
%12 = load i8*, i8** %3
%13 = load i64, i64* %5
%14 = getelementptr inbounds i8, i8* %12, i64 %13
%15 = load i32, i32* @stdout
%16 = call i32 @fwrite(i8* %14, i32 1, i64 1024, i32 %15)
br label %17
17: ; preds = %11
%18 = load i64, i64* %5
%19 = add i64 %18, 1024
store i64 %19, i64* %5
br label %6
20: ; preds = %6
%21 = load i64, i64* %4
%22 = urem i64 %21, 1024
store i64 %22, i64* %5
%23 = load i64, i64* %5
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %35
25: ; preds = %20
%26 = load i8*, i8** %3
%27 = load i64, i64* %4
%28 = getelementptr inbounds i8, i8* %26, i64 %27
%29 = load i64, i64* %5
%30 = sub i64 0, %29
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i64, i64* %5
%33 = load i32, i32* @stdout
%34 = call i32 @fwrite(i8* %31, i32 1, i64 %32, i32 %33)
br label %35
35: ; preds = %25, %20
%36 = load i32, i32* @stdout
%37 = call i32 @fflush(i32 %36)
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
define void @dump(i8* %0, i64 %1) {
%3 = icmp ugt i64 %1, 1023
br i1 %3, label %4, label %12
4: ; preds = %2, %4
%5 = phi i64 [ %9, %4 ], [ 0, %2 ]
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i32, i32* @stdout
%8 = tail call i32 @fwrite(i8* %6, i32 1, i64 1024, i32 %7)
%9 = add i64 %5, 1024
%10 = or i64 %9, 1023
%11 = icmp ult i64 %10, %1
br i1 %11, label %4, label %12
12: ; preds = %4, %2
%13 = and i64 %1, 1023
%14 = icmp eq i64 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %12
%16 = getelementptr inbounds i8, i8* %0, i64 %1
%17 = sub nsw i64 0, %13
%18 = getelementptr inbounds i8, i8* %16, i64 %17
%19 = load i32, i32* @stdout
%20 = tail call i32 @fwrite(i8* %18, i32 1, i64 %13, i32 %19)
br label %21
21: ; preds = %15, %12
%22 = load i32, i32* @stdout
%23 = tail call i32 @fflush(i32 %22)
ret void
}