#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*/ memcpy(int *, int const *, int);
int numLimbs(int const *);
int *CopyPolynomial(int *dest, const int *src, int polyDegree) {
  int *ptrDest = dest;
  const int *ptrSrc = src;
  int currentDegree;
  if (polyDegree >= 0) {
    currentDegree = 0;
  } else {
    currentDegree = polyDegree;
  }
  for (; currentDegree <= polyDegree; currentDegree++) {
    int numLength = numLimbs(ptrSrc) + 1;
    int lenBytes = numLength * (int)sizeof(int);
    (void)memcpy(ptrDest, ptrSrc, lenBytes);
    ptrSrc += numLength;
    ptrDest += numLength;
  }
  return ptrDest;
}


x86 assembly (clang, -O0):
<CopyPolynomial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     1159 <CopyPolynomial+0x39>
movl   $0x0,-0x2c(%rbp)
jmp    115f <CopyPolynomial+0x3f>
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    1164 <CopyPolynomial+0x44>
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     11d0 <CopyPolynomial+0xb0>
mov    -0x28(%rbp),%rdi
call   1040 <numLimbs@plt>
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
shl    $0x2,%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x30(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1164 <CopyPolynomial+0x44>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CopyPolynomial>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %edx,%ebp
sar    $0x1f,%ebp
not    %ebp
and    %edx,%ebp
add    $0x1,%ebp
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1040 <numLimbs@plt>
mov    %eax,%r15d
lea    0x4(,%r15,4),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <memcpy@plt>
movslq %r15d,%rax
lea    (%rbx,%rax,4),%rbx
add    $0x4,%rbx
lea    (%r14,%rax,4),%r14
add    $0x4,%r14
add    $0xffffffff,%ebp
jne    1140 <CopyPolynomial+0x20>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32* @CopyPolynomial(i32* %0, i32* %1, i32 %2) {
%4 = icmp slt i32 %2, 0
%5 = select i1 %4, i32 %2, i32 0
br label %6
6: ; preds = %3, %6
%7 = phi i32* [ %0, %3 ], [ %16, %6 ]
%8 = phi i32* [ %1, %3 ], [ %15, %6 ]
%9 = phi i32 [ %5, %3 ], [ %17, %6 ]
%10 = tail call i32 @numLimbs(i32* %8)
%11 = add nsw i32 %10, 1
%12 = shl nsw i32 %11, 2
%13 = tail call i32 @memcpy(i32* %7, i32* %8, i32 %12)
%14 = sext i32 %11 to i64
%15 = getelementptr inbounds i32, i32* %8, i64 %14
%16 = getelementptr inbounds i32, i32* %7, i64 %14
%17 = add i32 %9, 1
%18 = icmp eq i32 %9, %2
br i1 %18, label %19, label %6
19: ; preds = %6
ret i32* %16
}