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

/* Variables and functions */
struct confctl_var *confctl_var_first_child(struct confctl_var *);
scalar_t__ confctl_var_has_children(struct confctl_var *);
scalar_t__ confctl_var_has_value(struct confctl_var *);
int /*<<< orphan*/ confctl_var_name(struct confctl_var *);
struct confctl_var *confctl_var_next(struct confctl_var *);
int /*<<< orphan*/ confctl_var_set_value(struct confctl_var *,
                                         int /*<<< orphan*/);
int /*<<< orphan*/ confctl_var_value(struct confctl_var *);
int /*<<< orphan*/ cv_mark(struct confctl_var *, int);
int /*<<< orphan*/ errx(int, char *);
scalar_t__ strcmp(int /*<<< orphan*/, int /*<<< orphan*/);
void cv_merge_existing(struct confctl_var *cv, struct confctl_var *newcv) {
  struct confctl_var *child, *newchild, *next, *newnext;
  if (strcmp(confctl_var_name(cv), confctl_var_name(newcv)) != 0)
    return;
  if (confctl_var_has_value(newcv)) {
    if (confctl_var_has_children(cv))
      errx(1, "cannot replace container node with leaf node");
    confctl_var_set_value(cv, confctl_var_value(newcv));
    cv_mark(newcv, true);
    return;
  }
  newchild = confctl_var_first_child(newcv);
  while (newchild != NULL) {
    newnext = confctl_var_next(newchild);
    child = confctl_var_first_child(cv);
    while (child != NULL) {
      next = confctl_var_next(child);
      cv_merge_existing(child, newchild);
      child = next;
    }
    newchild = newnext;
  }
}


