#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 abs(int);
int find_length(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n, length, digits;
  printf("\nEnter an integer > ");
  scanf("%d", &n);
  if (n == 0)
    printf("0\n");
  else {
    length = find_length(n);
    while (length != 0) {
      if (n < 0 && length != 1)
        digits = abs(n) % 10;
      else
        digits = n % 10;
      n = n / 10;
      length = length - 1;
      printf("%d\n", digits);
    }
  }
  printf("That's all, have a nice day!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb1(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jne    118a <main+0x4a>
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    120b <main+0xcb>
mov    -0x8(%rbp),%edi
call   1050 <find_length@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1206 <main+0xc6>
cmpl   $0x0,-0x8(%rbp)
jge    11cb <main+0x8b>
cmpl   $0x1,-0xc(%rbp)
je     11cb <main+0x8b>
mov    -0x8(%rbp),%edi
call   1030 <abs@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
jmp    11d9 <main+0x99>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1195 <main+0x55>
jmp    120b <main+0xcb>
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xebc(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x4(%rsp),%edi
test   %edi,%edi
je     11dc <main+0x9c>
call   1050 <find_length@plt>
test   %eax,%eax
je     11e8 <main+0xa8>
mov    %eax,%ebx
lea    0xe9b(%rip),%r14
nopl   (%rax)
movslq 0x4(%rsp),%rax
mov    %eax,%ecx
neg    %ecx
cmp    $0x1,%ebx
cmove  %eax,%ecx
test   %rax,%rax
cmovns %eax,%ecx
movslq %ecx,%rsi
imul   $0x66666667,%rsi,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%esi
imul   $0x66666667,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
mov    %eax,0x4(%rsp)
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffff,%ebx
jne    1180 <main+0x40>
jmp    11e8 <main+0xa8>
lea    0xe56(%rip),%rdi
call   1030 <puts@plt>
lea    0xe2d(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [21 x i8] c"\0AEnter an integer > \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"0\0A\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [30 x i8] c"That's all, have a nice day!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%7 = load i32, i32* %2
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %38
11: ; preds = %0
%12 = load i32, i32* %2
%13 = call i32 @find_length(i32 %12)
store i32 %13, i32* %3
br label %14
14: ; preds = %30, %11
%15 = load i32, i32* %3
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %37
17: ; preds = %14
%18 = load i32, i32* %2
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %27
20: ; preds = %17
%21 = load i32, i32* %3
%22 = icmp ne i32 %21, 1
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i32, i32* %2
%25 = call i32 @abs(i32 %24)
%26 = srem i32 %25, 10
store i32 %26, i32* %4
br label %30
27: ; preds = %20, %17
%28 = load i32, i32* %2
%29 = srem i32 %28, 10
store i32 %29, i32* %4
br label %30
30: ; preds = %27, %23
%31 = load i32, i32* %2
%32 = sdiv i32 %31, 10
store i32 %32, i32* %2
%33 = load i32, i32* %3
%34 = sub nsw i32 %33, 1
store i32 %34, i32* %3
%35 = load i32, i32* %4
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %35)
br label %14
37: ; preds = %14
br label %38
38: ; preds = %37, %9
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [21 x i8] c"\0AEnter an integer > \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@str = [29 x i8] c"That's all, have a nice day!\00"
@str.5 = [2 x i8] c"0\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.5, i64 0, i64 0))
br label %25
9: ; preds = %0
%10 = call i32 @find_length(i32 %5)
%11 = icmp eq i32 %10, 0
br i1 %11, label %25, label %12
12: ; preds = %9, %12
%13 = phi i32 [ %22, %12 ], [ %10, %9 ]
%14 = load i32, i32* %1
%15 = icmp slt i32 %14, 0
%16 = icmp ne i32 %13, 1
%17 = select i1 %15, i1 %16, i1 false
%18 = sub nsw i32 0, %14
%19 = select i1 %17, i32 %18, i32 %14
%20 = srem i32 %19, 10
%21 = sdiv i32 %14, 10
store i32 %21, i32* %1
%22 = add nsw i32 %13, -1
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %20)
%24 = icmp eq i32 %22, 0
br i1 %24, label %25, label %12
25: ; preds = %12, %9, %7
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
ret i32 0
}