#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 */
int mpui_list_length(void *);
scalar_t__ realloc(void **, int);
void *mpui_list_add(void *list, void *element) {
  void **l = list;
  int n = mpui_list_length(list) + 1;
  l = (void **)realloc(l, (n + 1) * sizeof(*l));
  l[n] = NULL;
  l[n - 1] = element;
  return l;
}


x86 assembly (clang, -O0):
<mpui_list_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <mpui_list_length@plt>
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1040 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mpui_list_add>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <mpui_list_length@plt>
mov    %eax,%r15d
lea    0x10(,%r15,8),%esi
mov    %rbx,%rdi
call   1040 <realloc@plt>
movslq %r15d,%rcx
movq   $0x0,0x8(%rax,%rcx,8)
mov    %r14,(%rax,%rcx,8)
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @mpui_list_add(i8* %0, i8* %1) {
%3 = bitcast i8* %0 to i8**
%4 = tail call i32 @mpui_list_length(i8* %0)
%5 = add nsw i32 %4, 1
%6 = shl i32 %4, 3
%7 = add i32 %6, 16
%8 = tail call i64 @realloc(i8** %3, i32 %7)
%9 = inttoptr i64 %8 to i8**
%10 = sext i32 %5 to i64
%11 = getelementptr inbounds i8*, i8** %9, i64 %10
store i8* null, i8** %11
%12 = sext i32 %4 to i64
%13 = getelementptr inbounds i8*, i8** %9, i64 %12
store i8* %1, i8** %13
%14 = inttoptr i64 %8 to i8*
ret i8* %14
}