#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 rev(int);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int number, right_digit;
  printf("Enter your number.\n");
  scanf("%i", &number);
  printf("Recursion -- %i\n", rev(number));
  printf("While Loop -- ");
  while (number != 0) {
    right_digit = number % 10;
    printf("%i", right_digit);
    number /= 10;
  }
  printf("\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   1040 <printf@plt>
lea    0xec0(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x8(%rbp),%edi
call   1030 <rev@plt>
mov    %eax,%esi
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
je     11bf <main+0x8f>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
jmp    1183 <main+0x53>
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xec7(%rip),%rdi
call   1040 <puts@plt>
lea    0xe98(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
mov    0xc(%rsp),%edi
call   1050 <rev@plt>
lea    0xe81(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe82(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
je     11fd <main+0xad>
lea    0xe58(%rip),%rbx
nopl   0x0(%rax,%rax,1)
movslq %eax,%rsi
imul   $0x66666667,%rsi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movslq 0xc(%rsp),%rcx
imul   $0x66666667,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rax
add    %edx,%eax
mov    %eax,0xc(%rsp)
add    $0x9,%ecx
cmp    $0x12,%ecx
ja     11b0 <main+0x60>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Enter your number.\0A\00"
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [17 x i8] c"Recursion -- %i\0A\00"
@.str.3 = [15 x i8] c"While Loop -- \00"
@.str.4 = [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 ([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 = load i32, i32* %2
%7 = call i32 @rev(i32 %6)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %10
10: ; preds = %13, %0
%11 = load i32, i32* %2
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = load i32, i32* %2
%15 = srem i32 %14, 10
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %2
%19 = sdiv i32 %18, 10
store i32 %19, i32* %2
br label %10
20: ; preds = %10
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [17 x i8] c"Recursion -- %i\0A\00"
@.str.3 = [15 x i8] c"While Loop -- \00"
@str = [19 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 ([19 x i8], [19 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 = call i32 @rev(i32 %5)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %6)
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%9 = load i32, i32* %1
%10 = icmp eq i32 %9, 0
br i1 %10, label %19, label %11
11: ; preds = %0, %11
%12 = phi i32 [ %16, %11 ], [ %9, %0 ]
%13 = srem i32 %12, 10
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %1
%16 = sdiv i32 %15, 10
store i32 %16, i32* %1
%17 = add i32 %15, 9
%18 = icmp ult i32 %17, 19
br i1 %18, label %19, label %11
19: ; preds = %11, %0
%20 = call i32 @putchar(i32 10)
ret i32 0
}