#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*/ getch();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int numero, clone, ordem, invertido;
  invertido = 0;
  printf("Vamos inverter numeros!\nDigite um numero INTEIRO POSITIVO, "
         "diferente de 0, de ate 10 casas, que eu irei inverter ele:\n");
  scanf("%d", &numero);
  while (numero <= 0) {
    printf("O numero deve ser INTEIRO POSITIVO e diferente de 0, digite outro "
           "numero:");
    scanf("%d", &numero);
  }
  clone = numero;
  while ((clone) != 0) {
    invertido = invertido * 10 + clone % 10;
    clone = clone / 10;
  }
  printf("O inverso do numero e %d\n", invertido);
  if (invertido == numero) {
    printf("O numero fornecido e um PALINDROMO!");
  }
  getch();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf1c(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jg     1191 <main+0x61>
lea    0xf05(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xef4(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
jmp    1164 <main+0x34>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11ce <main+0x9e>
imul   $0xa,-0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x18(%rbp),%eax
add    %edx,%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
jmp    1197 <main+0x67>
mov    -0x14(%rbp),%esi
lea    0xeec(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    11f9 <main+0xc9>
lea    0xeec(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <getch@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xf3b(%rip),%rdi
call   1030 <puts@plt>
lea    0xea4(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jg     11ad <main+0x6d>
lea    0xe8e(%rip),%r14
lea    0xe84(%rip),%r15
lea    0xc(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    1190 <main+0x50>
xor    %ebx,%ebx
nop
lea    (%rbx,%rbx,4),%ecx
movslq %eax,%rdx
imul   $0x66666667,%rdx,%rax
mov    %rax,%rsi
shr    $0x3f,%rsi
sar    $0x22,%rax
add    %esi,%eax
lea    (%rax,%rax,1),%esi
lea    (%rsi,%rsi,4),%esi
mov    %edx,%edi
sub    %esi,%edi
lea    (%rdi,%rcx,2),%ebx
add    $0x9,%edx
cmp    $0x12,%edx
ja     11b0 <main+0x70>
lea    0xe67(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    0xc(%rsp),%ebx
jne    1203 <main+0xc3>
lea    0xe6b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <getch@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [119 x i8] c"Vamos inverter numeros!\0ADigite um numero INTEIRO POSITIVO, diferente de 0, de ate 10 casas, que eu irei inverter ele:\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [74 x i8] c"O numero deve ser INTEIRO POSITIVO e diferente de 0, digite outro numero:\00"
@.str.3 = [26 x i8] c"O inverso do numero e %d\0A\00"
@.str.4 = [36 x i8] c"O numero fornecido e um PALINDROMO!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %5
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([119 x i8], [119 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
br label %8
8: ; preds = %11, %0
%9 = load i32, i32* %2
%10 = icmp sle i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
br label %8
14: ; preds = %8
%15 = load i32, i32* %2
store i32 %15, i32* %3
br label %16
16: ; preds = %19, %14
%17 = load i32, i32* %3
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %16
%20 = load i32, i32* %5
%21 = mul nsw i32 %20, 10
%22 = load i32, i32* %3
%23 = srem i32 %22, 10
%24 = add nsw i32 %21, %23
store i32 %24, i32* %5
%25 = load i32, i32* %3
%26 = sdiv i32 %25, 10
store i32 %26, i32* %3
br label %16
27: ; preds = %16
%28 = load i32, i32* %5
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %5
%31 = load i32, i32* %2
%32 = icmp eq i32 %30, %31
br i1 %32, label %33, label %35
33: ; preds = %27
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
br label %35
35: ; preds = %33, %27
%36 = call i32 (...) @getch()
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [74 x i8] c"O numero deve ser INTEIRO POSITIVO e diferente de 0, digite outro numero:\00"
@.str.3 = [26 x i8] c"O inverso do numero e %d\0A\00"
@.str.4 = [36 x i8] c"O numero fornecido e um PALINDROMO!\00"
@str = [118 x i8] c"Vamos inverter numeros!\0ADigite um numero INTEIRO POSITIVO, diferente de 0, de ate 10 casas, que eu irei inverter ele:\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([118 x i8], [118 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 slt i32 %5, 1
br i1 %6, label %7, label %12
7: ; preds = %0, %7
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%10 = load i32, i32* %1
%11 = icmp slt i32 %10, 1
br i1 %11, label %7, label %12
12: ; preds = %7, %0
%13 = phi i32 [ %5, %0 ], [ %10, %7 ]
br label %14
14: ; preds = %12, %14
%15 = phi i32 [ %19, %14 ], [ 0, %12 ]
%16 = phi i32 [ %20, %14 ], [ %13, %12 ]
%17 = mul nsw i32 %15, 10
%18 = srem i32 %16, 10
%19 = add nsw i32 %17, %18
%20 = sdiv i32 %16, 10
%21 = add i32 %16, 9
%22 = icmp ult i32 %21, 19
br i1 %22, label %23, label %14
23: ; preds = %14
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%25 = load i32, i32* %1
%26 = icmp eq i32 %19, %25
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
br label %29
29: ; preds = %27, %23
%30 = call i32 (...) @getch()
ret i32 0
}