#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*/ LC_ALL;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
int main() {
  setlocale(LC_ALL, "");
  int num = 0;
  int milhar = 0, centena = 0, dezena = 0, unidade = 0;
  while (num < 1000 || num > 9999) {
    printf("Insira um número de 1000 a 9999: ");
    scanf("%d", &num);
  }
  milhar = num / 1000;
  centena = (num / 100) % 10;
  dezena = (num / 10) % 10;
  unidade = num % 10;
  printf("M: %d\n", milhar);
  printf("C: %d\n", centena);
  printf("D: %d\n", dezena);
  printf("U: %d\n", unidade);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
lea    0xee4(%rip),%rsi
call   1040 <setlocale@plt>
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    $0x1,%al
cmpl   $0x3e8,-0x8(%rbp)
mov    %al,-0x19(%rbp)
jl     1196 <main+0x66>
cmpl   $0x270f,-0x8(%rbp)
setg   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11a6 <main+0x76>
jmp    11c9 <main+0x99>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe68(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
jmp    1177 <main+0x47>
mov    -0x8(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2ea2(%rip),%rax
mov    (%rax),%edi
lea    0xeec(%rip),%rsi
call   1040 <setlocale@plt>
movl   $0x0,0x4(%rsp)
lea    0xea5(%rip),%r14
lea    0xec1(%rip),%r15
lea    0x4(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%eax
lea    -0x2710(%rax),%ecx
cmp    $0xffffdcd8,%ecx
jb     1170 <main+0x40>
movzwl %ax,%ecx
mov    %ecx,%edx
imul   $0xcccd,%ecx,%edi
shr    $0x3,%ecx
imul   $0x20c5,%ecx,%esi
shr    $0x14,%esi
shr    $0x2,%edx
imul   $0x147b,%edx,%ecx
shr    $0x11,%ecx
movzbl %cl,%ecx
imul   $0xcd,%ecx,%edx
shr    $0xa,%edx
and    $0xfffffffe,%edx
lea    (%rdx,%rdx,4),%edx
sub    %dl,%cl
movzbl %cl,%ebx
shr    $0x13,%edi
imul   $0xcccd,%edi,%ecx
shr    $0x12,%ecx
and    $0xfffffffe,%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %edi,%edx
sub    %ecx,%edx
movzwl %dx,%r14d
add    %edi,%edi
lea    (%rdi,%rdi,4),%ecx
sub    %ecx,%eax
movzwl %ax,%ebp
lea    0xe2a(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe23(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe1a(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe10(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [35 x i8] c"Insira um n\C3\BAmero de 1000 a 9999: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [7 x i8] c"M: %d\0A\00"
@.str.4 = [7 x i8] c"C: %d\0A\00"
@.str.5 = [7 x i8] c"D: %d\0A\00"
@.str.6 = [7 x i8] c"U: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = load i32, i32* @LC_ALL
%8 = call i32 @setlocale(i32 %7, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
br label %9
9: ; preds = %17, %0
%10 = load i32, i32* %2
%11 = icmp slt i32 %10, 1000
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = load i32, i32* %2
%14 = icmp sgt i32 %13, 9999
br label %15
15: ; preds = %12, %9
%16 = phi i1 [ true, %9 ], [ %14, %12 ]
br i1 %16, label %17, label %20
17: ; preds = %15
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
br label %9
20: ; preds = %15
%21 = load i32, i32* %2
%22 = sdiv i32 %21, 1000
store i32 %22, i32* %3
%23 = load i32, i32* %2
%24 = sdiv i32 %23, 100
%25 = srem i32 %24, 10
store i32 %25, i32* %4
%26 = load i32, i32* %2
%27 = sdiv i32 %26, 10
%28 = srem i32 %27, 10
store i32 %28, i32* %5
%29 = load i32, i32* %2
%30 = srem i32 %29, 10
store i32 %30, i32* %6
%31 = load i32, i32* %3
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %31)
%33 = load i32, i32* %4
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %33)
%35 = load i32, i32* %5
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %35)
%37 = load i32, i32* %6
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 %37)
ret i32 0
}

LLVM IR (-O2):
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [35 x i8] c"Insira um n\C3\BAmero de 1000 a 9999: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [7 x i8] c"M: %d\0A\00"
@.str.4 = [7 x i8] c"C: %d\0A\00"
@.str.5 = [7 x i8] c"D: %d\0A\00"
@.str.6 = [7 x i8] c"U: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = load i32, i32* @LC_ALL
%3 = tail call i32 @setlocale(i32 %2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%4 = bitcast i32* %1 to i8*
store i32 0, i32* %1
br label %5
5: ; preds = %0, %5
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%8 = load i32, i32* %1
%9 = add i32 %8, -10000
%10 = icmp ult i32 %9, -9000
br i1 %10, label %5, label %11
11: ; preds = %5
%12 = trunc i32 %8 to i16
%13 = udiv i16 %12, 1000
%14 = zext i16 %13 to i32
%15 = udiv i16 %12, 100
%16 = trunc i16 %15 to i8
%17 = urem i8 %16, 10
%18 = zext i8 %17 to i32
%19 = udiv i16 %12, 10
%20 = urem i16 %19, 10
%21 = zext i16 %20 to i32
%22 = urem i16 %12, 10
%23 = zext i16 %22 to i32
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %18)
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %21)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 %23)
ret i32 0
}