#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 */
typedef scalar_t__ bp;

/* Variables and functions */
int sizetoindex(unsigned int);
int list_remove(char *list[], void *bp) {
  int index = sizetoindex(((*(unsigned int *)(((char *)(bp)-4 - 8))) & ~0x7));
  void *prev = (void *)(*(unsigned int *)((char *)bp - 8));
  void *succ = (void *)(*(unsigned int *)((char *)bp - 4));
  if (prev != (void *)0) {
    (*(unsigned int *)((char *)prev - 4) = ((unsigned int)succ));
  } else {
    list[index] = (void *)succ;
  }
  if (succ != (void *)0) {
    (*(unsigned int *)((char *)succ - 8) = ((unsigned int)prev));
  }
  return 1;
}


x86 assembly (clang, -O0):
<list_remove>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    -0xc(%rax),%edi
and    $0xfffffff8,%edi
call   1030 <sizetoindex@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rax),%eax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x4(%rax),%eax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1165 <list_remove+0x55>
mov    -0x28(%rbp),%rax
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,-0x4(%rax)
jmp    1175 <list_remove+0x65>
mov    -0x28(%rbp),%rdx
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
cmpq   $0x0,-0x28(%rbp)
je     118d <list_remove+0x7d>
mov    -0x20(%rbp),%rax
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,-0x8(%rax)
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<list_remove>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    -0xc(%rsi),%edi
and    $0xfffffff8,%edi
call   1030 <sizetoindex@plt>
mov    -0x8(%rbx),%ecx
mov    -0x4(%rbx),%edx
test   %rcx,%rcx
je     1147 <list_remove+0x37>
mov    %edx,-0x4(%rcx)
test   %edx,%edx
je     113a <list_remove+0x2a>
mov    %ecx,-0x8(%rdx)
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
cltq
mov    %rdx,(%r14,%rax,8)
test   %edx,%edx
jne    1137 <list_remove+0x27>
jmp    113a <list_remove+0x2a>

LLVM IR (-O0):
define i32 @list_remove(i8** %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i8** %0, i8*** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = getelementptr inbounds i8, i8* %8, i64 -4
%10 = getelementptr inbounds i8, i8* %9, i64 -8
%11 = bitcast i8* %10 to i32*
%12 = load i32, i32* %11
%13 = and i32 %12, -8
%14 = call i32 @sizetoindex(i32 %13)
store i32 %14, i32* %5
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i64 -8
%17 = bitcast i8* %16 to i32*
%18 = load i32, i32* %17
%19 = zext i32 %18 to i64
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %6
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i64 -4
%23 = bitcast i8* %22 to i32*
%24 = load i32, i32* %23
%25 = zext i32 %24 to i64
%26 = inttoptr i64 %25 to i8*
store i8* %26, i8** %7
%27 = load i8*, i8** %6
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %35
29: ; preds = %2
%30 = load i8*, i8** %7
%31 = ptrtoint i8* %30 to i32
%32 = load i8*, i8** %6
%33 = getelementptr inbounds i8, i8* %32, i64 -4
%34 = bitcast i8* %33 to i32*
store i32 %31, i32* %34
br label %41
35: ; preds = %2
%36 = load i8*, i8** %7
%37 = load i8**, i8*** %3
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %37, i64 %39
store i8* %36, i8** %40
br label %41
41: ; preds = %35, %29
%42 = load i8*, i8** %7
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %50
44: ; preds = %41
%45 = load i8*, i8** %6
%46 = ptrtoint i8* %45 to i32
%47 = load i8*, i8** %7
%48 = getelementptr inbounds i8, i8* %47, i64 -8
%49 = bitcast i8* %48 to i32*
store i32 %46, i32* %49
br label %50
50: ; preds = %44, %41
ret i32 1
}

LLVM IR (-O2):
define i32 @list_remove(i8** nocapture writeonly %0, i8* nocapture %1) {
%3 = getelementptr inbounds i8, i8* %1, i64 -4
%4 = getelementptr inbounds i8, i8* %1, i64 -12
%5 = bitcast i8* %4 to i32*
%6 = load i32, i32* %5
%7 = and i32 %6, -8
%8 = tail call i32 @sizetoindex(i32 %7)
%9 = getelementptr inbounds i8, i8* %1, i64 -8
%10 = bitcast i8* %9 to i32*
%11 = load i32, i32* %10
%12 = bitcast i8* %3 to i32*
%13 = load i32, i32* %12
%14 = zext i32 %13 to i64
%15 = inttoptr i64 %14 to i8*
%16 = icmp eq i32 %11, 0
br i1 %16, label %22, label %17
17: ; preds = %2
%18 = zext i32 %11 to i64
%19 = inttoptr i64 %18 to i8*
%20 = getelementptr inbounds i8, i8* %19, i64 -4
%21 = bitcast i8* %20 to i32*
store i32 %13, i32* %21
br label %25
22: ; preds = %2
%23 = sext i32 %8 to i64
%24 = getelementptr inbounds i8*, i8** %0, i64 %23
store i8* %15, i8** %24
br label %25
25: ; preds = %22, %17
%26 = icmp eq i32 %13, 0
br i1 %26, label %30, label %27
27: ; preds = %25
%28 = getelementptr inbounds i8, i8* %15, i64 -8
%29 = bitcast i8* %28 to i32*
store i32 %11, i32* %29
br label %30
30: ; preds = %27, %25
ret i32 1
}