#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 */
char *malloc(size_t);
int /*<<< orphan*/ memory_error();
void darray_fill_ptr(void *arr, size_t sz, size_t init) {
  struct {
    char *data;
    size_t len;
    size_t size;
  } *ret = arr;
  if (!ret || !(ret->data = malloc(sz * init)))
    memory_error();
  ret->len = 0;
  ret->size = init;
}


x86 assembly (clang, -O0):
<darray_fill_ptr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1166 <darray_fill_ptr+0x46>
mov    -0x10(%rbp),%rdi
imul   -0x18(%rbp),%rdi
call   1030 <malloc@plt>
mov    -0x20(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    116d <darray_fill_ptr+0x4d>
mov    $0x0,%al
call   1040 <memory_error@plt>
mov    -0x20(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,0x10(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<darray_fill_ptr>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
je     1143 <darray_fill_ptr+0x23>
imul   %r14,%rsi
mov    %rsi,%rdi
call   1030 <malloc@plt>
mov    %rax,(%rbx)
test   %rax,%rax
jne    114a <darray_fill_ptr+0x2a>
xor    %eax,%eax
call   1040 <memory_error@plt>
movq   $0x0,0x8(%rbx)
mov    %r14,0x10(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.anon = type { i8*, i64, i64 }
define void @darray_fill_ptr(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca %struct.anon*
store i8* %0, i8** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%8 = load i8*, i8** %4
%9 = bitcast i8* %8 to %struct.anon*
store %struct.anon* %9, %struct.anon** %7
%10 = load %struct.anon*, %struct.anon** %7
%11 = icmp ne %struct.anon* %10, null
br i1 %11, label %12, label %20
12: ; preds = %3
%13 = load i64, i64* %5
%14 = load i64, i64* %6
%15 = mul i64 %13, %14
%16 = call i8* @malloc(i64 %15)
%17 = load %struct.anon*, %struct.anon** %7
%18 = getelementptr inbounds %struct.anon, %struct.anon* %17, i32 0, i32 0
store i8* %16, i8** %18
%19 = icmp ne i8* %16, null
br i1 %19, label %22, label %20
20: ; preds = %12, %3
%21 = call i32 (...) @memory_error()
br label %22
22: ; preds = %20, %12
%23 = load %struct.anon*, %struct.anon** %7
%24 = getelementptr inbounds %struct.anon, %struct.anon* %23, i32 0, i32 1
store i64 0, i64* %24
%25 = load i64, i64* %6
%26 = load %struct.anon*, %struct.anon** %7
%27 = getelementptr inbounds %struct.anon, %struct.anon* %26, i32 0, i32 2
store i64 %25, i64* %27
ret void
}

LLVM IR (-O2):
define void @darray_fill_ptr(i8* writeonly %0, i64 %1, i64 %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %10, label %5
5: ; preds = %3
%6 = mul i64 %2, %1
%7 = tail call i8* @malloc(i64 %6)
%8 = bitcast i8* %0 to i8**
store i8* %7, i8** %8
%9 = icmp eq i8* %7, null
br i1 %9, label %10, label %12
10: ; preds = %5, %3
%11 = tail call i32 (...) @memory_error()
br label %12
12: ; preds = %10, %5
%13 = getelementptr inbounds i8, i8* %0, i64 8
%14 = bitcast i8* %13 to i64*
store i64 0, i64* %14
%15 = getelementptr inbounds i8, i8* %0, i64 16
%16 = bitcast i8* %15 to i64*
store i64 %2, i64* %16
ret void
}