#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;
};
struct crunch_options {
  int dummy;
};
struct crunch_info {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ crunch_backwards(struct membuf *, struct membuf *,
                                    struct crunch_options *,
                                    struct crunch_info *);
char *membuf_get(struct membuf *);
int membuf_memlen(struct membuf *);
int /*<<< orphan*/ reverse_buffer(char *, int);
void crunch(struct membuf *inbuf, struct membuf *outbuf,
            struct crunch_options *options, struct crunch_info *info) {
  int outpos;
  reverse_buffer(membuf_get(inbuf), membuf_memlen(inbuf));
  outpos = membuf_memlen(outbuf);
  crunch_backwards(inbuf, outbuf, options, info);
  reverse_buffer(membuf_get(inbuf), membuf_memlen(inbuf));
  reverse_buffer((char *)membuf_get(outbuf) + outpos,
                 membuf_memlen(outbuf) - outpos);
}


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

x86 assembly (clang, -O2):
<crunch>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%rbx
call   1050 <membuf_get@plt>
mov    %rax,%r13
mov    %rbx,%rdi
call   1060 <membuf_memlen@plt>
mov    %r13,%rdi
mov    %eax,%esi
call   1030 <reverse_buffer@plt>
mov    %r14,%rdi
call   1060 <membuf_memlen@plt>
mov    %eax,%r13d
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
call   1040 <crunch_backwards@plt>
mov    %rbx,%rdi
call   1050 <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   1050 <membuf_get@plt>
movslq %r13d,%rbp
lea    (%rax,%rbp,1),%rbx
mov    %r14,%rdi
call   1060 <membuf_memlen@plt>
sub    %ebp,%eax
mov    %rbx,%rdi
mov    %eax,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <reverse_buffer@plt>

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

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