#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*/ addList(struct linkedList *, int);
int atoi(char *);
int /*<<< orphan*/ containsList(struct linkedList *, int);
struct linkedList *createLinkedList();
int /*<<< orphan*/ deleteLinkedList(struct linkedList *);
long getMemoryUsage();
double getMilliseconds();
int /*<<< orphan*/ printf(char *, int, ...);
int main(int argc, char *argv[]) {
  struct linkedList *b;
  int n, i;
  double t1, t2;
  long m1, m2;
  m1 = getMemoryUsage();
  if (argc != 2)
    return 0;
  b = createLinkedList();
  n = atoi(argv[1]);
  for (i = 0; i < n; i++) {
    addList(b, (int)i);
  }
  m2 = getMemoryUsage();
  printf("Memory used by LinkedList: %ld KB \n", m2 - m1);
  t1 = getMilliseconds();
  for (i = 0; i < n; i++) {
    containsList(b, i);
  }
  t2 = getMilliseconds();
  printf("Time for running contains() on %d elements: %g ms\n", n, t2 - t1);
  deleteLinkedList(b);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1090 <getMemoryUsage@plt>
mov    %rax,-0x38(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11b7 <main+0x37>
movl   $0x0,-0x4(%rbp)
jmp    1292 <main+0x112>
mov    $0x0,%al
call   1030 <createLinkedList@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11ff <main+0x7f>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1060 <addList@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11d9 <main+0x59>
mov    $0x0,%al
call   1090 <getMemoryUsage@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
sub    -0x38(%rbp),%rax
mov    %eax,%esi
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getMilliseconds@plt>
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    125b <main+0xdb>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1080 <containsList@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1235 <main+0xb5>
mov    $0x0,%al
call   1050 <getMilliseconds@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x1c(%rbp),%esi
movsd  -0x30(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
lea    0xda9(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1070 <deleteLinkedList@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    %edi,%ebx
xor    %eax,%eax
call   1090 <getMemoryUsage@plt>
cmp    $0x2,%ebx
jne    1235 <main+0xb5>
mov    %rax,%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <createLinkedList@plt>
mov    %rax,%r15
mov    0x8(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    11d1 <main+0x51>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %ebx,%esi
call   1060 <addList@plt>
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    11c0 <main+0x40>
xor    %ebx,%ebx
xor    %eax,%eax
call   1090 <getMemoryUsage@plt>
sub    %r14d,%eax
lea    0xe1c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getMilliseconds@plt>
movsd  %xmm0,(%rsp)
test   %ebp,%ebp
jle    1211 <main+0x91>
nopl   (%rax)
mov    %r15,%rdi
mov    %ebx,%esi
call   1080 <containsList@plt>
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    1200 <main+0x80>
xor    %eax,%eax
call   1050 <getMilliseconds@plt>
subsd  (%rsp),%xmm0
lea    0xe00(%rip),%rdi
mov    %ebp,%esi
mov    $0x1,%al
call   1040 <printf@plt>
mov    %r15,%rdi
call   1070 <deleteLinkedList@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.linkedList = type { i32 }
@.str = [36 x i8] c"Memory used by LinkedList: %ld KB \0A\00"
@.str.1 = [51 x i8] c"Time for running contains() on %d elements: %g ms\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.linkedList*
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca i64
%12 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = call i64 (...) @getMemoryUsage()
store i64 %13, i64* %11
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 2
br i1 %15, label %16, label %17
16: ; preds = %2
store i32 0, i32* %3
br label %62
17: ; preds = %2
%18 = call %struct.linkedList* (...) @createLinkedList()
store %struct.linkedList* %18, %struct.linkedList** %6
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %7
store i32 0, i32* %8
br label %23
23: ; preds = %31, %17
%24 = load i32, i32* %8
%25 = load i32, i32* %7
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %34
27: ; preds = %23
%28 = load %struct.linkedList*, %struct.linkedList** %6
%29 = load i32, i32* %8
%30 = call i32 @addList(%struct.linkedList* %28, i32 %29)
br label %31
31: ; preds = %27
%32 = load i32, i32* %8
%33 = add nsw i32 %32, 1
store i32 %33, i32* %8
br label %23
34: ; preds = %23
%35 = call i64 (...) @getMemoryUsage()
store i64 %35, i64* %12
%36 = load i64, i64* %12
%37 = load i64, i64* %11
%38 = sub nsw i64 %36, %37
%39 = trunc i64 %38 to i32
%40 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %39)
%41 = call double (...) @getMilliseconds()
store double %41, double* %9
store i32 0, i32* %8
br label %42
42: ; preds = %50, %34
%43 = load i32, i32* %8
%44 = load i32, i32* %7
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %53
46: ; preds = %42
%47 = load %struct.linkedList*, %struct.linkedList** %6
%48 = load i32, i32* %8
%49 = call i32 @containsList(%struct.linkedList* %47, i32 %48)
br label %50
50: ; preds = %46
%51 = load i32, i32* %8
%52 = add nsw i32 %51, 1
store i32 %52, i32* %8
br label %42
53: ; preds = %42
%54 = call double (...) @getMilliseconds()
store double %54, double* %10
%55 = load i32, i32* %7
%56 = load double, double* %10
%57 = load double, double* %9
%58 = fsub double %56, %57
%59 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %55, double %58)
%60 = load %struct.linkedList*, %struct.linkedList** %6
%61 = call i32 @deleteLinkedList(%struct.linkedList* %60)
store i32 0, i32* %3
br label %62
62: ; preds = %53, %16
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
%struct.linkedList = type { i32 }
@.str = [36 x i8] c"Memory used by LinkedList: %ld KB \0A\00"
@.str.1 = [51 x i8] c"Time for running contains() on %d elements: %g ms\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i64 (...) @getMemoryUsage()
%4 = icmp eq i32 %0, 2
br i1 %4, label %5, label %32
5: ; preds = %2
%6 = tail call %struct.linkedList* (...) @createLinkedList()
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %5, %11
%12 = phi i32 [ %14, %11 ], [ 0, %5 ]
%13 = tail call i32 @addList(%struct.linkedList* %6, i32 %12)
%14 = add nuw nsw i32 %12, 1
%15 = icmp eq i32 %14, %9
br i1 %15, label %16, label %11
16: ; preds = %11, %5
%17 = tail call i64 (...) @getMemoryUsage()
%18 = sub nsw i64 %17, %3
%19 = trunc i64 %18 to i32
%20 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = tail call double (...) @getMilliseconds()
br i1 %10, label %22, label %27
22: ; preds = %16, %22
%23 = phi i32 [ %25, %22 ], [ 0, %16 ]
%24 = tail call i32 @containsList(%struct.linkedList* %6, i32 %23)
%25 = add nuw nsw i32 %23, 1
%26 = icmp eq i32 %25, %9
br i1 %26, label %27, label %22
27: ; preds = %22, %16
%28 = tail call double (...) @getMilliseconds()
%29 = fsub double %28, %21
%30 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %9, double %29)
%31 = tail call i32 @deleteLinkedList(%struct.linkedList* %6)
br label %32
32: ; preds = %2, %27
ret i32 0
}