#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int x, y, i;
  int step1 = 10, step2 = 100;
  int num;
  int max = 0;
  printf("Enter an integer > ");
  scanf("%d", &x);
  if (x < 0) {
    printf("%d\n", x % 10);
    x = x * -1;
  } else {
    printf("%d\n", x % 10);
  }
  y = x;
  while (y >= 10) {
    y /= 10;
    max++;
  }
  for (i = 0; i < max; i++) {
    num = ((x % step2 - x % step1) / step1);
    printf("%d\n", num);
    step2 *= 10;
    step1 *= 10;
  }
  printf("That's all, have a nice day!\n");
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xa,-0x14(%rbp)
movl   $0x64,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebb(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jge    1193 <main+0x73>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%esi
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
imul   $0xffffffff,-0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    11ae <main+0x8e>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%esi
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jl     11da <main+0xba>
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11b4 <main+0x94>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1237 <main+0x117>
mov    -0x8(%rbp),%eax
cltd
idivl  -0x18(%rbp)
mov    %edx,-0x24(%rbp)
mov    -0x8(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    -0x24(%rbp),%eax
sub    %edx,%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
imul   $0xa,-0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
imul   $0xa,-0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11e1 <main+0xc1>
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xebd(%rip),%rdi
xor    %r15d,%r15d
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec0(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%esi
test   %esi,%esi
js     119a <main+0x6a>
mov    %esi,%eax
mov    $0xcccccccd,%ecx
imul   %rax,%rcx
shr    $0x23,%rcx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%eax
sub    %eax,%esi
lea    0xe94(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%r15d
cmp    $0xa,%r15d
jge    11cf <main+0x9f>
jmp    124a <main+0x11a>
mov    %esi,%eax
neg    %eax
mov    $0xcccccccd,%ecx
imul   %rax,%rcx
shr    $0x23,%rcx
lea    (%rcx,%rcx,4),%eax
lea    (%rsi,%rax,2),%esi
lea    0xe5f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
sub    0xc(%rsp),%r15d
mov    %r15d,0xc(%rsp)
cmp    $0xa,%r15d
jl     124a <main+0x11a>
mov    $0xffffffff,%ebp
mov    $0xcccccccd,%eax
mov    %r15d,%ecx
nopl   0x0(%rax)
mov    %ecx,%edx
imul   %rax,%rdx
shr    $0x23,%rdx
add    $0x1,%ebp
cmp    $0x63,%ecx
mov    %edx,%ecx
ja     11e0 <main+0xb0>
mov    $0xa,%ebx
mov    $0x64,%r12d
lea    0xe11(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
mov    %r15d,%eax
cltd
idiv   %r12d
mov    %edx,%ecx
mov    %r15d,%eax
cltd
idiv   %ebx
sub    %edx,%ecx
mov    %ecx,%eax
cltd
idiv   %ebx
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
sub    $0x1,%ebp
jb     124a <main+0x11a>
add    %ebx,%ebx
lea    (%rbx,%rbx,4),%ebx
add    %r12d,%r12d
lea    (%r12,%r12,4),%r12d
mov    0xc(%rsp),%r15d
jmp    1210 <main+0xe0>
lea    0xdca(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Enter an integer > \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [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
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
store i32 10, i32* %5
store i32 100, i32* %6
store i32 0, i32* %8
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%11 = load i32, i32* %2
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %0
%14 = load i32, i32* %2
%15 = srem i32 %14, 10
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = load i32, i32* %2
%18 = mul nsw i32 %17, -1
store i32 %18, i32* %2
br label %23
19: ; preds = %0
%20 = load i32, i32* %2
%21 = srem i32 %20, 10
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %19, %13
%24 = load i32, i32* %2
store i32 %24, i32* %3
br label %25
25: ; preds = %28, %23
%26 = load i32, i32* %3
%27 = icmp sge i32 %26, 10
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = load i32, i32* %3
%30 = sdiv i32 %29, 10
store i32 %30, i32* %3
%31 = load i32, i32* %8
%32 = add nsw i32 %31, 1
store i32 %32, i32* %8
br label %25
33: ; preds = %25
store i32 0, i32* %4
br label %34
34: ; preds = %54, %33
%35 = load i32, i32* %4
%36 = load i32, i32* %8
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %57
38: ; preds = %34
%39 = load i32, i32* %2
%40 = load i32, i32* %6
%41 = srem i32 %39, %40
%42 = load i32, i32* %2
%43 = load i32, i32* %5
%44 = srem i32 %42, %43
%45 = sub nsw i32 %41, %44
%46 = load i32, i32* %5
%47 = sdiv i32 %45, %46
store i32 %47, i32* %7
%48 = load i32, i32* %7
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %48)
%50 = load i32, i32* %6
%51 = mul nsw i32 %50, 10
store i32 %51, i32* %6
%52 = load i32, i32* %5
%53 = mul nsw i32 %52, 10
store i32 %53, i32* %5
br label %54
54: ; preds = %38
%55 = load i32, i32* %4
%56 = add nsw i32 %55, 1
store i32 %56, i32* %4
br label %34
57: ; preds = %34
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"Enter an integer > \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@str = [29 x i8] c"That's all, have a nice day!\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 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 slt i32 %5, 0
br i1 %6, label %7, label %14
7: ; preds = %0
%8 = sub i32 0, %5
%9 = urem i32 %8, 10
%10 = sub nsw i32 0, %9
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = load i32, i32* %1
%13 = sub nsw i32 0, %12
store i32 %13, i32* %1
br label %18
14: ; preds = %0
%15 = urem i32 %5, 10
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = load i32, i32* %1
br label %18
18: ; preds = %14, %7
%19 = phi i32 [ %17, %14 ], [ %13, %7 ]
%20 = icmp sgt i32 %19, 9
br i1 %20, label %21, label %43
21: ; preds = %18, %21
%22 = phi i32 [ %25, %21 ], [ 0, %18 ]
%23 = phi i32 [ %24, %21 ], [ %19, %18 ]
%24 = udiv i32 %23, 10
%25 = add nuw nsw i32 %22, 1
%26 = icmp ugt i32 %23, 99
br i1 %26, label %21, label %27
27: ; preds = %21, %38
%28 = phi i32 [ %42, %38 ], [ %19, %21 ]
%29 = phi i32 [ %41, %38 ], [ 100, %21 ]
%30 = phi i32 [ %40, %38 ], [ 10, %21 ]
%31 = phi i32 [ %39, %38 ], [ 0, %21 ]
%32 = srem i32 %28, %29
%33 = srem i32 %28, %30
%34 = sub nsw i32 %32, %33
%35 = sdiv i32 %34, %30
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %35)
%37 = icmp eq i32 %31, %22
br i1 %37, label %43, label %38
38: ; preds = %27
%39 = add nuw i32 %31, 1
%40 = mul nsw i32 %30, 10
%41 = mul nsw i32 %29, 10
%42 = load i32, i32* %1
br label %27
43: ; preds = %27, %18
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
ret i32 0
}