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


x86 assembly (clang, -O0):
<makeST>:
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)
mov    -0x14(%rbp),%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 <makeSTUtil@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makeST>:
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    (%rax,%rax,1),%edi
add    $0xffffffff,%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 <makeSTUtil@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32* @makeST(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 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i32*
store i32* %19, i32** %7
%20 = load i32*, i32** %3
%21 = load i32, i32* %4
%22 = sub nsw i32 %21, 1
%23 = load i32*, i32** %7
%24 = call i32 @makeSTUtil(i32* %20, i32 0, i32 %22, i32* %23, i32 0)
%25 = load i32*, i32** %7
ret i32* %25
}

LLVM IR (-O2):
define i32* @makeST(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 nsw i32 %7, 1
%9 = add nsw i32 %8, -1
%10 = tail call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i32*
%12 = add nsw i32 %1, -1
%13 = tail call i32 @makeSTUtil(i32* %0, i32 0, i32 %12, i32* %11, i32 0)
ret i32* %11
}