#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 */
int *change_basis_ptr(int, int, int *);
int /*<<< orphan*/ printf(char *, int);
int main() {
  int x = 3876344, ptr_size = 0, i, check = 0;
  int *ptr;
  ptr = change_basis_ptr(x, 256, &ptr_size);
  printf("Base 10 -> %d\n", x);
  printf("Base %d -> ", 256);
  for (i = 0; i < ptr_size; i++) {
    printf("%d ", ptr[i]);
    check = check * 256 + ptr[i];
  }
  printf(" \nBase 10 -> %d\n", check);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x3b25f8,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x100,%esi
lea    -0xc(%rbp),%rdx
call   1040 <change_basis_ptr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%esi
lea    0xeaf(%rip),%rdi
call   1030 <printf@plt>
lea    0xe91(%rip),%rdi
mov    $0x100,%esi
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c5 <main+0xa5>
mov    -0x20(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe6e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
shl    $0x8,%eax
mov    -0x20(%rbp),%rcx
movslq -0x10(%rbp),%rdx
add    (%rcx,%rdx,4),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1180 <main+0x60>
mov    -0x14(%rbp),%esi
lea    0xe41(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
movl   $0x0,0x4(%rsp)
lea    0x4(%rsp),%rdx
mov    $0x3b25f8,%edi
mov    $0x100,%esi
call   1040 <change_basis_ptr@plt>
mov    %rax,%r15
lea    0xec5(%rip),%rdi
mov    $0x3b25f8,%esi
call   1030 <printf@plt>
lea    0xea2(%rip),%rdi
mov    $0x100,%esi
call   1030 <printf@plt>
cmpl   $0x0,0x4(%rsp)
jle    11a3 <main+0x83>
xor    %ebx,%ebx
lea    0xe94(%rip),%r14
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    (%r15,%rbx,4),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
shl    $0x8,%ebp
add    (%r15,%rbx,4),%ebp
add    $0x1,%rbx
movslq 0x4(%rsp),%rax
cmp    %rax,%rbx
jl     1180 <main+0x60>
jmp    11a5 <main+0x85>
xor    %ebp,%ebp
lea    0xe64(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Base 10 -> %d\0A\00"
@.str.1 = [12 x i8] c"Base %d -> \00"
@.str.2 = [4 x i8] c"%d \00"
@.str.3 = [17 x i8] c" \0ABase 10 -> %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
store i32 0, i32* %1
store i32 3876344, i32* %2
store i32 0, i32* %3
store i32 0, i32* %5
%7 = load i32, i32* %2
%8 = call i32* @change_basis_ptr(i32 %7, i32 256, i32* %3)
store i32* %8, i32** %6
%9 = load i32, i32* %2
%10 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 256)
store i32 0, i32* %4
br label %12
12: ; preds = %31, %0
%13 = load i32, i32* %4
%14 = load i32, i32* %3
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %34
16: ; preds = %12
%17 = load i32*, i32** %6
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %17, i64 %19
%21 = load i32, i32* %20
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %5
%24 = mul nsw i32 %23, 256
%25 = load i32*, i32** %6
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
%29 = load i32, i32* %28
%30 = add nsw i32 %24, %29
store i32 %30, i32* %5
br label %31
31: ; preds = %16
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 1
store i32 %33, i32* %4
br label %12
34: ; preds = %12
%35 = load i32, i32* %5
%36 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %35)
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"Base 10 -> %d\0A\00"
@.str.1 = [12 x i8] c"Base %d -> \00"
@.str.2 = [4 x i8] c"%d \00"
@.str.3 = [17 x i8] c" \0ABase 10 -> %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = call i32* @change_basis_ptr(i32 3876344, i32 256, i32* %1)
%4 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 3876344)
%5 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 256)
%6 = load i32, i32* %1
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %21
8: ; preds = %0, %8
%9 = phi i64 [ %17, %8 ], [ 0, %0 ]
%10 = phi i32 [ %16, %8 ], [ 0, %0 ]
%11 = getelementptr inbounds i32, i32* %3, i64 %9
%12 = load i32, i32* %11
%13 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = shl nsw i32 %10, 8
%15 = load i32, i32* %11
%16 = add nsw i32 %15, %14
%17 = add nuw nsw i64 %9, 1
%18 = load i32, i32* %1
%19 = sext i32 %18 to i64
%20 = icmp slt i64 %17, %19
br i1 %20, label %8, label %21
21: ; preds = %8, %0
%22 = phi i32 [ 0, %0 ], [ %16, %8 ]
%23 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %22)
ret i32 0
}