#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 */
typedef int /*<<< orphan*/ uint8_t;

/* Variables and functions */
scalar_t__ ceil(double);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ *realloc(int /*<<< orphan*/ *, size_t);
uint8_t *grow(uint8_t *digits, size_t *nallocp) {
  size_t nalloc = *nallocp;
  size_t prev = nalloc;
  nalloc = (size_t)ceil(1.618 * (double)nalloc);
  digits = realloc(digits, nalloc);
  memset(&digits[prev], 0, nalloc - prev);
  *nallocp = nalloc;
  return digits;
}


x86 assembly (clang, -O0):
<grow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
movaps 0xeb6(%rip),%xmm0
movq   -0x18(%rbp),%xmm1
punpckldq %xmm0,%xmm1
movapd 0xeb5(%rip),%xmm0
subpd  %xmm0,%xmm1
movaps %xmm1,%xmm0
unpckhpd %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe7e(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1030 <ceil@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <realloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rdx
sub    -0x20(%rbp),%rdx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grow>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    (%rsi),%r12
movq   %r12,%xmm1
punpckldq 0xeb2(%rip),%xmm1
subpd  0xeba(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xeb6(%rip),%xmm0
call   1030 <ceil@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1050 <realloc@plt>
mov    %rax,%r14
lea    (%rax,%r12,4),%rdi
mov    %rbx,%rdx
sub    %r12,%rdx
xor    %esi,%esi
call   1040 <memset@plt>
mov    %rbx,(%r15)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32* @grow(i32* %0, i64* %1) {
%3 = alloca i32*
%4 = alloca i64*
%5 = alloca i64
%6 = alloca i64
store i32* %0, i32** %3
store i64* %1, i64** %4
%7 = load i64*, i64** %4
%8 = load i64, i64* %7
store i64 %8, i64* %5
%9 = load i64, i64* %5
store i64 %9, i64* %6
%10 = load i64, i64* %5
%11 = uitofp i64 %10 to double
%12 = fmul double 1.618000e+00, %11
%13 = call i64 @ceil(double %12)
store i64 %13, i64* %5
%14 = load i32*, i32** %3
%15 = load i64, i64* %5
%16 = call i32* @realloc(i32* %14, i64 %15)
store i32* %16, i32** %3
%17 = load i32*, i32** %3
%18 = load i64, i64* %6
%19 = getelementptr inbounds i32, i32* %17, i64 %18
%20 = load i64, i64* %5
%21 = load i64, i64* %6
%22 = sub i64 %20, %21
%23 = call i32 @memset(i32* %19, i32 0, i64 %22)
%24 = load i64, i64* %5
%25 = load i64*, i64** %4
store i64 %24, i64* %25
%26 = load i32*, i32** %3
ret i32* %26
}

LLVM IR (-O2):
define i32* @grow(i32* nocapture %0, i64* nocapture %1) {
%3 = load i64, i64* %1
%4 = uitofp i64 %3 to double
%5 = fmul double %4, 1.618000e+00
%6 = tail call i64 @ceil(double %5)
%7 = tail call i32* @realloc(i32* %0, i64 %6)
%8 = getelementptr inbounds i32, i32* %7, i64 %3
%9 = sub i64 %6, %3
%10 = tail call i32 @memset(i32* %8, i32 0, i64 %9)
store i64 %6, i64* %1
ret i32* %7
}