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


x86 assembly (clang, -O0):
<strmaxins>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x24(%rbp),%ecx
mov    %eax,%edx
mov    -0x20(%rbp),%eax
sub    %edx,%ecx
cmp    %ecx,%eax
jle    1182 <strmaxins+0x62>
mov    -0x18(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%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
sub    -0x14(%rbp),%edx
call   1040 <memmove@plt>
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <memmove@plt>
add    $0x40,%rsp
pop    %rbp
ret

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

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

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