#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_node {
  int dummy;
};
struct list {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ free(struct list_node *);
struct list_node *list_find_node(struct list *, int /*<<< orphan*/ *, void *);
int list_remove_node(struct list *, struct list_node *);
int list_remove(struct list *list, void *data) {
  struct list_node *node = list_find_node(list, NULL, data);
  if (node == NULL)
    return (-1);
  int ret = list_remove_node(list, node);
  free(node);
  return ret;
}


x86 assembly (clang, -O0):
<list_remove>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%esi
call   1040 <list_find_node@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    116c <list_remove+0x3c>
movl   $0xffffffff,-0x4(%rbp)
jmp    118b <list_remove+0x5b>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <list_remove_node@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<list_remove>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rdx
mov    %rdi,%r14
xor    %esi,%esi
call   1040 <list_find_node@plt>
test   %rax,%rax
je     1162 <list_remove+0x32>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1050 <list_remove_node@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
jmp    1167 <list_remove+0x37>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.list = type { i32 }
%struct.list_node = type { i32 }
define i32 @list_remove(%struct.list* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.list*
%5 = alloca i8*
%6 = alloca %struct.list_node*
%7 = alloca i32
store %struct.list* %0, %struct.list** %4
store i8* %1, i8** %5
%8 = load %struct.list*, %struct.list** %4
%9 = load i8*, i8** %5
%10 = call %struct.list_node* @list_find_node(%struct.list* %8, i32* null, i8* %9)
store %struct.list_node* %10, %struct.list_node** %6
%11 = load %struct.list_node*, %struct.list_node** %6
%12 = icmp eq %struct.list_node* %11, null
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 -1, i32* %3
br label %21
14: ; preds = %2
%15 = load %struct.list*, %struct.list** %4
%16 = load %struct.list_node*, %struct.list_node** %6
%17 = call i32 @list_remove_node(%struct.list* %15, %struct.list_node* %16)
store i32 %17, i32* %7
%18 = load %struct.list_node*, %struct.list_node** %6
%19 = call i32 @free(%struct.list_node* %18)
%20 = load i32, i32* %7
store i32 %20, i32* %3
br label %21
21: ; preds = %14, %13
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
%struct.list = type { i32 }
%struct.list_node = type { i32 }
define i32 @list_remove(%struct.list* %0, i8* %1) {
%3 = tail call %struct.list_node* @list_find_node(%struct.list* %0, i32* null, i8* %1)
%4 = icmp eq %struct.list_node* %3, null
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i32 @list_remove_node(%struct.list* %0, %struct.list_node* %3)
%7 = tail call i32 @free(%struct.list_node* %3)
br label %8
8: ; preds = %2, %5
%9 = phi i32 [ %6, %5 ], [ -1, %2 ]
ret i32 %9
}