#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 /*<<< orphan*/ memmove(char *, char *, size_t);
scalar_t__ realloc(char *, size_t);
size_t _ll_byte_destuff(char **message, size_t size) {
  size_t i;
  for (i = 1; i < size - 1; ++i) {
    if ((*message)[i] == 0x7D) {
      memmove(*message + i, *message + i + 1, size - i - 1);
      size--;
      (*message)[i] ^= 0x20;
    }
  }
  *message = (char *)realloc(*message, size);
  return size;
}


x86 assembly (clang, -O0):
<_ll_byte_destuff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jae    11c7 <_ll_byte_destuff+0xa7>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x7d,%eax
jne    11b1 <_ll_byte_destuff+0x91>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
add    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
add    -0x18(%rbp),%rsi
add    $0x1,%rsi
mov    -0x10(%rbp),%rdx
sub    -0x18(%rbp),%rdx
sub    $0x1,%rdx
call   1040 <memmove@plt>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
xor    $0x20,%edx
mov    %dl,(%rax,%rcx,1)
jmp    11b6 <_ll_byte_destuff+0x96>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1138 <_ll_byte_destuff+0x18>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <realloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_ll_byte_destuff>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
lea    -0x1(%rsi),%r13
cmp    $0x2,%r13
jb     118c <_ll_byte_destuff+0x6c>
mov    $0x1,%ebx
mov    $0xfffffffffffffffe,%r12
jmp    1161 <_ll_byte_destuff+0x41>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
lea    -0x1(%r15),%r13
add    $0xffffffffffffffff,%r12
cmp    %r13,%rbx
jae    118c <_ll_byte_destuff+0x6c>
mov    (%r14),%rdi
cmpb   $0x7d,(%rdi,%rbx,1)
jne    1150 <_ll_byte_destuff+0x30>
lea    (%rdi,%rbx,1),%rsi
add    $0x1,%rsi
add    %rbx,%rdi
add    %r12,%r15
mov    %r15,%rdx
call   1040 <memmove@plt>
mov    (%r14),%rax
xorb   $0x20,(%rax,%rbx,1)
mov    %r13,%r15
jmp    1150 <_ll_byte_destuff+0x30>
mov    (%r14),%rdi
mov    %r15,%rsi
call   1030 <realloc@plt>
mov    %rax,(%r14)
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @_ll_byte_destuff(i8** %0, i64 %1) {
%3 = alloca i8**
%4 = alloca i64
%5 = alloca i64
store i8** %0, i8*** %3
store i64 %1, i64* %4
store i64 1, i64* %5
br label %6
6: ; preds = %45, %2
%7 = load i64, i64* %5
%8 = load i64, i64* %4
%9 = sub i64 %8, 1
%10 = icmp ult i64 %7, %9
br i1 %10, label %11, label %48
11: ; preds = %6
%12 = load i8**, i8*** %3
%13 = load i8*, i8** %12
%14 = load i64, i64* %5
%15 = getelementptr inbounds i8, i8* %13, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 125
br i1 %18, label %19, label %44
19: ; preds = %11
%20 = load i8**, i8*** %3
%21 = load i8*, i8** %20
%22 = load i64, i64* %5
%23 = getelementptr inbounds i8, i8* %21, i64 %22
%24 = load i8**, i8*** %3
%25 = load i8*, i8** %24
%26 = load i64, i64* %5
%27 = getelementptr inbounds i8, i8* %25, i64 %26
%28 = getelementptr inbounds i8, i8* %27, i64 1
%29 = load i64, i64* %4
%30 = load i64, i64* %5
%31 = sub i64 %29, %30
%32 = sub i64 %31, 1
%33 = call i32 @memmove(i8* %23, i8* %28, i64 %32)
%34 = load i64, i64* %4
%35 = add i64 %34, -1
store i64 %35, i64* %4
%36 = load i8**, i8*** %3
%37 = load i8*, i8** %36
%38 = load i64, i64* %5
%39 = getelementptr inbounds i8, i8* %37, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = xor i32 %41, 32
%43 = trunc i32 %42 to i8
store i8 %43, i8* %39
br label %44
44: ; preds = %19, %11
br label %45
45: ; preds = %44
%46 = load i64, i64* %5
%47 = add i64 %46, 1
store i64 %47, i64* %5
br label %6
48: ; preds = %6
%49 = load i8**, i8*** %3
%50 = load i8*, i8** %49
%51 = load i64, i64* %4
%52 = call i64 @realloc(i8* %50, i64 %51)
%53 = inttoptr i64 %52 to i8*
%54 = load i8**, i8*** %3
store i8* %53, i8** %54
%55 = load i64, i64* %4
ret i64 %55
}

LLVM IR (-O2):
define i64 @_ll_byte_destuff(i8** nocapture %0, i64 %1) {
%3 = add i64 %1, -1
%4 = icmp ugt i64 %3, 1
br i1 %4, label %5, label %27
5: ; preds = %2, %22
%6 = phi i64 [ %25, %22 ], [ %3, %2 ]
%7 = phi i64 [ %24, %22 ], [ 1, %2 ]
%8 = phi i64 [ %23, %22 ], [ %1, %2 ]
%9 = load i8*, i8** %0
%10 = getelementptr inbounds i8, i8* %9, i64 %7
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 125
br i1 %12, label %13, label %22
13: ; preds = %5
%14 = getelementptr inbounds i8, i8* %10, i64 1
%15 = xor i64 %7, -1
%16 = add i64 %8, %15
%17 = tail call i32 @memmove(i8* %10, i8* %14, i64 %16)
%18 = load i8*, i8** %0
%19 = getelementptr inbounds i8, i8* %18, i64 %7
%20 = load i8, i8* %19
%21 = xor i8 %20, 32
store i8 %21, i8* %19
br label %22
22: ; preds = %5, %13
%23 = phi i64 [ %6, %13 ], [ %8, %5 ]
%24 = add nuw i64 %7, 1
%25 = add i64 %23, -1
%26 = icmp ult i64 %24, %25
br i1 %26, label %5, label %27
27: ; preds = %22, %2
%28 = phi i64 [ %1, %2 ], [ %23, %22 ]
%29 = load i8*, i8** %0
%30 = tail call i64 @realloc(i8* %29, i64 %28)
%31 = inttoptr i64 %30 to i8*
store i8* %31, i8** %0
ret i64 %28
}