#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*/ test_arr;

/* Variables and functions */
int arr_to_state(int *, int, int);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ print_arr(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ state_to_arr(int, int, int *, int);
int main() {
  int test_base = 7;
  int test_arr[] = {5, 4, 1, 6, 3, 2};
  int test_arr_len = sizeof(test_arr) / sizeof(int);
  printf("test_arr: {");
  print_arr(test_arr, test_arr_len);
  puts("}");
  int test_state = arr_to_state(test_arr, test_arr_len, test_base);
  printf("test_state == %d\n", test_state);
  int *restored_arr = (int *)calloc(test_arr_len, sizeof(int));
  state_to_arr(test_state, test_base, restored_arr, test_arr_len);
  printf("restored_arr: {");
  print_arr(restored_arr, test_arr_len);
  puts("}");
  free(restored_arr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x7,-0x8(%rbp)
mov    0xe73(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe70(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xe6d(%rip),%rax
mov    %rax,-0x10(%rbp)
movl   $0x6,-0x24(%rbp)
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1050 <print_arr@plt>
lea    0xe55(%rip),%rdi
call   1040 <puts@plt>
lea    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x8(%rbp),%edx
call   1090 <arr_to_state@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%esi
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x24(%rbp),%edi
mov    $0x4,%esi
call   1070 <calloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x30(%rbp),%rdx
mov    -0x24(%rbp),%ecx
call   1080 <state_to_arr@plt>
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1050 <print_arr@plt>
lea    0xde9(%rip),%rdi
call   1040 <puts@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    0xe91(%rip),%rax
mov    %rax,0x10(%rsp)
movaps 0xe75(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xe82(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x6,%esi
call   1050 <print_arr@plt>
lea    0xe70(%rip),%r14
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
mov    $0x7,%edx
call   1090 <arr_to_state@plt>
mov    %eax,%ebp
lea    0xe4f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x6,%edi
mov    $0x4,%esi
call   1070 <calloc@plt>
mov    %rax,%rbx
mov    %ebp,%edi
mov    $0x7,%esi
mov    %rax,%rdx
mov    $0x6,%ecx
call   1080 <state_to_arr@plt>
lea    0xe2b(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
call   1050 <print_arr@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.test_arr = [6 x i32] [i32 5, i32 4, i32 1, i32 6, i32 3, i32 2]
@.str = [12 x i8] c"test_arr: {\00"
@.str.1 = [2 x i8] c"}\00"
@.str.2 = [18 x i8] c"test_state == %d\0A\00"
@.str.3 = [16 x i8] c"restored_arr: {\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [6 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
store i32 0, i32* %1
store i32 7, i32* %2
%7 = bitcast [6 x i32]* %3 to i8*
store i32 6, i32* %4
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 0
%10 = load i32, i32* %4
%11 = call i32 @print_arr(i32* %9, i32 %10)
%12 = call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 0
%14 = load i32, i32* %4
%15 = load i32, i32* %2
%16 = call i32 @arr_to_state(i32* %13, i32 %14, i32 %15)
store i32 %16, i32* %5
%17 = load i32, i32* %5
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %4
%20 = call i64 @calloc(i32 %19, i32 4)
%21 = inttoptr i64 %20 to i32*
store i32* %21, i32** %6
%22 = load i32, i32* %5
%23 = load i32, i32* %2
%24 = load i32*, i32** %6
%25 = load i32, i32* %4
%26 = call i32 @state_to_arr(i32 %22, i32 %23, i32* %24, i32 %25)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%28 = load i32*, i32** %6
%29 = load i32, i32* %4
%30 = call i32 @print_arr(i32* %28, i32 %29)
%31 = call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%32 = load i32*, i32** %6
%33 = call i32 @free(i32* %32)
ret i32 0
}

LLVM IR (-O2):
@__const.main.test_arr = [6 x i32] [i32 5, i32 4, i32 1, i32 6, i32 3, i32 2]
@.str = [12 x i8] c"test_arr: {\00"
@.str.1 = [2 x i8] c"}\00"
@.str.2 = [18 x i8] c"test_state == %d\0A\00"
@.str.3 = [16 x i8] c"restored_arr: {\00"
define i32 @main() {
%1 = alloca [6 x i32]
%2 = bitcast [6 x i32]* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [6 x i32], [6 x i32]* %1, i64 0, i64 0
%5 = call i32 @print_arr(i32* %4, i32 6)
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @arr_to_state(i32* %4, i32 6, i32 7)
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = call i64 @calloc(i32 6, i32 4)
%10 = inttoptr i64 %9 to i32*
%11 = call i32 @state_to_arr(i32 %7, i32 7, i32* %10, i32 6)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 @print_arr(i32* %10, i32 6)
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @free(i32* %10)
ret i32 0
}