#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 floor(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n, digit;
  printf("Enter an integer > ");
  scanf("%d", &n);
  printf("\n");
  if (n < 0) {
    n = -n;
    while (n >= 10) {
      digit = n % 10;
      n = floor(n / 10);
      printf("%d\n", digit);
    }
    if (n < 10)
      printf("-%d\n", n);
    if (n == 0)
      printf("0\n");
  } else {
    while (n >= 10) {
      digit = n % 10;
      n = floor(n / 10);
      printf("%d\n", digit);
    }
    if (n < 10)
      printf("%d\n", n);
    if (n == 0)
      printf("0\n");
  }
  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    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec0(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xed7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
jge    11f8 <main+0xc8>
xor    %eax,%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jl     11c0 <main+0x90>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1050 <floor@plt>
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    117d <main+0x4d>
cmpl   $0xa,-0x8(%rbp)
jge    11db <main+0xab>
mov    -0x8(%rbp),%esi
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
jne    11f3 <main+0xc3>
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1278 <main+0x148>
jmp    11fd <main+0xcd>
cmpl   $0xa,-0x8(%rbp)
jl     1240 <main+0x110>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1050 <floor@plt>
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%esi
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11fd <main+0xcd>
cmpl   $0xa,-0x8(%rbp)
jge    125b <main+0x12b>
mov    -0x8(%rbp),%esi
lea    0xdc4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
jne    1273 <main+0x143>
lea    0xdb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1278 <main+0x148>
lea    0xda0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xea7(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0xc(%rsp),%ebx
test   %ebx,%ebx
js     11db <main+0x8b>
cmp    $0xa,%ebx
jb     11d0 <main+0x80>
mov    $0xcccccccd,%r14d
lea    0xe7d(%rip),%rbp
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
imul   %r14,%rdi
shr    $0x23,%rdi
lea    (%rdi,%rdi,1),%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ebx
call   1070 <floor@plt>
mov    %eax,0xc(%rsp)
mov    %rbp,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%ebx
cmp    $0x9,%ebx
jg     11a0 <main+0x50>
lea    0xe41(%rip),%rdi
mov    %ebx,%esi
jmp    1239 <main+0xe9>
mov    %ebx,%ebp
neg    %ebp
mov    %ebp,0xc(%rsp)
cmp    $0xfffffff6,%ebx
ja     1230 <main+0xe0>
mov    $0xcccccccd,%r14d
lea    0xe23(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
imul   %r14,%rdi
shr    $0x23,%rdi
lea    (%rdi,%rdi,1),%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ebp
call   1070 <floor@plt>
mov    %eax,0xc(%rsp)
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%ebp
cmp    $0x9,%ebp
jg     1200 <main+0xb0>
lea    0xde0(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x0,0xc(%rsp)
jne    1253 <main+0x103>
lea    0xdeb(%rip),%rdi
call   1040 <puts@plt>
lea    0xdc2(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
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 = [2 x i8] c"\0A\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [5 x i8] c"-%d\0A\00"
@.str.5 = [3 x i8] c"0\0A\00"
@.str.6 = [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
store i32 0, i32* %1
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %35
9: ; preds = %0
%10 = load i32, i32* %2
%11 = sub nsw i32 0, %10
store i32 %11, i32* %2
br label %12
12: ; preds = %15, %9
%13 = load i32, i32* %2
%14 = icmp sge i32 %13, 10
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = load i32, i32* %2
%17 = srem i32 %16, 10
store i32 %17, i32* %3
%18 = load i32, i32* %2
%19 = sdiv i32 %18, 10
%20 = call i32 @floor(i32 %19)
store i32 %20, i32* %2
%21 = load i32, i32* %3
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %21)
br label %12
23: ; preds = %12
%24 = load i32, i32* %2
%25 = icmp slt i32 %24, 10
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* %2
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %26, %23
%30 = load i32, i32* %2
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %34
34: ; preds = %32, %29
br label %59
35: ; preds = %0
br label %36
36: ; preds = %39, %35
%37 = load i32, i32* %2
%38 = icmp sge i32 %37, 10
br i1 %38, label %39, label %47
39: ; preds = %36
%40 = load i32, i32* %2
%41 = srem i32 %40, 10
store i32 %41, i32* %3
%42 = load i32, i32* %2
%43 = sdiv i32 %42, 10
%44 = call i32 @floor(i32 %43)
store i32 %44, i32* %2
%45 = load i32, i32* %3
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %45)
br label %36
47: ; preds = %36
%48 = load i32, i32* %2
%49 = icmp slt i32 %48, 10
br i1 %49, label %50, label %53
50: ; preds = %47
%51 = load i32, i32* %2
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %51)
br label %53
53: ; preds = %50, %47
%54 = load i32, i32* %2
%55 = icmp eq i32 %54, 0
br i1 %55, label %56, label %58
56: ; preds = %53
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %58
58: ; preds = %56, %53
br label %59
59: ; preds = %58, %34
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, 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.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [5 x i8] c"-%d\0A\00"
@str = [29 x i8] c"That's all, have a nice day!\00"
@str.8 = [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 ([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 = call i32 @putchar(i32 10)
%6 = load i32, i32* %1
%7 = icmp slt i32 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %0
%9 = icmp ugt i32 %6, 9
br i1 %9, label %26, label %34
10: ; preds = %0
%11 = sub nsw i32 0, %6
store i32 %11, i32* %1
%12 = icmp ult i32 %6, -9
br i1 %12, label %13, label %21
13: ; preds = %10, %13
%14 = phi i32 [ %19, %13 ], [ %11, %10 ]
%15 = urem i32 %14, 10
%16 = udiv i32 %14, 10
%17 = call i32 @floor(i32 %16)
store i32 %17, i32* %1
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %15)
%19 = load i32, i32* %1
%20 = icmp sgt i32 %19, 9
br i1 %20, label %13, label %21
21: ; preds = %13, %10
%22 = phi i32 [ %11, %10 ], [ %19, %13 ]
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %22)
%24 = load i32, i32* %1
%25 = icmp eq i32 %24, 0
br i1 %25, label %39, label %42
26: ; preds = %8, %26
%27 = phi i32 [ %32, %26 ], [ %6, %8 ]
%28 = urem i32 %27, 10
%29 = udiv i32 %27, 10
%30 = call i32 @floor(i32 %29)
store i32 %30, i32* %1
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %28)
%32 = load i32, i32* %1
%33 = icmp sgt i32 %32, 9
br i1 %33, label %26, label %34
34: ; preds = %26, %8
%35 = phi i32 [ %6, %8 ], [ %32, %26 ]
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %35)
%37 = load i32, i32* %1
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %34, %21
%40 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @str.8, i64 0, i64 0), %21 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @str.8, i64 0, i64 0), %34 ]
%41 = call i32 @puts(i8* dereferenceable(1) %40)
br label %42
42: ; preds = %39, %34, %21
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
ret i32 0
}