#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 list_append_after_node(struct list *, struct list_node *, void *);
struct list_node *list_find_node(struct list *, int /*<<< orphan*/ *, void *);
int list_append_after(struct list *list, void *target, void *data) {
  struct list_node *node = list_find_node(list, NULL, target);
  if (node == NULL)
    return (-1);
  return list_append_after_node(list, node, data);
}


x86 assembly (clang, -O0):
<list_append_after>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%esi
call   1040 <list_find_node@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1160 <list_append_after+0x40>
movl   $0xffffffff,-0x4(%rbp)
jmp    1174 <list_append_after+0x54>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <list_append_after_node@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<list_append_after>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rdx
mov    %rdi,%rbx
xor    %esi,%esi
call   1040 <list_find_node@plt>
test   %rax,%rax
je     114e <list_append_after+0x2e>
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <list_append_after_node@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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