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

/* Variables and functions */
int /*<<< orphan*/ dlist_root_append(struct dlist_root *, int /*<<< orphan*/);
int /*<<< orphan*/ dlist_root_empty(struct dlist_root *);
int /*<<< orphan*/ dlist_root_pop(struct dlist_root *);
int /*<<< orphan*/ path_ends_dot_dot(struct dlist_root *);
int /*<<< orphan*/ path_pop(struct dlist_root *, struct inter *);
int /*<<< orphan*/ path_pop_back(struct dlist_root *, struct inter *);
scalar_t__ path_starts_dot_dot(struct dlist_root *);
void path_merge(struct dlist_root *start, struct dlist_root *end,
                struct inter *inter) {
  while (!dlist_root_empty(start) && path_starts_dot_dot(end) &&
         !path_ends_dot_dot(start)) {
    path_pop_back(start, inter);
    path_pop(end, inter);
  }
  while (!dlist_root_empty(end)) {
    dlist_root_append(start, dlist_root_pop(end));
  }
}


x86 assembly (clang, -O0):
<path_merge>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <dlist_root_empty@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
jne    11cc <path_merge+0x5c>
mov    -0x10(%rbp),%rdi
call   1050 <path_starts_dot_dot@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x19(%rbp)
je     11cc <path_merge+0x5c>
mov    -0x8(%rbp),%rdi
call   1080 <path_ends_dot_dot@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11dc <path_merge+0x6c>
jmp    11fb <path_merge+0x8b>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <path_pop_back@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <path_pop@plt>
jmp    1184 <path_merge+0x14>
jmp    1200 <path_merge+0x90>
mov    -0x10(%rbp),%rdi
call   1060 <dlist_root_empty@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    121e <path_merge+0xae>
jmp    123f <path_merge+0xcf>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <dlist_root_pop@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
call   1070 <dlist_root_append@plt>
jmp    1200 <path_merge+0x90>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_merge>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
call   1060 <dlist_root_empty@plt>
test   %eax,%eax
jne    11d2 <path_merge+0x62>
mov    %rbx,%rdi
call   1050 <path_starts_dot_dot@plt>
test   %rax,%rax
je     11d2 <path_merge+0x62>
mov    %r14,%rdi
call   1080 <path_ends_dot_dot@plt>
test   %eax,%eax
jne    11d2 <path_merge+0x62>
mov    %r14,%rdi
mov    %r15,%rsi
call   1090 <path_pop_back@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <path_pop@plt>
mov    %r14,%rdi
jmp    117e <path_merge+0xe>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <dlist_root_pop@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1070 <dlist_root_append@plt>
mov    %rbx,%rdi
call   1060 <dlist_root_empty@plt>
test   %eax,%eax
je     11c0 <path_merge+0x50>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.dlist_root = type { i32 }
%struct.inter = type { i32 }
define void @path_merge(%struct.dlist_root* %0, %struct.dlist_root* %1, %struct.inter* %2) {
%4 = alloca %struct.dlist_root*
%5 = alloca %struct.dlist_root*
%6 = alloca %struct.inter*
store %struct.dlist_root* %0, %struct.dlist_root** %4
store %struct.dlist_root* %1, %struct.dlist_root** %5
store %struct.inter* %2, %struct.inter** %6
br label %7
7: ; preds = %22, %3
%8 = load %struct.dlist_root*, %struct.dlist_root** %4
%9 = call i32 @dlist_root_empty(%struct.dlist_root* %8)
%10 = icmp ne i32 %9, 0
br i1 %10, label %20, label %11
11: ; preds = %7
%12 = load %struct.dlist_root*, %struct.dlist_root** %5
%13 = call i64 @path_starts_dot_dot(%struct.dlist_root* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = load %struct.dlist_root*, %struct.dlist_root** %4
%17 = call i32 @path_ends_dot_dot(%struct.dlist_root* %16)
%18 = icmp ne i32 %17, 0
%19 = xor i1 %18, true
br label %20
20: ; preds = %15, %11, %7
%21 = phi i1 [ false, %11 ], [ false, %7 ], [ %19, %15 ]
br i1 %21, label %22, label %29
22: ; preds = %20
%23 = load %struct.dlist_root*, %struct.dlist_root** %4
%24 = load %struct.inter*, %struct.inter** %6
%25 = call i32 @path_pop_back(%struct.dlist_root* %23, %struct.inter* %24)
%26 = load %struct.dlist_root*, %struct.dlist_root** %5
%27 = load %struct.inter*, %struct.inter** %6
%28 = call i32 @path_pop(%struct.dlist_root* %26, %struct.inter* %27)
br label %7
29: ; preds = %20
br label %30
30: ; preds = %35, %29
%31 = load %struct.dlist_root*, %struct.dlist_root** %5
%32 = call i32 @dlist_root_empty(%struct.dlist_root* %31)
%33 = icmp ne i32 %32, 0
%34 = xor i1 %33, true
br i1 %34, label %35, label %40
35: ; preds = %30
%36 = load %struct.dlist_root*, %struct.dlist_root** %4
%37 = load %struct.dlist_root*, %struct.dlist_root** %5
%38 = call i32 @dlist_root_pop(%struct.dlist_root* %37)
%39 = call i32 @dlist_root_append(%struct.dlist_root* %36, i32 %38)
br label %30
40: ; preds = %30
ret void
}

LLVM IR (-O2):
%struct.dlist_root = type { i32 }
%struct.inter = type { i32 }
define void @path_merge(%struct.dlist_root* %0, %struct.dlist_root* %1, %struct.inter* %2) {
%4 = tail call i32 @dlist_root_empty(%struct.dlist_root* %0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %17
6: ; preds = %3, %12
%7 = tail call i64 @path_starts_dot_dot(%struct.dlist_root* %1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %17, label %9
9: ; preds = %6
%10 = tail call i32 @path_ends_dot_dot(%struct.dlist_root* %0)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %9
%13 = tail call i32 @path_pop_back(%struct.dlist_root* %0, %struct.inter* %2)
%14 = tail call i32 @path_pop(%struct.dlist_root* %1, %struct.inter* %2)
%15 = tail call i32 @dlist_root_empty(%struct.dlist_root* %0)
%16 = icmp eq i32 %15, 0
br i1 %16, label %6, label %17
17: ; preds = %9, %6, %12, %3
%18 = tail call i32 @dlist_root_empty(%struct.dlist_root* %1)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %17, %20
%21 = tail call i32 @dlist_root_pop(%struct.dlist_root* %1)
%22 = tail call i32 @dlist_root_append(%struct.dlist_root* %0, i32 %21)
%23 = tail call i32 @dlist_root_empty(%struct.dlist_root* %1)
%24 = icmp eq i32 %23, 0
br i1 %24, label %20, label %25
25: ; preds = %20, %17
ret void
}