#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() {
  int num, i = 0, j, vet[20];
  printf("Digite um numero decimal:\n");
  scanf("%d", &num);
  while (num > 0) {
    vet[i] = num % 2;
    i++;
    num = num / 2;
  }
  printf("o numero em binário é: ");
  for (j = i - 1; j >= 0; j--) {
    printf("%d", vet[j]);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed0(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jle    118d <main+0x6d>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
movslq -0xc(%rbp),%rax
mov    %edx,-0x60(%rbp,%rax,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
jmp    1154 <main+0x34>
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     11d2 <main+0xb2>
movslq -0x10(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%esi
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    11a4 <main+0x84>
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x68,%rsp
lea    0xecf(%rip),%rdi
call   1040 <puts@plt>
lea    0xea6(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    11ca <main+0x8a>
xor    %ebx,%ebx
xchg   %ax,%ax
mov    %eax,%ecx
mov    %eax,%edx
and    $0x1,%edx
mov    %edx,0x10(%rsp,%rbx,4)
add    $0x1,%rbx
shr    %eax
cmp    $0x1,%ecx
ja     1170 <main+0x30>
mov    %eax,0xc(%rsp)
lea    0xe72(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
test   %ebx,%ebx
jle    11d8 <main+0x98>
add    $0x1,%rbx
lea    0xe59(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    0x8(%rsp,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     11b0 <main+0x70>
jmp    11d8 <main+0x98>
lea    0xe32(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Digite um numero decimal:\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [26 x i8] c"o numero em bin\C3\A1rio \C3\A9: \00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [20 x i32]
store i32 0, i32* %1
store i32 0, i32* %3
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 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 sgt i32 %9, 0
br i1 %10, label %11, label %21
11: ; preds = %8
%12 = load i32, i32* %2
%13 = srem i32 %12, 2
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [20 x i32], [20 x i32]* %5, i64 0, i64 %15
store i32 %13, i32* %16
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
%19 = load i32, i32* %2
%20 = sdiv i32 %19, 2
store i32 %20, i32* %2
br label %8
21: ; preds = %8
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%23 = load i32, i32* %3
%24 = sub nsw i32 %23, 1
store i32 %24, i32* %4
br label %25
25: ; preds = %34, %21
%26 = load i32, i32* %4
%27 = icmp sge i32 %26, 0
br i1 %27, label %28, label %37
28: ; preds = %25
%29 = load i32, i32* %4
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [20 x i32], [20 x i32]* %5, i64 0, i64 %30
%32 = load i32, i32* %31
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %28
%35 = load i32, i32* %4
%36 = add nsw i32 %35, -1
store i32 %36, i32* %4
br label %25
37: ; preds = %25
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

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