#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 const *, int);
int strlen(char const *);
void strmaxprep(char *Dest, const char *Src, int MaxLen) {
  int RLen;
  RLen = strlen(Src);
  if (RLen > MaxLen - ((int)strlen(Dest)))
    RLen = MaxLen - strlen(Dest);
  memmove(Dest + RLen, Dest, strlen(Dest) + 1);
  memmove(Dest, Src, RLen);
}


x86 assembly (clang, -O0):
<strmaxprep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x20(%rbp),%ecx
mov    %eax,%edx
mov    -0x1c(%rbp),%eax
sub    %edx,%ecx
cmp    %ecx,%eax
jle    117f <strmaxprep+0x5f>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1040 <memmove@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1040 <memmove@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strmaxprep>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r15d,%ecx
sub    %eax,%ecx
cmp    %ecx,%ebp
jle    1159 <strmaxprep+0x39>
mov    %rbx,%rdi
call   1030 <strlen@plt>
sub    %eax,%r15d
mov    %r15d,%ebp
movslq %ebp,%rbp
lea    (%rbx,%rbp,1),%r15
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <memmove@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <memmove@plt>

LLVM IR (-O0):
define void @strmaxprep(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i8*, i8** %5
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = load i32, i32* %6
%12 = load i8*, i8** %4
%13 = call i32 @strlen(i8* %12)
%14 = sub nsw i32 %11, %13
%15 = icmp sgt i32 %10, %14
br i1 %15, label %16, label %21
16: ; preds = %3
%17 = load i32, i32* %6
%18 = load i8*, i8** %4
%19 = call i32 @strlen(i8* %18)
%20 = sub nsw i32 %17, %19
store i32 %20, i32* %7
br label %21
21: ; preds = %16, %3
%22 = load i8*, i8** %4
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8*, i8** %4
%27 = load i8*, i8** %4
%28 = call i32 @strlen(i8* %27)
%29 = add nsw i32 %28, 1
%30 = call i32 @memmove(i8* %25, i8* %26, i32 %29)
%31 = load i8*, i8** %4
%32 = load i8*, i8** %5
%33 = load i32, i32* %7
%34 = call i32 @memmove(i8* %31, i8* %32, i32 %33)
ret void
}

LLVM IR (-O2):
define void @strmaxprep(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %1)
%5 = tail call i32 @strlen(i8* %0)
%6 = sub nsw i32 %2, %5
%7 = icmp sgt i32 %4, %6
br i1 %7, label %8, label %11
8: ; preds = %3
%9 = tail call i32 @strlen(i8* %0)
%10 = sub nsw i32 %2, %9
br label %11
11: ; preds = %8, %3
%12 = phi i32 [ %10, %8 ], [ %4, %3 ]
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = tail call i32 @strlen(i8* %0)
%16 = add nsw i32 %15, 1
%17 = tail call i32 @memmove(i8* %14, i8* %0, i32 %16)
%18 = tail call i32 @memmove(i8* %0, i8* %1, i32 %12)
ret void
}