#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*/ assert(int /*<<< orphan*/);
char *memmem(char *, size_t, char *, int);
int /*<<< orphan*/ memmove(char *, char *, size_t);
void ftp_input_shift_buf(char *buf, size_t *len) {
  assert(buf != NULL);
  assert(len != NULL);
  char *next_start = memmem(buf, *len, "\0", 2), *buf_end = buf + *len + 1;
  assert(next_start != NULL);
  do {
    ++next_start;
  } while (next_start < buf_end && *next_start == '\0');
  size_t copy_len = buf_end - next_start;
  if (copy_len == 0) {
    *buf = '\0';
    *len = 0;
  } else {
    memmove(buf, next_start, copy_len);
    *len = copy_len;
  }
}


x86 assembly (clang, -O0):
<ftp_input_shift_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe8a(%rip),%rdx
mov    $0x2,%ecx
call   1040 <memmem@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
add    (%rcx),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x20(%rbp),%rcx
mov    %al,-0x29(%rbp)
jae    11d8 <ftp_input_shift_buf+0xa8>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
sete   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11a9 <ftp_input_shift_buf+0x79>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1214 <ftp_input_shift_buf+0xe4>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
jmp    1230 <ftp_input_shift_buf+0x100>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <memmove@plt>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ftp_input_shift_buf>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %edi,%edi
test   %r15,%r15
setne  %dil
call   1030 <assert@plt>
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1030 <assert@plt>
mov    (%r14),%rsi
lea    0xe9b(%rip),%rdx
mov    %r15,%rdi
mov    $0x2,%ecx
call   1040 <memmem@plt>
mov    %rax,%rbx
mov    (%r14),%r13
add    %r15,%r13
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1030 <assert@plt>
mov    %r13,%rax
sub    %rbx,%rax
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rsi
mov    %rax,%r12
lea    -0x1(%rbx),%rax
cmp    %r13,%rax
jae    11bd <ftp_input_shift_buf+0x8d>
lea    0x1(%rsi),%rbx
lea    -0x1(%r12),%rax
cmpb   $0x0,(%rsi)
je     11a0 <ftp_input_shift_buf+0x70>
test   %r12,%r12
je     11cf <ftp_input_shift_buf+0x9f>
mov    %r15,%rdi
mov    %r12,%rdx
call   1050 <memmove@plt>
jmp    11d3 <ftp_input_shift_buf+0xa3>
movb   $0x0,(%r15)
mov    %r12,(%r14)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] zeroinitializer
define void @ftp_input_shift_buf(i8* %0, i64* %1) {
%3 = alloca i8*
%4 = alloca i64*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
store i8* %0, i8** %3
store i64* %1, i64** %4
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i64*, i64** %4
%13 = icmp ne i64* %12, null
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i8*, i8** %3
%17 = load i64*, i64** %4
%18 = load i64, i64* %17
%19 = call i8* @memmem(i8* %16, i64 %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 2)
store i8* %19, i8** %5
%20 = load i8*, i8** %3
%21 = load i64*, i64** %4
%22 = load i64, i64* %21
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = getelementptr inbounds i8, i8* %23, i64 1
store i8* %24, i8** %6
%25 = load i8*, i8** %5
%26 = icmp ne i8* %25, null
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
br label %29
29: ; preds = %41, %2
%30 = load i8*, i8** %5
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %5
br label %32
32: ; preds = %29
%33 = load i8*, i8** %5
%34 = load i8*, i8** %6
%35 = icmp ult i8* %33, %34
br i1 %35, label %36, label %41
36: ; preds = %32
%37 = load i8*, i8** %5
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 0
br label %41
41: ; preds = %36, %32
%42 = phi i1 [ false, %32 ], [ %40, %36 ]
br i1 %42, label %29, label %43
43: ; preds = %41
%44 = load i8*, i8** %6
%45 = load i8*, i8** %5
%46 = ptrtoint i8* %44 to i64
%47 = ptrtoint i8* %45 to i64
%48 = sub i64 %46, %47
store i64 %48, i64* %7
%49 = load i64, i64* %7
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %43
%52 = load i8*, i8** %3
store i8 0, i8* %52
%53 = load i64*, i64** %4
store i64 0, i64* %53
br label %61
54: ; preds = %43
%55 = load i8*, i8** %3
%56 = load i8*, i8** %5
%57 = load i64, i64* %7
%58 = call i32 @memmove(i8* %55, i8* %56, i64 %57)
%59 = load i64, i64* %7
%60 = load i64*, i64** %4
store i64 %59, i64* %60
br label %61
61: ; preds = %54, %51
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] zeroinitializer
define void @ftp_input_shift_buf(i8* %0, i64* %1) {
%3 = icmp ne i8* %0, null
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = icmp ne i64* %1, null
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = load i64, i64* %1
%10 = tail call i8* @memmem(i8* %0, i64 %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 2)
%11 = load i64, i64* %1
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = icmp ne i8* %10, null
%15 = zext i1 %14 to i32
%16 = tail call i32 @assert(i32 %15)
br label %17
17: ; preds = %21, %2
%18 = phi i8* [ %10, %2 ], [ %19, %21 ]
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = icmp ult i8* %18, %12
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i8, i8* %19
%23 = icmp eq i8 %22, 0
br i1 %23, label %17, label %24
24: ; preds = %17, %21
%25 = ptrtoint i8* %13 to i64
%26 = ptrtoint i8* %19 to i64
%27 = sub i64 %25, %26
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %24
store i8 0, i8* %0
br label %32
30: ; preds = %24
%31 = tail call i32 @memmove(i8* %0, i8* %19, i64 %27)
br label %32
32: ; preds = %30, %29
store i64 %27, i64* %1
ret void
}