#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 */
void *malloc(size_t);
void *__trapuv_malloc(size_t size) {
  void *p;
  int *q;
  size_t roundoff_size;
  roundoff_size = sizeof(int) * ((size + sizeof(int) - 1) / sizeof(int));
  p = malloc(roundoff_size);
  q = (int *)((char *)p + roundoff_size);
  while (q > (int *)p) {
    *--q = 0xfffa5a5a;
    ;
  }
  return (void *)((char *)p + (roundoff_size - size));
}


x86 assembly (clang, -O0):
<__trapuv_malloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x4,%rax
sub    $0x1,%rax
shr    $0x2,%rax
shl    $0x2,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmp    %rcx,%rax
jbe    1179 <__trapuv_malloc+0x69>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xfffffffffffffffc,%rcx
mov    %rcx,-0x18(%rbp)
movl   $0xfffa5a5a,-0x4(%rax)
jmp    114d <__trapuv_malloc+0x3d>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    -0x8(%rbp),%rcx
add    %rcx,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__trapuv_malloc>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0x3(%rdi),%rbx
and    $0xfffffffffffffffc,%rbx
mov    %rbx,%rdi
call   1030 <malloc@plt>
test   %rbx,%rbx
jle    1140 <__trapuv_malloc+0x30>
lea    (%rax,%rbx,1),%rcx
movl   $0xfffa5a5a,-0x4(%rcx)
add    $0xfffffffffffffffc,%rcx
cmp    %rax,%rcx
ja     1130 <__trapuv_malloc+0x20>
sub    %r14,%rbx
add    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @__trapuv_malloc(i64 %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i64
store i64 %0, i64* %2
%6 = load i64, i64* %2
%7 = add i64 %6, 4
%8 = sub i64 %7, 1
%9 = udiv i64 %8, 4
%10 = mul i64 4, %9
store i64 %10, i64* %5
%11 = load i64, i64* %5
%12 = call i8* @malloc(i64 %11)
store i8* %12, i8** %3
%13 = load i8*, i8** %3
%14 = load i64, i64* %5
%15 = getelementptr inbounds i8, i8* %13, i64 %14
%16 = bitcast i8* %15 to i32*
store i32* %16, i32** %4
br label %17
17: ; preds = %22, %1
%18 = load i32*, i32** %4
%19 = load i8*, i8** %3
%20 = bitcast i8* %19 to i32*
%21 = icmp ugt i32* %18, %20
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = load i32*, i32** %4
%24 = getelementptr inbounds i32, i32* %23, i32 -1
store i32* %24, i32** %4
store i32 -370086, i32* %24
br label %17
25: ; preds = %17
%26 = load i8*, i8** %3
%27 = load i64, i64* %5
%28 = load i64, i64* %2
%29 = sub i64 %27, %28
%30 = getelementptr inbounds i8, i8* %26, i64 %29
ret i8* %30
}

LLVM IR (-O2):
define i8* @__trapuv_malloc(i64 %0) {
%2 = add i64 %0, 3
%3 = and i64 %2, -4
%4 = tail call i8* @malloc(i64 %3)
%5 = bitcast i8* %4 to i32*
%6 = icmp sgt i64 %3, 0
br i1 %6, label %7, label %14
7: ; preds = %1
%8 = getelementptr inbounds i8, i8* %4, i64 %3
%9 = bitcast i8* %8 to i32*
br label %10
10: ; preds = %7, %10
%11 = phi i32* [ %12, %10 ], [ %9, %7 ]
%12 = getelementptr inbounds i32, i32* %11, i64 -1
store i32 -370086, i32* %12
%13 = icmp ugt i32* %12, %5
br i1 %13, label %10, label %14
14: ; preds = %10, %1
%15 = sub i64 %3, %0
%16 = getelementptr inbounds i8, i8* %4, i64 %15
ret i8* %16
}