#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 num, right_digit;
  printf("Enter your number\n");
  scanf("%i", &num);
  do {
    if (num < 0) {
      right_digit = num % 10;
      printf("%i", -right_digit);
      num /= 10;
      if (num == 0) {
        printf("-");
      }
    } else {
      right_digit = num % 10;
      printf("%i", right_digit);
      num /= 10;
    }
  } while (num != 0);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecf(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jge    11a3 <main+0x83>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
xor    %esi,%esi
sub    -0xc(%rbp),%esi
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    119e <main+0x7e>
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d0 <main+0xb0>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
jmp    11d5 <main+0xb5>
cmpl   $0x0,-0x8(%rbp)
jne    114d <main+0x2d>
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xeb8(%rip),%rdi
call   1040 <puts@plt>
lea    0xea9(%rip),%r14
lea    0x4(%rsp),%rsi
mov    %r14,%rdi
call   1060 <scanf@plt>
mov    0x4(%rsp),%esi
mov    $0xcccccccd,%ebx
jmp    11ac <main+0x6c>
nop
mov    %esi,%eax
imul   %rbx,%rax
shr    $0x23,%rax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movslq 0x4(%rsp),%rax
imul   $0x66666667,%rax,%rsi
mov    %rsi,%rax
shr    $0x3f,%rax
sar    $0x22,%rsi
add    %eax,%esi
mov    %esi,0x4(%rsp)
test   %esi,%esi
je     1203 <main+0xc3>
test   %esi,%esi
jns    1170 <main+0x30>
neg    %esi
mov    %rsi,%rax
imul   %rbx,%rax
shr    $0x23,%rax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movslq 0x4(%rsp),%rax
imul   $0x66666667,%rax,%rsi
mov    %rsi,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rsi
add    %ecx,%esi
mov    %esi,0x4(%rsp)
add    $0x9,%eax
cmp    $0x12,%eax
ja     11a8 <main+0x68>
mov    $0x2d,%edi
call   1030 <putchar@plt>
mov    0x4(%rsp),%esi
jmp    11a8 <main+0x68>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Enter your number\0A\00"
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [2 x i8] c"-\00"
@.str.3 = [2 x i8] c"\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 ([19 x i8], [19 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)
br label %6
6: ; preds = %30, %0
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %22
9: ; preds = %6
%10 = load i32, i32* %2
%11 = srem i32 %10, 10
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = sub nsw i32 0, %12
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %2
%16 = sdiv i32 %15, 10
store i32 %16, i32* %2
%17 = load i32, i32* %2
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %9
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %19, %9
br label %29
22: ; preds = %6
%23 = load i32, i32* %2
%24 = srem i32 %23, 10
store i32 %24, i32* %3
%25 = load i32, i32* %3
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = load i32, i32* %2
%28 = sdiv i32 %27, 10
store i32 %28, i32* %2
br label %29
29: ; preds = %22, %21
br label %30
30: ; preds = %29
%31 = load i32, i32* %2
%32 = icmp ne i32 %31, 0
br i1 %32, label %6, label %33
33: ; preds = %30
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%i\00"
@str = [18 x i8] c"Enter your number\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 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
br label %6
6: ; preds = %25, %0
%7 = phi i32 [ %26, %25 ], [ %5, %0 ]
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %20
9: ; preds = %6
%10 = sub i32 0, %7
%11 = urem i32 %10, 10
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = load i32, i32* %1
%14 = sdiv i32 %13, 10
store i32 %14, i32* %1
%15 = add i32 %13, 9
%16 = icmp ult i32 %15, 19
br i1 %16, label %17, label %25
17: ; preds = %9
%18 = call i32 @putchar(i32 45)
%19 = load i32, i32* %1
br label %25
20: ; preds = %6
%21 = urem i32 %7, 10
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %1
%24 = sdiv i32 %23, 10
store i32 %24, i32* %1
br label %25
25: ; preds = %20, %17, %9
%26 = phi i32 [ %24, %20 ], [ %19, %17 ], [ %14, %9 ]
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %6
28: ; preds = %25
%29 = call i32 @putchar(i32 10)
ret i32 0
}