#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 *, long *);
void main() {
  long num, decimal_num, remainder, base = 1, binary = 0, no_of_1s = 0;
  printf("Enter a decimal integer \n");
  scanf("%ld", &num);
  decimal_num = num;
  while (num > 0) {
    remainder = num % 2;
    if (remainder == 1) {
      no_of_1s++;
    }
    binary = binary + remainder * base;
    num = num / 2;
    base = base * 10;
  }
  printf("Input number is = %d\n", decimal_num);
  printf("Its binary equivalent is = %ld\n", binary);
  printf("No.of 1's in the binary number is = %d\n", no_of_1s);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x1,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec5(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jle    11ce <main+0xae>
mov    -0x8(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x18(%rbp)
cmpq   $0x1,-0x18(%rbp)
jne    119a <main+0x7a>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
imul   -0x20(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,-0x8(%rbp)
imul   $0xa,-0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1166 <main+0x46>
mov    -0x10(%rbp),%rsi
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rsi
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rsi
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xf27(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb9(%rip),%rdi
mov    %rsp,%rsi
call   1050 <scanf@plt>
mov    (%rsp),%rsi
test   %rsi,%rsi
jle    1198 <main+0x68>
mov    $0x1,%eax
xor    %r14d,%r14d
xor    %ebx,%ebx
mov    %rsi,%rcx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rcx,%rdx
mov    %edx,%edi
and    $0x1,%edi
add    %rdi,%r14
imul   %rax,%rdi
add    %rdi,%rbx
shr    %rcx
add    %rax,%rax
lea    (%rax,%rax,4),%rax
cmp    $0x1,%rdx
ja     1170 <main+0x40>
mov    %rcx,(%rsp)
jmp    119d <main+0x6d>
xor    %ebx,%ebx
xor    %r14d,%r14d
lea    0xe60(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe68(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe77(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Enter a decimal integer \0A\00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [22 x i8] c"Input number is = %d\0A\00"
@.str.3 = [32 x i8] c"Its binary equivalent is = %ld\0A\00"
@.str.4 = [40 x i8] c"No.of 1's in the binary number is = %d\0A\00"
define void @main() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i64 1, i64* %4
store i64 0, i64* %5
store i64 0, i64* %6
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %1)
%9 = load i64, i64* %1
store i64 %9, i64* %2
br label %10
10: ; preds = %21, %0
%11 = load i64, i64* %1
%12 = icmp sgt i64 %11, 0
br i1 %12, label %13, label %31
13: ; preds = %10
%14 = load i64, i64* %1
%15 = srem i64 %14, 2
store i64 %15, i64* %3
%16 = load i64, i64* %3
%17 = icmp eq i64 %16, 1
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i64, i64* %6
%20 = add nsw i64 %19, 1
store i64 %20, i64* %6
br label %21
21: ; preds = %18, %13
%22 = load i64, i64* %5
%23 = load i64, i64* %3
%24 = load i64, i64* %4
%25 = mul nsw i64 %23, %24
%26 = add nsw i64 %22, %25
store i64 %26, i64* %5
%27 = load i64, i64* %1
%28 = sdiv i64 %27, 2
store i64 %28, i64* %1
%29 = load i64, i64* %4
%30 = mul nsw i64 %29, 10
store i64 %30, i64* %4
br label %10
31: ; preds = %10
%32 = load i64, i64* %2
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i64 %32)
%34 = load i64, i64* %5
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i64 %34)
%36 = load i64, i64* %6
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i64 %36)
ret void
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [22 x i8] c"Input number is = %d\0A\00"
@.str.3 = [32 x i8] c"Its binary equivalent is = %ld\0A\00"
@.str.4 = [40 x i8] c"No.of 1's in the binary number is = %d\0A\00"
@str = [25 x i8] c"Enter a decimal integer \00"
define void @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %1)
%5 = load i64, i64* %1
%6 = icmp sgt i64 %5, 0
br i1 %6, label %7, label %20
7: ; preds = %0, %7
%8 = phi i64 [ %13, %7 ], [ 0, %0 ]
%9 = phi i64 [ %15, %7 ], [ 0, %0 ]
%10 = phi i64 [ %17, %7 ], [ 1, %0 ]
%11 = phi i64 [ %16, %7 ], [ %5, %0 ]
%12 = and i64 %11, 1
%13 = add nuw nsw i64 %8, %12
%14 = mul nuw nsw i64 %12, %10
%15 = add nuw nsw i64 %9, %14
%16 = lshr i64 %11, 1
%17 = mul nsw i64 %10, 10
%18 = icmp ult i64 %11, 2
br i1 %18, label %19, label %7
19: ; preds = %7
store i64 %16, i64* %1
br label %20
20: ; preds = %19, %0
%21 = phi i64 [ %15, %19 ], [ 0, %0 ]
%22 = phi i64 [ %13, %19 ], [ 0, %0 ]
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i64 %5)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i64 %21)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i64 %22)
ret void
}