#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(long, struct arraylist *);
long arraylist_head(struct arraylist *);
struct arraylist *arraylist_tail(struct arraylist *);
struct arraylist *arraylist_insert(long n, unsigned i, struct arraylist *l) {
  long new_head;
  struct arraylist *rec;
  if (i == 0)
    return arraylist_cons(n, l);
  new_head = arraylist_head(l);
  rec = arraylist_insert(n, i - 1, arraylist_tail(l));
  return arraylist_cons(new_head, rec);
}


x86 assembly (clang, -O0):
<arraylist_insert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1173 <arraylist_insert+0x33>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <arraylist_cons@plt>
mov    %rax,-0x8(%rbp)
jmp    11be <arraylist_insert+0x7e>
mov    -0x20(%rbp),%rdi
call   1040 <arraylist_head@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <arraylist_tail@plt>
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    %rax,%rdx
call   1030 <arraylist_insert@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1060 <arraylist_cons@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arraylist_insert>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rdi,%r14
test   %esi,%esi
je     117f <arraylist_insert+0x3f>
mov    %esi,%ebx
mov    %r15,%rdi
call   1040 <arraylist_head@plt>
mov    %rax,%r12
add    $0xffffffff,%ebx
mov    %r15,%rdi
call   1050 <arraylist_tail@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %rax,%rdx
call   1030 <arraylist_insert@plt>
mov    %r12,%rdi
mov    %rax,%rsi
jmp    1185 <arraylist_insert+0x45>
mov    %r14,%rdi
mov    %r15,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1060 <arraylist_cons@plt>

LLVM IR (-O0):
%struct.arraylist = type { i32 }
define %struct.arraylist* @arraylist_insert(i64 %0, i32 %1, %struct.arraylist* %2) {
%4 = alloca %struct.arraylist*
%5 = alloca i64
%6 = alloca i32
%7 = alloca %struct.arraylist*
%8 = alloca i64
%9 = alloca %struct.arraylist*
store i64 %0, i64* %5
store i32 %1, i32* %6
store %struct.arraylist* %2, %struct.arraylist** %7
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %3
%13 = load i64, i64* %5
%14 = load %struct.arraylist*, %struct.arraylist** %7
%15 = call %struct.arraylist* @arraylist_cons(i64 %13, %struct.arraylist* %14)
store %struct.arraylist* %15, %struct.arraylist** %4
br label %28
16: ; preds = %3
%17 = load %struct.arraylist*, %struct.arraylist** %7
%18 = call i64 @arraylist_head(%struct.arraylist* %17)
store i64 %18, i64* %8
%19 = load i64, i64* %5
%20 = load i32, i32* %6
%21 = sub i32 %20, 1
%22 = load %struct.arraylist*, %struct.arraylist** %7
%23 = call %struct.arraylist* @arraylist_tail(%struct.arraylist* %22)
%24 = call %struct.arraylist* @arraylist_insert(i64 %19, i32 %21, %struct.arraylist* %23)
store %struct.arraylist* %24, %struct.arraylist** %9
%25 = load i64, i64* %8
%26 = load %struct.arraylist*, %struct.arraylist** %9
%27 = call %struct.arraylist* @arraylist_cons(i64 %25, %struct.arraylist* %26)
store %struct.arraylist* %27, %struct.arraylist** %4
br label %28
28: ; preds = %16, %12
%29 = load %struct.arraylist*, %struct.arraylist** %4
ret %struct.arraylist* %29
}

LLVM IR (-O2):
%struct.arraylist = type { i32 }
define %struct.arraylist* @arraylist_insert(i64 %0, i32 %1, %struct.arraylist* %2) {
%4 = icmp eq i32 %1, 0
br i1 %4, label %5, label %9
5: ; preds = %3
%6 = tail call %struct.arraylist* @arraylist_cons(i64 %0, %struct.arraylist* %2)
br label %7
7: ; preds = %5, %9
%8 = phi %struct.arraylist* [ %14, %9 ], [ %6, %5 ]
ret %struct.arraylist* %8
9: ; preds = %3
%10 = tail call i64 @arraylist_head(%struct.arraylist* %2)
%11 = add i32 %1, -1
%12 = tail call %struct.arraylist* @arraylist_tail(%struct.arraylist* %2)
%13 = tail call %struct.arraylist* @arraylist_insert(i64 %0, i32 %11, %struct.arraylist* %12)
%14 = tail call %struct.arraylist* @arraylist_cons(i64 %10, %struct.arraylist* %13)
br label %7
}