#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*/ getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  printf("Enter mode: \n");
  printf("1 - char to bin\n");
  printf("2 - bin to char\n");
  printf("0 - exit:\n");
  printf("> ");
  int mode;
  scanf("%d", &mode);
  getchar();
  if (mode == 1) {
    char c;
    scanf("%c", &c);
    int i;
    for (i = 0; i < 8; i++) {
      char ai = 0;
      ai = (c & (1 << i)) >> i;
      printf("%d", ai);
    }
    printf("\n");
    return 0;
  }
  if (mode == 2) {
    char c = 0;
    int i;
    for (i = 0; i < 8; i++) {
      int ai;
      scanf("%d", &ai);
      c = c + (ai << i);
    }
    printf("%c\n", c);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb2(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
cmpl   $0x1,-0x8(%rbp)
jne    1223 <main+0xf3>
lea    0xe92(%rip),%rdi
lea    -0x9(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0x8,-0x10(%rbp)
jge    1209 <main+0xd9>
movb   $0x0,-0x11(%rbp)
movsbl -0x9(%rbp),%eax
mov    -0x10(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
mov    -0x10(%rbp),%ecx
sar    %cl,%eax
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%esi
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11c1 <main+0x91>
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    128e <main+0x15e>
cmpl   $0x2,-0x8(%rbp)
jne    1287 <main+0x157>
movb   $0x0,-0x12(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x8,-0x18(%rbp)
jge    1275 <main+0x145>
lea    0xdf5(%rip),%rdi
lea    -0x1c(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
movsbl -0x12(%rbp),%eax
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%ecx
shl    %cl,%edx
mov    %edx,%ecx
add    %ecx,%eax
mov    %al,-0x12(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1238 <main+0x108>
movsbl -0x12(%rbp),%esi
lea    0xdc4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xeac(%rip),%rdi
call   1040 <puts@plt>
lea    0xead(%rip),%rdi
call   1040 <puts@plt>
lea    0xeb1(%rip),%rdi
call   1040 <puts@plt>
lea    0xeb5(%rip),%rdi
call   1040 <puts@plt>
lea    0xe6f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe64(%rip),%rdi
lea    0x14(%rsp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
mov    0x14(%rsp),%eax
cmp    $0x1,%eax
je     128f <main+0x13f>
cmp    $0x2,%eax
jne    1354 <main+0x204>
lea    0xe34(%rip),%r14
lea    0x10(%rsp),%r15
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0x10(%rsp),%ebx
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0x10(%rsp),%eax
lea    (%rbx,%rax,2),%ebx
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0x10(%rsp),%eax
lea    (%rbx,%rax,4),%ebx
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0x10(%rsp),%eax
lea    (%rbx,%rax,8),%ebx
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0x10(%rsp),%ebp
shl    $0x4,%ebp
add    %ebx,%ebp
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0x10(%rsp),%ebx
shl    $0x5,%ebx
add    %ebp,%ebx
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0x10(%rsp),%ebp
shl    $0x6,%ebp
add    %ebx,%ebp
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0x10(%rsp),%eax
shl    $0x7,%eax
add    %ebp,%eax
movsbl %al,%esi
lea    0xd86(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1354 <main+0x204>
lea    0xd70(%rip),%rdi
lea    0xf(%rsp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
movzbl 0xf(%rsp),%esi
and    $0x1,%esi
lea    0xd52(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0xf(%rsp),%esi
shr    %esi
and    $0x1,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0xf(%rsp),%esi
shr    $0x2,%esi
and    $0x1,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0xf(%rsp),%esi
shr    $0x3,%esi
and    $0x1,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0xf(%rsp),%esi
shr    $0x4,%esi
and    $0x1,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0xf(%rsp),%esi
shr    $0x5,%esi
and    $0x1,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0xf(%rsp),%esi
shr    $0x6,%esi
and    $0x1,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0xf(%rsp),%esi
shr    $0x7,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Enter mode: \0A\00"
@.str.1 = [17 x i8] c"1 - char to bin\0A\00"
@.str.2 = [17 x i8] c"2 - bin to char\0A\00"
@.str.3 = [11 x i8] c"0 - exit:\0A\00"
@.str.4 = [3 x i8] c"> \00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [3 x i8] c"%c\00"
@.str.7 = [2 x i8] c"\0A\00"
@.str.8 = [4 x i8] c"%c\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %2)
%15 = call i32 (...) @getchar()
%16 = load i32, i32* %2
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %40
18: ; preds = %0
%19 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %3)
store i32 0, i32* %4
br label %20
20: ; preds = %35, %18
%21 = load i32, i32* %4
%22 = icmp slt i32 %21, 8
br i1 %22, label %23, label %38
23: ; preds = %20
store i8 0, i8* %5
%24 = load i8, i8* %3
%25 = sext i8 %24 to i32
%26 = load i32, i32* %4
%27 = shl i32 1, %26
%28 = and i32 %25, %27
%29 = load i32, i32* %4
%30 = ashr i32 %28, %29
%31 = trunc i32 %30 to i8
store i8 %31, i8* %5
%32 = load i8, i8* %5
%33 = sext i8 %32 to i32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %23
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
store i32 %37, i32* %4
br label %20
38: ; preds = %20
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %1
br label %64
40: ; preds = %0
%41 = load i32, i32* %2
%42 = icmp eq i32 %41, 2
br i1 %42, label %43, label %63
43: ; preds = %40
store i8 0, i8* %6
store i32 0, i32* %7
br label %44
44: ; preds = %56, %43
%45 = load i32, i32* %7
%46 = icmp slt i32 %45, 8
br i1 %46, label %47, label %59
47: ; preds = %44
%48 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %8)
%49 = load i8, i8* %6
%50 = sext i8 %49 to i32
%51 = load i32, i32* %8
%52 = load i32, i32* %7
%53 = shl i32 %51, %52
%54 = add nsw i32 %50, %53
%55 = trunc i32 %54 to i8
store i8 %55, i8* %6
br label %56
56: ; preds = %47
%57 = load i32, i32* %7
%58 = add nsw i32 %57, 1
store i32 %58, i32* %7
br label %44
59: ; preds = %44
%60 = load i8, i8* %6
%61 = sext i8 %60 to i32
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 %61)
br label %63
63: ; preds = %59, %40
store i32 0, i32* %1
br label %64
64: ; preds = %63, %38
%65 = load i32, i32* %1
ret i32 %65
}

LLVM IR (-O2):
@.str.4 = [3 x i8] c"> \00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [3 x i8] c"%c\00"
@.str.8 = [4 x i8] c"%c\0A\00"
@str = [13 x i8] c"Enter mode: \00"
@str.9 = [16 x i8] c"1 - char to bin\00"
@str.10 = [16 x i8] c"2 - bin to char\00"
@str.11 = [10 x i8] c"0 - exit:\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.9, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.10, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.11, i64 0, i64 0))
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%9 = bitcast i32* %1 to i8*
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %1)
%11 = call i32 (...) @getchar()
%12 = load i32, i32* %1
switch i32 %12, label %89 [
i32 1, label %48
i32 2, label %13
]
13: ; preds = %0
%14 = bitcast i32* %3 to i8*
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %3)
%16 = load i32, i32* %3
%17 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %3)
%18 = load i32, i32* %3
%19 = shl i32 %18, 1
%20 = add i32 %19, %16
%21 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %3)
%22 = load i32, i32* %3
%23 = shl i32 %22, 2
%24 = add i32 %23, %20
%25 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %3)
%26 = load i32, i32* %3
%27 = shl i32 %26, 3
%28 = add i32 %27, %24
%29 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %3)
%30 = load i32, i32* %3
%31 = shl i32 %30, 4
%32 = add i32 %31, %28
%33 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %3)
%34 = load i32, i32* %3
%35 = shl i32 %34, 5
%36 = add i32 %35, %32
%37 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %3)
%38 = load i32, i32* %3
%39 = shl i32 %38, 6
%40 = add i32 %39, %36
%41 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %3)
%42 = load i32, i32* %3
%43 = shl i32 %42, 7
%44 = add i32 %43, %40
%45 = shl i32 %44, 24
%46 = ashr exact i32 %45, 24
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 %46)
br label %89
48: ; preds = %0
%49 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %2)
%50 = load i8, i8* %2
%51 = and i8 %50, 1
%52 = zext i8 %51 to i32
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %52)
%54 = load i8, i8* %2
%55 = lshr i8 %54, 1
%56 = and i8 %55, 1
%57 = zext i8 %56 to i32
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %57)
%59 = load i8, i8* %2
%60 = lshr i8 %59, 2
%61 = and i8 %60, 1
%62 = zext i8 %61 to i32
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %62)
%64 = load i8, i8* %2
%65 = lshr i8 %64, 3
%66 = and i8 %65, 1
%67 = zext i8 %66 to i32
%68 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %67)
%69 = load i8, i8* %2
%70 = lshr i8 %69, 4
%71 = and i8 %70, 1
%72 = zext i8 %71 to i32
%73 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %72)
%74 = load i8, i8* %2
%75 = lshr i8 %74, 5
%76 = and i8 %75, 1
%77 = zext i8 %76 to i32
%78 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %77)
%79 = load i8, i8* %2
%80 = lshr i8 %79, 6
%81 = and i8 %80, 1
%82 = zext i8 %81 to i32
%83 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %82)
%84 = load i8, i8* %2
%85 = lshr i8 %84, 7
%86 = zext i8 %85 to i32
%87 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %86)
%88 = call i32 @putchar(i32 10)
br label %89
89: ; preds = %13, %0, %48
ret i32 0
}