#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_next_node(void const *, int, int *);
int fdt_next_subnode(const void *fdt, int offset) {
  int depth = 1;
  do {
    offset = fdt_next_node(fdt, offset, &depth);
    if (offset < 0 || depth < 1)
      return -1;
  } while (depth > 1);
  return offset;
}


x86 assembly (clang, -O0):
<fdt_next_subnode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x18(%rbp),%rdx
call   1030 <fdt_next_node@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     114d <fdt_next_subnode+0x3d>
cmpl   $0x1,-0x18(%rbp)
jge    1159 <fdt_next_subnode+0x49>
movl   $0xffffffff,-0x4(%rbp)
jmp    116e <fdt_next_subnode+0x5e>
jmp    115e <fdt_next_subnode+0x4e>
cmpl   $0x1,-0x18(%rbp)
jg     1126 <fdt_next_subnode+0x16>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fdt_next_subnode>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%eax
mov    %rdi,%rbx
movl   $0x1,0x4(%rsp)
lea    0x4(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r14,%rdx
call   1030 <fdt_next_node@plt>
mov    $0xffffffff,%ecx
test   %eax,%eax
js     1155 <fdt_next_subnode+0x45>
mov    0x4(%rsp),%edx
test   %edx,%edx
jle    1155 <fdt_next_subnode+0x45>
mov    %eax,%ecx
cmp    $0x1,%edx
ja     1130 <fdt_next_subnode+0x20>
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @fdt_next_subnode(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 1, i32* %6
br label %7
7: ; preds = %18, %2
%8 = load i8*, i8** %4
%9 = load i32, i32* %5
%10 = call i32 @fdt_next_node(i8* %8, i32 %9, i32* %6)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp slt i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %7
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 1
br i1 %15, label %16, label %17
16: ; preds = %13, %7
store i32 -1, i32* %3
br label %23
17: ; preds = %13
br label %18
18: ; preds = %17
%19 = load i32, i32* %6
%20 = icmp sgt i32 %19, 1
br i1 %20, label %7, label %21
21: ; preds = %18
%22 = load i32, i32* %5
store i32 %22, i32* %3
br label %23
23: ; preds = %21, %16
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
define i32 @fdt_next_subnode(i8* %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 1, i32* %3
br label %5
5: ; preds = %12, %2
%6 = phi i32 [ %1, %2 ], [ %7, %12 ]
%7 = call i32 @fdt_next_node(i8* %0, i32 %6, i32* %3)
%8 = icmp slt i32 %7, 0
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 1
%11 = select i1 %8, i1 true, i1 %10
br i1 %11, label %14, label %12
12: ; preds = %5
%13 = icmp ugt i32 %9, 1
br i1 %13, label %5, label %14
14: ; preds = %12, %5
%15 = phi i32 [ -1, %5 ], [ %7, %12 ]
ret i32 %15
}