#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 */
struct arraylist {
  int dummy;
};

/* Variables and functions */
struct arraylist *arraylist_cons(int, struct arraylist *);
int /*<<< orphan*/ arraylist_head(struct arraylist *);
struct arraylist *arraylist_insert(int, int, struct arraylist *);
struct arraylist *arraylist_new();
int /*<<< orphan*/ arraylist_print(struct arraylist *);
struct arraylist *arraylist_remove(int, struct arraylist *);
struct arraylist *arraylist_tail(struct arraylist *);
int /*<<< orphan*/ free(struct arraylist *);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  struct arraylist *l;
  l = arraylist_new();
  l = arraylist_cons(1, arraylist_cons(2, arraylist_cons(3, l)));
  l = arraylist_cons(4, l);
  printf("l = ");
  arraylist_print(l);
  l = arraylist_insert(5, 2, l);
  printf("after inserting at pos 2, l = ");
  arraylist_print(l);
  printf("head(l) = %ld\n", arraylist_head(l));
  l = arraylist_tail(l);
  printf("l = tail(l) = ");
  arraylist_print(l);
  l = arraylist_remove(2, l);
  printf("removed l[2]; l = ");
  arraylist_print(l);
  l = arraylist_remove(0, l);
  printf("removed l[0]; l = ");
  arraylist_print(l);
  free(l);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   10a0 <arraylist_new@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
