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


x86 assembly (clang, -O0):
<arraylist_remove>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    116b <arraylist_remove+0x2b>
mov    -0x18(%rbp),%rdi
call   1040 <arraylist_tail@plt>
mov    %rax,-0x8(%rbp)
jmp    11aa <arraylist_remove+0x6a>
mov    -0x18(%rbp),%rdi
call   1030 <arraylist_head@plt>
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <arraylist_tail@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rsi
call   1050 <arraylist_remove@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <arraylist_cons@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arraylist_remove>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
test   %edi,%edi
je     117e <arraylist_remove+0x3e>
mov    %edi,%ebx
mov    %r14,%rdi
call   1030 <arraylist_head@plt>
mov    %rax,%r15
add    $0xffffffff,%ebx
mov    %r14,%rdi
call   1040 <arraylist_tail@plt>
mov    %ebx,%edi
mov    %rax,%rsi
call   1050 <arraylist_remove@plt>
mov    %r15,%rdi
mov    %rax,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <arraylist_cons@plt>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <arraylist_tail@plt>

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

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