#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 *);
int main(void) {
  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 = %ld\n", decimal_num);
  printf("Its binary equivalent is = %ld\n", binary);
  printf("No.of 1's in the binary number is = %ld\n", no_of_1s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x1,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebe(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jle    11d5 <main+0xb5>
mov    -0x10(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x20(%rbp)
cmpq   $0x1,-0x20(%rbp)
jne    11a1 <main+0x81>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
imul   -0x28(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
imul   $0xa,-0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    116d <main+0x4d>
mov    -0x18(%rbp),%rsi
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rsi
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rsi
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xf29(%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    0xe69(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe78(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
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 = [23 x i8] c"Input number is = %ld\0A\00"
@.str.3 = [32 x i8] c"Its binary equivalent is = %ld\0A\00"
@.str.4 = [41 x i8] c"No.of 1's in the binary number is = %ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i32 0, i32* %1
store i64 1, i64* %5
store i64 0, i64* %6
store i64 0, i64* %7
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %2)
%10 = load i64, i64* %2
store i64 %10, i64* %3
br label %11
11: ; preds = %22, %0
%12 = load i64, i64* %2
%13 = icmp sgt i64 %12, 0
br i1 %13, label %14, label %32
14: ; preds = %11
%15 = load i64, i64* %2
%16 = srem i64 %15, 2
store i64 %16, i64* %4
%17 = load i64, i64* %4
%18 = icmp eq i64 %17, 1
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i64, i64* %7
%21 = add nsw i64 %20, 1
store i64 %21, i64* %7
br label %22
22: ; preds = %19, %14
%23 = load i64, i64* %6
%24 = load i64, i64* %4
%25 = load i64, i64* %5
%26 = mul nsw i64 %24, %25
%27 = add nsw i64 %23, %26
store i64 %27, i64* %6
%28 = load i64, i64* %2
%29 = sdiv i64 %28, 2
store i64 %29, i64* %2
%30 = load i64, i64* %5
%31 = mul nsw i64 %30, 10
store i64 %31, i64* %5
br label %11
32: ; preds = %11
%33 = load i64, i64* %3
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i64 %33)
%35 = load i64, i64* %6
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i64 %35)
%37 = load i64, i64* %7
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i64 %37)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [23 x i8] c"Input number is = %ld\0A\00"
@.str.3 = [32 x i8] c"Its binary equivalent is = %ld\0A\00"
@.str.4 = [41 x i8] c"No.of 1's in the binary number is = %ld\0A\00"
@str = [25 x i8] c"Enter a decimal integer \00"
define i32 @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 ([23 x i8], [23 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 ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i64 %22)
ret i32 0
}