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

/* Variables and functions */
size_t DHCP_getOptionLength(struct DHCPSingleOption *);
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ memmove(char *const, char *const, int);
size_t DHCP_removeOption(struct DHCPSingleOption *opt,
                         struct DHCPSingleOption **end_opt) {
  size_t len = DHCP_getOptionLength(opt);
  char *const start = ((char *)(opt));
  char const *const end = ((char const *)(*end_opt));
  assert(opt <= *end_opt);
  if (start + len > end)
    return 0;
  memmove(start, start + len, end - (start + len) + 1);
  *end_opt = ((struct DHCPSingleOption *)(end - len));
  return len;
}


x86 assembly (clang, -O0):
<DHCP_removeOption>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <DHCP_getOptionLength@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
setbe  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x28(%rbp),%rax
add    -0x20(%rbp),%rax
cmp    -0x30(%rbp),%rax
jbe    1197 <DHCP_removeOption+0x67>
movq   $0x0,-0x8(%rbp)
jmp    11d9 <DHCP_removeOption+0xa9>
mov    -0x28(%rbp),%rdi
mov    -0x28(%rbp),%rsi
add    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
add    -0x20(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edx
call   1040 <memmove@plt>
mov    -0x30(%rbp),%rcx
xor    %eax,%eax
sub    -0x20(%rbp),%rax
add    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DHCP_removeOption>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
call   1050 <DHCP_getOptionLength@plt>
mov    %rax,%r15
mov    (%r14),%rbx
xor    %edi,%edi
cmp    %r12,%rbx
setae  %dil
call   1030 <assert@plt>
lea    (%r12,%r15,1),%rsi
cmp    %rbx,%rsi
jbe    1165 <DHCP_removeOption+0x35>
xor    %r15d,%r15d
jmp    117a <DHCP_removeOption+0x4a>
mov    %ebx,%edx
sub    %esi,%edx
add    $0x1,%edx
mov    %r12,%rdi
call   1040 <memmove@plt>
sub    %r15,%rbx
mov    %rbx,(%r14)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.DHCPSingleOption = type { i32 }
define i64 @DHCP_removeOption(%struct.DHCPSingleOption* %0, %struct.DHCPSingleOption** %1) {
%3 = alloca i64
%4 = alloca %struct.DHCPSingleOption*
%5 = alloca %struct.DHCPSingleOption**
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
store %struct.DHCPSingleOption* %0, %struct.DHCPSingleOption** %4
store %struct.DHCPSingleOption** %1, %struct.DHCPSingleOption*** %5
%9 = load %struct.DHCPSingleOption*, %struct.DHCPSingleOption** %4
%10 = call i64 @DHCP_getOptionLength(%struct.DHCPSingleOption* %9)
store i64 %10, i64* %6
%11 = load %struct.DHCPSingleOption*, %struct.DHCPSingleOption** %4
%12 = bitcast %struct.DHCPSingleOption* %11 to i8*
store i8* %12, i8** %7
%13 = load %struct.DHCPSingleOption**, %struct.DHCPSingleOption*** %5
%14 = load %struct.DHCPSingleOption*, %struct.DHCPSingleOption** %13
%15 = bitcast %struct.DHCPSingleOption* %14 to i8*
store i8* %15, i8** %8
%16 = load %struct.DHCPSingleOption*, %struct.DHCPSingleOption** %4
%17 = load %struct.DHCPSingleOption**, %struct.DHCPSingleOption*** %5
%18 = load %struct.DHCPSingleOption*, %struct.DHCPSingleOption** %17
%19 = icmp ule %struct.DHCPSingleOption* %16, %18
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = load i8*, i8** %7
%23 = load i64, i64* %6
%24 = getelementptr inbounds i8, i8* %22, i64 %23
%25 = load i8*, i8** %8
%26 = icmp ugt i8* %24, %25
br i1 %26, label %27, label %28
27: ; preds = %2
store i64 0, i64* %3
br label %50
28: ; preds = %2
%29 = load i8*, i8** %7
%30 = load i8*, i8** %7
%31 = load i64, i64* %6
%32 = getelementptr inbounds i8, i8* %30, i64 %31
%33 = load i8*, i8** %8
%34 = load i8*, i8** %7
%35 = load i64, i64* %6
%36 = getelementptr inbounds i8, i8* %34, i64 %35
%37 = ptrtoint i8* %33 to i64
%38 = ptrtoint i8* %36 to i64
%39 = sub i64 %37, %38
%40 = add nsw i64 %39, 1
%41 = trunc i64 %40 to i32
%42 = call i32 @memmove(i8* %29, i8* %32, i32 %41)
%43 = load i8*, i8** %8
%44 = load i64, i64* %6
%45 = sub i64 0, %44
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = bitcast i8* %46 to %struct.DHCPSingleOption*
%48 = load %struct.DHCPSingleOption**, %struct.DHCPSingleOption*** %5
store %struct.DHCPSingleOption* %47, %struct.DHCPSingleOption** %48
%49 = load i64, i64* %6
store i64 %49, i64* %3
br label %50
50: ; preds = %28, %27
%51 = load i64, i64* %3
ret i64 %51
}

LLVM IR (-O2):
%struct.DHCPSingleOption = type { i32 }
define i64 @DHCP_removeOption(%struct.DHCPSingleOption* %0, %struct.DHCPSingleOption** nocapture %1) {
%3 = tail call i64 @DHCP_getOptionLength(%struct.DHCPSingleOption* %0)
%4 = bitcast %struct.DHCPSingleOption* %0 to i8*
%5 = load %struct.DHCPSingleOption*, %struct.DHCPSingleOption** %1
%6 = bitcast %struct.DHCPSingleOption* %5 to i8*
%7 = icmp uge %struct.DHCPSingleOption* %5, %0
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = getelementptr inbounds i8, i8* %4, i64 %3
%11 = icmp ugt i8* %10, %6
br i1 %11, label %22, label %12
12: ; preds = %2
%13 = ptrtoint %struct.DHCPSingleOption* %5 to i64
%14 = ptrtoint i8* %10 to i64
%15 = sub i64 %13, %14
%16 = trunc i64 %15 to i32
%17 = add i32 %16, 1
%18 = tail call i32 @memmove(i8* %4, i8* %10, i32 %17)
%19 = sub i64 0, %3
%20 = getelementptr inbounds i8, i8* %6, i64 %19
%21 = bitcast %struct.DHCPSingleOption** %1 to i8**
store i8* %20, i8** %21
br label %22
22: ; preds = %2, %12
%23 = phi i64 [ %3, %12 ], [ 0, %2 ]
ret i64 %23
}