#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*/ 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]);
    i++;
    decimalno = decimalno / 2;
    printf("decimalno - %d\n", decimalno);
  }
  puts("\n\n\n");
  int j;
  for (j = i - 1; j >= 0; j--) {
    printf("%d", d[j]);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x68(%rbp)
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xede(%rip),%rdi
lea    -0x64(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,-0x64(%rbp)
jle    11c4 <main+0x94>
mov    -0x64(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
movslq -0x68(%rbp),%rax
mov    %edx,-0x60(%rbp,%rax,4)
movslq -0x68(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%esi
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
mov    -0x64(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%esi
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1164 <main+0x34>
lea    0xe8c(%rip),%rdi
call   1030 <puts@plt>
mov    -0x68(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x6c(%rbp)
cmpl   $0x0,-0x6c(%rbp)
jl     1207 <main+0xd7>
movslq -0x6c(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%esi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x6c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x6c(%rbp)
jmp    11d9 <main+0xa9>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x60,%rsp
lea    0xee2(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb4(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%esi
test   %esi,%esi
jle    11fd <main+0xcd>
lea    0xe9a(%rip),%r14
lea    0xe9e(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
and    $0x1,%esi
mov    %esi,0x10(%rsp,%rbx,4)
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
mov    0xc(%rsp),%eax
mov    %eax,%esi
shr    $0x1f,%esi
add    %eax,%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+0x50>
lea    0xe5f(%rip),%rdi
call   1030 <puts@plt>
test   %ebx,%ebx
jle    1209 <main+0xd9>
mov    %ebx,%ebx
add    $0x1,%rbx
lea    0xe2b(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
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     11e0 <main+0xb0>
jmp    1209 <main+0xd9>
lea    0xe1a(%rip),%rdi
call   1030 <puts@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 %28
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 = sext i32 %17 to i64
%19 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %18
%20 = load i32, i32* %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
store i32 %23, i32* %4
%24 = load i32, i32* %3
%25 = sdiv i32 %24, 2
store i32 %25, i32* %3
%26 = load i32, i32* %3
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %26)
br label %8
28: ; preds = %8
%29 = call i32 @puts(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%30 = load i32, i32* %4
%31 = sub nsw i32 %30, 1
store i32 %31, i32* %5
br label %32
32: ; preds = %41, %28
%33 = load i32, i32* %5
%34 = icmp sge i32 %33, 0
br i1 %34, label %35, label %44
35: ; preds = %32
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %37
%39 = load i32, i32* %38
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %35
%42 = load i32, i32* %5
%43 = add nsw i32 %42, -1
store i32 %43, i32* %5
br label %32
44: ; preds = %32
%45 = load i32, i32* %1
ret i32 %45
}

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 [ %17, %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 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%17 = add nuw i64 %12, 1
%18 = load i32, i32* %2
%19 = sdiv i32 %18, 2
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 %17 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 %17, 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
ret i32 0
}