#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*/ bzero_char(char *, size_t const);
int /*<<< orphan*/ bzero_long(long *, size_t);
void bzero(void *ptr, size_t size) {
  const size_t i = size % sizeof(long);
  if (!i) {
    bzero_long((long *)ptr, size / sizeof(long));
  } else {
    if (size < sizeof(long)) {
      bzero_char((char *)ptr, size);
    } else {
      bzero_char((char *)ptr, i);
      bzero_long((long *)((char *)ptr + i), (size - i) / sizeof(long));
    }
  }
}


x86 assembly (clang, -O0):
<bzero>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
and    $0x7,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    115d <bzero+0x3d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
shr    $0x3,%rsi
call   1030 <bzero_long@plt>
jmp    11a5 <bzero+0x85>
cmpq   $0x8,-0x10(%rbp)
jae    117a <bzero+0x5a>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <bzero_char@plt>
jmp    11a0 <bzero+0x80>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <bzero_char@plt>
mov    -0x8(%rbp),%rdi
add    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
sub    -0x18(%rbp),%rsi
shr    $0x3,%rsi
call   1030 <bzero_long@plt>
jmp    11a5 <bzero+0x85>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bzero>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%r15
and    $0x7,%r15
je     1158 <bzero+0x38>
cmp    $0x7,%rbx
ja     114a <bzero+0x2a>
mov    %r14,%rdi
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <bzero_char@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <bzero_char@plt>
add    %r15,%r14
shr    $0x3,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <bzero_long@plt>

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

LLVM IR (-O2):
define void @bzero(i8* %0, i64 %1) {
%3 = and i64 %1, 7
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = bitcast i8* %0 to i64*
%7 = lshr i64 %1, 3
%8 = tail call i32 @bzero_long(i64* %6, i64 %7)
br label %19
9: ; preds = %2
%10 = icmp ult i64 %1, 8
br i1 %10, label %11, label %13
11: ; preds = %9
%12 = tail call i32 @bzero_char(i8* %0, i64 %1)
br label %19
13: ; preds = %9
%14 = tail call i32 @bzero_char(i8* %0, i64 %3)
%15 = getelementptr inbounds i8, i8* %0, i64 %3
%16 = bitcast i8* %15 to i64*
%17 = lshr i64 %1, 3
%18 = tail call i32 @bzero_long(i64* %16, i64 %17)
br label %19
19: ; preds = %11, %13, %5
ret void
}