#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 */
struct iodesc {
  int dummy;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ xwrite(struct iodesc const *, char *, size_t);
void xzero(const struct iodesc *id, size_t nbyte) {
  char buf[8192];
  size_t n;
  memset(buf, 0, sizeof(buf));
  while (nbyte) {
    if ((n = sizeof(buf)) > nbyte)
      n = nbyte;
    xwrite(id, buf, n);
    nbyte -= n;
  }
}


x86 assembly (clang, -O0):
<xzero>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2020,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x2010(%rbp),%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1040 <memset@plt>
cmpq   $0x0,-0x10(%rbp)
je     11a4 <xzero+0x84>
movq   $0x2000,-0x2018(%rbp)
mov    $0x2000,%eax
cmp    -0x10(%rbp),%rax
jbe    1176 <xzero+0x56>
mov    -0x10(%rbp),%rax
mov    %rax,-0x2018(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x2010(%rbp),%rsi
mov    -0x2018(%rbp),%rdx
call   1030 <xwrite@plt>
mov    -0x2018(%rbp),%rcx
mov    -0x10(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    1146 <xzero+0x26>
add    $0x2020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xzero>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x2008,%rsp
mov    %rsi,%r12
mov    %rdi,%r14
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1040 <memset@plt>
test   %r12,%r12
je     1173 <xzero+0x53>
mov    %rsp,%r15
nopl   0x0(%rax,%rax,1)
cmp    $0x2000,%r12
mov    $0x2000,%ebx
cmovb  %r12,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1030 <xwrite@plt>
sub    %rbx,%r12
jne    1150 <xzero+0x30>
add    $0x2008,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.iodesc = type { i32 }
define void @xzero(%struct.iodesc* %0, i64 %1) {
%3 = alloca %struct.iodesc*
%4 = alloca i64
%5 = alloca [8192 x i8]
%6 = alloca i64
store %struct.iodesc* %0, %struct.iodesc** %3
store i64 %1, i64* %4
%7 = getelementptr inbounds [8192 x i8], [8192 x i8]* %5, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i32 0, i32 8192)
br label %9
9: ; preds = %17, %2
%10 = load i64, i64* %4
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %25
12: ; preds = %9
store i64 8192, i64* %6
%13 = load i64, i64* %4
%14 = icmp ugt i64 8192, %13
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = load i64, i64* %4
store i64 %16, i64* %6
br label %17
17: ; preds = %15, %12
%18 = load %struct.iodesc*, %struct.iodesc** %3
%19 = getelementptr inbounds [8192 x i8], [8192 x i8]* %5, i64 0, i64 0
%20 = load i64, i64* %6
%21 = call i32 @xwrite(%struct.iodesc* %18, i8* %19, i64 %20)
%22 = load i64, i64* %6
%23 = load i64, i64* %4
%24 = sub i64 %23, %22
store i64 %24, i64* %4
br label %9
25: ; preds = %9
ret void
}

LLVM IR (-O2):
%struct.iodesc = type { i32 }
define void @xzero(%struct.iodesc* %0, i64 %1) {
%3 = alloca [8192 x i8]
%4 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 8192)
%6 = icmp eq i64 %1, 0
br i1 %6, label %14, label %7
7: ; preds = %2, %7
%8 = phi i64 [ %12, %7 ], [ %1, %2 ]
%9 = icmp ult i64 %8, 8192
%10 = select i1 %9, i64 %8, i64 8192
%11 = call i32 @xwrite(%struct.iodesc* %0, i8* %4, i64 %10)
%12 = sub i64 %8, %10
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %7
14: ; preds = %7, %2
ret void
}