#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(int *);
int *malloc(int);
int /*<<< orphan*/ number_get_digits(long, int **, unsigned int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ test_get_number_count_digits();
int /*<<< orphan*/ test_number_itoa();
void test_number() {
  test_get_number_count_digits();
  test_number_itoa();
  int *digits;
  unsigned int len;
  long int number = -1000000;
  digits = malloc(sizeof(int));
  number_get_digits(number, &digits, &len);
  printf("%ld --> [", number);
  for (int i = 0; i < len; ++i) {
    if (i == len - 1)
      printf("%d", digits[i]);
    else
      printf("%d, ", digits[i]);
  }
  printf("]\n");
  free(digits);
}


x86 assembly (clang, -O0):
<test_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1070 <test_get_number_count_digits@plt>
mov    $0x0,%al
call   1080 <test_number_itoa@plt>
movq   $0xfffffffffff0bdc0,-0x18(%rbp)
ff
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1040 <number_get_digits@plt>
mov    -0x18(%rbp),%rsi
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    121d <test_number+0xbd>
mov    -0x1c(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    11f1 <test_number+0x91>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    120a <test_number+0xaa>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    120f <test_number+0xaf>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b6 <test_number+0x56>
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_number>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1080 <test_get_number_count_digits@plt>
xor    %eax,%eax
call   1090 <test_number_itoa@plt>
mov    $0x4,%edi
call   1070 <malloc@plt>
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
mov    $0xfffffffffff0bdc0,%rdi
call   1050 <number_get_digits@plt>
lea    0xe4d(%rip),%rdi
mov    $0xfffffffffff0bdc0,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x4(%rsp),%eax
test   %eax,%eax
je     1209 <test_number+0x99>
lea    0xe3a(%rip),%r14
lea    0xe36(%rip),%r15
xor    %ebx,%ebx
nopl   0x0(%rax)
add    $0xffffffff,%eax
cmp    %rax,%rbx
mov    0x8(%rsp),%rax
mov    (%rax,%rbx,4),%esi
mov    %r15,%rdi
cmove  %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
mov    0x4(%rsp),%eax
cmp    %rax,%rbx
jb     11e0 <test_number+0x70>
lea    0xe02(%rip),%rdi
call   1040 <puts@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"%ld --> [\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [5 x i8] c"%d, \00"
@.str.3 = [3 x i8] c"]\0A\00"
define void @test_number() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca i64
%4 = alloca i32
%5 = call i32 (...) @test_get_number_count_digits()
%6 = call i32 (...) @test_number_itoa()
store i64 -1000000, i64* %3
%7 = call i32* @malloc(i32 4)
store i32* %7, i32** %1
%8 = load i64, i64* %3
%9 = call i32 @number_get_digits(i64 %8, i32** %1, i32* %2)
%10 = load i64, i64* %3
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i64 %10)
store i32 0, i32* %4
br label %12
12: ; preds = %36, %0
%13 = load i32, i32* %4
%14 = load i32, i32* %2
%15 = icmp ult i32 %13, %14
br i1 %15, label %16, label %39
16: ; preds = %12
%17 = load i32, i32* %4
%18 = load i32, i32* %2
%19 = sub i32 %18, 1
%20 = icmp eq i32 %17, %19
br i1 %20, label %21, label %28
21: ; preds = %16
%22 = load i32*, i32** %1
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = load i32, i32* %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %26)
br label %35
28: ; preds = %16
%29 = load i32*, i32** %1
%30 = load i32, i32* %4
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
%33 = load i32, i32* %32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %28, %21
br label %36
36: ; preds = %35
%37 = load i32, i32* %4
%38 = add nsw i32 %37, 1
store i32 %38, i32* %4
br label %12
39: ; preds = %12
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%41 = load i32*, i32** %1
%42 = call i32 @free(i32* %41)
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"%ld --> [\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [5 x i8] c"%d, \00"
@str = [2 x i8] c"]\00"
define void @test_number() {
%1 = alloca i32*
%2 = alloca i32
%3 = tail call i32 (...) @test_get_number_count_digits()
%4 = tail call i32 (...) @test_number_itoa()
%5 = bitcast i32** %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = tail call i32* @malloc(i32 4)
store i32* %7, i32** %1
%8 = call i32 @number_get_digits(i64 -1000000, i32** %1, i32* %2)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i64 -1000000)
%10 = load i32, i32* %2
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %16, %0
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%14 = load i32*, i32** %1
%15 = call i32 @free(i32* %14)
ret void
16: ; preds = %0, %16
%17 = phi i64 [ %27, %16 ], [ 0, %0 ]
%18 = phi i32 [ %28, %16 ], [ %10, %0 ]
%19 = add i32 %18, -1
%20 = zext i32 %19 to i64
%21 = icmp eq i64 %17, %20
%22 = load i32*, i32** %1
%23 = getelementptr inbounds i32, i32* %22, i64 %17
%24 = load i32, i32* %23
%25 = select i1 %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0)
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %25, i32 %24)
%27 = add nuw nsw i64 %17, 1
%28 = load i32, i32* %2
%29 = zext i32 %28 to i64
%30 = icmp ult i64 %27, %29
br i1 %30, label %16, label %12
}