#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 /*<<< orphan*/ free(unsigned int *);
unsigned int *numToDigits(long);
int /*<<< orphan*/ outArrInt(unsigned int *, int);
int /*<<< orphan*/ palin(unsigned int *, int /*<<< orphan*/, int,
                         int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
void testPalin() {
  int test_cases = 8;
  int sizes[] = {1, 2, 3, 4, 5, 8, 13, 18};
  long ns[] = {8,     12,       113,           4999,
               69999, 22833822, 2053320533443, 100000000000000002L};
  for (int i = 0; i < test_cases; i++) {
    unsigned *xs = numToDigits(ns[i]);
    printf("%ld: \n", ns[i]);
    outArrInt(xs, sizes[i]);
    palin(xs, 0, sizes[i] - 1, 0);
    outArrInt(xs, sizes[i]);
    printf("\n");
    free(xs);
  }
}


x86 assembly (clang, -O0):
<testPalin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x8,-0x4(%rbp)
mov    0xe87(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe84(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe81(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe7e(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x70(%rbp),%rdi
lea    0xe77(%rip),%rsi
mov    $0x40,%edx
call   1060 <memcpy@plt>
movl   $0x0,-0x74(%rbp)
mov    -0x74(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    124e <testPalin+0xee>
movslq -0x74(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rdi
call   1040 <numToDigits@plt>
mov    %rax,-0x80(%rbp)
movslq -0x74(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rsi
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x80(%rbp),%rdi
movslq -0x74(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%esi
call   1080 <outArrInt@plt>
mov    -0x80(%rbp),%rdi
movslq -0x74(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edx
sub    $0x1,%edx
xor    %ecx,%ecx
mov    %ecx,%esi
call   1070 <palin@plt>
mov    -0x80(%rbp),%rdi
movslq -0x74(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%esi
call   1080 <outArrInt@plt>
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x80(%rbp),%rdi
call   1030 <free@plt>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    11ba <testPalin+0x5a>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testPalin>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xeae(%rip),%r12
lea    0xee7(%rip),%r14
lea    0xe80(%rip),%r13
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r12),%rbx
mov    %rbx,%rdi
call   1050 <numToDigits@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x0(%rbp,%r13,1),%ebx
mov    %r15,%rdi
mov    %ebx,%esi
call   1080 <outArrInt@plt>
lea    -0x1(%rbx),%edx
mov    %r15,%rdi
xor    %esi,%esi
xor    %ecx,%ecx
call   1070 <palin@plt>
mov    %r15,%rdi
mov    %ebx,%esi
call   1080 <outArrInt@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r15,%rdi
call   1030 <free@plt>
add    $0x4,%rbp
add    $0x8,%r12
cmp    $0x20,%rbp
jne    1190 <testPalin+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.testPalin.sizes = [8 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 8, i32 13, i32 18]
@__const.testPalin.ns = [8 x i64] [i64 8, i64 12, i64 113, i64 4999, i64 69999, i64 22833822, i64 2053320533443, i64 100000000000000002]
@.str = [7 x i8] c"%ld: \0A\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @testPalin() {
%1 = alloca i32
%2 = alloca [8 x i32]
%3 = alloca [8 x i64]
%4 = alloca i32
%5 = alloca i32*
store i32 8, i32* %1
%6 = bitcast [8 x i32]* %2 to i8*
%7 = bitcast [8 x i64]* %3 to i8*
store i32 0, i32* %4
br label %8
8: ; preds = %45, %0
%9 = load i32, i32* %4
%10 = load i32, i32* %1
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %48
12: ; preds = %8
%13 = load i32, i32* %4
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [8 x i64], [8 x i64]* %3, i64 0, i64 %14
%16 = load i64, i64* %15
%17 = call i32* @numToDigits(i64 %16)
store i32* %17, i32** %5
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [8 x i64], [8 x i64]* %3, i64 0, i64 %19
%21 = load i64, i64* %20
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %21)
%23 = load i32*, i32** %5
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = call i32 @outArrInt(i32* %23, i32 %27)
%29 = load i32*, i32** %5
%30 = load i32, i32* %4
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 %31
%33 = load i32, i32* %32
%34 = sub nsw i32 %33, 1
%35 = call i32 @palin(i32* %29, i32 0, i32 %34, i32 0)
%36 = load i32*, i32** %5
%37 = load i32, i32* %4
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 %38
%40 = load i32, i32* %39
%41 = call i32 @outArrInt(i32* %36, i32 %40)
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%43 = load i32*, i32** %5
%44 = call i32 @free(i32* %43)
br label %45
45: ; preds = %12
%46 = load i32, i32* %4
%47 = add nsw i32 %46, 1
store i32 %47, i32* %4
br label %8
48: ; preds = %8
ret void
}

LLVM IR (-O2):
@__const.testPalin.sizes = [8 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 8, i32 13, i32 18]
@__const.testPalin.ns = [8 x i64] [i64 8, i64 12, i64 113, i64 4999, i64 69999, i64 22833822, i64 2053320533443, i64 100000000000000002]
@.str = [7 x i8] c"%ld: \0A\00"
define void @testPalin() {
br label %2
1: ; preds = %2
ret void
2: ; preds = %0, %2
%3 = phi i64 [ 0, %0 ], [ %16, %2 ]
%4 = getelementptr inbounds [8 x i64], [8 x i64]* @__const.testPalin.ns, i64 0, i64 %3
%5 = load i64, i64* %4
%6 = tail call i32* @numToDigits(i64 %5)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %5)
%8 = getelementptr inbounds [8 x i32], [8 x i32]* @__const.testPalin.sizes, i64 0, i64 %3
%9 = load i32, i32* %8
%10 = tail call i32 @outArrInt(i32* %6, i32 %9)
%11 = add nsw i32 %9, -1
%12 = tail call i32 @palin(i32* %6, i32 0, i32 %11, i32 0)
%13 = tail call i32 @outArrInt(i32* %6, i32 %9)
%14 = tail call i32 @putchar(i32 10)
%15 = tail call i32 @free(i32* %6)
%16 = add nuw nsw i64 %3, 1
%17 = icmp eq i64 %16, 8
br i1 %17, label %1, label %2
}