#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(unsigned char *, unsigned char const *, int);
void add_residual(int targ_size, unsigned char *targ_residual, int unit_size,
                  const unsigned char *unit_residual) {
  if (unit_size < targ_size)
    memmove(&targ_residual[((targ_size - unit_size) / 2)], &unit_residual[0],
            unit_size * sizeof(unsigned char));
  else {
    memmove(&targ_residual[0], &unit_residual[((unit_size - targ_size) / 2)],
            targ_size * sizeof(unsigned char));
  }
}


x86 assembly (clang, -O0):
<add_residual>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1161 <add_residual+0x51>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cltq
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edx
call   1030 <memmove@plt>
jmp    118b <add_residual+0x7b>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%eax
sub    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cltq
add    %rax,%rsi
movslq -0x4(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edx
call   1030 <memmove@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_residual>:
mov    %edi,%eax
mov    %edx,%edi
sub    %eax,%edi
jge    1134 <add_residual+0x24>
sub    %edx,%eax
mov    %eax,%edi
shr    $0x1f,%edi
add    %eax,%edi
sar    %edi
movslq %edi,%rax
add    %rax,%rsi
mov    %rsi,%rdi
mov    %rcx,%rsi
jmp    1030 <memmove@plt>
mov    %edi,%edx
shr    $0x1f,%edx
add    %edi,%edx
sar    %edx
movslq %edx,%rdx
add    %rdx,%rcx
mov    %rsi,%rdi
mov    %rcx,%rsi
mov    %eax,%edx
jmp    1030 <memmove@plt>

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

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