#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 */
typedef int /*<<< orphan*/ uint8_t;

/* Variables and functions */
int imax(int const, int);
int /*<<< orphan*/ imin(int, int);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *const,
                          int /*<<< orphan*/ const *const, int /*<<< orphan*/);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *const, int, int const);
void insert_border(uint8_t *const dst, const uint8_t *const src,
                   const int ctr) {
  if (ctr > 4)
    memset(dst, 0, ctr - 4);
  memcpy(dst + imax(ctr, 4) - 4, src + imax(4 - ctr, 0), imin(64 - ctr, 8));
  if (ctr < 64 - 4)
    memset(dst + ctr + 4, 64, 64 - 4 - ctr);
}


x86 assembly (clang, -O0):
<insert_border>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jle    116e <insert_border+0x2e>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
sub    $0x4,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x4,%esi
call   1050 <imax@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
add    $0xfffffffffffffff0,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    $0x4,%edi
sub    -0x14(%rbp),%edi
xor    %esi,%esi
call   1050 <imax@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    $0x40,%edi
sub    -0x14(%rbp),%edi
mov    $0x8,%esi
call   1030 <imin@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1060 <memcpy@plt>
cmpl   $0x3c,-0x14(%rbp)
jge    1216 <insert_border+0xd6>
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
add    $0x10,%rdi
mov    $0x3c,%edx
sub    -0x14(%rbp),%edx
mov    $0x40,%esi
call   1040 <memset@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insert_border>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r15
mov    %rdi,%r14
cmp    $0x5,%edx
jl     1162 <insert_border+0x22>
lea    -0x4(%rbx),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    $0x4,%ebp
mov    %ebx,%edi
mov    $0x4,%esi
call   1050 <imax@plt>
cltq
lea    (%r14,%rax,4),%r12
add    $0xfffffffffffffff0,%r12
sub    %ebx,%ebp
mov    %ebp,%edi
xor    %esi,%esi
call   1050 <imax@plt>
cltq
lea    (%r15,%rax,4),%rbp
mov    $0x40,%edi
sub    %ebx,%edi
mov    $0x8,%esi
call   1030 <imin@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1060 <memcpy@plt>
cmp    $0x3b,%ebx
jg     11d5 <insert_border+0x95>
movslq %ebx,%rax
lea    (%r14,%rax,4),%rdi
add    $0x10,%rdi
mov    $0x3c,%edx
sub    %ebx,%edx
mov    $0x40,%esi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <memset@plt>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @insert_border(i32* %0, i32* %1, i32 %2) {
%4 = icmp sgt i32 %2, 4
br i1 %4, label %5, label %8
5: ; preds = %3
%6 = add nsw i32 %2, -4
%7 = tail call i32 @memset(i32* %0, i32 0, i32 %6)
br label %8
8: ; preds = %5, %3
%9 = tail call i32 @imax(i32 %2, i32 4)
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i32, i32* %0, i64 %10
%12 = getelementptr inbounds i32, i32* %11, i64 -4
%13 = sub nsw i32 4, %2
%14 = tail call i32 @imax(i32 %13, i32 0)
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %1, i64 %15
%17 = sub nsw i32 64, %2
%18 = tail call i32 @imin(i32 %17, i32 8)
%19 = tail call i32 @memcpy(i32* %12, i32* %16, i32 %18)
%20 = icmp slt i32 %2, 60
br i1 %20, label %21, label %27
21: ; preds = %8
%22 = sext i32 %2 to i64
%23 = getelementptr inbounds i32, i32* %0, i64 %22
%24 = getelementptr inbounds i32, i32* %23, i64 4
%25 = sub nsw i32 60, %2
%26 = tail call i32 @memset(i32* %24, i32 64, i32 %25)
br label %27
27: ; preds = %21, %8
ret void
}