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

/* Variables and functions */
struct rk_rule *rk_do_merge_rules(struct rk_rule *, struct rk_rule *);
int /*<<< orphan*/ rk_rules_free(struct rk_rule *);
struct rk_rule *rk_sort_rule(struct rk_rule const *);
struct rk_rule *rk_merge_rules(const struct rk_rule *r1,
                               const struct rk_rule *r2) {
  struct rk_rule *t1, *t2;
  struct rk_rule *rules;
  t1 = rk_sort_rule(r1);
  if (!t1) {
    return NULL;
  }
  t2 = rk_sort_rule(r2);
  if (!t2) {
    rk_rules_free(t1);
    return NULL;
  }
  rules = rk_do_merge_rules(t1, t2);
  rk_rules_free(t1);
  rk_rules_free(t2);
  return rules;
}


x86 assembly (clang, -O0):
<rk_merge_rules>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <rk_sort_rule@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1165 <rk_merge_rules+0x35>
movq   $0x0,-0x8(%rbp)
jmp    11be <rk_merge_rules+0x8e>
mov    -0x18(%rbp),%rdi
call   1050 <rk_sort_rule@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1193 <rk_merge_rules+0x63>
mov    -0x20(%rbp),%rdi
call   1040 <rk_rules_free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11be <rk_merge_rules+0x8e>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <rk_do_merge_rules@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <rk_rules_free@plt>
mov    -0x28(%rbp),%rdi
call   1040 <rk_rules_free@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rk_merge_rules>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
call   1050 <rk_sort_rule@plt>
test   %rax,%rax
je     1170 <rk_merge_rules+0x40>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <rk_sort_rule@plt>
test   %rax,%rax
je     1175 <rk_merge_rules+0x45>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <rk_do_merge_rules@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <rk_rules_free@plt>
mov    %r15,%rbx
jmp    1178 <rk_merge_rules+0x48>
xor    %r14d,%r14d
jmp    1180 <rk_merge_rules+0x50>
xor    %r14d,%r14d
mov    %rbx,%rdi
call   1040 <rk_rules_free@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.rk_rule = type { i32 }
define %struct.rk_rule* @rk_merge_rules(%struct.rk_rule* %0, %struct.rk_rule* %1) {
%3 = alloca %struct.rk_rule*
%4 = alloca %struct.rk_rule*
%5 = alloca %struct.rk_rule*
%6 = alloca %struct.rk_rule*
%7 = alloca %struct.rk_rule*
%8 = alloca %struct.rk_rule*
store %struct.rk_rule* %0, %struct.rk_rule** %4
store %struct.rk_rule* %1, %struct.rk_rule** %5
%9 = load %struct.rk_rule*, %struct.rk_rule** %4
%10 = call %struct.rk_rule* @rk_sort_rule(%struct.rk_rule* %9)
store %struct.rk_rule* %10, %struct.rk_rule** %6
%11 = load %struct.rk_rule*, %struct.rk_rule** %6
%12 = icmp ne %struct.rk_rule* %11, null
br i1 %12, label %14, label %13
13: ; preds = %2
store %struct.rk_rule* null, %struct.rk_rule** %3
br label %31
14: ; preds = %2
%15 = load %struct.rk_rule*, %struct.rk_rule** %5
%16 = call %struct.rk_rule* @rk_sort_rule(%struct.rk_rule* %15)
store %struct.rk_rule* %16, %struct.rk_rule** %7
%17 = load %struct.rk_rule*, %struct.rk_rule** %7
%18 = icmp ne %struct.rk_rule* %17, null
br i1 %18, label %22, label %19
19: ; preds = %14
%20 = load %struct.rk_rule*, %struct.rk_rule** %6
%21 = call i32 @rk_rules_free(%struct.rk_rule* %20)
store %struct.rk_rule* null, %struct.rk_rule** %3
br label %31
22: ; preds = %14
%23 = load %struct.rk_rule*, %struct.rk_rule** %6
%24 = load %struct.rk_rule*, %struct.rk_rule** %7
%25 = call %struct.rk_rule* @rk_do_merge_rules(%struct.rk_rule* %23, %struct.rk_rule* %24)
store %struct.rk_rule* %25, %struct.rk_rule** %8
%26 = load %struct.rk_rule*, %struct.rk_rule** %6
%27 = call i32 @rk_rules_free(%struct.rk_rule* %26)
%28 = load %struct.rk_rule*, %struct.rk_rule** %7
%29 = call i32 @rk_rules_free(%struct.rk_rule* %28)
%30 = load %struct.rk_rule*, %struct.rk_rule** %8
store %struct.rk_rule* %30, %struct.rk_rule** %3
br label %31
31: ; preds = %22, %19, %13
%32 = load %struct.rk_rule*, %struct.rk_rule** %3
ret %struct.rk_rule* %32
}

LLVM IR (-O2):
%struct.rk_rule = type { i32 }
define %struct.rk_rule* @rk_merge_rules(%struct.rk_rule* %0, %struct.rk_rule* %1) {
%3 = tail call %struct.rk_rule* @rk_sort_rule(%struct.rk_rule* %0)
%4 = icmp eq %struct.rk_rule* %3, null
br i1 %4, label %15, label %5
5: ; preds = %2
%6 = tail call %struct.rk_rule* @rk_sort_rule(%struct.rk_rule* %1)
%7 = icmp eq %struct.rk_rule* %6, null
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = tail call %struct.rk_rule* @rk_do_merge_rules(%struct.rk_rule* %3, %struct.rk_rule* %6)
%10 = tail call i32 @rk_rules_free(%struct.rk_rule* %3)
br label %11
11: ; preds = %5, %8
%12 = phi %struct.rk_rule* [ %6, %8 ], [ %3, %5 ]
%13 = phi %struct.rk_rule* [ %9, %8 ], [ null, %5 ]
%14 = tail call i32 @rk_rules_free(%struct.rk_rule* %12)
br label %15
15: ; preds = %11, %2
%16 = phi %struct.rk_rule* [ null, %2 ], [ %13, %11 ]
ret %struct.rk_rule* %16
}