#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 *CopyPolyProduct(const int *ptrSrc, int *ptrDest, int polyDegree) {
  const int *ptrValueSrc = ptrSrc;
  int *ptrValueDest = ptrDest;
  for (int currentDegree = 0; currentDegree <= polyDegree; currentDegree++) {
    int nbrLength = 1 + numLimbs(ptrValueSrc);
    int lenBytes = nbrLength * (int)sizeof(int);
    (void)memcpy(ptrValueDest, ptrValueSrc, lenBytes);
    ptrValueSrc += nbrLength;
    ptrValueDest += nbrLength;
  }
  return ptrValueDest;
}


x86 assembly (clang, -O0):
<CopyPolyProduct>:
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)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     11b6 <CopyPolyProduct+0x96>
mov    -0x20(%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    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x30(%rbp),%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    114a <CopyPolyProduct+0x2a>
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CopyPolyProduct>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
test   %edx,%edx
js     1174 <CopyPolyProduct+0x54>
mov    %edx,%r14d
mov    %rdi,%rbp
add    $0x1,%r14d
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1040 <numLimbs@plt>
mov    %eax,%r15d
lea    0x4(,%r15,4),%edx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1030 <memcpy@plt>
movslq %r15d,%rax
lea    0x4(%rbp,%rax,4),%rbp
lea    (%rbx,%rax,4),%rbx
add    $0x4,%rbx
add    $0xffffffff,%r14d
jne    1140 <CopyPolyProduct+0x20>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32* @CopyPolyProduct(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
store i32 0, i32* %9
br label %14
14: ; preds = %36, %3
%15 = load i32, i32* %9
%16 = load i32, i32* %6
%17 = icmp sle i32 %15, %16
br i1 %17, label %18, label %39
18: ; preds = %14
%19 = load i32*, i32** %7
%20 = call i32 @numLimbs(i32* %19)
%21 = add nsw i32 1, %20
store i32 %21, i32* %10
%22 = load i32, i32* %10
%23 = mul nsw i32 %22, 4
store i32 %23, i32* %11
%24 = load i32*, i32** %8
%25 = load i32*, i32** %7
%26 = load i32, i32* %11
%27 = call i32 @memcpy(i32* %24, i32* %25, i32 %26)
%28 = load i32, i32* %10
%29 = load i32*, i32** %7
%30 = sext i32 %28 to i64
%31 = getelementptr inbounds i32, i32* %29, i64 %30
store i32* %31, i32** %7
%32 = load i32, i32* %10
%33 = load i32*, i32** %8
%34 = sext i32 %32 to i64
%35 = getelementptr inbounds i32, i32* %33, i64 %34
store i32* %35, i32** %8
br label %36
36: ; preds = %18
%37 = load i32, i32* %9
%38 = add nsw i32 %37, 1
store i32 %38, i32* %9
br label %14
39: ; preds = %14
%40 = load i32*, i32** %8
ret i32* %40
}

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