#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 */
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int d[20];
  int decimalno, i = 0;
  printf("Enter the decimal number you want to conver to binary: \n");
  scanf("%d", &decimalno);
  while (decimalno > 0) {
    d[i] = decimalno % 2;
    printf("d[i] - %d\n", d[i++]);
    decimalno >>= 1;
    printf("decimalno - %d\n", decimalno);
  }
  puts("\n\n\n");
  int j;
  for (j = i - 1; j >= 0; j--) {
    printf("%d", d[j]);
  }
  while (getchar() != '\0')
    continue;
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x68(%rbp)
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xece(%rip),%rdi
lea    -0x64(%rbp),%rsi
call   1060 <scanf@plt>
cmpl   $0x0,-0x64(%rbp)
jle    11cf <main+0x8f>
mov    -0x64(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
movslq -0x68(%rbp),%rax
mov    %edx,-0x60(%rbp,%rax,4)
mov    -0x68(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x68(%rbp)
cltq
mov    -0x60(%rbp,%rax,4),%esi
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x64(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%esi
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1174 <main+0x34>
lea    0xe81(%rip),%rdi
call   1030 <puts@plt>
mov    -0x68(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x6c(%rbp)
cmpl   $0x0,-0x6c(%rbp)
jl     1212 <main+0xd2>
movslq -0x6c(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%esi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x6c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x6c(%rbp)
jmp    11e4 <main+0xa4>
jmp    1217 <main+0xd7>
mov    $0x0,%al
call   1050 <getchar@plt>
movsbl %al,%eax
cmp    $0x0,%eax
je     122f <main+0xef>
jmp    1217 <main+0xd7>
mov    $0x0,%al
call   1050 <getchar@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x60,%rsp
lea    0xed2(%rip),%rdi
call   1030 <puts@plt>
lea    0xea4(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%esi
test   %esi,%esi
jle    11ed <main+0xad>
lea    0xe8e(%rip),%r14
lea    0xe92(%rip),%r15
xor    %ebx,%ebx
xchg   %ax,%ax
and    $0x1,%esi
mov    %esi,0x10(%rsp,%rbx,4)
add    $0x1,%rbx
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%esi
sar    %esi
mov    %esi,0xc(%rsp)
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%esi
test   %esi,%esi
jg     1180 <main+0x40>
lea    0xe66(%rip),%rdi
call   1030 <puts@plt>
test   %ebx,%ebx
jle    1200 <main+0xc0>
mov    %ebx,%ebx
add    $0x1,%rbx
lea    0xe32(%rip),%r14
xchg   %ax,%ax
lea    -0x2(%rbx),%eax
mov    0x10(%rsp,%rax,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     11d0 <main+0x90>
jmp    1200 <main+0xc0>
lea    0xe2a(%rip),%rdi
call   1030 <puts@plt>
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <getchar@plt>
test   %al,%al
jne    1200 <main+0xc0>
xor    %eax,%eax
call   1050 <getchar@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [57 x i8] c"Enter the decimal number you want to conver to binary: \0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [11 x i8] c"d[i] - %d\0A\00"
@.str.3 = [16 x i8] c"decimalno - %d\0A\00"
@.str.4 = [4 x i8] c"\0A\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
br label %8
8: ; preds = %11, %0
%9 = load i32, i32* %3
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %27
11: ; preds = %8
%12 = load i32, i32* %3
%13 = srem i32 %12, 2
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %15
store i32 %13, i32* %16
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
%19 = sext i32 %17 to i64
%20 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %19
%21 = load i32, i32* %20
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %3
%24 = ashr i32 %23, 1
store i32 %24, i32* %3
%25 = load i32, i32* %3
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %25)
br label %8
27: ; preds = %8
%28 = call i32 @puts(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%29 = load i32, i32* %4
%30 = sub nsw i32 %29, 1
store i32 %30, i32* %5
br label %31
31: ; preds = %40, %27
%32 = load i32, i32* %5
%33 = icmp sge i32 %32, 0
br i1 %33, label %34, label %43
34: ; preds = %31
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %36
%38 = load i32, i32* %37
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %38)
br label %40
40: ; preds = %34
%41 = load i32, i32* %5
%42 = add nsw i32 %41, -1
store i32 %42, i32* %5
br label %31
43: ; preds = %31
br label %44
44: ; preds = %48, %43
%45 = call signext i8 (...) @getchar()
%46 = sext i8 %45 to i32
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %44
br label %44
49: ; preds = %44
%50 = call signext i8 (...) @getchar()
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [11 x i8] c"d[i] - %d\0A\00"
@.str.3 = [16 x i8] c"decimalno - %d\0A\00"
@.str.4 = [4 x i8] c"\0A\0A\0A\00"
@str = [56 x i8] c"Enter the decimal number you want to conver to binary: \00"
define i32 @main() {
%1 = alloca [20 x i32]
%2 = alloca i32
%3 = bitcast [20 x i32]* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 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)
%7 = load i32, i32* %2
%8 = icmp sgt i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %0
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
br label %37
11: ; preds = %0, %11
%12 = phi i64 [ %16, %11 ], [ 0, %0 ]
%13 = phi i32 [ %21, %11 ], [ %7, %0 ]
%14 = and i32 %13, 1
%15 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 %12
store i32 %14, i32* %15
%16 = add nuw i64 %12, 1
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%18 = load i32, i32* %2
%19 = ashr i32 %18, 1
store i32 %19, i32* %2
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%21 = load i32, i32* %2
%22 = icmp sgt i32 %21, 0
br i1 %22, label %11, label %23
23: ; preds = %11
%24 = trunc i64 %16 to i32
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%26 = icmp sgt i32 %24, 0
br i1 %26, label %27, label %37
27: ; preds = %23
%28 = and i64 %16, 4294967295
br label %29
29: ; preds = %27, %29
%30 = phi i64 [ %28, %27 ], [ %31, %29 ]
%31 = add nsw i64 %30, -1
%32 = and i64 %31, 4294967295
%33 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 %32
%34 = load i32, i32* %33
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %34)
%36 = icmp ugt i64 %30, 1
br i1 %36, label %29, label %37
37: ; preds = %29, %9, %23
br label %38
38: ; preds = %37, %38
%39 = call signext i8 (...) @getchar()
%40 = icmp eq i8 %39, 0
br i1 %40, label %41, label %38
41: ; preds = %38
%42 = call signext i8 (...) @getchar()
ret i32 0
}