#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(void) {
  int n = 0, k = 32;
  printf("\nenter a decimal number: ");
  scanf("%d", &n);
  printf("\nbinary equivalent: ");
  while (k != 0) {
    if ((n & 1) != 0)
      printf("1");
    else
      printf("0");
    k--;
    n = n >> 1;
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x20,-0xc(%rbp)
lea    0xebc(%rip),%rdi
call   1030 <printf@plt>
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xebd(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x0,-0xc(%rbp)
je     11b2 <main+0x92>
mov    -0x8(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     118f <main+0x6f>
lea    0xead(%rip),%rdi
call   1030 <printf@plt>
jmp    119b <main+0x7b>
lea    0xe9e(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1165 <main+0x45>
lea    0xe7d(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
lea    0xebc(%rip),%rdi
call   1040 <printf@plt>
lea    0xeca(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
lea    0xebc(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffe0,%ebx
mov    0xc(%rsp),%edi
nop
and    $0x1,%edi
or     $0x30,%edi
call   1030 <putchar@plt>
mov    0xc(%rsp),%edi
sar    %edi
mov    %edi,0xc(%rsp)
inc    %ebx
jne    1170 <main+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [26 x i8] c"\0Aenter a decimal number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [21 x i8] c"\0Abinary equivalent: \00"
@.str.3 = [2 x i8] c"1\00"
@.str.4 = [2 x i8] c"0\00"
@.str.5 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 32, i32* %3
%4 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%6 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %7
7: ; preds = %18, %0
%8 = load i32, i32* %3
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %23
10: ; preds = %7
%11 = load i32, i32* %2
%12 = and i32 %11, 1
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %18
16: ; preds = %10
%17 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %18
18: ; preds = %16, %14
%19 = load i32, i32* %3
%20 = add nsw i32 %19, -1
store i32 %20, i32* %3
%21 = load i32, i32* %2
%22 = ashr i32 %21, 1
store i32 %22, i32* %2
br label %7
23: ; preds = %7
%24 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [26 x i8] c"\0Aenter a decimal number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [21 x i8] c"\0Abinary equivalent: \00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%6 = load i32, i32* %1
br label %7
7: ; preds = %0, %7
%8 = phi i32 [ %6, %0 ], [ %15, %7 ]
%9 = phi i32 [ 32, %0 ], [ %13, %7 ]
%10 = and i32 %8, 1
%11 = or i32 %10, 48
%12 = call i32 @putchar(i32 %11)
%13 = add nsw i32 %9, -1
%14 = load i32, i32* %1
%15 = ashr i32 %14, 1
store i32 %15, i32* %1
%16 = icmp eq i32 %13, 0
br i1 %16, label %17, label %7
17: ; preds = %7
%18 = call i32 @putchar(i32 10)
ret i32 0
}