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

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ link_to_final(int /*<<< orphan*/ *, struct typ *,
                                 struct typ *);
int /*<<< orphan*/ link_to_tentative(int /*<<< orphan*/ *, struct typ *,
                                     struct typ *);
int /*<<< orphan*/ typ_is_generic_functor(struct typ *);
int /*<<< orphan*/ typ_is_tentative(struct typ *);
scalar_t__ typ_is_ungenarg(struct typ *);
void typ_link_tentative_functor(struct module *mod, struct typ *dst,
                                struct typ *src) {
  if (typ_is_ungenarg(src)) {
    return;
  }
  assert(mod != NULL);
  assert(typ_is_tentative(src));
  assert(typ_is_generic_functor(src));
  assert(typ_is_generic_functor(dst));
  if (dst == src) {
    return;
  }
  if (!typ_is_tentative(dst)) {
    link_to_final(NULL, dst, src);
  } else {
    link_to_tentative(NULL, dst, src);
  }
}


x86 assembly (clang, -O0):
<typ_link_tentative_functor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <typ_is_ungenarg@plt>
cmp    $0x0,%rax
je     118c <typ_link_tentative_functor+0x2c>
jmp    121a <typ_link_tentative_functor+0xba>
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1060 <typ_is_tentative@plt>
mov    %eax,%edi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1070 <typ_is_generic_functor@plt>
mov    %eax,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1070 <typ_is_generic_functor@plt>
mov    %eax,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    11e1 <typ_link_tentative_functor+0x81>
jmp    121a <typ_link_tentative_functor+0xba>
mov    -0x10(%rbp),%rdi
call   1060 <typ_is_tentative@plt>
cmp    $0x0,%eax
jne    1209 <typ_link_tentative_functor+0xa9>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%edi
call   1040 <link_to_final@plt>
jmp    121a <typ_link_tentative_functor+0xba>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%edi
call   1080 <link_to_tentative@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<typ_link_tentative_functor>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rdx,%rdi
call   1030 <typ_is_ungenarg@plt>
test   %rax,%rax
je     1181 <typ_link_tentative_functor+0x21>
pop    %rbx
pop    %r14
pop    %r15
ret
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1050 <assert@plt>
mov    %r15,%rdi
call   1060 <typ_is_tentative@plt>
mov    %eax,%edi
call   1050 <assert@plt>
mov    %r15,%rdi
call   1070 <typ_is_generic_functor@plt>
mov    %eax,%edi
call   1050 <assert@plt>
mov    %r14,%rdi
call   1070 <typ_is_generic_functor@plt>
mov    %eax,%edi
call   1050 <assert@plt>
cmp    %r15,%r14
je     117b <typ_link_tentative_functor+0x1b>
mov    %r14,%rdi
call   1060 <typ_is_tentative@plt>
xor    %edi,%edi
mov    %r14,%rsi
mov    %r15,%rdx
test   %eax,%eax
je     11df <typ_link_tentative_functor+0x7f>
pop    %rbx
pop    %r14
pop    %r15
jmp    1080 <link_to_tentative@plt>
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <link_to_final@plt>

LLVM IR (-O0):
%struct.module = type { i32 }
%struct.typ = type { i32 }
define void @typ_link_tentative_functor(%struct.module* %0, %struct.typ* %1, %struct.typ* %2) {
%4 = alloca %struct.module*
%5 = alloca %struct.typ*
%6 = alloca %struct.typ*
store %struct.module* %0, %struct.module** %4
store %struct.typ* %1, %struct.typ** %5
store %struct.typ* %2, %struct.typ** %6
%7 = load %struct.typ*, %struct.typ** %6
%8 = call i64 @typ_is_ungenarg(%struct.typ* %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %3
br label %41
11: ; preds = %3
%12 = load %struct.module*, %struct.module** %4
%13 = icmp ne %struct.module* %12, null
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load %struct.typ*, %struct.typ** %6
%17 = call i32 @typ_is_tentative(%struct.typ* %16)
%18 = call i32 @assert(i32 %17)
%19 = load %struct.typ*, %struct.typ** %6
%20 = call i32 @typ_is_generic_functor(%struct.typ* %19)
%21 = call i32 @assert(i32 %20)
%22 = load %struct.typ*, %struct.typ** %5
%23 = call i32 @typ_is_generic_functor(%struct.typ* %22)
%24 = call i32 @assert(i32 %23)
%25 = load %struct.typ*, %struct.typ** %5
%26 = load %struct.typ*, %struct.typ** %6
%27 = icmp eq %struct.typ* %25, %26
br i1 %27, label %28, label %29
28: ; preds = %11
br label %41
29: ; preds = %11
%30 = load %struct.typ*, %struct.typ** %5
%31 = call i32 @typ_is_tentative(%struct.typ* %30)
%32 = icmp ne i32 %31, 0
br i1 %32, label %37, label %33
33: ; preds = %29
%34 = load %struct.typ*, %struct.typ** %5
%35 = load %struct.typ*, %struct.typ** %6
%36 = call i32 @link_to_final(i32* null, %struct.typ* %34, %struct.typ* %35)
br label %41
37: ; preds = %29
%38 = load %struct.typ*, %struct.typ** %5
%39 = load %struct.typ*, %struct.typ** %6
%40 = call i32 @link_to_tentative(i32* null, %struct.typ* %38, %struct.typ* %39)
br label %41
41: ; preds = %10, %28, %37, %33
ret void
}

LLVM IR (-O2):
%struct.module = type { i32 }
%struct.typ = type { i32 }
define void @typ_link_tentative_functor(%struct.module* readnone %0, %struct.typ* %1, %struct.typ* %2) {
%4 = tail call i64 @typ_is_ungenarg(%struct.typ* %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %24
6: ; preds = %3
%7 = icmp ne %struct.module* %0, null
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = tail call i32 @typ_is_tentative(%struct.typ* %2)
%11 = tail call i32 @assert(i32 %10)
%12 = tail call i32 @typ_is_generic_functor(%struct.typ* %2)
%13 = tail call i32 @assert(i32 %12)
%14 = tail call i32 @typ_is_generic_functor(%struct.typ* %1)
%15 = tail call i32 @assert(i32 %14)
%16 = icmp eq %struct.typ* %1, %2
br i1 %16, label %24, label %17
17: ; preds = %6
%18 = tail call i32 @typ_is_tentative(%struct.typ* %1)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = tail call i32 @link_to_final(i32* null, %struct.typ* %1, %struct.typ* %2)
br label %24
22: ; preds = %17
%23 = tail call i32 @link_to_tentative(i32* null, %struct.typ* %1, %struct.typ* %2)
br label %24
24: ; preds = %6, %3, %22, %20
ret void
}