#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 binToDec(int);
int decToBin(int);
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int x;
  char c;
  printf("Enter a number: \n");
  scanf("%d", &x);
  printf("For DecToBin conversion press d, for BinToDec conversion press b: ");
  c = getchar();
  c = getchar();
  if (c == 'd' || c == 'D')
    printf("Binary value of %d is %d", x, decToBin(x));
  else if (c == 'b' || c == 'B')
    printf("Decimal value of %d is %d", x, binToDec(x));
  else
    printf("Invalid charaster!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf11(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x9(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0x64,%eax
je     11b9 <main+0x69>
movsbl -0x9(%rbp),%eax
cmp    $0x44,%eax
jne    11df <main+0x8f>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <decToBin@plt>
mov    -0x10(%rbp),%esi
mov    %eax,%edx
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1232 <main+0xe2>
movsbl -0x9(%rbp),%eax
cmp    $0x62,%eax
je     11f9 <main+0xa9>
movsbl -0x9(%rbp),%eax
cmp    $0x42,%eax
jne    121f <main+0xcf>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
call   1070 <binToDec@plt>
mov    -0x14(%rbp),%esi
mov    %eax,%edx
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    122d <main+0xdd>
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1232 <main+0xe2>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xf0a(%rip),%rdi
call   1030 <puts@plt>
lea    0xefb(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
lea    0xe77(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
and    $0xdf,%al
cmp    $0x42,%al
je     11bc <main+0x5c>
cmp    $0x44,%al
jne    11db <main+0x7b>
mov    0xc(%rsp),%ebx
mov    %ebx,%edi
call   1040 <decToBin@plt>
lea    0xe89(%rip),%rdi
jmp    11ce <main+0x6e>
mov    0xc(%rsp),%ebx
mov    %ebx,%edi
call   1080 <binToDec@plt>
lea    0xe8e(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11e7 <main+0x87>
lea    0xea5(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Enter a number: \0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [67 x i8] c"For DecToBin conversion press d, for BinToDec conversion press b: \00"
@.str.3 = [25 x i8] c"Binary value of %d is %d\00"
@.str.4 = [26 x i8] c"Decimal value of %d is %d\00"
@.str.5 = [20 x i8] c"Invalid charaster!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
store i32 0, i32* %1
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.2, i64 0, i64 0))
%7 = call signext i8 (...) @getchar()
store i8 %7, i8* %3
%8 = call signext i8 (...) @getchar()
store i8 %8, i8* %3
%9 = load i8, i8* %3
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 100
br i1 %11, label %16, label %12
12: ; preds = %0
%13 = load i8, i8* %3
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 68
br i1 %15, label %16, label %21
16: ; preds = %12, %0
%17 = load i32, i32* %2
%18 = load i32, i32* %2
%19 = call i32 @decToBin(i32 %18)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %17, i32 %19)
br label %37
21: ; preds = %12
%22 = load i8, i8* %3
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 98
br i1 %24, label %29, label %25
25: ; preds = %21
%26 = load i8, i8* %3
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 66
br i1 %28, label %29, label %34
29: ; preds = %25, %21
%30 = load i32, i32* %2
%31 = load i32, i32* %2
%32 = call i32 @binToDec(i32 %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %30, i32 %32)
br label %36
34: ; preds = %25
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
br label %36
36: ; preds = %34, %29
br label %37
37: ; preds = %36, %16
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [67 x i8] c"For DecToBin conversion press d, for BinToDec conversion press b: \00"
@.str.3 = [25 x i8] c"Binary value of %d is %d\00"
@.str.4 = [26 x i8] c"Decimal value of %d is %d\00"
@str = [17 x i8] c"Enter a number: \00"
@str.6 = [19 x i8] c"Invalid charaster!\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 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 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @.str.2, i64 0, i64 0))
%6 = call signext i8 (...) @getchar()
%7 = call signext i8 (...) @getchar()
%8 = and i8 %7, -33
switch i8 %8, label %17 [
i8 68, label %9
i8 66, label %13
]
9: ; preds = %0
%10 = load i32, i32* %1
%11 = call i32 @decToBin(i32 %10)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %10, i32 %11)
br label %19
13: ; preds = %0
%14 = load i32, i32* %1
%15 = call i32 @binToDec(i32 %14)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %14, i32 %15)
br label %19
17: ; preds = %0
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.6, i64 0, i64 0))
br label %19
19: ; preds = %13, %17, %9
ret i32 0
}