#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 binarydigits(int, int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ getch();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ stdin;
int main() {
  int x, nb, i;
  printf("\n Input an decimal integer number to be converted: ");
  scanf("%d", &x);
  fflush(stdin);
  if (x == 0 || x == 1) {
    printf("\n\n %d in binary : %d", x, x);
  } else {
    printf("\n\n %d in binary : ", x);
    nb = binarydigits(x, 2);
    int remind[nb];
    for (i = (nb - 1); i >= 0; --i, x /= 2) {
      remind[i] = x % 2;
    }
    for (i = nb; i > 0; --i) {
      printf("%d", remind[nb - i]);
    }
  }
  getch();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed2(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
cmpl   $0x0,-0x8(%rbp)
je     119f <main+0x4f>
cmpl   $0x1,-0x8(%rbp)
jne    11b8 <main+0x68>
mov    -0x8(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1288 <main+0x138>
mov    -0x8(%rbp),%esi
lea    0xe87(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
mov    $0x2,%esi
call   1070 <binarydigits@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     1245 <main+0xf5>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x28(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
jmp    1209 <main+0xb9>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    1281 <main+0x131>
mov    -0x28(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    -0x10(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdda(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    124b <main+0xfb>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    $0x0,%al
call   1060 <getch@plt>
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe9a(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xed2(%rip),%rdi
lea    -0x24(%rbp),%rsi
call   1050 <scanf@plt>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
mov    -0x24(%rbp),%esi
cmp    $0x1,%esi
ja     11a8 <main+0x58>
lea    0xe9a(%rip),%rdi
mov    %esi,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    129d <main+0x14d>
lea    0xe9a(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    -0x24(%rbp),%edi
mov    $0x2,%esi
call   1070 <binarydigits@plt>
mov    %rsp,%r14
mov    %eax,%r12d
lea    0xf(,%r12,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rbx
sub    %rcx,%rbx
mov    %rbx,%rsp
test   %eax,%eax
jle    129a <main+0x14a>
mov    -0x24(%rbp),%ecx
test   $0x1,%r12b
jne    11fa <main+0xaa>
mov    %r12,%rax
cmp    $0x1,%r12d
jne    121c <main+0xcc>
jmp    1265 <main+0x115>
lea    -0x1(%r12),%rax
mov    %eax,%esi
mov    %ecx,%edx
shr    $0x1f,%edx
add    %ecx,%edx
mov    %edx,%edi
and    $0xfffffffe,%edi
sub    %edi,%ecx
mov    %ecx,(%rbx,%rsi,4)
sar    %edx
mov    %edx,%ecx
cmp    $0x1,%r12d
je     1265 <main+0x115>
add    $0xfffffffffffffffe,%rax
lea    0x1(%rax),%r8
mov    %r8d,%r9d
mov    %ecx,%edi
shr    $0x1f,%edi
add    %ecx,%edi
mov    %edi,%esi
and    $0xfffffffe,%esi
mov    %ecx,%edx
sub    %esi,%edx
mov    %edx,(%rbx,%r9,4)
mov    %edi,%esi
sar    %esi
shr    $0x1f,%edi
add    %esi,%edi
and    $0xfffffffe,%edi
sub    %edi,%esi
mov    %eax,%edi
lea    0x3(%rcx),%edx
test   %ecx,%ecx
cmovns %ecx,%edx
mov    %esi,(%rbx,%rdi,4)
sar    $0x2,%edx
add    $0xfffffffffffffffe,%rax
mov    %edx,%ecx
cmp    $0x1,%r8
ja     1220 <main+0xd0>
mov    %edx,-0x24(%rbp)
test   %r12d,%r12d
jle    129a <main+0x14a>
add    $0x1,%r12
lea    0xdce(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    (%rbx),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0xffffffffffffffff,%r12
add    $0x4,%rbx
cmp    $0x1,%r12
ja     1280 <main+0x130>
mov    %r14,%rsp
xor    %eax,%eax
call   1060 <getch@plt>
xor    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [52 x i8] c"\0A Input an decimal integer number to be converted: \00"
@.str.1 = [3 x i8] c"%d\00"
@stdin = global i32 0
@.str.2 = [21 x i8] c"\0A\0A %d in binary : %d\00"
@.str.3 = [19 x i8] c"\0A\0A %d in binary : \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = load i32, i32* @stdin
%10 = call i32 @fflush(i32 %9)
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %0
%14 = load i32, i32* %2
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %20
16: ; preds = %13, %0
%17 = load i32, i32* %2
%18 = load i32, i32* %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %17, i32 %18)
br label %63
20: ; preds = %13
%21 = load i32, i32* %2
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %2
%24 = call i32 @binarydigits(i32 %23, i32 2)
store i32 %24, i32* %3
%25 = load i32, i32* %3
%26 = zext i32 %25 to i64
%27 = call i8* @llvm.stacksave()
store i8* %27, i8** %5
%28 = alloca i32, i64 %26
store i64 %26, i64* %6
%29 = load i32, i32* %3
%30 = sub nsw i32 %29, 1
store i32 %30, i32* %4
br label %31
31: ; preds = %40, %20
%32 = load i32, i32* %4
%33 = icmp sge i32 %32, 0
br i1 %33, label %34, label %45
34: ; preds = %31
%35 = load i32, i32* %2
%36 = srem i32 %35, 2
%37 = load i32, i32* %4
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %28, i64 %38
store i32 %36, i32* %39
br label %40
40: ; preds = %34
%41 = load i32, i32* %4
%42 = add nsw i32 %41, -1
store i32 %42, i32* %4
%43 = load i32, i32* %2
%44 = sdiv i32 %43, 2
store i32 %44, i32* %2
br label %31
45: ; preds = %31
%46 = load i32, i32* %3
store i32 %46, i32* %4
br label %47
47: ; preds = %58, %45
%48 = load i32, i32* %4
%49 = icmp sgt i32 %48, 0
br i1 %49, label %50, label %61
50: ; preds = %47
%51 = load i32, i32* %3
%52 = load i32, i32* %4
%53 = sub nsw i32 %51, %52
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i32, i32* %28, i64 %54
%56 = load i32, i32* %55
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %56)
br label %58
58: ; preds = %50
%59 = load i32, i32* %4
%60 = add nsw i32 %59, -1
store i32 %60, i32* %4
br label %47
61: ; preds = %47
%62 = load i8*, i8** %5
br label %63
63: ; preds = %61, %16
%64 = call i32 (...) @getch()
ret i32 0
}

LLVM IR (-O2):
@.str = [52 x i8] c"\0A Input an decimal integer number to be converted: \00"
@.str.1 = [3 x i8] c"%d\00"
@stdin = global i32 0
@.str.2 = [21 x i8] c"\0A\0A %d in binary : %d\00"
@.str.3 = [19 x i8] c"\0A\0A %d in binary : \00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 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* @stdin
%6 = call i32 @fflush(i32 %5)
%7 = load i32, i32* %1
%8 = icmp ult i32 %7, 2
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %7, i32 %7)
br label %61
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %7)
%13 = load i32, i32* %1
%14 = call i32 @binarydigits(i32 %13, i32 2)
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
%17 = alloca i32, i64 %15
%18 = icmp sgt i32 %14, 0
br i1 %18, label %19, label %60
19: ; preds = %11
%20 = load i32, i32* %1
%21 = and i64 %15, 1
%22 = icmp eq i64 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %19
%24 = add nsw i64 %15, -1
%25 = srem i32 %20, 2
%26 = and i64 %24, 4294967295
%27 = getelementptr inbounds i32, i32* %17, i64 %26
store i32 %25, i32* %27
%28 = sdiv i32 %20, 2
br label %29
29: ; preds = %23, %19
%30 = phi i64 [ %15, %19 ], [ %24, %23 ]
%31 = phi i32 [ %20, %19 ], [ %28, %23 ]
%32 = phi i32 [ undef, %19 ], [ %28, %23 ]
%33 = icmp eq i32 %14, 1
br i1 %33, label %34, label %38
34: ; preds = %38, %29
%35 = phi i32 [ %32, %29 ], [ %50, %38 ]
store i32 %35, i32* %1
br i1 %18, label %36, label %60
36: ; preds = %34
%37 = zext i32 %14 to i64
br label %52
38: ; preds = %29, %38
%39 = phi i64 [ %46, %38 ], [ %30, %29 ]
%40 = phi i32 [ %50, %38 ], [ %31, %29 ]
%41 = add nsw i64 %39, -1
%42 = srem i32 %40, 2
%43 = and i64 %41, 4294967295
%44 = getelementptr inbounds i32, i32* %17, i64 %43
store i32 %42, i32* %44
%45 = sdiv i32 %40, 2
%46 = add nsw i64 %39, -2
%47 = srem i32 %45, 2
%48 = and i64 %46, 4294967295
%49 = getelementptr inbounds i32, i32* %17, i64 %48
store i32 %47, i32* %49
%50 = sdiv i32 %40, 4
%51 = icmp ugt i64 %41, 1
br i1 %51, label %38, label %34
52: ; preds = %36, %52
%53 = phi i64 [ %37, %36 ], [ %58, %52 ]
%54 = sub nuw nsw i64 %37, %53
%55 = getelementptr inbounds i32, i32* %17, i64 %54
%56 = load i32, i32* %55
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %56)
%58 = add nsw i64 %53, -1
%59 = icmp ugt i64 %53, 1
br i1 %59, label %52, label %60
60: ; preds = %52, %11, %34
br label %61
61: ; preds = %60, %9
%62 = call i32 (...) @getch()
ret i32 0
}