#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 */
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int /*<<< orphan*/ *data;
  scalar_t__ max;
  scalar_t__ length;
};
typedef TYPE_1__ BUF_MEM;

/* Variables and functions */
int /*<<< orphan*/ BUF_F_BUF_MEM_NEW;
int /*<<< orphan*/ BUFerr(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ ERR_R_MALLOC_FAILURE;
TYPE_1__ *malloc(int);
BUF_MEM *BUF_MEM_new(void) {
  BUF_MEM *ret;
  ret = malloc(sizeof(BUF_MEM));
  if (ret == NULL) {
    BUFerr(BUF_F_BUF_MEM_NEW, ERR_R_MALLOC_FAILURE);
    return (NULL);
  }
  ret->length = 0;
  ret->max = 0;
  ret->data = NULL;
  return (ret);
}


x86 assembly (clang, -O0):
<BUF_MEM_new>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x18,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1165 <BUF_MEM_new+0x45>
mov    0x2ea0(%rip),%rax
mov    (%rax),%edi
mov    0x2e8f(%rip),%rax
mov    (%rax),%esi
call   1030 <BUFerr@plt>
movq   $0x0,-0x8(%rbp)
jmp    1190 <BUF_MEM_new+0x70>
mov    -0x10(%rbp),%rax
movq   $0x0,0x10(%rax)
mov    -0x10(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BUF_MEM_new>:
push   %rbx
mov    $0x18,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1143 <BUF_MEM_new+0x23>
xorps  %xmm0,%xmm0
movups %xmm0,(%rbx)
movq   $0x0,0x10(%rbx)
jmp    115a <BUF_MEM_new+0x3a>
mov    0x2e9e(%rip),%rax
mov    (%rax),%edi
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
call   1030 <BUFerr@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32*, i64, i64 }
@BUF_F_BUF_MEM_NEW = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
define %struct.TYPE_4__* @BUF_MEM_new() {
%1 = alloca %struct.TYPE_4__*
%2 = alloca %struct.TYPE_4__*
%3 = call %struct.TYPE_4__* @malloc(i32 24)
store %struct.TYPE_4__* %3, %struct.TYPE_4__** %2
%4 = load %struct.TYPE_4__*, %struct.TYPE_4__** %2
%5 = icmp eq %struct.TYPE_4__* %4, null
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = load i32, i32* @BUF_F_BUF_MEM_NEW
%8 = load i32, i32* @ERR_R_MALLOC_FAILURE
%9 = call i32 @BUFerr(i32 %7, i32 %8)
store %struct.TYPE_4__* null, %struct.TYPE_4__** %1
br label %18
10: ; preds = %0
%11 = load %struct.TYPE_4__*, %struct.TYPE_4__** %2
%12 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %11, i32 0, i32 2
store i64 0, i64* %12
%13 = load %struct.TYPE_4__*, %struct.TYPE_4__** %2
%14 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %13, i32 0, i32 1
store i64 0, i64* %14
%15 = load %struct.TYPE_4__*, %struct.TYPE_4__** %2
%16 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %15, i32 0, i32 0
store i32* null, i32** %16
%17 = load %struct.TYPE_4__*, %struct.TYPE_4__** %2
store %struct.TYPE_4__* %17, %struct.TYPE_4__** %1
br label %18
18: ; preds = %10, %6
%19 = load %struct.TYPE_4__*, %struct.TYPE_4__** %1
ret %struct.TYPE_4__* %19
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32*, i64, i64 }
@BUF_F_BUF_MEM_NEW = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
define noalias %struct.TYPE_4__* @BUF_MEM_new() {
%1 = tail call %struct.TYPE_4__* @malloc(i32 24)
%2 = icmp eq %struct.TYPE_4__* %1, null
br i1 %2, label %3, label %7
3: ; preds = %0
%4 = load i32, i32* @BUF_F_BUF_MEM_NEW
%5 = load i32, i32* @ERR_R_MALLOC_FAILURE
%6 = tail call i32 @BUFerr(i32 %4, i32 %5)
br label %9
7: ; preds = %0
%8 = bitcast %struct.TYPE_4__* %1 to i8*
br label %9
9: ; preds = %7, %3
ret %struct.TYPE_4__* %1
}