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

/* Variables and functions */
int /*<<< orphan*/ text_link(struct piece *, struct piece *);
int /*<<< orphan*/ text_unlink(struct piece *, struct piece *);
void text_relink(struct piece *x, struct piece *u, struct piece *v) {
  if (x && v)
    text_unlink(x, v);
  text_link(x, u);
  text_link(u, v);
}


x86 assembly (clang, -O0):
<text_relink>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1157 <text_relink+0x37>
cmpq   $0x0,-0x18(%rbp)
je     1157 <text_relink+0x37>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <text_unlink@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <text_link@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <text_link@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<text_relink>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
je     1143 <text_relink+0x23>
test   %r15,%r15
je     1143 <text_relink+0x23>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <text_unlink@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <text_link@plt>
mov    %r14,%rdi
mov    %r15,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <text_link@plt>

LLVM IR (-O0):
%struct.piece = type { i32 }
define void @text_relink(%struct.piece* %0, %struct.piece* %1, %struct.piece* %2) {
%4 = alloca %struct.piece*
%5 = alloca %struct.piece*
%6 = alloca %struct.piece*
store %struct.piece* %0, %struct.piece** %4
store %struct.piece* %1, %struct.piece** %5
store %struct.piece* %2, %struct.piece** %6
%7 = load %struct.piece*, %struct.piece** %4
%8 = icmp ne %struct.piece* %7, null
br i1 %8, label %9, label %16
9: ; preds = %3
%10 = load %struct.piece*, %struct.piece** %6
%11 = icmp ne %struct.piece* %10, null
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load %struct.piece*, %struct.piece** %4
%14 = load %struct.piece*, %struct.piece** %6
%15 = call i32 @text_unlink(%struct.piece* %13, %struct.piece* %14)
br label %16
16: ; preds = %12, %9, %3
%17 = load %struct.piece*, %struct.piece** %4
%18 = load %struct.piece*, %struct.piece** %5
%19 = call i32 @text_link(%struct.piece* %17, %struct.piece* %18)
%20 = load %struct.piece*, %struct.piece** %5
%21 = load %struct.piece*, %struct.piece** %6
%22 = call i32 @text_link(%struct.piece* %20, %struct.piece* %21)
ret void
}

LLVM IR (-O2):
%struct.piece = type { i32 }
define void @text_relink(%struct.piece* %0, %struct.piece* %1, %struct.piece* %2) {
%4 = icmp ne %struct.piece* %0, null
%5 = icmp ne %struct.piece* %2, null
%6 = and i1 %4, %5
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @text_unlink(%struct.piece* %0, %struct.piece* %2)
br label %9
9: ; preds = %7, %3
%10 = tail call i32 @text_link(%struct.piece* %0, %struct.piece* %1)
%11 = tail call i32 @text_link(%struct.piece* %1, %struct.piece* %2)
ret void
}