#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 */

/* Variables and functions */
int fdt_first_subnode(void *, int /*<<< orphan*/);
int fdt_next_subnode(void *, int);
int fdt_subnode_offset(void *, int, char *);
int overlay_apply_node(void *, int, void *, int);
int overlay_get_target(void *, void *, int);
int overlay_merge(void *fdt, void *fdto) {
  int fragment;
  for (fragment = fdt_first_subnode(fdto, 0); fragment >= 0;
       fragment = fdt_next_subnode(fdto, fragment)) {
    int overlay;
    int target;
    int ret;
    overlay = fdt_subnode_offset(fdto, fragment, "__overlay__");
    if (overlay == -1)
      continue;
    if (overlay < 0)
      return overlay;
    target = overlay_get_target(fdt, fdto, fragment);
    if (target < 0)
      return target;
    ret = overlay_apply_node(fdt, target, fdto, overlay);
    if (ret)
      return ret;
  }
  return 0;
}


x86 assembly (clang, -O0):
<overlay_merge>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1070 <fdt_first_subnode@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     121e <overlay_merge+0xce>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
lea    0xe7a(%rip),%rdx
call   1060 <fdt_subnode_offset@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    119d <overlay_merge+0x4d>
jmp    120a <overlay_merge+0xba>
cmpl   $0x0,-0x20(%rbp)
jge    11b2 <overlay_merge+0x62>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1225 <overlay_merge+0xd5>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <overlay_get_target@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11da <overlay_merge+0x8a>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1225 <overlay_merge+0xd5>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%ecx
call   1050 <overlay_apply_node@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     1205 <overlay_merge+0xb5>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1225 <overlay_merge+0xd5>
jmp    120a <overlay_merge+0xba>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <fdt_next_subnode@plt>
mov    %eax,-0x1c(%rbp)
jmp    116e <overlay_merge+0x1e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<overlay_merge>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
mov    %rdi,%r15
xor    %r14d,%r14d
mov    %rsi,%rdi
xor    %esi,%esi
call   1070 <fdt_first_subnode@plt>
test   %eax,%eax
js     11d4 <overlay_merge+0x84>
mov    %eax,%ebp
lea    0xe85(%rip),%r12
jmp    1190 <overlay_merge+0x40>
nopl   (%rax)
mov    %r13,%rdi
mov    %ebp,%esi
call   1040 <fdt_next_subnode@plt>
mov    %eax,%ebp
test   %eax,%eax
js     11d4 <overlay_merge+0x84>
mov    %r13,%rdi
mov    %ebp,%esi
mov    %r12,%rdx
call   1060 <fdt_subnode_offset@plt>
cmp    $0xffffffff,%eax
je     1180 <overlay_merge+0x30>
mov    %eax,%ebx
test   %eax,%eax
js     11d1 <overlay_merge+0x81>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %ebp,%edx
call   1030 <overlay_get_target@plt>
test   %eax,%eax
js     11cc <overlay_merge+0x7c>
mov    %r15,%rdi
mov    %eax,%esi
mov    %r13,%rdx
mov    %ebx,%ecx
call   1050 <overlay_apply_node@plt>
test   %eax,%eax
je     1180 <overlay_merge+0x30>
mov    %eax,%r14d
jmp    11d4 <overlay_merge+0x84>
mov    %ebx,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"__overlay__\00"
define i32 @overlay_merge(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %5
%11 = call i32 @fdt_first_subnode(i8* %10, i32 0)
store i32 %11, i32* %6
br label %12
12: ; preds = %47, %2
%13 = load i32, i32* %6
%14 = icmp sge i32 %13, 0
br i1 %14, label %15, label %51
15: ; preds = %12
%16 = load i8*, i8** %5
%17 = load i32, i32* %6
%18 = call i32 @fdt_subnode_offset(i8* %16, i32 %17, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %22
21: ; preds = %15
br label %47
22: ; preds = %15
%23 = load i32, i32* %7
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = load i32, i32* %7
store i32 %26, i32* %3
br label %52
27: ; preds = %22
%28 = load i8*, i8** %4
%29 = load i8*, i8** %5
%30 = load i32, i32* %6
%31 = call i32 @overlay_get_target(i8* %28, i8* %29, i32 %30)
store i32 %31, i32* %8
%32 = load i32, i32* %8
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %27
%35 = load i32, i32* %8
store i32 %35, i32* %3
br label %52
36: ; preds = %27
%37 = load i8*, i8** %4
%38 = load i32, i32* %8
%39 = load i8*, i8** %5
%40 = load i32, i32* %7
%41 = call i32 @overlay_apply_node(i8* %37, i32 %38, i8* %39, i32 %40)
store i32 %41, i32* %9
%42 = load i32, i32* %9
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %36
%45 = load i32, i32* %9
store i32 %45, i32* %3
br label %52
46: ; preds = %36
br label %47
47: ; preds = %46, %21
%48 = load i8*, i8** %5
%49 = load i32, i32* %6
%50 = call i32 @fdt_next_subnode(i8* %48, i32 %49)
store i32 %50, i32* %6
br label %12
51: ; preds = %12
store i32 0, i32* %3
br label %52
52: ; preds = %51, %44, %34, %25
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
@.str = [12 x i8] c"__overlay__\00"
define i32 @overlay_merge(i8* %0, i8* %1) {
%3 = tail call i32 @fdt_first_subnode(i8* %1, i32 0)
%4 = icmp sgt i32 %3, -1
br i1 %4, label %5, label %20
5: ; preds = %2, %17
%6 = phi i32 [ %18, %17 ], [ %3, %2 ]
%7 = tail call i32 @fdt_subnode_offset(i8* %1, i32 %6, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32 %7, -1
br i1 %8, label %17, label %9
9: ; preds = %5
%10 = icmp slt i32 %7, 0
br i1 %10, label %20, label %11
11: ; preds = %9
%12 = tail call i32 @overlay_get_target(i8* %0, i8* %1, i32 %6)
%13 = icmp slt i32 %12, 0
br i1 %13, label %20, label %14
14: ; preds = %11
%15 = tail call i32 @overlay_apply_node(i8* %0, i32 %12, i8* %1, i32 %7)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14, %5
%18 = tail call i32 @fdt_next_subnode(i8* %1, i32 %6)
%19 = icmp sgt i32 %18, -1
br i1 %19, label %5, label %20
20: ; preds = %17, %9, %11, %14, %2
%21 = phi i32 [ 0, %2 ], [ %15, %14 ], [ %12, %11 ], [ %7, %9 ], [ 0, %17 ]
ret i32 %21
}