#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*/ abort();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, long);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(int *, int const *, long);
int /*<<< orphan*/ stderr;
int *ivec_new_cpy(const int *v, long n) {
  int *ret = (int *)malloc(sizeof(int) * n);
  if (!ret) {
    fprintf(stderr, "ivec_new %ld : out of memory\n", n);
    abort();
  }
  memcpy(ret, v, n * sizeof(*ret));
  return ret;
}


x86 assembly (clang, -O0):
<ivec_new_cpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118e <ivec_new_cpy+0x4e>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe7e(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
shl    $0x2,%rdx
call   1050 <memcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ivec_new_cpy>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x0(,%rsi,4),%r12
mov    %r12d,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     1183 <ivec_new_cpy+0x43>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <memcpy@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"ivec_new %ld : out of memory\0A\00"
define i32* @ivec_new_cpy(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i32*
store i32* %0, i32** %3
store i64 %1, i64* %4
%6 = load i64, i64* %4
%7 = mul i64 4, %6
%8 = trunc i64 %7 to i32
%9 = call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to i32*
store i32* %10, i32** %5
%11 = load i32*, i32** %5
%12 = icmp ne i32* %11, null
br i1 %12, label %18, label %13
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i64, i64* %4
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i64 %15)
%17 = call i32 (...) @abort()
unreachable
18: ; preds = %2
%19 = load i32*, i32** %5
%20 = load i32*, i32** %3
%21 = load i64, i64* %4
%22 = mul i64 %21, 4
%23 = call i32 @memcpy(i32* %19, i32* %20, i64 %22)
%24 = load i32*, i32** %5
ret i32* %24
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"ivec_new %ld : out of memory\0A\00"
define i32* @ivec_new_cpy(i32* %0, i64 %1) {
%3 = shl i64 %1, 2
%4 = trunc i64 %3 to i32
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to i32*
%7 = icmp eq i64 %5, 0
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i64 %1)
%11 = tail call i32 (...) @abort()
unreachable
12: ; preds = %2
%13 = tail call i32 @memcpy(i32* %6, i32* %0, i64 %3)
ret i32* %6
}