#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 power(int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, long *);
int main() {
  long num, num_reverse;
  int n, i;
  int factor;
  printf("Enter the five digit number: ");
  scanf("%ld", &num);
  i = 4;
  num_reverse = 0;
  while (num != 0) {
    n = num % 10;
    factor = power(10, i);
    num_reverse = num_reverse + n * factor;
    num = num / 10;
    i--;
  }
  printf("The reversed number is %d\n", num_reverse);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeca(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <scanf@plt>
movl   $0x4,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11cf <main+0x9f>
mov    -0x10(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %edx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%esi
mov    $0xa,%edi
call   1030 <power@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
imul   -0x24(%rbp),%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    116c <main+0x3c>
mov    -0x18(%rbp),%rsi
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xec2(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xecf(%rip),%rdi
mov    %rsp,%rsi
call   1050 <scanf@plt>
mov    (%rsp),%rbx
test   %rbx,%rbx
je     11db <main+0xab>
mov    $0x4,%ebp
xor    %r14d,%r14d
movabs $0x6666666666666667,%r15
66 66 66
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rax
imul   %r15
mov    %rdx,%rax
shr    $0x3f,%rax
shr    $0x2,%rdx
add    %eax,%edx
add    %edx,%edx
lea    (%rdx,%rdx,4),%eax
sub    %eax,%ebx
mov    $0xa,%edi
mov    %ebp,%esi
call   1030 <power@plt>
imul   %ebx,%eax
movslq %eax,%rsi
mov    (%rsp),%rcx
mov    %rcx,%rax
imul   %r15
add    %rsi,%r14
mov    %rdx,%rbx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x2,%rbx
add    %rax,%rbx
mov    %rbx,(%rsp)
add    $0xffffffff,%ebp
add    $0x9,%rcx
cmp    $0x12,%rcx
ja     1180 <main+0x50>
lea    0xe40(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Enter the five digit number: \00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [27 x i8] c"The reversed number is %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %2)
store i32 4, i32* %5
store i64 0, i64* %3
br label %9
9: ; preds = %12, %0
%10 = load i64, i64* %2
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %28
12: ; preds = %9
%13 = load i64, i64* %2
%14 = srem i64 %13, 10
%15 = trunc i64 %14 to i32
store i32 %15, i32* %4
%16 = load i32, i32* %5
%17 = call i32 @power(i32 10, i32 %16)
store i32 %17, i32* %6
%18 = load i64, i64* %3
%19 = load i32, i32* %4
%20 = load i32, i32* %6
%21 = mul nsw i32 %19, %20
%22 = sext i32 %21 to i64
%23 = add nsw i64 %18, %22
store i64 %23, i64* %3
%24 = load i64, i64* %2
%25 = sdiv i64 %24, 10
store i64 %25, i64* %2
%26 = load i32, i32* %5
%27 = add nsw i32 %26, -1
store i32 %27, i32* %5
br label %9
28: ; preds = %9
%29 = load i64, i64* %3
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i64 %29)
ret i32 0
}

LLVM IR (-O2):
@.str = [30 x i8] c"Enter the five digit number: \00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [27 x i8] c"The reversed number is %d\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %1)
%5 = load i64, i64* %1
%6 = icmp eq i64 %5, 0
br i1 %6, label %22, label %7
7: ; preds = %0, %7
%8 = phi i64 [ %16, %7 ], [ 0, %0 ]
%9 = phi i32 [ %19, %7 ], [ 4, %0 ]
%10 = phi i64 [ %18, %7 ], [ %5, %0 ]
%11 = srem i64 %10, 10
%12 = trunc i64 %11 to i32
%13 = call i32 @power(i32 10, i32 %9)
%14 = mul nsw i32 %13, %12
%15 = sext i32 %14 to i64
%16 = add nsw i64 %8, %15
%17 = load i64, i64* %1
%18 = sdiv i64 %17, 10
store i64 %18, i64* %1
%19 = add nsw i32 %9, -1
%20 = add i64 %17, 9
%21 = icmp ult i64 %20, 19
br i1 %21, label %22, label %7
22: ; preds = %7, %0
%23 = phi i64 [ 0, %0 ], [ %16, %7 ]
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i64 %23)
ret i32 0
}