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

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ link_to_final(int /*<<< orphan*/ *, struct typ *,
                                 struct typ *);
int typ_is_tentative(struct typ *);
void typ_link_to_existing_final(struct typ *dst, struct typ *src) {
  assert(!typ_is_tentative(dst));
  assert(typ_is_tentative(src));
  if (dst == src) {
    return;
  }
  link_to_final(NULL, dst, src);
}


x86 assembly (clang, -O0):
<typ_link_to_existing_final>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <typ_is_tentative@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1050 <typ_is_tentative@plt>
mov    %eax,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    117e <typ_link_to_existing_final+0x4e>
jmp    118f <typ_link_to_existing_final+0x5f>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%edi
call   1030 <link_to_final@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<typ_link_to_existing_final>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1050 <typ_is_tentative@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
mov    %r14,%rdi
call   1050 <typ_is_tentative@plt>
mov    %eax,%edi
call   1040 <assert@plt>
cmp    %r14,%rbx
je     1174 <typ_link_to_existing_final+0x44>
xor    %edi,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <link_to_final@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
%struct.typ = type { i32 }
define void @typ_link_to_existing_final(%struct.typ* %0, %struct.typ* %1) {
%3 = tail call i32 @typ_is_tentative(%struct.typ* %0)
%4 = icmp eq i32 %3, 0
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = tail call i32 @typ_is_tentative(%struct.typ* %1)
%8 = tail call i32 @assert(i32 %7)
%9 = icmp eq %struct.typ* %0, %1
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = tail call i32 @link_to_final(i32* null, %struct.typ* %0, %struct.typ* %1)
br label %12
12: ; preds = %2, %10
ret void
}