#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__ ceil(int /*<<< orphan*/);
int /*<<< orphan*/ constructSTUtil(int *, int /*<<< orphan*/, int, int *,
                                   int /*<<< orphan*/);
int /*<<< orphan*/ log2(int);
scalar_t__ malloc(int);
scalar_t__ pow(int, int);
int *constructST(int arr[], int n) {
  int x = (int)(ceil(log2(n)));
  int max_size = 2 * (int)pow(2, x) - 1;
  int *st = (int *)malloc(sizeof(int) * max_size);
  constructSTUtil(arr, 0, n - 1, st, 0);
  return st;
}


x86 assembly (clang, -O0):
<constructST>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <log2@plt>
mov    %eax,%edi
call   1040 <ceil@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
mov    $0x2,%edi
call   1070 <pow@plt>
shl    $0x1,%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
mov    -0x20(%rbp),%rcx
xor    %r8d,%r8d
mov    %r8d,%esi
call   1060 <constructSTUtil@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<constructST>:
push   %r15
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %rdi,%r14
mov    %esi,%edi
call   1030 <log2@plt>
mov    %eax,%edi
call   1040 <ceil@plt>
mov    $0x2,%edi
mov    %eax,%esi
call   1070 <pow@plt>
lea    -0x4(,%rax,8),%edi
call   1050 <malloc@plt>
mov    %rax,%r15
add    $0xffffffff,%ebx
mov    %r14,%rdi
xor    %esi,%esi
mov    %ebx,%edx
mov    %rax,%rcx
xor    %r8d,%r8d
call   1060 <constructSTUtil@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32* @constructST(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
store i32* %0, i32** %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = call i32 @log2(i32 %8)
%10 = call i64 @ceil(i32 %9)
%11 = trunc i64 %10 to i32
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = call i64 @pow(i32 2, i32 %12)
%14 = trunc i64 %13 to i32
%15 = mul nsw i32 2, %14
%16 = sub nsw i32 %15, 1
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = mul i64 4, %18
%20 = trunc i64 %19 to i32
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i32*
store i32* %22, i32** %7
%23 = load i32*, i32** %3
%24 = load i32, i32* %4
%25 = sub nsw i32 %24, 1
%26 = load i32*, i32** %7
%27 = call i32 @constructSTUtil(i32* %23, i32 0, i32 %25, i32* %26, i32 0)
%28 = load i32*, i32** %7
ret i32* %28
}

LLVM IR (-O2):
define i32* @constructST(i32* %0, i32 %1) {
%3 = tail call i32 @log2(i32 %1)
%4 = tail call i64 @ceil(i32 %3)
%5 = trunc i64 %4 to i32
%6 = tail call i64 @pow(i32 2, i32 %5)
%7 = trunc i64 %6 to i32
%8 = shl i32 %7, 3
%9 = add i32 %8, -4
%10 = tail call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i32*
%12 = add nsw i32 %1, -1
%13 = tail call i32 @constructSTUtil(i32* %0, i32 0, i32 %12, i32* %11, i32 0)
ret i32* %11
}