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

/* Variables and functions */
int /*<<< orphan*/ mesh_memcpy(uintptr_t, int /*<<< orphan*/ const *, int);
void mesh_memclear(uintptr_t dst, size_t size) {
  const uint64_t zero = 0;
  while (size) {
    if (size <= 8) {
      mesh_memcpy(dst, &zero, size);
      return;
    }
    mesh_memcpy(dst, &zero, 8);
    dst += 8;
    size += 8;
  }
}


x86 assembly (clang, -O0):
<mesh_memclear>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1184 <mesh_memclear+0x74>
cmpq   $0x8,-0x10(%rbp)
ja     1155 <mesh_memclear+0x45>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    %eax,%edx
lea    -0x14(%rbp),%rsi
call   1030 <mesh_memcpy@plt>
jmp    1184 <mesh_memclear+0x74>
mov    -0x8(%rbp),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x8,%edx
call   1030 <mesh_memcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    1127 <mesh_memclear+0x17>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mesh_memclear>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
test   %rsi,%rsi
je     1172 <mesh_memclear+0x62>
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xc(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0x8,%r14
jbe    1162 <mesh_memclear+0x52>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x8,%edx
call   1030 <mesh_memcpy@plt>
add    $0x8,%rbx
add    $0x8,%r14
jne    1140 <mesh_memclear+0x30>
jmp    1172 <mesh_memclear+0x62>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
call   1030 <mesh_memcpy@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @mesh_memclear(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
store i64 %0, i64* %3
store i64 %1, i64* %4
store i32 0, i32* %5
br label %6
6: ; preds = %17, %2
%7 = load i64, i64* %4
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %24
9: ; preds = %6
%10 = load i64, i64* %4
%11 = icmp ule i64 %10, 8
br i1 %11, label %12, label %17
12: ; preds = %9
%13 = load i64, i64* %3
%14 = load i64, i64* %4
%15 = trunc i64 %14 to i32
%16 = call i32 @mesh_memcpy(i64 %13, i32* %5, i32 %15)
br label %24
17: ; preds = %9
%18 = load i64, i64* %3
%19 = call i32 @mesh_memcpy(i64 %18, i32* %5, i32 8)
%20 = load i64, i64* %3
%21 = add i64 %20, 8
store i64 %21, i64* %3
%22 = load i64, i64* %4
%23 = add i64 %22, 8
store i64 %23, i64* %4
br label %6
24: ; preds = %12, %6
ret void
}

LLVM IR (-O2):
define void @mesh_memclear(i64 %0, i64 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = icmp eq i64 %1, 0
br i1 %5, label %18, label %6
6: ; preds = %2, %13
%7 = phi i64 [ %16, %13 ], [ %1, %2 ]
%8 = phi i64 [ %15, %13 ], [ %0, %2 ]
%9 = icmp ult i64 %7, 9
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = trunc i64 %7 to i32
%12 = call i32 @mesh_memcpy(i64 %8, i32* %3, i32 %11)
br label %18
13: ; preds = %6
%14 = call i32 @mesh_memcpy(i64 %8, i32* %3, i32 8)
%15 = add i64 %8, 8
%16 = add i64 %7, 8
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %6
18: ; preds = %13, %2, %10
ret void
}