#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 linkedlist {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ free(struct linkedlist *);
struct linkedlist *linkedlist_cons(int, struct linkedlist *);
int /*<<< orphan*/ linkedlist_head(struct linkedlist *);
struct linkedlist *linkedlist_insert(int, int, struct linkedlist *);
struct linkedlist *linkedlist_new();
int /*<<< orphan*/ linkedlist_print(struct linkedlist *);
struct linkedlist *linkedlist_remove(int, struct linkedlist *);
struct linkedlist *linkedlist_tail(struct linkedlist *);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  struct linkedlist *l;
  l = linkedlist_new();
  l = linkedlist_cons(1, linkedlist_cons(2, linkedlist_cons(3, l)));
  l = linkedlist_cons(4, l);
  printf("l = ");
  linkedlist_print(l);
  l = linkedlist_insert(5, 2, l);
  printf("after inserting at pos 2, l = ");
  linkedlist_print(l);
  printf("head(l) = %ld\n", linkedlist_head(l));
  l = linkedlist_tail(l);
  printf("l = tail(l) = ");
  linkedlist_print(l);
  l = linkedlist_remove(2, l);
  printf("removed l[2]; l = ");
  linkedlist_print(l);
  l = linkedlist_remove(0, l);
  printf("removed l[0]; l = ");
  linkedlist_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   1080 <linkedlist_new@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
