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

/* Variables and functions */
int pc_adoption_sub(struct map_session_data *, struct map_session_data *,
                    struct map_session_data *);
struct map_session_data *pc_get_partner(struct map_session_data *);
int pc_adoption(struct map_session_data *sd, struct map_session_data *parent) {
  struct map_session_data *parent2;
  if (sd == NULL || parent == NULL)
    return 0;
  parent2 = pc_get_partner(parent);
  if (parent2)
    return pc_adoption_sub(sd, parent, parent2);
  return 0;
}


x86 assembly (clang, -O0):
<pc_adoption>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1146 <pc_adoption+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1152 <pc_adoption+0x32>
movl   $0x0,-0x4(%rbp)
jmp    118a <pc_adoption+0x6a>
mov    -0x18(%rbp),%rdi
call   1030 <pc_get_partner@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1183 <pc_adoption+0x63>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <pc_adoption_sub@plt>
mov    %eax,-0x4(%rbp)
jmp    118a <pc_adoption+0x6a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pc_adoption>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1156 <pc_adoption+0x36>
mov    %rsi,%rbx
test   %rsi,%rsi
je     1156 <pc_adoption+0x36>
mov    %rdi,%r14
mov    %rbx,%rdi
call   1030 <pc_get_partner@plt>
test   %rax,%rax
je     1156 <pc_adoption+0x36>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <pc_adoption_sub@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
%struct.map_session_data = type { i32 }
define i32 @pc_adoption(%struct.map_session_data* %0, %struct.map_session_data* %1) {
%3 = icmp eq %struct.map_session_data* %0, null
%4 = icmp eq %struct.map_session_data* %1, null
%5 = or i1 %3, %4
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = tail call %struct.map_session_data* @pc_get_partner(%struct.map_session_data* %1)
%8 = icmp eq %struct.map_session_data* %7, null
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = tail call i32 @pc_adoption_sub(%struct.map_session_data* %0, %struct.map_session_data* %1, %struct.map_session_data* %7)
br label %11
11: ; preds = %6, %2, %9
%12 = phi i32 [ %10, %9 ], [ 0, %2 ], [ 0, %6 ]
ret i32 %12
}