#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;
    if ((__err = _fdt_rw_check_header(fdt)) != 0)
      return __err;
  };
  if (n >= fdt_num_mem_rsv(fdt))
    return -1;
  return _fdt_splice_mem_rsv(fdt, re, 1, 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,-0x24(%rbp)
cmp    $0x0,%eax
je     117f <fdt_del_mem_rsv+0x3f>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11be <fdt_del_mem_rsv+0x7e>
mov    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <fdt_num_mem_rsv@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
jl     11a7 <fdt_del_mem_rsv+0x67>
movl   $0xffffffff,-0x4(%rbp)
jmp    11be <fdt_del_mem_rsv+0x7e>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1060 <_fdt_splice_mem_rsv@plt>
mov    %eax,-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
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i8*, i8** %4
%9 = load i32, i32* %5
%10 = call %struct.fdt_reserve_entry* @_fdt_mem_rsv_w(i8* %8, i32 %9)
store %struct.fdt_reserve_entry* %10, %struct.fdt_reserve_entry** %6
%11 = load i8*, i8** %4
%12 = call i32 @_fdt_rw_check_header(i8* %11)
store i32 %12, i32* %7
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = load i32, i32* %7
store i32 %15, i32* %3
br label %26
16: ; preds = %2
%17 = load i32, i32* %5
%18 = load i8*, i8** %4
%19 = call i32 @fdt_num_mem_rsv(i8* %18)
%20 = icmp sge i32 %17, %19
br i1 %20, label %21, label %22
21: ; preds = %16
store i32 -1, i32* %3
br label %26
22: ; preds = %16
%23 = load i8*, i8** %4
%24 = load %struct.fdt_reserve_entry*, %struct.fdt_reserve_entry** %6
%25 = call i32 @_fdt_splice_mem_rsv(i8* %23, %struct.fdt_reserve_entry* %24, i32 1, i32 0)
store i32 %25, i32* %3
br label %26
26: ; preds = %22, %21, %14
%27 = load i32, i32* %3
ret i32 %27
}

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 = %6, %2, %9
%12 = phi i32 [ %10, %9 ], [ %4, %2 ], [ -1, %6 ]
ret i32 %12
}