#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 lst_append(void *lst, int v) {
  void *head = lst;
  void *tail = lst + sizeof(void *);
  void *aux = (void *)malloc(sizeof(void *) + sizeof(int));
  *(void **)aux = NULL;
  *(int *)(aux + sizeof(void *)) = v;
  if (*(void **)head == NULL)
    *(void **)head = *(void **)tail = aux;
  else {
    *(void **)(*(void **)tail) = aux;
    *(void **)tail = aux;
  }
  return;
}


x86 assembly (clang, -O0):
<lst_append>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
mov    $0xc,%edi
call   1030 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
mov    -0xc(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    117b <lst_append+0x6b>
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    1194 <lst_append+0x84>
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lst_append>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0x8(%rdi),%rbp
mov    $0xc,%edi
call   1030 <malloc@plt>
movq   $0x0,(%rax)
mov    %r14d,0x8(%rax)
cmpq   $0x0,(%rbx)
je     1140 <lst_append+0x30>
mov    %rbp,%rbx
mov    0x0(%rbp),%rbp
mov    %rax,0x0(%rbp)
mov    %rax,(%rbx)
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define void @lst_append(i8* nocapture %0, i32 %1) {
%3 = getelementptr i8, i8* %0, i64 8
%4 = tail call i64 @malloc(i32 12)
%5 = inttoptr i64 %4 to i8*
%6 = inttoptr i64 %4 to i8**
store i8* null, i8** %6
%7 = getelementptr i8, i8* %5, i64 8
%8 = bitcast i8* %7 to i32*
store i32 %1, i32* %8
%9 = bitcast i8* %0 to i8**
%10 = load i8*, i8** %9
%11 = icmp eq i8* %10, null
%12 = bitcast i8* %3 to i8**
br i1 %11, label %16, label %13
13: ; preds = %2
%14 = bitcast i8* %3 to i8***
%15 = load i8**, i8*** %14
br label %16
16: ; preds = %2, %13
%17 = phi i8** [ %15, %13 ], [ %12, %2 ]
%18 = phi i8** [ %12, %13 ], [ %9, %2 ]
store i8* %5, i8** %17
store i8* %5, i8** %18
ret void
}