#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 n;
  printf("Enter a Number: ");
  scanf("%d", &n);
  if (n < 0) {
    printf("Sry.. Negavite No. is Allowed.. ||| Converting to Positive \n");
    n = -n;
  }
  printf("%d in Binary is: ", n);
  if (!n)
    printf("0 ");
  while (n > 0) {
    printf("%d ", n % 2);
    if (n % 2 == 0)
      n /= 2;
    else
      n = (n - 1) / 2;
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecd(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jge    116d <main+0x4d>
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xeda(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
jne    1196 <main+0x76>
lea    0xed4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    119b <main+0x7b>
cmpl   $0x0,-0x8(%rbp)
jle    11fd <main+0xdd>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,%esi
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11e7 <main+0xc7>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
jmp    11f8 <main+0xd8>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
jmp    119b <main+0x7b>
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xeb4(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeb5(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%esi
test   %esi,%esi
jns    1184 <main+0x44>
lea    0xeb8(%rip),%rdi
call   1040 <puts@plt>
sub    0xc(%rsp),%ebx
mov    %ebx,0xc(%rsp)
mov    %ebx,%esi
lea    0xe89(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%esi
test   %esi,%esi
je     11a0 <main+0x60>
test   %esi,%esi
jg     11b6 <main+0x76>
jmp    11e1 <main+0xa1>
lea    0xe7f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%esi
test   %esi,%esi
jle    11e1 <main+0xa1>
lea    0xe6c(%rip),%rbx
nopl   (%rax)
and    $0x1,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%esi
mov    %esi,%eax
and    $0xfffffffe,%eax
sar    %esi
mov    %esi,0xc(%rsp)
cmp    $0x1,%eax
jg     11c0 <main+0x80>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Enter a Number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [61 x i8] c"Sry.. Negavite No. is Allowed.. ||| Converting to Positive \0A\00"
@.str.3 = [18 x i8] c"%d in Binary is: \00"
@.str.4 = [3 x i8] c"0 \00"
@.str.5 = [4 x i8] c"%d \00"
@.str.6 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 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* %2)
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0))
%9 = load i32, i32* %2
%10 = sub nsw i32 0, %9
store i32 %10, i32* %2
br label %11
11: ; preds = %7, %0
%12 = load i32, i32* %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %2
%15 = icmp ne i32 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %11
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %18
18: ; preds = %16, %11
br label %19
19: ; preds = %36, %18
%20 = load i32, i32* %2
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %37
22: ; preds = %19
%23 = load i32, i32* %2
%24 = srem i32 %23, 2
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %2
%27 = srem i32 %26, 2
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %22
%30 = load i32, i32* %2
%31 = sdiv i32 %30, 2
store i32 %31, i32* %2
br label %36
32: ; preds = %22
%33 = load i32, i32* %2
%34 = sub nsw i32 %33, 1
%35 = sdiv i32 %34, 2
store i32 %35, i32* %2
br label %36
36: ; preds = %32, %29
br label %19
37: ; preds = %19
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"Enter a Number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [18 x i8] c"%d in Binary is: \00"
@.str.4 = [3 x i8] c"0 \00"
@.str.5 = [4 x i8] c"%d \00"
@str = [60 x i8] c"Sry.. Negavite No. is Allowed.. ||| Converting to Positive \00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 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 = load i32, i32* %1
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str, i64 0, i64 0))
%9 = load i32, i32* %1
%10 = sub nsw i32 0, %9
store i32 %10, i32* %1
br label %11
11: ; preds = %7, %0
%12 = phi i32 [ %10, %7 ], [ %5, %0 ]
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %1
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%18 = load i32, i32* %1
br label %19
19: ; preds = %16, %11
%20 = phi i32 [ %18, %16 ], [ %14, %11 ]
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %19, %22
%23 = phi i32 [ %28, %22 ], [ %20, %19 ]
%24 = and i32 %23, 1
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %1
%27 = and i32 %26, -2
%28 = sdiv i32 %27, 2
store i32 %28, i32* %1
%29 = icmp sgt i32 %27, 1
br i1 %29, label %22, label %30
30: ; preds = %22, %19
%31 = call i32 @putchar(i32 10)
ret i32 0
}