#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, resto, divisao;
  int bin[10], i = 0, j;
  printf("Entre com um número inteiro:");
  scanf("%d", &num);
  do {
    resto = num % 2;
    bin[i] = resto;
    divisao = num / 2;
    num = divisao;
    i++;
  } while (divisao > 0);
  for (j = i - 1; j >= 0; j--) {
    printf("%d ", bin[j]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x44(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed3(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%ecx
movslq -0x44(%rbp),%rax
mov    %ecx,-0x40(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x10(%rbp)
jg     1154 <main+0x34>
mov    -0x44(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
jl     11cb <main+0xab>
movslq -0x48(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%esi
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x48(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x48(%rbp)
jmp    119d <main+0x7d>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xece(%rip),%rdi
xor    %r12d,%r12d
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xedb(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
mov    0xc(%rsp),%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %eax,%ecx
shr    $0x1f,%eax
add    %ecx,%eax
mov    %eax,%edx
and    $0xfffffffe,%edx
mov    %ecx,%esi
sub    %edx,%esi
mov    %esi,0x10(%rsp,%r12,4)
sar    %eax
add    $0x1,%r12
cmp    $0x1,%ecx
jg     1160 <main+0x40>
mov    %eax,0xc(%rsp)
add    $0xffffffffffffffff,%r12
mov    %r12d,%eax
lea    (%rsp,%rax,4),%r15
add    $0x10,%r15
lea    0xe87(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    (%r15,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    -0x1(%rbx),%rax
add    %r12d,%ebx
test   %ebx,%ebx
mov    %rax,%rbx
jg     11a0 <main+0x80>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [30 x i8] c"Entre com um n\C3\BAmero inteiro:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%d \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = bitcast i32* %1 to i8*
%4 = bitcast [10 x i32]* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 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
br label %8
8: ; preds = %8, %0
%9 = phi i64 [ %14, %8 ], [ 0, %0 ]
%10 = phi i32 [ %13, %8 ], [ %7, %0 ]
%11 = srem i32 %10, 2
%12 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %9
store i32 %11, i32* %12
%13 = sdiv i32 %10, 2
%14 = add nuw i64 %9, 1
%15 = icmp sgt i32 %10, 1
br i1 %15, label %8, label %16
16: ; preds = %8
store i32 %13, i32* %1
%17 = and i64 %9, 4294967295
br label %18
18: ; preds = %16, %18
%19 = phi i64 [ %17, %16 ], [ %23, %18 ]
%20 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %19
%21 = load i32, i32* %20
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = add nsw i64 %19, -1
%24 = trunc i64 %19 to i32
%25 = icmp sgt i32 %24, 0
br i1 %25, label %18, label %26
26: ; preds = %18
ret i32 0
}