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

/* Variables and functions */
int /*<<< orphan*/ decrunch(int, struct membuf *, struct membuf *);
char *membuf_get(struct membuf *);
int membuf_memlen(struct membuf *);
int /*<<< orphan*/ reverse_buffer(char *, int);
void decrunch_backwards(int level, struct membuf *inbuf,
                        struct membuf *outbuf) {
  int outpos;
  reverse_buffer(membuf_get(inbuf), membuf_memlen(inbuf));
  outpos = membuf_memlen(outbuf);
  decrunch(level, inbuf, outbuf);
  reverse_buffer(membuf_get(inbuf), membuf_memlen(inbuf));
  reverse_buffer((char *)membuf_get(outbuf) + outpos,
                 membuf_memlen(outbuf) - outpos);
}


x86 assembly (clang, -O0):
<decrunch_backwards>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <membuf_get@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <membuf_memlen@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
call   1030 <reverse_buffer@plt>
mov    -0x18(%rbp),%rdi
call   1060 <membuf_memlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <decrunch@plt>
mov    -0x10(%rbp),%rdi
call   1040 <membuf_get@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <membuf_memlen@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
call   1030 <reverse_buffer@plt>
mov    -0x18(%rbp),%rdi
call   1040 <membuf_get@plt>
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <membuf_memlen@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
sub    -0x1c(%rbp),%esi
call   1030 <reverse_buffer@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decrunch_backwards>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%r15d
mov    %rsi,%rdi
call   1040 <membuf_get@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1060 <membuf_memlen@plt>
mov    %rbp,%rdi
mov    %eax,%esi
call   1030 <reverse_buffer@plt>
mov    %r14,%rdi
call   1060 <membuf_memlen@plt>
mov    %eax,%r12d
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1050 <decrunch@plt>
mov    %rbx,%rdi
call   1040 <membuf_get@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1060 <membuf_memlen@plt>
mov    %rbp,%rdi
mov    %eax,%esi
call   1030 <reverse_buffer@plt>
mov    %r14,%rdi
call   1040 <membuf_get@plt>
movslq %r12d,%rbp
lea    (%rax,%rbp,1),%rbx
mov    %r14,%rdi
call   1060 <membuf_memlen@plt>
sub    %ebp,%eax
mov    %rbx,%rdi
mov    %eax,%esi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <reverse_buffer@plt>

LLVM IR (-O0):
%struct.membuf = type { i32 }
define void @decrunch_backwards(i32 %0, %struct.membuf* %1, %struct.membuf* %2) {
%4 = alloca i32
%5 = alloca %struct.membuf*
%6 = alloca %struct.membuf*
%7 = alloca i32
store i32 %0, i32* %4
store %struct.membuf* %1, %struct.membuf** %5
store %struct.membuf* %2, %struct.membuf** %6
%8 = load %struct.membuf*, %struct.membuf** %5
%9 = call i8* @membuf_get(%struct.membuf* %8)
%10 = load %struct.membuf*, %struct.membuf** %5
%11 = call i32 @membuf_memlen(%struct.membuf* %10)
%12 = call i32 @reverse_buffer(i8* %9, i32 %11)
%13 = load %struct.membuf*, %struct.membuf** %6
%14 = call i32 @membuf_memlen(%struct.membuf* %13)
store i32 %14, i32* %7
%15 = load i32, i32* %4
%16 = load %struct.membuf*, %struct.membuf** %5
%17 = load %struct.membuf*, %struct.membuf** %6
%18 = call i32 @decrunch(i32 %15, %struct.membuf* %16, %struct.membuf* %17)
%19 = load %struct.membuf*, %struct.membuf** %5
%20 = call i8* @membuf_get(%struct.membuf* %19)
%21 = load %struct.membuf*, %struct.membuf** %5
%22 = call i32 @membuf_memlen(%struct.membuf* %21)
%23 = call i32 @reverse_buffer(i8* %20, i32 %22)
%24 = load %struct.membuf*, %struct.membuf** %6
%25 = call i8* @membuf_get(%struct.membuf* %24)
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load %struct.membuf*, %struct.membuf** %6
%30 = call i32 @membuf_memlen(%struct.membuf* %29)
%31 = load i32, i32* %7
%32 = sub nsw i32 %30, %31
%33 = call i32 @reverse_buffer(i8* %28, i32 %32)
ret void
}

LLVM IR (-O2):
%struct.membuf = type { i32 }
define void @decrunch_backwards(i32 %0, %struct.membuf* %1, %struct.membuf* %2) {
%4 = tail call i8* @membuf_get(%struct.membuf* %1)
%5 = tail call i32 @membuf_memlen(%struct.membuf* %1)
%6 = tail call i32 @reverse_buffer(i8* %4, i32 %5)
%7 = tail call i32 @membuf_memlen(%struct.membuf* %2)
%8 = tail call i32 @decrunch(i32 %0, %struct.membuf* %1, %struct.membuf* %2)
%9 = tail call i8* @membuf_get(%struct.membuf* %1)
%10 = tail call i32 @membuf_memlen(%struct.membuf* %1)
%11 = tail call i32 @reverse_buffer(i8* %9, i32 %10)
%12 = tail call i8* @membuf_get(%struct.membuf* %2)
%13 = sext i32 %7 to i64
%14 = getelementptr inbounds i8, i8* %12, i64 %13
%15 = tail call i32 @membuf_memlen(%struct.membuf* %2)
%16 = sub nsw i32 %15, %7
%17 = tail call i32 @reverse_buffer(i8* %14, i32 %16)
ret void
}