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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed1(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
je     118c <main+0x6c>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0x38(%rbp)
mov    -0x38(%rbp),%ecx
movslq -0x34(%rbp),%rax
mov    %ecx,-0x30(%rbp,%rax,4)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
jmp    114d <main+0x2d>
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jl     11c3 <main+0xa3>
movslq -0x3c(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%esi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x3c(%rbp)
jmp    1195 <main+0x75>
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x38,%rsp
lea    0xec2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec9(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%ecx
test   %ecx,%ecx
je     11bb <main+0x8b>
xor    %eax,%eax
mov    %ecx,%edx
shr    $0x1f,%ecx
add    %edx,%ecx
mov    %ecx,%esi
and    $0xfffffffe,%esi
mov    %edx,%edi
sub    %esi,%edi
mov    %edi,0x10(%rsp,%rax,4)
add    $0x1,%rax
sar    %ecx
add    $0x1,%edx
cmp    $0x3,%edx
jae    1160 <main+0x30>
mov    %ecx,0xc(%rsp)
test   %eax,%eax
jle    11bb <main+0x8b>
mov    %eax,%ebx
add    $0x1,%rbx
lea    0xe7e(%rip),%r14
nopw   0x0(%rax,%rax,1)
lea    -0x2(%rbx),%eax
mov    0x10(%rsp,%rax,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     11a0 <main+0x70>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [21 x i8] c"\0A Entre com inteiro:\00"
@.str.1 = [3 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 ([21 x i8], [21 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 %31, label %14
9: ; preds = %14
%10 = trunc i64 %19 to i32
store i32 %20, i32* %1
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %31
12: ; preds = %9
%13 = and i64 %19, 4294967295
br label %23
14: ; preds = %0, %14
%15 = phi i64 [ %19, %14 ], [ 0, %0 ]
%16 = phi i32 [ %20, %14 ], [ %7, %0 ]
%17 = srem i32 %16, 2
%18 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %15
store i32 %17, i32* %18
%19 = add i64 %15, 1
%20 = sdiv i32 %16, 2
%21 = add i32 %16, 1
%22 = icmp ult i32 %21, 3
br i1 %22, label %9, label %14
23: ; preds = %12, %23
%24 = phi i64 [ %13, %12 ], [ %25, %23 ]
%25 = add nsw i64 %24, -1
%26 = and i64 %25, 4294967295
%27 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = icmp ugt i64 %24, 1
br i1 %30, label %23, label %31
31: ; preds = %23, %0, %9
%32 = call i32 @putchar(i32 10)
ret i32 0
}