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

/* Variables and functions */
int /*<<< orphan*/ listcopy(struct node const *);
scalar_t__ listgetnode(struct node *, int);
struct node *listinsert(struct node *, int, int /*<<< orphan*/);
struct node *listinsertcopy(struct node *head, int index,
                            const struct node *insertant) {
  if (listgetnode(head, index) || index == 0)
    head = listinsert(head, index, listcopy(insertant));
  return head;
}


x86 assembly (clang, -O0):
<listinsertcopy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <listgetnode@plt>
cmp    $0x0,%rax
jne    1163 <listinsertcopy+0x33>
cmpl   $0x0,-0xc(%rbp)
jne    118c <listinsertcopy+0x5c>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <listcopy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    %eax,%edx
call   1030 <listinsert@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<listinsertcopy>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %esi,%ebx
mov    %rdi,%r14
call   1040 <listgetnode@plt>
test   %ebx,%ebx
je     1154 <listinsertcopy+0x24>
test   %rax,%rax
jne    1154 <listinsertcopy+0x24>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %r15,%rdi
call   1050 <listcopy@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %eax,%edx
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <listinsert@plt>

LLVM IR (-O0):
%struct.node = type { i32 }
define %struct.node* @listinsertcopy(%struct.node* %0, i32 %1, %struct.node* %2) {
%4 = alloca %struct.node*
%5 = alloca i32
%6 = alloca %struct.node*
store %struct.node* %0, %struct.node** %4
store i32 %1, i32* %5
store %struct.node* %2, %struct.node** %6
%7 = load %struct.node*, %struct.node** %4
%8 = load i32, i32* %5
%9 = call i64 @listgetnode(%struct.node* %7, i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %3
%12 = load i32, i32* %5
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %11, %3
%15 = load %struct.node*, %struct.node** %4
%16 = load i32, i32* %5
%17 = load %struct.node*, %struct.node** %6
%18 = call i32 @listcopy(%struct.node* %17)
%19 = call %struct.node* @listinsert(%struct.node* %15, i32 %16, i32 %18)
store %struct.node* %19, %struct.node** %4
br label %20
20: ; preds = %14, %11
%21 = load %struct.node*, %struct.node** %4
ret %struct.node* %21
}

LLVM IR (-O2):
%struct.node = type { i32 }
define %struct.node* @listinsertcopy(%struct.node* %0, i32 %1, %struct.node* %2) {
%4 = tail call i64 @listgetnode(%struct.node* %0, i32 %1)
%5 = icmp ne i64 %4, 0
%6 = icmp eq i32 %1, 0
%7 = or i1 %6, %5
br i1 %7, label %8, label %11
8: ; preds = %3
%9 = tail call i32 @listcopy(%struct.node* %2)
%10 = tail call %struct.node* @listinsert(%struct.node* %0, i32 %1, i32 %9)
br label %11
11: ; preds = %3, %8
%12 = phi %struct.node* [ %10, %8 ], [ %0, %3 ]
ret %struct.node* %12
}