#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(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
void num(int n) {
  char *tab, *p;
  tab = (char *)malloc(20);
  p = tab;
  while (1) {
    *p = 48 + (n % 10);
    p++;
    n = n / 10;
    if (n == 0)
      break;
  }
  while (p != tab) {
    p--;
    printf("%c", *p);
  }
  printf("\n");
  free(tab);
}


x86 assembly (clang, -O0):
<num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x14,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    %dl,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1190 <num+0x60>
jmp    1195 <num+0x65>
jmp    1151 <num+0x21>
jmp    119a <num+0x6a>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     11ce <num+0x9e>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%esi
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    119a <num+0x6a>
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<num>:
push   %r15
push   %r14
push   %rbx
mov    %edi,%ebx
mov    $0x14,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
xor    %r15d,%r15d
nopw   0x0(%rax,%rax,1)
movslq %ebx,%rax
imul   $0x66666667,%rax,%rbx
mov    %rbx,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rbx
add    %ecx,%ebx
lea    (%rbx,%rbx,1),%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %eax,%edx
sub    %ecx,%edx
add    $0x30,%dl
mov    %dl,(%r14,%r15,1)
add    $0x9,%eax
add    $0x1,%r15
cmp    $0x12,%eax
ja     1150 <num+0x20>
test   %r15,%r15
je     11a1 <num+0x71>
nopl   0x0(%rax)
movsbl -0x1(%r14,%r15,1),%edi
call   1040 <putchar@plt>
add    $0xffffffffffffffff,%r15
jne    1190 <num+0x60>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>

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

LLVM IR (-O2):
define void @num(i32 %0) {
%2 = tail call i64 @malloc(i32 20)
%3 = inttoptr i64 %2 to i8*
br label %4
4: ; preds = %4, %1
%5 = phi i32 [ %0, %1 ], [ %11, %4 ]
%6 = phi i8* [ %3, %1 ], [ %10, %4 ]
%7 = srem i32 %5, 10
%8 = trunc i32 %7 to i8
%9 = add nsw i8 %8, 48
store i8 %9, i8* %6
%10 = getelementptr inbounds i8, i8* %6, i64 1
%11 = sdiv i32 %5, 10
%12 = add i32 %5, 9
%13 = icmp ult i32 %12, 19
br i1 %13, label %14, label %4
14: ; preds = %4
%15 = icmp eq i8* %10, %3
br i1 %15, label %23, label %16
16: ; preds = %14, %16
%17 = phi i8* [ %18, %16 ], [ %10, %14 ]
%18 = getelementptr inbounds i8, i8* %17, i64 -1
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = tail call i32 @putchar(i32 %20)
%22 = icmp eq i8* %18, %3
br i1 %22, label %23, label %16
23: ; preds = %16, %14
%24 = tail call i32 @putchar(i32 10)
%25 = tail call i32 @free(i8* %3)
ret void
}