#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() {
  int n, a, sum;
  printf("Enter x: ");
  scanf("%d", &n);
  sum = 0;
  if (n == 0)
    printf("0");
  else
    do {
      a = n % 10;
      n = n / 10;
      sum = sum * 10 + a;
    } while (n != 0);
  printf("%d", sum);
  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    0xec6(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1171 <main+0x51>
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ab <main+0x8b>
jmp    1176 <main+0x56>
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,-0x8(%rbp)
imul   $0xa,-0x10(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1176 <main+0x56>
jmp    11ab <main+0x8b>
mov    -0x10(%rbp),%esi
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xec4(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xebe(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
je     1195 <main+0x65>
xchg   %ax,%ax
movslq %eax,%rcx
imul   $0x66666667,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rax
add    %edx,%eax
lea    (%rax,%rax,1),%edx
lea    (%rdx,%rdx,4),%edx
mov    %ecx,%esi
sub    %edx,%esi
lea    (%rbx,%rbx,4),%edx
lea    (%rsi,%rdx,2),%ebx
add    $0x9,%ecx
cmp    $0x12,%ecx
ja     1160 <main+0x30>
mov    %eax,0xc(%rsp)
jmp    11a1 <main+0x71>
mov    $0x30,%edi
call   1030 <putchar@plt>
xor    %ebx,%ebx
lea    0xe62(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [10 x i8] c"Enter x: \00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 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 eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @putchar(i32 48)
br label %19
9: ; preds = %0, %9
%10 = phi i32 [ %13, %9 ], [ %5, %0 ]
%11 = phi i32 [ %15, %9 ], [ 0, %0 ]
%12 = srem i32 %10, 10
%13 = sdiv i32 %10, 10
%14 = mul nsw i32 %11, 10
%15 = add nsw i32 %12, %14
%16 = add i32 %10, 9
%17 = icmp ult i32 %16, 19
br i1 %17, label %18, label %9
18: ; preds = %9
store i32 %13, i32* %1
br label %19
19: ; preds = %18, %7
%20 = phi i32 [ 0, %7 ], [ %15, %18 ]
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %20)
ret i32 0
}