char *strings_postfix(char *string, unsigned int length) {
  assert(string);
  unsigned int string_length = strings_length(string);
  assert(length <= string_length);
  char *ret = strings_alloc(length + 1);
  memcpy(ret, &string[string_length - length], (length + 1) * sizeof(char));
  return ret;
}


x86 assembly (clang, -O0):
<strings_postfix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1030 <strings_length@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
setbe  %al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1050 <assert@plt>
mov    -0xc(%rbp),%edi
add    $0x1,%edi
mov    $0x0,%al
call   1040 <strings_alloc@plt>
cltq
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    %eax,%eax
add    %rax,%rsi
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,%eax
mov    %eax,%edx
shl    $0x0,%rdx
call   1060 <memcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strings_postfix>:
push   %r15
push   %r14
push   %rbx
mov    %esi,%r15d
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <assert@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <strings_length@plt>
mov    %eax,%ebx
xor    %edi,%edi
sub    %r15d,%ebx
setae  %dil
xor    %eax,%eax
call   1050 <assert@plt>
add    $0x1,%r15d
mov    %r15d,%edi
xor    %eax,%eax
call   1040 <strings_alloc@plt>
movslq %eax,%rdi
add    %r14,%rbx
mov    %rbx,%rsi
mov    %r15,%rdx
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <memcpy@plt>

LLVM IR (-O0):
define i8* @strings_postfix(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = call i32 (i8*, ...) bitcast (i32 (...)* @assert to i32 (i8*, ...)*)(i8* %7)
%9 = load i8*, i8** %3
%10 = call i32 (i8*, ...) bitcast (i32 (...)* @strings_length to i32 (i8*, ...)*)(i8* %9)
store i32 %10, i32* %5
%11 = load i32, i32* %4
%12 = load i32, i32* %5
%13 = icmp ule i32 %11, %12
%14 = zext i1 %13 to i32
%15 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %14)
%16 = load i32, i32* %4
%17 = add i32 %16, 1
%18 = call i32 (i32, ...) bitcast (i32 (...)* @strings_alloc to i32 (i32, ...)*)(i32 %17)
%19 = sext i32 %18 to i64
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %6
%21 = load i8*, i8** %6
%22 = load i8*, i8** %3
%23 = load i32, i32* %5
%24 = load i32, i32* %4
%25 = sub i32 %23, %24
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %22, i64 %26
%28 = load i32, i32* %4
%29 = add i32 %28, 1
%30 = zext i32 %29 to i64
%31 = mul i64 %30, 1
%32 = load i8*, i8** %6
ret i8* %32
}

LLVM IR (-O2):
define i8* @strings_postfix(i8* %0, i32 %1) {
%3 = tail call i32 (i8*, ...) bitcast (i32 (...)* @assert to i32 (i8*, ...)*)(i8* %0)
%4 = tail call i32 (i8*, ...) bitcast (i32 (...)* @strings_length to i32 (i8*, ...)*)(i8* %0)
%5 = icmp uge i32 %4, %1
%6 = zext i1 %5 to i32
%7 = tail call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %6)
%8 = add i32 %1, 1
%9 = tail call i32 (i32, ...) bitcast (i32 (...)* @strings_alloc to i32 (i32, ...)*)(i32 %8)
%10 = sext i32 %9 to i64
%11 = inttoptr i64 %10 to i8*
%12 = sub i32 %4, %1
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = zext i32 %8 to i64
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 %11, i8* align 1 %14, i64 %15, i1 false)
ret i8* %11
}