#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__ calloc(int, int);
int *calc(int source, int base) {
  int i;
  int *p = NULL;
  int *array = (int *)calloc(32, 32 * sizeof(int));
  p = &array[32 - 1];
  do {
    *p = source % base;
    source = source / base;
    p--;
  } while (source != 0);
  p = &array[0];
  return p;
}


x86 assembly (clang, -O0):
<calc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
mov    $0x20,%edi
mov    $0x80,%esi
call   1030 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x7c,%rax
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    -0x18(%rbp),%rax
mov    %edx,(%rax)
mov    -0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,-0x4(%rbp)
mov    -0x18(%rbp),%rax
add    $0xfffffffffffffffc,%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1145 <calc+0x35>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
mov    $0x20,%edi
mov    $0x80,%esi
call   1030 <calloc@plt>
mov    %rax,%rcx
mov    %rax,%rsi
add    $0x7c,%rsi
mov    %ebp,%eax
cltd
idiv   %ebx
mov    %edx,(%rsi)
add    $0xfffffffffffffffc,%rsi
mov    %eax,%ebp
test   %eax,%eax
jne    1130 <calc+0x20>
mov    %rcx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32* @calc(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
store i32* null, i32** %6
%8 = call i64 @calloc(i32 32, i32 128)
%9 = inttoptr i64 %8 to i32*
store i32* %9, i32** %7
%10 = load i32*, i32** %7
%11 = getelementptr inbounds i32, i32* %10, i64 31
store i32* %11, i32** %6
br label %12
12: ; preds = %22, %2
%13 = load i32, i32* %3
%14 = load i32, i32* %4
%15 = srem i32 %13, %14
%16 = load i32*, i32** %6
store i32 %15, i32* %16
%17 = load i32, i32* %3
%18 = load i32, i32* %4
%19 = sdiv i32 %17, %18
store i32 %19, i32* %3
%20 = load i32*, i32** %6
%21 = getelementptr inbounds i32, i32* %20, i32 -1
store i32* %21, i32** %6
br label %22
22: ; preds = %12
%23 = load i32, i32* %3
%24 = icmp ne i32 %23, 0
br i1 %24, label %12, label %25
25: ; preds = %22
%26 = load i32*, i32** %7
%27 = getelementptr inbounds i32, i32* %26, i64 0
store i32* %27, i32** %6
%28 = load i32*, i32** %6
ret i32* %28
}

LLVM IR (-O2):
define i32* @calc(i32 %0, i32 %1) {
%3 = tail call i64 @calloc(i32 32, i32 128)
%4 = inttoptr i64 %3 to i32*
%5 = getelementptr inbounds i32, i32* %4, i64 31
br label %6
6: ; preds = %6, %2
%7 = phi i32* [ %5, %2 ], [ %11, %6 ]
%8 = phi i32 [ %0, %2 ], [ %10, %6 ]
%9 = srem i32 %8, %1
store i32 %9, i32* %7
%10 = sdiv i32 %8, %1
%11 = getelementptr inbounds i32, i32* %7, i64 -1
%12 = icmp eq i32 %10, 0
br i1 %12, label %13, label %6
13: ; preds = %6
ret i32* %4
}