#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(int);
void *WpeExpArrayCreate(int initial_num, int elem_size, int growth_num) {
  int *exp_array;
  exp_array = (int *)malloc(initial_num * elem_size + sizeof(int) * 4);
  *(exp_array) = initial_num;
  *(exp_array + 1) = elem_size;
  *(exp_array + 2) = growth_num;
  *(exp_array + 3) = initial_num;
  return ((void *)(exp_array + 4));
}


x86 assembly (clang, -O0):
<WpeExpArrayCreate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%eax
imul   -0x8(%rbp),%eax
cltq
add    $0x10,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0xc(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x4(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0xc(%rax)
mov    -0x18(%rbp),%rax
add    $0x10,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WpeExpArrayCreate>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%ebx
mov    %esi,%edi
imul   %ebx,%edi
add    $0x10,%edi
call   1030 <malloc@plt>
mov    %ebx,(%rax)
mov    %ebp,0x4(%rax)
mov    %r14d,0x8(%rax)
mov    %ebx,0xc(%rax)
add    $0x10,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @WpeExpArrayCreate(i32 %0, i32 %1, i32 %2) {
%4 = mul nsw i32 %1, %0
%5 = add i32 %4, 16
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i32*
store i32 %0, i32* %7
%8 = getelementptr inbounds i32, i32* %7, i64 1
store i32 %1, i32* %8
%9 = getelementptr inbounds i32, i32* %7, i64 2
store i32 %2, i32* %9
%10 = getelementptr inbounds i32, i32* %7, i64 3
store i32 %0, i32* %10
%11 = getelementptr inbounds i32, i32* %7, i64 4
%12 = bitcast i32* %11 to i8*
ret i8* %12
}