#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 *, long *);
int main() {
  long int decimalNumber, quotient;
  int i = 1, buffer[100], j;
  printf("Enter the decimal number: ");
  scanf("%ld", &decimalNumber);
  quotient = decimalNumber;
  while (quotient != 0) {
    buffer[i++] = quotient % 2;
    quotient = quotient / 2;
  }
  printf("Binary val of decimal number %d is [", decimalNumber);
  for (j = i - 1; j > 0; j--)
    printf("%d", buffer[j]);
  puts("]");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x1c(%rbp)
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xebd(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11b5 <main+0x85>
mov    -0x18(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %edx,%ecx
mov    -0x1c(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x1c(%rbp)
cltq
mov    %ecx,-0x1b0(%rbp,%rax,4)
mov    -0x18(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,-0x18(%rbp)
jmp    116f <main+0x3f>
mov    -0x10(%rbp),%rsi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1b4(%rbp)
cmpl   $0x0,-0x1b4(%rbp)
jle    1210 <main+0xe0>
movslq -0x1b4(%rbp),%rax
mov    -0x1b0(%rbp,%rax,4),%esi
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1b4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1b4(%rbp)
jmp    11d3 <main+0xa3>
lea    0xe30(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x1a8,%rsp
lea    0xebf(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xecc(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x8(%rsp),%rsi
test   %rsi,%rsi
je     11dd <main+0xad>
mov    $0x1,%ebx
mov    %rsi,%rcx
mov    %rsi,%rax
xchg   %ax,%ax
shr    $0x3f,%rax
add    %rcx,%rax
mov    %eax,%edx
and    $0xfffffffe,%edx
mov    %ecx,%edi
sub    %edx,%edi
mov    %edi,0x10(%rsp,%rbx,4)
add    $0x1,%rbx
sar    %rax
add    $0x1,%rcx
cmp    $0x2,%rcx
mov    %rax,%rcx
ja     1170 <main+0x40>
lea    0xe80(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x2,%ebx
jl     11eb <main+0xbb>
mov    %ebx,%ebx
add    $0x1,%rbx
lea    0xe8c(%rip),%r14
nopl   0x0(%rax,%rax,1)
lea    -0x2(%rbx),%eax
mov    0x10(%rsp,%rax,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x2,%rbx
ja     11c0 <main+0x90>
jmp    11eb <main+0xbb>
lea    0xe3b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe55(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x1a8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Enter the decimal number: \00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [37 x i8] c"Binary val of decimal number %d is [\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [2 x i8] c"]\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i32
%5 = alloca [100 x i32]
%6 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %4
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %2)
%9 = load i64, i64* %2
store i64 %9, i64* %3
br label %10
10: ; preds = %13, %0
%11 = load i64, i64* %3
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %23
13: ; preds = %10
%14 = load i64, i64* %3
%15 = srem i64 %14, 2
%16 = trunc i64 %15 to i32
%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 [100 x i32], [100 x i32]* %5, i64 0, i64 %19
store i32 %16, i32* %20
%21 = load i64, i64* %3
%22 = sdiv i64 %21, 2
store i64 %22, i64* %3
br label %10
23: ; preds = %10
%24 = load i64, i64* %2
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i64 %24)
%26 = load i32, i32* %4
%27 = sub nsw i32 %26, 1
store i32 %27, i32* %6
br label %28
28: ; preds = %37, %23
%29 = load i32, i32* %6
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %40
31: ; preds = %28
%32 = load i32, i32* %6
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [100 x i32], [100 x i32]* %5, i64 0, i64 %33
%35 = load i32, i32* %34
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %31
%38 = load i32, i32* %6
%39 = add nsw i32 %38, -1
store i32 %39, i32* %6
br label %28
40: ; preds = %28
%41 = call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [27 x i8] c"Enter the decimal number: \00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [37 x i8] c"Binary val of decimal number %d is [\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [2 x i8] c"]\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca [100 x i32]
%3 = bitcast i64* %1 to i8*
%4 = bitcast [100 x i32]* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %1)
%7 = load i64, i64* %1
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i64 %7)
br label %35
11: ; preds = %0, %11
%12 = phi i64 [ %16, %11 ], [ 1, %0 ]
%13 = phi i64 [ %18, %11 ], [ %7, %0 ]
%14 = srem i64 %13, 2
%15 = trunc i64 %14 to i32
%16 = add nuw i64 %12, 1
%17 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %12
store i32 %15, i32* %17
%18 = sdiv i64 %13, 2
%19 = add i64 %13, 1
%20 = icmp ult i64 %19, 3
br i1 %20, label %21, label %11
21: ; preds = %11
%22 = trunc i64 %16 to i32
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i64 %7)
%24 = icmp sgt i32 %22, 1
br i1 %24, label %25, label %35
25: ; preds = %21
%26 = and i64 %16, 4294967295
br label %27
27: ; preds = %25, %27
%28 = phi i64 [ %26, %25 ], [ %29, %27 ]
%29 = add nsw i64 %28, -1
%30 = and i64 %29, 4294967295
%31 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %30
%32 = load i32, i32* %31
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %32)
%34 = icmp ugt i64 %28, 2
br i1 %34, label %27, label %35
35: ; preds = %27, %9, %21
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}