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

/* Variables and functions */
struct fdt_reserve_entry *_fdt_mem_rsv_w(void *, int);
int _fdt_rw_check_header(void *);
int _fdt_splice_mem_rsv(void *, struct fdt_reserve_entry *, int,
                        int /*<<< orphan*/);
int fdt_num_mem_rsv(void *);
int fdt_del_mem_rsv(void *fdt, int n) {
  struct fdt_reserve_entry *re = _fdt_mem_rsv_w(fdt, n);
  int err;
  {
    int __err;
    if ((__err = _fdt_rw_check_header(fdt)) != 0)
      return __err;
  };
  if (n >= fdt_num_mem_rsv(fdt))
    return -1;
  err = _fdt_splice_mem_rsv(fdt, re, 1, 0);
  if (err)
    return err;
  return 0;
}


x86 assembly (clang, -O0):
<fdt_del_mem_rsv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <_fdt_mem_rsv_w@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <_fdt_rw_check_header@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
je     117f <fdt_del_mem_rsv+0x3f>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11da <fdt_del_mem_rsv+0x9a>
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <fdt_num_mem_rsv@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jl     11a7 <fdt_del_mem_rsv+0x67>
movl   $0xffffffff,-0x4(%rbp)
jmp    11da <fdt_del_mem_rsv+0x9a>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1060 <_fdt_splice_mem_rsv@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11d3 <fdt_del_mem_rsv+0x93>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11da <fdt_del_mem_rsv+0x9a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fdt_del_mem_rsv>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
call   1040 <_fdt_mem_rsv_w@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <_fdt_rw_check_header@plt>
test   %eax,%eax
jne    1186 <fdt_del_mem_rsv+0x46>
mov    %rbx,%rdi
call   1050 <fdt_num_mem_rsv@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ebp,%ecx
jle    1186 <fdt_del_mem_rsv+0x46>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <_fdt_splice_mem_rsv@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.fdt_reserve_entry = type { i32 }
define i32 @fdt_del_mem_rsv(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.fdt_reserve_entry*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = load i8*, i8** %4
%10 = load i32, i32* %5
%11 = call %struct.fdt_reserve_entry* @_fdt_mem_rsv_w(i8* %9, i32 %10)
store %struct.fdt_reserve_entry* %11, %struct.fdt_reserve_entry** %6
%12 = load i8*, i8** %4
%13 = call i32 @_fdt_rw_check_header(i8* %12)
store i32 %13, i32* %8
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = load i32, i32* %8
store i32 %16, i32* %3
br label %32
17: ; preds = %2
%18 = load i32, i32* %5
%19 = load i8*, i8** %4
%20 = call i32 @fdt_num_mem_rsv(i8* %19)
%21 = icmp sge i32 %18, %20
br i1 %21, label %22, label %23
22: ; preds = %17
store i32 -1, i32* %3
br label %32
23: ; preds = %17
%24 = load i8*, i8** %4
%25 = load %struct.fdt_reserve_entry*, %struct.fdt_reserve_entry** %6
%26 = call i32 @_fdt_splice_mem_rsv(i8* %24, %struct.fdt_reserve_entry* %25, i32 1, i32 0)
store i32 %26, i32* %7
%27 = load i32, i32* %7
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %23
%30 = load i32, i32* %7
store i32 %30, i32* %3
br label %32
31: ; preds = %23
store i32 0, i32* %3
br label %32
32: ; preds = %31, %29, %22, %15
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
%struct.fdt_reserve_entry = type { i32 }
define i32 @fdt_del_mem_rsv(i8* %0, i32 %1) {
%3 = tail call %struct.fdt_reserve_entry* @_fdt_mem_rsv_w(i8* %0, i32 %1)
%4 = tail call i32 @_fdt_rw_check_header(i8* %0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = tail call i32 @fdt_num_mem_rsv(i8* %0)
%8 = icmp sgt i32 %7, %1
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @_fdt_splice_mem_rsv(i8* %0, %struct.fdt_reserve_entry* %3, i32 1, i32 0)
br label %11
11: ; preds = %9, %6, %2
%12 = phi i32 [ %4, %2 ], [ -1, %6 ], [ %10, %9 ]
ret i32 %12
}