#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_property_offset(void *, int);
int fdt_next_property_offset(void *, int);
int fdt_path_offset(void *, char *);
int overlay_fixup_phandle(void *, void *, int, int);
int overlay_fixup_phandles(void *fdt, void *fdto) {
  int fixups_off, symbols_off;
  int property;
  fixups_off = fdt_path_offset(fdto, "/__fixups__");
  if (fixups_off == -1)
    return 0;
  if (fixups_off < 0)
    return fixups_off;
  symbols_off = fdt_path_offset(fdt, "/__symbols__");
  if ((symbols_off < 0 && (symbols_off != -1)))
    return symbols_off;
  for (property = fdt_first_property_offset(fdto, fixups_off); property >= 0;
       property = fdt_next_property_offset(fdto, property)) {
    int ret;
    ret = overlay_fixup_phandle(fdt, fdto, symbols_off, property);
    if (ret)
      return ret;
  }
  return 0;
}


x86 assembly (clang, -O0):
<overlay_fixup_phandles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1040 <fdt_path_offset@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1179 <overlay_fixup_phandles+0x39>
movl   $0x0,-0x4(%rbp)
jmp    1224 <overlay_fixup_phandles+0xe4>
cmpl   $0x0,-0x1c(%rbp)
jge    118e <overlay_fixup_phandles+0x4e>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1224 <overlay_fixup_phandles+0xe4>
mov    -0x10(%rbp),%rdi
lea    0xe73(%rip),%rsi
call   1040 <fdt_path_offset@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    11c0 <overlay_fixup_phandles+0x80>
cmpl   $0xffffffff,-0x20(%rbp)
je     11c0 <overlay_fixup_phandles+0x80>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1224 <overlay_fixup_phandles+0xe4>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <fdt_first_property_offset@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     121d <overlay_fixup_phandles+0xdd>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
mov    -0x24(%rbp),%ecx
call   1060 <overlay_fixup_phandle@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     1204 <overlay_fixup_phandles+0xc4>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1224 <overlay_fixup_phandles+0xe4>
jmp    1209 <overlay_fixup_phandles+0xc9>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1050 <fdt_next_property_offset@plt>
mov    %eax,-0x24(%rbp)
jmp    11cf <overlay_fixup_phandles+0x8f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<overlay_fixup_phandles>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0xeab(%rip),%rsi
mov    %rbx,%rdi
call   1040 <fdt_path_offset@plt>
xor    %r14d,%r14d
cmp    $0xffffffff,%eax
je     11c9 <overlay_fixup_phandles+0x89>
mov    %eax,%ebp
test   %eax,%eax
js     1187 <overlay_fixup_phandles+0x47>
lea    0xe9a(%rip),%rsi
mov    %r15,%rdi
call   1040 <fdt_path_offset@plt>
mov    %eax,%r12d
cmp    $0xffffffff,%eax
jge    118c <overlay_fixup_phandles+0x4c>
mov    %r12d,%r14d
jmp    11c9 <overlay_fixup_phandles+0x89>
mov    %ebp,%r14d
jmp    11c9 <overlay_fixup_phandles+0x89>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <fdt_first_property_offset@plt>
test   %eax,%eax
js     11c9 <overlay_fixup_phandles+0x89>
mov    %eax,%ebp
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
mov    %ebp,%ecx
call   1060 <overlay_fixup_phandle@plt>
test   %eax,%eax
jne    11c6 <overlay_fixup_phandles+0x86>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <fdt_next_property_offset@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    11a0 <overlay_fixup_phandles+0x60>
jmp    11c9 <overlay_fixup_phandles+0x89>
mov    %eax,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"/__fixups__\00"
@.str.1 = [13 x i8] c"/__symbols__\00"
define i32 @overlay_fixup_phandles(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_path_offset(i8* %10, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 0, i32* %3
br label %53
15: ; preds = %2
%16 = load i32, i32* %6
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = load i32, i32* %6
store i32 %19, i32* %3
br label %53
20: ; preds = %15
%21 = load i8*, i8** %4
%22 = call i32 @fdt_path_offset(i8* %21, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %20
%26 = load i32, i32* %7
%27 = icmp ne i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = load i32, i32* %7
store i32 %29, i32* %3
br label %53
30: ; preds = %25, %20
%31 = load i8*, i8** %5
%32 = load i32, i32* %6
%33 = call i32 @fdt_first_property_offset(i8* %31, i32 %32)
store i32 %33, i32* %8
br label %34
34: ; preds = %48, %30
%35 = load i32, i32* %8
%36 = icmp sge i32 %35, 0
br i1 %36, label %37, label %52
37: ; preds = %34
%38 = load i8*, i8** %4
%39 = load i8*, i8** %5
%40 = load i32, i32* %7
%41 = load i32, i32* %8
%42 = call i32 @overlay_fixup_phandle(i8* %38, i8* %39, i32 %40, i32 %41)
store i32 %42, i32* %9
%43 = load i32, i32* %9
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %37
%46 = load i32, i32* %9
store i32 %46, i32* %3
br label %53
47: ; preds = %37
br label %48
48: ; preds = %47
%49 = load i8*, i8** %5
%50 = load i32, i32* %8
%51 = call i32 @fdt_next_property_offset(i8* %49, i32 %50)
store i32 %51, i32* %8
br label %34
52: ; preds = %34
store i32 0, i32* %3
br label %53
53: ; preds = %52, %45, %28, %18, %14
%54 = load i32, i32* %3
ret i32 %54
}

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