#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 list_head {
  int dummy;
};
struct kv {
  int dummy;
};

/* Variables and functions */
char *calloc(int, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ list_append(struct list_head *, char *, char *);
int /*<<< orphan*/ list_free(struct list_head *);
int /*<<< orphan*/ list_insert(struct list_head *, int, char *, char *);
struct list_head *list_new();
int /*<<< orphan*/ list_remove(struct list_head *, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *);
int main() {
  int i;
  struct kv *kv;
  char *key = calloc(1, 32);
  char *val = calloc(1, 32);
  sprintf(key, "Some key");
  sprintf(val, "Some value");
  for (i = 0; i < 10000000; i++) {
    struct list_head *head = list_new();
    int j;
    for (j = 0; j < 10; j += 2) {
      list_append(head, key, val);
      list_append(head, key, val);
    }
    list_insert(head, 2, key, val);
    list_insert(head, 0, key, val);
    list_insert(head, 9, key, val);
    list_insert(head, 4, key, val);
    list_remove(head, 0);
    list_free(head);
  }
  free(key);
  free(val);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x1,%edi
mov    $0x20,%esi
call   1040 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x1,%edi
mov    $0x20,%esi
call   1040 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe40(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   1080 <sprintf@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x989680,-0x8(%rbp)
jge    12ac <main+0x12c>
mov    $0x0,%al
call   1070 <list_new@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0xa,-0x2c(%rbp)
jge    1235 <main+0xb5>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1090 <list_append@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1090 <list_append@plt>
mov    -0x2c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x2c(%rbp)
jmp    11fb <main+0x7b>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x2,%esi
call   1060 <list_insert@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
xor    %esi,%esi
call   1060 <list_insert@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x9,%esi
call   1060 <list_insert@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x4,%esi
call   1060 <list_insert@plt>
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
call   10a0 <list_remove@plt>
mov    -0x28(%rbp),%rdi
call   1050 <list_free@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11dc <main+0x5c>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x1,%edi
mov    $0x20,%esi
call   1040 <calloc@plt>
mov    %rax,%r14
mov    $0x1,%edi
mov    $0x20,%esi
call   1040 <calloc@plt>
mov    %rax,%r15
movabs $0x79656b20656d6f53,%rax
6b 65 79
mov    %rax,(%r14)
movb   $0x0,0x8(%r14)
movabs $0x6c617620656d6f53,%rax
76 61 6c
mov    %rax,(%r15)
movl   $0x65756c,0x7(%r15)
mov    $0x989680,%ebp
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <list_new@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1080 <list_append@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1080 <list_append@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1080 <list_append@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1080 <list_append@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1080 <list_append@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1080 <list_append@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1080 <list_append@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1080 <list_append@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1080 <list_append@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1080 <list_append@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
mov    %r14,%rdx
mov    %r15,%rcx
call   1060 <list_insert@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14,%rdx
mov    %r15,%rcx
call   1060 <list_insert@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
mov    %r14,%rdx
mov    %r15,%rcx
call   1060 <list_insert@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
mov    %r14,%rdx
mov    %r15,%rcx
call   1060 <list_insert@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <list_remove@plt>
mov    %rbx,%rdi
call   1050 <list_free@plt>
add    $0xffffffff,%ebp
jne    11d0 <main+0x60>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.kv = type { i32 }
%struct.list_head = type { i32 }
@.str = [9 x i8] c"Some key\00"
@.str.1 = [11 x i8] c"Some value\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.kv*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.list_head*
%7 = alloca i32
store i32 0, i32* %1
%8 = call i8* @calloc(i32 1, i32 32)
store i8* %8, i8** %4
%9 = call i8* @calloc(i32 1, i32 32)
store i8* %9, i8** %5
%10 = load i8*, i8** %4
%11 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%12 = load i8*, i8** %5
%13 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %2
br label %14
14: ; preds = %55, %0
%15 = load i32, i32* %2
%16 = icmp slt i32 %15, 10000000
br i1 %16, label %17, label %58
17: ; preds = %14
%18 = call %struct.list_head* (...) @list_new()
store %struct.list_head* %18, %struct.list_head** %6
store i32 0, i32* %7
br label %19
19: ; preds = %31, %17
%20 = load i32, i32* %7
%21 = icmp slt i32 %20, 10
br i1 %21, label %22, label %34
22: ; preds = %19
%23 = load %struct.list_head*, %struct.list_head** %6
%24 = load i8*, i8** %4
%25 = load i8*, i8** %5
%26 = call i32 @list_append(%struct.list_head* %23, i8* %24, i8* %25)
%27 = load %struct.list_head*, %struct.list_head** %6
%28 = load i8*, i8** %4
%29 = load i8*, i8** %5
%30 = call i32 @list_append(%struct.list_head* %27, i8* %28, i8* %29)
br label %31
31: ; preds = %22
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 2
store i32 %33, i32* %7
br label %19
34: ; preds = %19
%35 = load %struct.list_head*, %struct.list_head** %6
%36 = load i8*, i8** %4
%37 = load i8*, i8** %5
%38 = call i32 @list_insert(%struct.list_head* %35, i32 2, i8* %36, i8* %37)
%39 = load %struct.list_head*, %struct.list_head** %6
%40 = load i8*, i8** %4
%41 = load i8*, i8** %5
%42 = call i32 @list_insert(%struct.list_head* %39, i32 0, i8* %40, i8* %41)
%43 = load %struct.list_head*, %struct.list_head** %6
%44 = load i8*, i8** %4
%45 = load i8*, i8** %5
%46 = call i32 @list_insert(%struct.list_head* %43, i32 9, i8* %44, i8* %45)
%47 = load %struct.list_head*, %struct.list_head** %6
%48 = load i8*, i8** %4
%49 = load i8*, i8** %5
%50 = call i32 @list_insert(%struct.list_head* %47, i32 4, i8* %48, i8* %49)
%51 = load %struct.list_head*, %struct.list_head** %6
%52 = call i32 @list_remove(%struct.list_head* %51, i32 0)
%53 = load %struct.list_head*, %struct.list_head** %6
%54 = call i32 @list_free(%struct.list_head* %53)
br label %55
55: ; preds = %34
%56 = load i32, i32* %2
%57 = add nsw i32 %56, 1
store i32 %57, i32* %2
br label %14
58: ; preds = %14
%59 = load i8*, i8** %4
%60 = call i32 @free(i8* %59)
%61 = load i8*, i8** %5
%62 = call i32 @free(i8* %61)
ret i32 0
}

LLVM IR (-O2):
%struct.kv = type { i32 }
%struct.list_head = type { i32 }
@.str = [9 x i8] c"Some key\00"
@.str.1 = [11 x i8] c"Some value\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(32) i8* @calloc(i32 1, i32 32)
%2 = tail call dereferenceable_or_null(32) i8* @calloc(i32 1, i32 32)
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(9) %1, i8* align 1 dereferenceable(9) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i64 9, i1 false)
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(11) %2, i8* align 1 dereferenceable(11) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i64 11, i1 false)
br label %3
3: ; preds = %0, %3
%4 = phi i32 [ 0, %0 ], [ %22, %3 ]
%5 = tail call %struct.list_head* (...) @list_new()
%6 = tail call i32 @list_append(%struct.list_head* %5, i8* %1, i8* %2)
%7 = tail call i32 @list_append(%struct.list_head* %5, i8* %1, i8* %2)
%8 = tail call i32 @list_append(%struct.list_head* %5, i8* %1, i8* %2)
%9 = tail call i32 @list_append(%struct.list_head* %5, i8* %1, i8* %2)
%10 = tail call i32 @list_append(%struct.list_head* %5, i8* %1, i8* %2)
%11 = tail call i32 @list_append(%struct.list_head* %5, i8* %1, i8* %2)
%12 = tail call i32 @list_append(%struct.list_head* %5, i8* %1, i8* %2)
%13 = tail call i32 @list_append(%struct.list_head* %5, i8* %1, i8* %2)
%14 = tail call i32 @list_append(%struct.list_head* %5, i8* %1, i8* %2)
%15 = tail call i32 @list_append(%struct.list_head* %5, i8* %1, i8* %2)
%16 = tail call i32 @list_insert(%struct.list_head* %5, i32 2, i8* %1, i8* %2)
%17 = tail call i32 @list_insert(%struct.list_head* %5, i32 0, i8* %1, i8* %2)
%18 = tail call i32 @list_insert(%struct.list_head* %5, i32 9, i8* %1, i8* %2)
%19 = tail call i32 @list_insert(%struct.list_head* %5, i32 4, i8* %1, i8* %2)
%20 = tail call i32 @list_remove(%struct.list_head* %5, i32 0)
%21 = tail call i32 @list_free(%struct.list_head* %5)
%22 = add nuw nsw i32 %4, 1
%23 = icmp eq i32 %22, 10000000
br i1 %23, label %24, label %3
24: ; preds = %3
%25 = tail call i32 @free(i8* %1)
%26 = tail call i32 @free(i8* %2)
ret i32 0
}