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

/* Variables and functions */
struct list_item *list_add(struct list *, void *);
int /*<<< orphan*/ list_contains(struct list *, int (*)(void *, void *),
                                 void *);
struct list_item *list_add_unique(struct list *target,
                                  int (*cmp)(void *, void *), void *data) {
  if (!list_contains(target, cmp, data))
    return list_add(target, data);
  return NULL;
}


x86 assembly (clang, -O0):
<list_add_unique>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <list_contains@plt>
cmp    $0x0,%eax
jne    1164 <list_add_unique+0x44>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <list_add@plt>
mov    %rax,-0x8(%rbp)
jmp    116c <list_add_unique+0x4c>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<list_add_unique>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%rbx
call   1040 <list_contains@plt>
test   %eax,%eax
je     113d <list_add_unique+0x1d>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <list_add@plt>

LLVM IR (-O0):
%struct.list_item = type { i32 }
%struct.list = type { i32 }
define %struct.list_item* @list_add_unique(%struct.list* %0, i32 (i8*, i8*)* %1, i8* %2) {
%4 = alloca %struct.list_item*
%5 = alloca %struct.list*
%6 = alloca i32 (i8*, i8*)*
%7 = alloca i8*
store %struct.list* %0, %struct.list** %5
store i32 (i8*, i8*)* %1, i32 (i8*, i8*)** %6
store i8* %2, i8** %7
%8 = load %struct.list*, %struct.list** %5
%9 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %6
%10 = load i8*, i8** %7
%11 = call i32 @list_contains(%struct.list* %8, i32 (i8*, i8*)* %9, i8* %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %3
%14 = load %struct.list*, %struct.list** %5
%15 = load i8*, i8** %7
%16 = call %struct.list_item* @list_add(%struct.list* %14, i8* %15)
store %struct.list_item* %16, %struct.list_item** %4
br label %18
17: ; preds = %3
store %struct.list_item* null, %struct.list_item** %4
br label %18
18: ; preds = %17, %13
%19 = load %struct.list_item*, %struct.list_item** %4
ret %struct.list_item* %19
}

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