#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(void) {
  int decimal = 0, binario[4], resto = 0;
  printf("Insira um numero decimal:\n");
  scanf("%d", &decimal);
  int cont = 0;
  for (int cont = 0; cont < 4; cont++)
    binario[cont] = 0;
  while (decimal != 0) {
    resto = decimal % 2;
    binario[cont] = resto == 0 ? 0 : 1;
    decimal = decimal / 2;
    cont++;
  }
  printf("\n");
  for (int cont = 3; cont >= 0; cont--)
    printf("%d", binario[cont]);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0x24(%rbp)
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec9(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x4,-0x2c(%rbp)
jge    118d <main+0x6d>
movslq -0x2c(%rbp),%rax
movl   $0x0,-0x20(%rbp,%rax,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1169 <main+0x49>
jmp    1192 <main+0x72>
cmpl   $0x0,-0x8(%rbp)
je     11de <main+0xbe>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0x24(%rbp)
mov    -0x24(%rbp),%edx
mov    $0x1,%ecx
xor    %eax,%eax
cmp    $0x0,%edx
cmove  %eax,%ecx
movslq -0x28(%rbp),%rax
mov    %ecx,-0x20(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1192 <main+0x72>
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x3,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jl     1221 <main+0x101>
movslq -0x30(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%esi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x30(%rbp)
jmp    11f3 <main+0xd3>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
movl   $0x0,0xc(%rsp)
lea    0xea8(%rip),%rdi
call   1040 <puts@plt>
lea    0xe99(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
mov    0xc(%rsp),%eax
test   %eax,%eax
je     11c5 <main+0x85>
lea    0x10(%rsp),%rcx
cs nopw 0x0(%rax,%rax,1)
mov    %eax,%edx
mov    %eax,%esi
and    $0x1,%esi
mov    %esi,(%rcx)
shr    $0x1f,%eax
add    %edx,%eax
sar    %eax
add    $0x1,%edx
add    $0x4,%rcx
cmp    $0x2,%edx
ja     1190 <main+0x50>
mov    %eax,0xc(%rsp)
mov    0x1c(%rsp),%ebp
mov    0x18(%rsp),%r12d
mov    0x10(%rsp),%r14d
mov    0x14(%rsp),%r15d
jmp    11d0 <main+0x90>
xor    %r14d,%r14d
xor    %r15d,%r15d
xor    %r12d,%r12d
xor    %ebp,%ebp
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe1f(%rip),%rbx
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Insira um numero decimal:\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [4 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %4
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
store i32 0, i32* %5
store i32 0, i32* %6
br label %10
10: ; preds = %17, %0
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 4
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = load i32, i32* %6
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 %15
store i32 0, i32* %16
br label %17
17: ; preds = %13
%18 = load i32, i32* %6
%19 = add nsw i32 %18, 1
store i32 %19, i32* %6
br label %10
20: ; preds = %10
br label %21
21: ; preds = %24, %20
%22 = load i32, i32* %2
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %38
24: ; preds = %21
%25 = load i32, i32* %2
%26 = srem i32 %25, 2
store i32 %26, i32* %4
%27 = load i32, i32* %4
%28 = icmp eq i32 %27, 0
%29 = zext i1 %28 to i64
%30 = select i1 %28, i32 0, i32 1
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 %32
store i32 %30, i32* %33
%34 = load i32, i32* %2
%35 = sdiv i32 %34, 2
store i32 %35, i32* %2
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
br label %21
38: ; preds = %21
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32 3, i32* %7
br label %40
40: ; preds = %49, %38
%41 = load i32, i32* %7
%42 = icmp sge i32 %41, 0
br i1 %42, label %43, label %52
43: ; preds = %40
%44 = load i32, i32* %7
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 %45
%47 = load i32, i32* %46
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %43
%50 = load i32, i32* %7
%51 = add nsw i32 %50, -1
store i32 %51, i32* %7
br label %40
52: ; preds = %40
%53 = load i32, i32* %1
ret i32 %53
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@str = [26 x i8] c"Insira um numero decimal:\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4 x i32]
%3 = bitcast [4 x i32]* %2 to i8*
%4 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 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* %1)
%7 = load i32, i32* %1
%8 = icmp eq i32 %7, 0
br i1 %8, label %27, label %9
9: ; preds = %0, %9
%10 = phi i64 [ %15, %9 ], [ 0, %0 ]
%11 = phi i32 [ %14, %9 ], [ %7, %0 ]
%12 = and i32 %11, 1
%13 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 %10
store i32 %12, i32* %13
%14 = sdiv i32 %11, 2
%15 = add nuw i64 %10, 1
%16 = add i32 %11, 1
%17 = icmp ult i32 %16, 3
br i1 %17, label %18, label %9
18: ; preds = %9
store i32 %14, i32* %1
%19 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 3
%20 = load i32, i32* %19
%21 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 2
%22 = load i32, i32* %21
%23 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 1
%24 = load i32, i32* %23
%25 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
%26 = load i32, i32* %25
br label %27
27: ; preds = %18, %0
%28 = phi i32 [ %26, %18 ], [ 0, %0 ]
%29 = phi i32 [ %24, %18 ], [ 0, %0 ]
%30 = phi i32 [ %22, %18 ], [ 0, %0 ]
%31 = phi i32 [ %20, %18 ], [ 0, %0 ]
%32 = call i32 @putchar(i32 10)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %31)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %30)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %29)
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %28)
ret i32 0
}