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


x86 assembly (clang, -O0):
<mips__nan_malloc_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movslq (%rax),%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    117c <mips__nan_malloc_+0x6c>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xfffffffffffffffc,%rcx
mov    %rcx,-0x18(%rbp)
movl   $0xfffa5a5a,-0x4(%rax)
jmp    1150 <mips__nan_malloc_+0x40>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rdx
movslq (%rdx),%rdx
sub    %rdx,%rcx
add    %rcx,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mips__nan_malloc_>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
movslq (%rdi),%rbx
add    $0x3,%rbx
and    $0xfffffffffffffffc,%rbx
mov    %rbx,%rdi
call   1030 <malloc@plt>
lea    (%rax,%rbx,1),%rcx
cmp    %rax,%rcx
jbe    1150 <mips__nan_malloc_+0x40>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movl   $0xfffa5a5a,-0x4(%rcx)
add    $0xfffffffffffffffc,%rcx
cmp    %rax,%rcx
ja     1140 <mips__nan_malloc_+0x30>
movslq (%r14),%rcx
sub    %rcx,%rbx
add    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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