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

/* Variables and functions */
int /*<<< orphan*/ destroy_seq(int **, int);
int **new_sequence(int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int slist_append(struct slist_node **, int *, int);
int slist_remove_head(struct slist_node **);
void test_remove_head(void) {
  int **seq = new_sequence(0, 10);
  int i = 0;
  struct slist_node *head = NULL;
  for (i = 0; i < 10; i++) {
    if (-1 == slist_append(&head, seq[i], sizeof(int)))
      printf("[!] failed to insert %d\n", *seq[i]);
  }
  printf("[+] destroying the list with remove_head\n");
  for (i = 0; i < 10; i++) {
    if (-1 == slist_remove_head(&head))
      printf("[!] failed to remove head!\n");
  }
  destroy_seq(seq, 10);
  printf("[+] remove_head complete\n");
}


x86 assembly (clang, -O0):
<test_remove_head>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
xor    %edi,%edi
mov    $0xa,%esi
call   1070 <new_sequence@plt>
mov    %rax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jge    11e0 <test_remove_head+0x90>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    -0x18(%rbp),%rdi
mov    $0x4,%edx
call   1050 <slist_append@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11cd <test_remove_head+0x7d>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    (%rax),%esi
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d2 <test_remove_head+0x82>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    117e <test_remove_head+0x2e>
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jge    1238 <test_remove_head+0xe8>
lea    -0x18(%rbp),%rdi
call   1060 <slist_remove_head@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1225 <test_remove_head+0xd5>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    122a <test_remove_head+0xda>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11f5 <test_remove_head+0xa5>
mov    -0x8(%rbp),%rdi
mov    $0xa,%esi
call   1040 <destroy_seq@plt>
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_remove_head>:
push   %rbx
sub    $0x10,%rsp
xor    %edi,%edi
mov    $0xa,%esi
call   1080 <new_sequence@plt>
mov    %rax,%rbx
movq   $0x0,0x8(%rsp)
mov    (%rax),%rsi
lea    0x8(%rsp),%rdi
mov    $0x4,%edx
call   1060 <slist_append@plt>
cmp    $0xffffffff,%eax
jne    11a7 <test_remove_head+0x47>
mov    (%rbx),%rax
mov    (%rax),%esi
lea    0xe60(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rbx),%rsi
lea    0x8(%rsp),%rdi
mov    $0x4,%edx
call   1060 <slist_append@plt>
cmp    $0xffffffff,%eax
jne    11d3 <test_remove_head+0x73>
mov    0x8(%rbx),%rax
mov    (%rax),%esi
lea    0xe34(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rbx),%rsi
lea    0x8(%rsp),%rdi
mov    $0x4,%edx
call   1060 <slist_append@plt>
cmp    $0xffffffff,%eax
jne    11ff <test_remove_head+0x9f>
mov    0x10(%rbx),%rax
mov    (%rax),%esi
lea    0xe08(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x18(%rbx),%rsi
lea    0x8(%rsp),%rdi
mov    $0x4,%edx
call   1060 <slist_append@plt>
cmp    $0xffffffff,%eax
jne    122b <test_remove_head+0xcb>
mov    0x18(%rbx),%rax
mov    (%rax),%esi
lea    0xddc(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x20(%rbx),%rsi
lea    0x8(%rsp),%rdi
mov    $0x4,%edx
call   1060 <slist_append@plt>
cmp    $0xffffffff,%eax
jne    1257 <test_remove_head+0xf7>
mov    0x20(%rbx),%rax
mov    (%rax),%esi
lea    0xdb0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x28(%rbx),%rsi
lea    0x8(%rsp),%rdi
mov    $0x4,%edx
call   1060 <slist_append@plt>
cmp    $0xffffffff,%eax
jne    1283 <test_remove_head+0x123>
mov    0x28(%rbx),%rax
mov    (%rax),%esi
lea    0xd84(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x30(%rbx),%rsi
lea    0x8(%rsp),%rdi
mov    $0x4,%edx
call   1060 <slist_append@plt>
cmp    $0xffffffff,%eax
jne    12af <test_remove_head+0x14f>
mov    0x30(%rbx),%rax
mov    (%rax),%esi
lea    0xd58(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x38(%rbx),%rsi
lea    0x8(%rsp),%rdi
mov    $0x4,%edx
call   1060 <slist_append@plt>
cmp    $0xffffffff,%eax
jne    12db <test_remove_head+0x17b>
mov    0x38(%rbx),%rax
mov    (%rax),%esi
lea    0xd2c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x40(%rbx),%rsi
lea    0x8(%rsp),%rdi
mov    $0x4,%edx
call   1060 <slist_append@plt>
cmp    $0xffffffff,%eax
jne    1307 <test_remove_head+0x1a7>
mov    0x40(%rbx),%rax
mov    (%rax),%esi
lea    0xd00(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x48(%rbx),%rsi
lea    0x8(%rsp),%rdi
mov    $0x4,%edx
call   1060 <slist_append@plt>
cmp    $0xffffffff,%eax
jne    1333 <test_remove_head+0x1d3>
mov    0x48(%rbx),%rax
mov    (%rax),%esi
lea    0xcd4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xcdf(%rip),%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%rdi
call   1070 <slist_remove_head@plt>
cmp    $0xffffffff,%eax
jne    135a <test_remove_head+0x1fa>
lea    0xd06(%rip),%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%rdi
call   1070 <slist_remove_head@plt>
cmp    $0xffffffff,%eax
jne    1375 <test_remove_head+0x215>
lea    0xceb(%rip),%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%rdi
call   1070 <slist_remove_head@plt>
cmp    $0xffffffff,%eax
jne    1390 <test_remove_head+0x230>
lea    0xcd0(%rip),%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%rdi
call   1070 <slist_remove_head@plt>
cmp    $0xffffffff,%eax
jne    13ab <test_remove_head+0x24b>
lea    0xcb5(%rip),%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%rdi
call   1070 <slist_remove_head@plt>
cmp    $0xffffffff,%eax
jne    13c6 <test_remove_head+0x266>
lea    0xc9a(%rip),%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%rdi
call   1070 <slist_remove_head@plt>
cmp    $0xffffffff,%eax
jne    13e1 <test_remove_head+0x281>
lea    0xc7f(%rip),%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%rdi
call   1070 <slist_remove_head@plt>
cmp    $0xffffffff,%eax
jne    13fc <test_remove_head+0x29c>
lea    0xc64(%rip),%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%rdi
call   1070 <slist_remove_head@plt>
cmp    $0xffffffff,%eax
jne    1417 <test_remove_head+0x2b7>
lea    0xc49(%rip),%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%rdi
call   1070 <slist_remove_head@plt>
cmp    $0xffffffff,%eax
jne    1432 <test_remove_head+0x2d2>
lea    0xc2e(%rip),%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%rdi
call   1070 <slist_remove_head@plt>
cmp    $0xffffffff,%eax
jne    144d <test_remove_head+0x2ed>
lea    0xc13(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1050 <destroy_seq@plt>
lea    0xbe1(%rip),%rdi
call   1030 <puts@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.slist_node = type { i32 }
@.str = [25 x i8] c"[!] failed to insert %d\0A\00"
@.str.1 = [42 x i8] c"[+] destroying the list with remove_head\0A\00"
@.str.2 = [28 x i8] c"[!] failed to remove head!\0A\00"
@.str.3 = [26 x i8] c"[+] remove_head complete\0A\00"
define void @test_remove_head() {
%1 = alloca i32**
%2 = alloca i32
%3 = alloca %struct.slist_node*
%4 = call i32** @new_sequence(i32 0, i32 10)
store i32** %4, i32*** %1
store i32 0, i32* %2
store %struct.slist_node* null, %struct.slist_node** %3
store i32 0, i32* %2
br label %5
5: ; preds = %25, %0
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 10
br i1 %7, label %8, label %28
8: ; preds = %5
%9 = load i32**, i32*** %1
%10 = load i32, i32* %2
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i32*, i32** %9, i64 %11
%13 = load i32*, i32** %12
%14 = call i32 @slist_append(%struct.slist_node** %3, i32* %13, i32 4)
%15 = icmp eq i32 -1, %14
br i1 %15, label %16, label %24
16: ; preds = %8
%17 = load i32**, i32*** %1
%18 = load i32, i32* %2
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32*, i32** %17, i64 %19
%21 = load i32*, i32** %20
%22 = load i32, i32* %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %16, %8
br label %25
25: ; preds = %24
%26 = load i32, i32* %2
%27 = add nsw i32 %26, 1
store i32 %27, i32* %2
br label %5
28: ; preds = %5
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %2
br label %30
30: ; preds = %39, %28
%31 = load i32, i32* %2
%32 = icmp slt i32 %31, 10
br i1 %32, label %33, label %42
33: ; preds = %30
%34 = call i32 @slist_remove_head(%struct.slist_node** %3)
%35 = icmp eq i32 -1, %34
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %38
38: ; preds = %36, %33
br label %39
39: ; preds = %38
%40 = load i32, i32* %2
%41 = add nsw i32 %40, 1
store i32 %41, i32* %2
br label %30
42: ; preds = %30
%43 = load i32**, i32*** %1
%44 = call i32 @destroy_seq(i32** %43, i32 10)
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.slist_node = type { i32 }
@.str = [25 x i8] c"[!] failed to insert %d\0A\00"
@str = [41 x i8] c"[+] destroying the list with remove_head\00"
@str.4 = [25 x i8] c"[+] remove_head complete\00"
@str.5 = [27 x i8] c"[!] failed to remove head!\00"
define void @test_remove_head() {
%1 = alloca %struct.slist_node*
%2 = tail call i32** @new_sequence(i32 0, i32 10)
%3 = bitcast %struct.slist_node** %1 to i8*
store %struct.slist_node* null, %struct.slist_node** %1
%4 = load i32*, i32** %2
%5 = call i32 @slist_append(%struct.slist_node** %1, i32* %4, i32 4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = load i32*, i32** %2
%9 = load i32, i32* %8
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %11
11: ; preds = %0, %7
%12 = getelementptr inbounds i32*, i32** %2, i64 1
%13 = load i32*, i32** %12
%14 = call i32 @slist_append(%struct.slist_node** %1, i32* %13, i32 4)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = load i32*, i32** %12
%18 = load i32, i32* %17
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %16, %11
%21 = getelementptr inbounds i32*, i32** %2, i64 2
%22 = load i32*, i32** %21
%23 = call i32 @slist_append(%struct.slist_node** %1, i32* %22, i32 4)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %29
25: ; preds = %20
%26 = load i32*, i32** %21
%27 = load i32, i32* %26
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %25, %20
%30 = getelementptr inbounds i32*, i32** %2, i64 3
%31 = load i32*, i32** %30
%32 = call i32 @slist_append(%struct.slist_node** %1, i32* %31, i32 4)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %38
34: ; preds = %29
%35 = load i32*, i32** %30
%36 = load i32, i32* %35
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %36)
br label %38
38: ; preds = %34, %29
%39 = getelementptr inbounds i32*, i32** %2, i64 4
%40 = load i32*, i32** %39
%41 = call i32 @slist_append(%struct.slist_node** %1, i32* %40, i32 4)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %47
43: ; preds = %38
%44 = load i32*, i32** %39
%45 = load i32, i32* %44
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %45)
br label %47
47: ; preds = %43, %38
%48 = getelementptr inbounds i32*, i32** %2, i64 5
%49 = load i32*, i32** %48
%50 = call i32 @slist_append(%struct.slist_node** %1, i32* %49, i32 4)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %56
52: ; preds = %47
%53 = load i32*, i32** %48
%54 = load i32, i32* %53
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %54)
br label %56
56: ; preds = %52, %47
%57 = getelementptr inbounds i32*, i32** %2, i64 6
%58 = load i32*, i32** %57
%59 = call i32 @slist_append(%struct.slist_node** %1, i32* %58, i32 4)
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %65
61: ; preds = %56
%62 = load i32*, i32** %57
%63 = load i32, i32* %62
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %63)
br label %65
65: ; preds = %61, %56
%66 = getelementptr inbounds i32*, i32** %2, i64 7
%67 = load i32*, i32** %66
%68 = call i32 @slist_append(%struct.slist_node** %1, i32* %67, i32 4)
%69 = icmp eq i32 %68, -1
br i1 %69, label %70, label %74
70: ; preds = %65
%71 = load i32*, i32** %66
%72 = load i32, i32* %71
%73 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %72)
br label %74
74: ; preds = %70, %65
%75 = getelementptr inbounds i32*, i32** %2, i64 8
%76 = load i32*, i32** %75
%77 = call i32 @slist_append(%struct.slist_node** %1, i32* %76, i32 4)
%78 = icmp eq i32 %77, -1
br i1 %78, label %79, label %83
79: ; preds = %74
%80 = load i32*, i32** %75
%81 = load i32, i32* %80
%82 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %81)
br label %83
83: ; preds = %79, %74
%84 = getelementptr inbounds i32*, i32** %2, i64 9
%85 = load i32*, i32** %84
%86 = call i32 @slist_append(%struct.slist_node** %1, i32* %85, i32 4)
%87 = icmp eq i32 %86, -1
br i1 %87, label %88, label %92
88: ; preds = %83
%89 = load i32*, i32** %84
%90 = load i32, i32* %89
%91 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %90)
br label %92
92: ; preds = %88, %83
%93 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
%94 = call i32 @slist_remove_head(%struct.slist_node** %1)
%95 = icmp eq i32 %94, -1
br i1 %95, label %96, label %98
96: ; preds = %92
%97 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.5, i64 0, i64 0))
br label %98
98: ; preds = %92, %96
%99 = call i32 @slist_remove_head(%struct.slist_node** %1)
%100 = icmp eq i32 %99, -1
br i1 %100, label %101, label %103
101: ; preds = %98
%102 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.5, i64 0, i64 0))
br label %103
103: ; preds = %101, %98
%104 = call i32 @slist_remove_head(%struct.slist_node** %1)
%105 = icmp eq i32 %104, -1
br i1 %105, label %106, label %108
106: ; preds = %103
%107 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.5, i64 0, i64 0))
br label %108
108: ; preds = %106, %103
%109 = call i32 @slist_remove_head(%struct.slist_node** %1)
%110 = icmp eq i32 %109, -1
br i1 %110, label %111, label %113
111: ; preds = %108
%112 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.5, i64 0, i64 0))
br label %113
113: ; preds = %111, %108
%114 = call i32 @slist_remove_head(%struct.slist_node** %1)
%115 = icmp eq i32 %114, -1
br i1 %115, label %116, label %118
116: ; preds = %113
%117 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.5, i64 0, i64 0))
br label %118
118: ; preds = %116, %113
%119 = call i32 @slist_remove_head(%struct.slist_node** %1)
%120 = icmp eq i32 %119, -1
br i1 %120, label %121, label %123
121: ; preds = %118
%122 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.5, i64 0, i64 0))
br label %123
123: ; preds = %121, %118
%124 = call i32 @slist_remove_head(%struct.slist_node** %1)
%125 = icmp eq i32 %124, -1
br i1 %125, label %126, label %128
126: ; preds = %123
%127 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.5, i64 0, i64 0))
br label %128
128: ; preds = %126, %123
%129 = call i32 @slist_remove_head(%struct.slist_node** %1)
%130 = icmp eq i32 %129, -1
br i1 %130, label %131, label %133
131: ; preds = %128
%132 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.5, i64 0, i64 0))
br label %133
133: ; preds = %131, %128
%134 = call i32 @slist_remove_head(%struct.slist_node** %1)
%135 = icmp eq i32 %134, -1
br i1 %135, label %136, label %138
136: ; preds = %133
%137 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.5, i64 0, i64 0))
br label %138
138: ; preds = %136, %133
%139 = call i32 @slist_remove_head(%struct.slist_node** %1)
%140 = icmp eq i32 %139, -1
br i1 %140, label %141, label %143
141: ; preds = %138
%142 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.5, i64 0, i64 0))
br label %143
143: ; preds = %141, %138
%144 = call i32 @destroy_seq(i32** %2, i32 10)
%145 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.4, i64 0, i64 0))
ret void
}