x86 assembly (clang, -O0):
<cv_merge_existing>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <confctl_var_name@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <confctl_var_name@plt>
mov    -0x34(%rbp),%edi
mov    %eax,%esi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     11ee <cv_merge_existing+0x3e>
jmp    12c5 <cv_merge_existing+0x115>
mov    -0x10(%rbp),%rdi
call   10c0 <confctl_var_has_value@plt>
cmp    $0x0,%rax
je     1254 <cv_merge_existing+0xa4>
mov    -0x8(%rbp),%rdi
call   1090 <confctl_var_has_children@plt>
cmp    $0x0,%rax
je     1225 <cv_merge_existing+0x75>
mov    $0x1,%edi
lea    0xde0(%rip),%rsi
call   1050 <errx@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   10d0 <confctl_var_value@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
call   1060 <confctl_var_set_value@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   10b0 <cv_mark@plt>
jmp    12c5 <cv_merge_existing+0x115>
mov    -0x10(%rbp),%rdi
call   1030 <confctl_var_first_child@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     12c5 <cv_merge_existing+0x115>
mov    -0x20(%rbp),%rdi
call   10a0 <confctl_var_next@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <confctl_var_first_child@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12b8 <cv_merge_existing+0x108>
mov    -0x18(%rbp),%rdi
call   10a0 <confctl_var_next@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <cv_merge_existing@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1286 <cv_merge_existing+0xd6>
mov    -0x30(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1261 <cv_merge_existing+0xb1>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cv_merge_existing>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1080 <confctl_var_name@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1080 <confctl_var_name@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11e6 <cv_merge_existing+0x36>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
call   10c0 <confctl_var_has_value@plt>
test   %rax,%rax
je     1239 <cv_merge_existing+0x89>
mov    %r15,%rdi
call   1090 <confctl_var_has_children@plt>
test   %rax,%rax
je     1211 <cv_merge_existing+0x61>
lea    0xdf9(%rip),%rsi
mov    $0x1,%edi
call   1050 <errx@plt>
mov    %r14,%rdi
call   10d0 <confctl_var_value@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1060 <confctl_var_set_value@plt>
mov    %r14,%rdi
mov    $0x1,%esi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    10b0 <cv_mark@plt>
mov    %r14,%rdi
call   1030 <confctl_var_first_child@plt>
test   %rax,%rax
je     11dc <cv_merge_existing+0x2c>
mov    %rax,%r12
jmp    1258 <cv_merge_existing+0xa8>
nopl   0x0(%rax,%rax,1)
mov    %r14,%r12
test   %r14,%r14
je     11dc <cv_merge_existing+0x2c>
mov    %r12,%rdi
call   10a0 <confctl_var_next@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1030 <confctl_var_first_child@plt>
test   %rax,%rax
je     1250 <cv_merge_existing+0xa0>
mov    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   10a0 <confctl_var_next@plt>
mov    %rax,%r13
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <cv_merge_existing@plt>
mov    %r13,%rbx
test   %r13,%r13
jne    1280 <cv_merge_existing+0xd0>
jmp    1250 <cv_merge_existing+0xa0>

LLVM IR (-O0):
%struct.confctl_var = type { i32 }
@.str = [45 x i8] c"cannot replace container node with leaf node\00"
define void @cv_merge_existing(%struct.confctl_var* %0, %struct.confctl_var* %1) {
%3 = alloca %struct.confctl_var*
%4 = alloca %struct.confctl_var*
%5 = alloca %struct.confctl_var*
%6 = alloca %struct.confctl_var*
%7 = alloca %struct.confctl_var*
%8 = alloca %struct.confctl_var*
store %struct.confctl_var* %0, %struct.confctl_var** %3
store %struct.confctl_var* %1, %struct.confctl_var** %4
%9 = load %struct.confctl_var*, %struct.confctl_var** %3
%10 = call i32 @confctl_var_name(%struct.confctl_var* %9)
%11 = load %struct.confctl_var*, %struct.confctl_var** %4
%12 = call i32 @confctl_var_name(%struct.confctl_var* %11)
%13 = call i64 @strcmp(i32 %10, i32 %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %2
br label %55
16: ; preds = %2
%17 = load %struct.confctl_var*, %struct.confctl_var** %4
%18 = call i64 @confctl_var_has_value(%struct.confctl_var* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %33
20: ; preds = %16
%21 = load %struct.confctl_var*, %struct.confctl_var** %3
%22 = call i64 @confctl_var_has_children(%struct.confctl_var* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = call i32 @errx(i32 1, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %24, %20
%27 = load %struct.confctl_var*, %struct.confctl_var** %3
%28 = load %struct.confctl_var*, %struct.confctl_var** %4
%29 = call i32 @confctl_var_value(%struct.confctl_var* %28)
%30 = call i32 @confctl_var_set_value(%struct.confctl_var* %27, i32 %29)
%31 = load %struct.confctl_var*, %struct.confctl_var** %4
%32 = call i32 @cv_mark(%struct.confctl_var* %31, i32 1)
br label %55
33: ; preds = %16
%34 = load %struct.confctl_var*, %struct.confctl_var** %4
%35 = call %struct.confctl_var* @confctl_var_first_child(%struct.confctl_var* %34)
store %struct.confctl_var* %35, %struct.confctl_var** %6
br label %36
36: ; preds = %53, %33
%37 = load %struct.confctl_var*, %struct.confctl_var** %6
%38 = icmp ne %struct.confctl_var* %37, null
br i1 %38, label %39, label %55
39: ; preds = %36
%40 = load %struct.confctl_var*, %struct.confctl_var** %6
%41 = call %struct.confctl_var* @confctl_var_next(%struct.confctl_var* %40)
store %struct.confctl_var* %41, %struct.confctl_var** %8
%42 = load %struct.confctl_var*, %struct.confctl_var** %3
%43 = call %struct.confctl_var* @confctl_var_first_child(%struct.confctl_var* %42)
store %struct.confctl_var* %43, %struct.confctl_var** %5
br label %44
44: ; preds = %47, %39
%45 = load %struct.confctl_var*, %struct.confctl_var** %5
%46 = icmp ne %struct.confctl_var* %45, null
br i1 %46, label %47, label %53
47: ; preds = %44
%48 = load %struct.confctl_var*, %struct.confctl_var** %5
%49 = call %struct.confctl_var* @confctl_var_next(%struct.confctl_var* %48)
store %struct.confctl_var* %49, %struct.confctl_var** %7
%50 = load %struct.confctl_var*, %struct.confctl_var** %5
%51 = load %struct.confctl_var*, %struct.confctl_var** %6
%52 = load %struct.confctl_var*, %struct.confctl_var** %7
store %struct.confctl_var* %52, %struct.confctl_var** %5
br label %44
53: ; preds = %44
%54 = load %struct.confctl_var*, %struct.confctl_var** %8
store %struct.confctl_var* %54, %struct.confctl_var** %6
br label %36
55: ; preds = %15, %26, %36
ret void
}

LLVM IR (-O2):
%struct.confctl_var = type { i32 }
@.str = [45 x i8] c"cannot replace container node with leaf node\00"
define void @cv_merge_existing(%struct.confctl_var* %0, %struct.confctl_var* %1) {
%3 = tail call i32 @confctl_var_name(%struct.confctl_var* %0)
%4 = tail call i32 @confctl_var_name(%struct.confctl_var* %1)
%5 = tail call i64 @strcmp(i32 %3, i32 %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %33
7: ; preds = %2
%8 = tail call i64 @confctl_var_has_value(%struct.confctl_var* %1)
%9 = icmp eq i64 %8, 0
br i1 %9, label %19, label %10
10: ; preds = %7
%11 = tail call i64 @confctl_var_has_children(%struct.confctl_var* %0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call i32 @errx(i32 1, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %10
%16 = tail call i32 @confctl_var_value(%struct.confctl_var* %1)
%17 = tail call i32 @confctl_var_set_value(%struct.confctl_var* %0, i32 %16)
%18 = tail call i32 @cv_mark(%struct.confctl_var* %1, i32 1)
br label %33
19: ; preds = %7
%20 = tail call %struct.confctl_var* @confctl_var_first_child(%struct.confctl_var* %1)
%21 = icmp eq %struct.confctl_var* %20, null
br i1 %21, label %33, label %24
22: ; preds = %29, %24
%23 = icmp eq %struct.confctl_var* %26, null
br i1 %23, label %33, label %24
24: ; preds = %19, %22
%25 = phi %struct.confctl_var* [ %26, %22 ], [ %20, %19 ]
%26 = tail call %struct.confctl_var* @confctl_var_next(%struct.confctl_var* %25)
%27 = tail call %struct.confctl_var* @confctl_var_first_child(%struct.confctl_var* %0)
%28 = icmp eq %struct.confctl_var* %27, null
br i1 %28, label %22, label %29
29: ; preds = %24, %29
%30 = phi %struct.confctl_var* [ %31, %29 ], [ %27, %24 ]
%31 = tail call %struct.confctl_var* @confctl_var_next(%struct.confctl_var* %30)
tail call void @cv_merge_existing(%struct.confctl_var* %30, %struct.confctl_var* %25)
%32 = icmp eq %struct.confctl_var* %31, null
br i1 %32, label %22, label %29
33: ; preds = %22, %19, %2, %15
ret void
}