#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, c, k;
  printf("Enter a decimal number");
  scanf("%d", &n);
  for (c = 31; c >= 0; c--) {
    k = n >> c;
    if (k & 1) {
      printf("1");
    } else
      printf("0");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
call   1030 <printf@plt>
lea    0xed5(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x1f,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     11a6 <main+0x86>
mov    -0x8(%rbp),%eax
mov    -0xc(%rbp),%ecx
sar    %cl,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1187 <main+0x67>
lea    0xe9d(%rip),%rdi
call   1030 <printf@plt>
jmp    1193 <main+0x73>
lea    0xe8e(%rip),%rdi
call   1030 <printf@plt>
jmp    1198 <main+0x78>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1152 <main+0x32>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xec4(%rip),%rdi
call   1040 <printf@plt>
lea    0xecf(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    $0x1f,%ebx
nopw   0x0(%rax,%rax,1)
mov    0xc(%rsp),%eax
bt     %ebx,%eax
mov    $0x31,%edi
adc    $0xffffffff,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebx
jb     1160 <main+0x30>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [23 x i8] c"Enter a decimal number\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 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)
br label %5
5: ; preds = %0, %5
%6 = phi i32 [ 31, %0 ], [ %13, %5 ]
%7 = load i32, i32* %1
%8 = shl nuw i32 1, %6
%9 = and i32 %7, %8
%10 = icmp eq i32 %9, 0
%11 = select i1 %10, i32 48, i32 49
%12 = call i32 @putchar(i32 %11)
%13 = add nsw i32 %6, -1
%14 = icmp eq i32 %6, 0
br i1 %14, label %15, label %5
15: ; preds = %5
ret i32 0
}