#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 *malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ set_param_array_copy(int *, int *, int);
int *init_param_array_copy(int *src, int n) {
  int *dst;
  dst = malloc(n * sizeof *dst);
  if (dst == NULL) {
    printf("Error allocating memory.\n");
    return NULL;
  }
  set_param_array_copy(dst, src, n);
  return dst;
}


x86 assembly (clang, -O0):
<init_param_array_copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1176 <init_param_array_copy+0x46>
lea    0xe9c(%rip),%rdi
call   1040 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    118e <init_param_array_copy+0x5e>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <set_param_array_copy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_param_array_copy>:
push   %r15
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r15
lea    0x0(,%r14,4),%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1160 <init_param_array_copy+0x30>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1040 <set_param_array_copy@plt>
jmp    116c <init_param_array_copy+0x3c>
lea    0xe99(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Error allocating memory.\0A\00"
define i32* @init_param_array_copy(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32*
store i32* %0, i32** %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = sext i32 %7 to i64
%9 = mul i64 %8, 4
%10 = trunc i64 %9 to i32
%11 = call i32* @malloc(i32 %10)
store i32* %11, i32** %6
%12 = load i32*, i32** %6
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32* null, i32** %3
br label %22
16: ; preds = %2
%17 = load i32*, i32** %6
%18 = load i32*, i32** %4
%19 = load i32, i32* %5
%20 = call i32 @set_param_array_copy(i32* %17, i32* %18, i32 %19)
%21 = load i32*, i32** %6
store i32* %21, i32** %3
br label %22
22: ; preds = %16, %14
%23 = load i32*, i32** %3
ret i32* %23
}

LLVM IR (-O2):
@str = [25 x i8] c"Error allocating memory.\00"
define i32* @init_param_array_copy(i32* %0, i32 %1) {
%3 = shl i32 %1, 2
%4 = tail call i32* @malloc(i32 %3)
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %10
8: ; preds = %2
%9 = tail call i32 @set_param_array_copy(i32* %4, i32* %0, i32 %1)
br label %10
10: ; preds = %8, %6
ret i32* %4
}