mov    $0x3,%edi
call   1040 <linkedlist_cons@plt>
mov    %rax,%rsi
mov    $0x2,%edi
call   1040 <linkedlist_cons@plt>
mov    %rax,%rsi
mov    $0x1,%edi
call   1040 <linkedlist_cons@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
mov    $0x4,%edi
call   1040 <linkedlist_cons@plt>
mov    %rax,-0x10(%rbp)
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <linkedlist_print@plt>
mov    -0x10(%rbp),%rdx
mov    $0x5,%edi
mov    $0x2,%esi
call   10a0 <linkedlist_insert@plt>
mov    %rax,-0x10(%rbp)
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <linkedlist_print@plt>
mov    -0x10(%rbp),%rdi
call   1090 <linkedlist_head@plt>
mov    %eax,%esi
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <linkedlist_tail@plt>
mov    %rax,-0x10(%rbp)
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <linkedlist_print@plt>
mov    -0x10(%rbp),%rsi
mov    $0x2,%edi
call   10b0 <linkedlist_remove@plt>
mov    %rax,-0x10(%rbp)
lea    0xdba(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <linkedlist_print@plt>
mov    -0x10(%rbp),%rsi
xor    %edi,%edi
call   10b0 <linkedlist_remove@plt>
mov    %rax,-0x10(%rbp)
lea    0xda7(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <linkedlist_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   1080 <linkedlist_new@plt>
mov    $0x3,%edi
mov    %rax,%rsi
call   1040 <linkedlist_cons@plt>
mov    $0x2,%edi
mov    %rax,%rsi
call   1040 <linkedlist_cons@plt>
mov    $0x1,%edi
mov    %rax,%rsi
call   1040 <linkedlist_cons@plt>
mov    $0x4,%edi
mov    %rax,%rsi
call   1040 <linkedlist_cons@plt>
mov    %rax,%rbx
lea    0xe44(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1060 <linkedlist_print@plt>
mov    $0x5,%edi
mov    $0x2,%esi
mov    %rbx,%rdx
call   10a0 <linkedlist_insert@plt>
mov    %rax,%rbx
lea    0xdff(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1060 <linkedlist_print@plt>
mov    %rbx,%rdi
call   1090 <linkedlist_head@plt>
lea    0xe00(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1050 <linkedlist_tail@plt>
mov    %rax,%rbx
lea    0xdf4(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1060 <linkedlist_print@plt>
mov    $0x2,%edi
mov    %rbx,%rsi
call   10b0 <linkedlist_remove@plt>
mov    %rax,%rbx
lea    0xddd(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1060 <linkedlist_print@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   10b0 <linkedlist_remove@plt>
mov    %rax,%rbx
lea    0xdcd(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1060 <linkedlist_print@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.linkedlist = 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.linkedlist*
store i32 0, i32* %1
%3 = call %struct.linkedlist* (...) @linkedlist_new()
store %struct.linkedlist* %3, %struct.linkedlist** %2
%4 = load %struct.linkedlist*, %struct.linkedlist** %2
%5 = call %struct.linkedlist* @linkedlist_cons(i32 3, %struct.linkedlist* %4)
%6 = call %struct.linkedlist* @linkedlist_cons(i32 2, %struct.linkedlist* %5)
%7 = call %struct.linkedlist* @linkedlist_cons(i32 1, %struct.linkedlist* %6)
store %struct.linkedlist* %7, %struct.linkedlist** %2
%8 = load %struct.linkedlist*, %struct.linkedlist** %2
%9 = call %struct.linkedlist* @linkedlist_cons(i32 4, %struct.linkedlist* %8)
store %struct.linkedlist* %9, %struct.linkedlist** %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%11 = load %struct.linkedlist*, %struct.linkedlist** %2
%12 = call i32 @linkedlist_print(%struct.linkedlist* %11)
%13 = load %struct.linkedlist*, %struct.linkedlist** %2
%14 = call %struct.linkedlist* @linkedlist_insert(i32 5, i32 2, %struct.linkedlist* %13)
store %struct.linkedlist* %14, %struct.linkedlist** %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%16 = load %struct.linkedlist*, %struct.linkedlist** %2
%17 = call i32 @linkedlist_print(%struct.linkedlist* %16)
%18 = load %struct.linkedlist*, %struct.linkedlist** %2
%19 = call i32 @linkedlist_head(%struct.linkedlist* %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.linkedlist*, %struct.linkedlist** %2
%22 = call %struct.linkedlist* @linkedlist_tail(%struct.linkedlist* %21)
store %struct.linkedlist* %22, %struct.linkedlist** %2
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%24 = load %struct.linkedlist*, %struct.linkedlist** %2
%25 = call i32 @linkedlist_print(%struct.linkedlist* %24)
%26 = load %struct.linkedlist*, %struct.linkedlist** %2
%27 = call %struct.linkedlist* @linkedlist_remove(i32 2, %struct.linkedlist* %26)
store %struct.linkedlist* %27, %struct.linkedlist** %2
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%29 = load %struct.linkedlist*, %struct.linkedlist** %2
%30 = call i32 @linkedlist_print(%struct.linkedlist* %29)
%31 = load %struct.linkedlist*, %struct.linkedlist** %2
%32 = call %struct.linkedlist* @linkedlist_remove(i32 0, %struct.linkedlist* %31)
store %struct.linkedlist* %32, %struct.linkedlist** %2
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
%34 = load %struct.linkedlist*, %struct.linkedlist** %2
%35 = call i32 @linkedlist_print(%struct.linkedlist* %34)
%36 = load %struct.linkedlist*, %struct.linkedlist** %2
%37 = call i32 @free(%struct.linkedlist* %36)
ret i32 0
}

LLVM IR (-O2):
%struct.linkedlist = 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.linkedlist* (...) @linkedlist_new()
%2 = tail call %struct.linkedlist* @linkedlist_cons(i32 3, %struct.linkedlist* %1)
%3 = tail call %struct.linkedlist* @linkedlist_cons(i32 2, %struct.linkedlist* %2)
%4 = tail call %struct.linkedlist* @linkedlist_cons(i32 1, %struct.linkedlist* %3)
%5 = tail call %struct.linkedlist* @linkedlist_cons(i32 4, %struct.linkedlist* %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 @linkedlist_print(%struct.linkedlist* %5)
%8 = tail call %struct.linkedlist* @linkedlist_insert(i32 5, i32 2, %struct.linkedlist* %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 @linkedlist_print(%struct.linkedlist* %8)
%11 = tail call i32 @linkedlist_head(%struct.linkedlist* %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.linkedlist* @linkedlist_tail(%struct.linkedlist* %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 @linkedlist_print(%struct.linkedlist* %13)
%16 = tail call %struct.linkedlist* @linkedlist_remove(i32 2, %struct.linkedlist* %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 @linkedlist_print(%struct.linkedlist* %16)
%19 = tail call %struct.linkedlist* @linkedlist_remove(i32 0, %struct.linkedlist* %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 @linkedlist_print(%struct.linkedlist* %19)
%22 = tail call i32 @free(%struct.linkedlist* %19)
ret i32 0
}