#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 */
scalar_t__ malloc(size_t);
scalar_t__ realloc(double *, size_t);
int resize_arrayd(double **array, size_t count) {
  typedef double type;
  size_t new_size = count * sizeof(type);
  if (*array) {
    type *old_array = *array;
    *array = (type *)realloc(*array, new_size);
    if (!*array) {
      *array = old_array;
      return 1;
    }
  } else {
    *array = (type *)malloc(new_size);
    if (!*array)
      return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<resize_arrayd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x3,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     1199 <resize_arrayd+0x79>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <realloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1194 <resize_arrayd+0x74>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11d2 <resize_arrayd+0xb2>
jmp    11cb <resize_arrayd+0xab>
mov    -0x20(%rbp),%rdi
call   1030 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11c6 <resize_arrayd+0xa6>
movl   $0x1,-0x4(%rbp)
jmp    11d2 <resize_arrayd+0xb2>
jmp    11cb <resize_arrayd+0xab>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resize_arrayd>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
shl    $0x3,%rsi
mov    (%rdi),%rbx
test   %rbx,%rbx
je     114d <resize_arrayd+0x2d>
mov    %rbx,%rdi
call   1040 <realloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
jne    115d <resize_arrayd+0x3d>
mov    %rbx,(%r14)
mov    $0x1,%eax
jmp    115f <resize_arrayd+0x3f>
mov    %rsi,%rdi
call   1030 <malloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     1167 <resize_arrayd+0x47>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    $0x1,%eax
jmp    115f <resize_arrayd+0x3f>

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

LLVM IR (-O2):
define i32 @resize_arrayd(double** nocapture %0, i64 %1) {
%3 = shl i64 %1, 3
%4 = load double*, double** %0
%5 = icmp eq double* %4, null
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = tail call i64 @realloc(double* %4, i64 %3)
%8 = inttoptr i64 %7 to double*
store double* %8, double** %0
%9 = icmp eq i64 %7, 0
br i1 %9, label %10, label %15
10: ; preds = %6
store double* %4, double** %0
br label %16
11: ; preds = %2
%12 = tail call i64 @malloc(i64 %3)
%13 = inttoptr i64 %12 to double*
store double* %13, double** %0
%14 = icmp eq i64 %12, 0
br i1 %14, label %16, label %15
15: ; preds = %6, %11
br label %16
16: ; preds = %10, %11, %15
%17 = phi i32 [ 0, %15 ], [ 1, %10 ], [ 1, %11 ]
ret i32 %17
}