mov    $0x3,%edi
call   10b0 <arraylist_cons@plt>
mov    %rax,%rsi
mov    $0x2,%edi
call   10b0 <arraylist_cons@plt>
mov    %rax,%rsi
mov    $0x1,%edi
call   10b0 <arraylist_cons@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
mov    $0x4,%edi
call   10b0 <arraylist_cons@plt>
mov    %rax,-0x10(%rbp)
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <arraylist_print@plt>
mov    -0x10(%rbp),%rdx
mov    $0x5,%edi
mov    $0x2,%esi
call   1050 <arraylist_insert@plt>
mov    %rax,-0x10(%rbp)
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <arraylist_print@plt>
mov    -0x10(%rbp),%rdi
call   1060 <arraylist_head@plt>
mov    %eax,%esi
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1080 <arraylist_tail@plt>
mov    %rax,-0x10(%rbp)
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <arraylist_print@plt>
mov    -0x10(%rbp),%rsi
mov    $0x2,%edi
call   1090 <arraylist_remove@plt>
mov    %rax,-0x10(%rbp)
lea    0xdba(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <arraylist_print@plt>
mov    -0x10(%rbp),%rsi
xor    %edi,%edi
call   1090 <arraylist_remove@plt>
mov    %rax,-0x10(%rbp)
lea    0xda7(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <arraylist_print@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   10a0 <arraylist_new@plt>
mov    $0x3,%edi
mov    %rax,%rsi
call   10b0 <arraylist_cons@plt>
mov    $0x2,%edi
mov    %rax,%rsi
call   10b0 <arraylist_cons@plt>
mov    $0x1,%edi
mov    %rax,%rsi
call   10b0 <arraylist_cons@plt>
mov    $0x4,%edi
mov    %rax,%rsi
call   10b0 <arraylist_cons@plt>
mov    %rax,%rbx
lea    0xe44(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1040 <arraylist_print@plt>
mov    $0x5,%edi
mov    $0x2,%esi
mov    %rbx,%rdx
call   1050 <arraylist_insert@plt>
mov    %rax,%rbx
lea    0xdff(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1040 <arraylist_print@plt>
mov    %rbx,%rdi
call   1060 <arraylist_head@plt>
lea    0xe00(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1080 <arraylist_tail@plt>
mov    %rax,%rbx
lea    0xdf4(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1040 <arraylist_print@plt>
mov    $0x2,%edi
mov    %rbx,%rsi
call   1090 <arraylist_remove@plt>
mov    %rax,%rbx
lea    0xddd(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1040 <arraylist_print@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1090 <arraylist_remove@plt>
mov    %rax,%rbx
lea    0xdcd(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1040 <arraylist_print@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.arraylist = type { i32 }
@.str = [5 x i8] c"l = \00"
@.str.1 = [31 x i8] c"after inserting at pos 2, l = \00"
@.str.2 = [15 x i8] c"head(l) = %ld\0A\00"
@.str.3 = [15 x i8] c"l = tail(l) = \00"
@.str.4 = [19 x i8] c"removed l[2]; l = \00"
@.str.5 = [19 x i8] c"removed l[0]; l = \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.arraylist*
store i32 0, i32* %1
%3 = call %struct.arraylist* (...) @arraylist_new()
store %struct.arraylist* %3, %struct.arraylist** %2
%4 = load %struct.arraylist*, %struct.arraylist** %2
%5 = call %struct.arraylist* @arraylist_cons(i32 3, %struct.arraylist* %4)
%6 = call %struct.arraylist* @arraylist_cons(i32 2, %struct.arraylist* %5)
%7 = call %struct.arraylist* @arraylist_cons(i32 1, %struct.arraylist* %6)
store %struct.arraylist* %7, %struct.arraylist** %2
%8 = load %struct.arraylist*, %struct.arraylist** %2
%9 = call %struct.arraylist* @arraylist_cons(i32 4, %struct.arraylist* %8)
store %struct.arraylist* %9, %struct.arraylist** %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%11 = load %struct.arraylist*, %struct.arraylist** %2
%12 = call i32 @arraylist_print(%struct.arraylist* %11)
%13 = load %struct.arraylist*, %struct.arraylist** %2
%14 = call %struct.arraylist* @arraylist_insert(i32 5, i32 2, %struct.arraylist* %13)
store %struct.arraylist* %14, %struct.arraylist** %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%16 = load %struct.arraylist*, %struct.arraylist** %2
%17 = call i32 @arraylist_print(%struct.arraylist* %16)
%18 = load %struct.arraylist*, %struct.arraylist** %2
%19 = call i32 @arraylist_head(%struct.arraylist* %18)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = load %struct.arraylist*, %struct.arraylist** %2
%22 = call %struct.arraylist* @arraylist_tail(%struct.arraylist* %21)
store %struct.arraylist* %22, %struct.arraylist** %2
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%24 = load %struct.arraylist*, %struct.arraylist** %2
%25 = call i32 @arraylist_print(%struct.arraylist* %24)
%26 = load %struct.arraylist*, %struct.arraylist** %2
%27 = call %struct.arraylist* @arraylist_remove(i32 2, %struct.arraylist* %26)
store %struct.arraylist* %27, %struct.arraylist** %2
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%29 = load %struct.arraylist*, %struct.arraylist** %2
%30 = call i32 @arraylist_print(%struct.arraylist* %29)
%31 = load %struct.arraylist*, %struct.arraylist** %2
%32 = call %struct.arraylist* @arraylist_remove(i32 0, %struct.arraylist* %31)
store %struct.arraylist* %32, %struct.arraylist** %2
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
%34 = load %struct.arraylist*, %struct.arraylist** %2
%35 = call i32 @arraylist_print(%struct.arraylist* %34)
%36 = load %struct.arraylist*, %struct.arraylist** %2
%37 = call i32 @free(%struct.arraylist* %36)
ret i32 0
}

LLVM IR (-O2):
%struct.arraylist = type { i32 }
@.str = [5 x i8] c"l = \00"
@.str.1 = [31 x i8] c"after inserting at pos 2, l = \00"
@.str.2 = [15 x i8] c"head(l) = %ld\0A\00"
@.str.3 = [15 x i8] c"l = tail(l) = \00"
@.str.4 = [19 x i8] c"removed l[2]; l = \00"
@.str.5 = [19 x i8] c"removed l[0]; l = \00"
define i32 @main() {
%1 = tail call %struct.arraylist* (...) @arraylist_new()
%2 = tail call %struct.arraylist* @arraylist_cons(i32 3, %struct.arraylist* %1)
%3 = tail call %struct.arraylist* @arraylist_cons(i32 2, %struct.arraylist* %2)
%4 = tail call %struct.arraylist* @arraylist_cons(i32 1, %struct.arraylist* %3)
%5 = tail call %struct.arraylist* @arraylist_cons(i32 4, %struct.arraylist* %4)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @arraylist_print(%struct.arraylist* %5)
%8 = tail call %struct.arraylist* @arraylist_insert(i32 5, i32 2, %struct.arraylist* %5)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @arraylist_print(%struct.arraylist* %8)
%11 = tail call i32 @arraylist_head(%struct.arraylist* %8)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = tail call %struct.arraylist* @arraylist_tail(%struct.arraylist* %8)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%15 = tail call i32 @arraylist_print(%struct.arraylist* %13)
%16 = tail call %struct.arraylist* @arraylist_remove(i32 2, %struct.arraylist* %13)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%18 = tail call i32 @arraylist_print(%struct.arraylist* %16)
%19 = tail call %struct.arraylist* @arraylist_remove(i32 0, %struct.arraylist* %16)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
%21 = tail call i32 @arraylist_print(%struct.arraylist* %19)
%22 = tail call i32 @free(%struct.arraylist* %19)
ret i32 0
}