#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*/ memset(char *, int /*<<< orphan*/, int);
char *realloc(char *, int);
void roxml_realloc_buf(char **buf, int *len, int min_len) {
  int append = (min_len & (512 - 1)) + 1;
  *buf = realloc(*buf, *len + append);
  memset(*buf + *len, 0, append);
  *len += append;
}


x86 assembly (clang, -O0):
<roxml_realloc_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
and    $0x1ff,%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
add    -0x18(%rbp),%esi
call   1040 <realloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<roxml_realloc_buf>:
push   %r15
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
and    $0x1ff,%ebx
add    $0x1,%ebx
mov    (%rdi),%rdi
mov    (%rsi),%esi
add    %ebx,%esi
call   1040 <realloc@plt>
mov    %rax,(%r15)
movslq (%r14),%rdi
add    %rax,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1030 <memset@plt>
add    %ebx,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @roxml_realloc_buf(i8** %0, i32* %1, i32 %2) {
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i8** %0, i8*** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%8 = load i32, i32* %6
%9 = and i32 %8, 511
%10 = add nsw i32 %9, 1
store i32 %10, i32* %7
%11 = load i8**, i8*** %4
%12 = load i8*, i8** %11
%13 = load i32*, i32** %5
%14 = load i32, i32* %13
%15 = load i32, i32* %7
%16 = add nsw i32 %14, %15
%17 = call i8* @realloc(i8* %12, i32 %16)
%18 = load i8**, i8*** %4
store i8* %17, i8** %18
%19 = load i8**, i8*** %4
%20 = load i8*, i8** %19
%21 = load i32*, i32** %5
%22 = load i32, i32* %21
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
%25 = load i32, i32* %7
%26 = call i32 @memset(i8* %24, i32 0, i32 %25)
%27 = load i32, i32* %7
%28 = load i32*, i32** %5
%29 = load i32, i32* %28
%30 = add nsw i32 %29, %27
store i32 %30, i32* %28
ret void
}

LLVM IR (-O2):
define void @roxml_realloc_buf(i8** nocapture %0, i32* nocapture %1, i32 %2) {
%4 = and i32 %2, 511
%5 = add nuw nsw i32 %4, 1
%6 = load i8*, i8** %0
%7 = load i32, i32* %1
%8 = add nsw i32 %7, %5
%9 = tail call i8* @realloc(i8* %6, i32 %8)
store i8* %9, i8** %0
%10 = load i32, i32* %1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = tail call i32 @memset(i8* %12, i32 0, i32 %5)
%14 = load i32, i32* %1
%15 = add nsw i32 %14, %5
store i32 %15, i32* %1
ret void
}