#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 */
struct cd_grid {
  int dummy;
};

/* Variables and functions */
int cd_grid_create_sizeown(struct cd_grid **, void *, int, int, int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(int *, int *, int);
int cd_grid_create_sizearray(struct cd_grid **gp, void *cell_init,
                             int cell_size, int n, int *sizes) {
  int *new_sizes;
  new_sizes = (int *)malloc(n * sizeof(int));
  if (!new_sizes) {
    return -1;
  }
  memcpy(new_sizes, sizes, n * sizeof(int));
  return cd_grid_create_sizeown(gp, cell_init, cell_size, n, new_sizes);
}


x86 assembly (clang, -O0):
<cd_grid_create_sizearray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movslq -0x20(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1174 <cd_grid_create_sizearray+0x44>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a5 <cd_grid_create_sizearray+0x75>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
movslq -0x20(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   1040 <memcpy@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x30(%rbp),%r8
call   1030 <cd_grid_create_sizeown@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cd_grid_create_sizearray>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r12
mov    %ecx,%ebx
mov    %edx,0x4(%rsp)
mov    %rsi,%r15
mov    %rdi,%r13
lea    0x0(,%rbx,4),%r14d
mov    %r14d,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1192 <cd_grid_create_sizearray+0x62>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r14d,%edx
call   1040 <memcpy@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    0x4(%rsp),%edx
mov    %ebx,%ecx
mov    %rbp,%r8
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <cd_grid_create_sizeown@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.cd_grid = type { i32 }
define i32 @cd_grid_create_sizearray(%struct.cd_grid** %0, i8* %1, i32 %2, i32 %3, i32* %4) {
%6 = alloca i32
%7 = alloca %struct.cd_grid**
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32*
store %struct.cd_grid** %0, %struct.cd_grid*** %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32* %4, i32** %11
%13 = load i32, i32* %10
%14 = sext i32 %13 to i64
%15 = mul i64 %14, 4
%16 = trunc i64 %15 to i32
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i32*
store i32* %18, i32** %12
%19 = load i32*, i32** %12
%20 = icmp ne i32* %19, null
br i1 %20, label %22, label %21
21: ; preds = %5
store i32 -1, i32* %6
br label %36
22: ; preds = %5
%23 = load i32*, i32** %12
%24 = load i32*, i32** %11
%25 = load i32, i32* %10
%26 = sext i32 %25 to i64
%27 = mul i64 %26, 4
%28 = trunc i64 %27 to i32
%29 = call i32 @memcpy(i32* %23, i32* %24, i32 %28)
%30 = load %struct.cd_grid**, %struct.cd_grid*** %7
%31 = load i8*, i8** %8
%32 = load i32, i32* %9
%33 = load i32, i32* %10
%34 = load i32*, i32** %12
%35 = call i32 @cd_grid_create_sizeown(%struct.cd_grid** %30, i8* %31, i32 %32, i32 %33, i32* %34)
store i32 %35, i32* %6
br label %36
36: ; preds = %22, %21
%37 = load i32, i32* %6
ret i32 %37
}

LLVM IR (-O2):
%struct.cd_grid = type { i32 }
define i32 @cd_grid_create_sizearray(%struct.cd_grid** %0, i8* %1, i32 %2, i32 %3, i32* %4) {
%6 = shl i32 %3, 2
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i32*
%9 = icmp eq i64 %7, 0
br i1 %9, label %13, label %10
10: ; preds = %5
%11 = tail call i32 @memcpy(i32* %8, i32* %4, i32 %6)
%12 = tail call i32 @cd_grid_create_sizeown(%struct.cd_grid** %0, i8* %1, i32 %2, i32 %3, i32* %8)
br label %13
13: ; preds = %5, %10
%14 = phi i32 [ %12, %10 ], [ -1, %5 ]
ret i32 %14
}