#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, numSomado, 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;
  numSomado = num1 + num2 + num3 + num4;
  printf("A soma dos algarismos %i eh %i", numInicial, numSomado);
}


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    0xf09(%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)
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    0xe7c(%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    0xf10(%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,%eax
sub    %ecx,%eax
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,%rdx
mov    %rdx,%rdi
shr    $0x3f,%rdi
sar    $0x26,%rdx
add    %edi,%edx
imul   $0x3e8,%edx,%edi
mov    %esi,%ecx
sub    %edi,%ecx
movswl %cx,%ecx
imul   $0x147b,%ecx,%ecx
mov    %ecx,%edi
shr    $0x1f,%edi
sar    $0x13,%ecx
add    %edi,%ecx
add    %eax,%edx
add    %r8d,%edx
add    %ecx,%edx
lea    0xe56(%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 = [31 x i8] c"A soma dos algarismos %i eh %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* %3
%20 = load i32, i32* %4
%21 = add nsw i32 %19, %20
%22 = load i32, i32* %5
%23 = add nsw i32 %21, %22
%24 = load i32, i32* %6
%25 = add nsw i32 %23, %24
store i32 %25, i32* %2
%26 = load i32, i32* %1
%27 = load i32, i32* %2
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %26, i32 %27)
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 = [31 x i8] c"A soma dos algarismos %i eh %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 = sext i16 %13 to i32
%15 = sdiv i32 %5, 1000
%16 = add nsw i32 %15, %6
%17 = add nsw i32 %16, %10
%18 = add nsw i32 %17, %14
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %5, i32 %18)
ret void
}