#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 *);
void main(void) {
  int numInicial, numInv, num1, num2, num3, num4;
  printf("Insira o numero inicial de 4 algarismos: ");
  scanf("%i", &numInicial);
  num1 = numInicial % 10;
  num2 = numInicial % 100 / 10;
  num3 = numInicial % 1000 / 100;
  num4 = numInicial / 1000;
  num3 *= 10;
  num2 *= 100;
  num1 *= 1000;
  numInv = num1 + num2 + num3 + num4;
  printf("O numero %i invertido e %i", numInicial, numInv);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xed1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf05(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
imul   $0xa,-0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
imul   $0x64,-0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
imul   $0x3e8,-0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xed8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf0c(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
movslq 0x4(%rsp),%rsi
imul   $0x66666667,%rsi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%ecx
mov    %esi,%r9d
sub    %ecx,%r9d
imul   $0x51eb851f,%rsi,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
mov    %esi,%edx
sub    %ecx,%edx
movsbl %dl,%ecx
imul   $0x67,%ecx,%ecx
movzwl %cx,%ecx
movswl %cx,%edx
shr    $0xf,%ecx
shr    $0xa,%edx
add    %cl,%dl
movsbl %dl,%r8d
imul   $0x10624dd3,%rsi,%rdi
mov    %rdi,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rdi
add    %edx,%edi
imul   $0x3e8,%edi,%edx
mov    %esi,%ecx
sub    %edx,%ecx
movswl %cx,%ecx
imul   $0x147b,%ecx,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x13,%ecx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
movswl %cx,%ecx
imul   $0x64,%r8d,%eax
imul   $0x3e8,%r9d,%edx
add    %edi,%edx
add    %eax,%edx
add    %ecx,%edx
lea    0xe42(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [42 x i8] c"Insira o numero inicial de 4 algarismos: \00"
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [27 x i8] c"O numero %i invertido e %i\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%9 = load i32, i32* %1
%10 = srem i32 %9, 10
store i32 %10, i32* %3
%11 = load i32, i32* %1
%12 = srem i32 %11, 100
%13 = sdiv i32 %12, 10
store i32 %13, i32* %4
%14 = load i32, i32* %1
%15 = srem i32 %14, 1000
%16 = sdiv i32 %15, 100
store i32 %16, i32* %5
%17 = load i32, i32* %1
%18 = sdiv i32 %17, 1000
store i32 %18, i32* %6
%19 = load i32, i32* %5
%20 = mul nsw i32 %19, 10
store i32 %20, i32* %5
%21 = load i32, i32* %4
%22 = mul nsw i32 %21, 100
store i32 %22, i32* %4
%23 = load i32, i32* %3
%24 = mul nsw i32 %23, 1000
store i32 %24, i32* %3
%25 = load i32, i32* %3
%26 = load i32, i32* %4
%27 = add nsw i32 %25, %26
%28 = load i32, i32* %5
%29 = add nsw i32 %27, %28
%30 = load i32, i32* %6
%31 = add nsw i32 %29, %30
store i32 %31, i32* %2
%32 = load i32, i32* %1
%33 = load i32, i32* %2
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %32, i32 %33)
ret void
}

LLVM IR (-O2):
@.str = [42 x i8] c"Insira o numero inicial de 4 algarismos: \00"
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [27 x i8] c"O numero %i invertido e %i\00"
define void @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 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 = srem i32 %5, 10
%7 = srem i32 %5, 100
%8 = trunc i32 %7 to i8
%9 = sdiv i8 %8, 10
%10 = sext i8 %9 to i32
%11 = srem i32 %5, 1000
%12 = trunc i32 %11 to i16
%13 = sdiv i16 %12, 100
%14 = sdiv i32 %5, 1000
%15 = mul nsw i16 %13, 10
%16 = sext i16 %15 to i32
%17 = mul nsw i32 %10, 100
%18 = mul nsw i32 %6, 1000
%19 = add nsw i32 %18, %14
%20 = add nsw i32 %19, %17
%21 = add nsw i32 %20, %16
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %5, i32 %21)
ret void
}