#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*/ FILE;

/* Variables and functions */
size_t fwrite(char const *, int, size_t, int /*<<< orphan*/ *const);
int rfwrite(FILE *const fptr, const void *ptr, size_t n) {
  size_t na;
  const char *p = ptr;
  while (n && (na = fwrite(p, 1, n, fptr)))
    n -= na, p += na;
  return n != 0;
}


x86 assembly (clang, -O0):
<rfwrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x29(%rbp)
je     1160 <rfwrite+0x50>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fwrite@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    1170 <rfwrite+0x60>
jmp    1190 <rfwrite+0x80>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    112c <rfwrite+0x1c>
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rfwrite>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdx,%rdx
je     1150 <rfwrite+0x40>
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    $0x1,%ebp
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    %r15,%rcx
call   1030 <fwrite@plt>
test   %rax,%rax
je     1152 <rfwrite+0x42>
add    %rax,%rbx
sub    %rax,%r14
jne    1130 <rfwrite+0x20>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @rfwrite(i32* %0, i8* %1, i64 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
store i32* %0, i32** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%9 = load i8*, i8** %5
store i8* %9, i8** %8
br label %10
10: ; preds = %21, %3
%11 = load i64, i64* %6
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %10
%14 = load i8*, i8** %8
%15 = load i64, i64* %6
%16 = load i32*, i32** %4
%17 = call i64 @fwrite(i8* %14, i32 1, i64 %15, i32* %16)
store i64 %17, i64* %7
%18 = icmp ne i64 %17, 0
br label %19
19: ; preds = %13, %10
%20 = phi i1 [ false, %10 ], [ %18, %13 ]
br i1 %20, label %21, label %28
21: ; preds = %19
%22 = load i64, i64* %7
%23 = load i64, i64* %6
%24 = sub i64 %23, %22
store i64 %24, i64* %6
%25 = load i64, i64* %7
%26 = load i8*, i8** %8
%27 = getelementptr inbounds i8, i8* %26, i64 %25
store i8* %27, i8** %8
br label %10
28: ; preds = %19
%29 = load i64, i64* %6
%30 = icmp ne i64 %29, 0
%31 = zext i1 %30 to i32
ret i32 %31
}

LLVM IR (-O2):
define i32 @rfwrite(i32* nocapture %0, i8* nocapture %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %14, label %5
5: ; preds = %3, %10
%6 = phi i8* [ %12, %10 ], [ %1, %3 ]
%7 = phi i64 [ %11, %10 ], [ %2, %3 ]
%8 = tail call i64 @fwrite(i8* %6, i32 1, i64 %7, i32* %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %5
%11 = sub i64 %7, %8
%12 = getelementptr inbounds i8, i8* %6, i64 %8
%13 = icmp eq i64 %11, 0
br i1 %13, label %14, label %5
14: ; preds = %5, %10, %3
%15 = phi i32 [ 0, %3 ], [ 0, %10 ], [ 1, %5 ]
ret i32 %15
}