#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 atoi(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ guess_binary_from_num();
int guess_num_from_binary();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stdin;
int main(void) {
  int play_on = 1;
  int ans;
  char response[10];
  puts("\t The BitShape Game ");
  while (play_on) {
    puts("Enter a choice, which game you would like to play:");
    puts("1 - Guess a number from it's bit shape ...");
    puts("2 - Given an integer type in it's bit shape ...");
    puts("3 - Exit the game");
    fgets(response, 10, stdin);
    printf("Printing s: %s\n", response);
    switch (atoi(response)) {
    case 1:
      printf("Guess a number from it's bit shape ...\n");
      ans = guess_num_from_binary();
      if (!ans) {
        puts("\nThat's Correct!\n");
      } else {
        printf("\nThat's Wrong! The correct answer is %d\n", ans);
      }
      break;
    case 2:
      puts("Play version 2\n");
      guess_binary_from_num();
      break;
    case 3:
      puts("Good bye");
      play_on = 0;
      break;
    default:
      puts("Did not understand your input...");
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
lea    0xe83(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,-0x8(%rbp)
je     12b1 <main+0x151>
lea    0xe82(%rip),%rdi
call   1030 <puts@plt>
lea    0xea9(%rip),%rdi
call   1030 <puts@plt>
lea    0xec8(%rip),%rdi
call   1030 <puts@plt>
lea    0xeec(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%edx
lea    -0x16(%rbp),%rdi
mov    %rdi,-0x28(%rbp)
mov    $0xa,%esi
call   1050 <fgets@plt>
mov    -0x28(%rbp),%rsi
lea    0xed3(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
sub    $0x1,%eax
je     1227 <main+0xc7>
jmp    1205 <main+0xa5>
mov    -0x1c(%rbp),%eax
sub    $0x2,%eax
je     1270 <main+0x110>
jmp    1216 <main+0xb6>
mov    -0x1c(%rbp),%eax
sub    $0x3,%eax
je     1288 <main+0x128>
jmp    12a0 <main+0x140>
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1080 <guess_num_from_binary@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    125a <main+0xfa>
lea    0xe9d(%rip),%rdi
call   1030 <puts@plt>
jmp    126b <main+0x10b>
mov    -0xc(%rbp),%esi
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12ac <main+0x14c>
lea    0xeb1(%rip),%rdi
call   1030 <puts@plt>
mov    $0x0,%al
call   1060 <guess_binary_from_num@plt>
jmp    12ac <main+0x14c>
lea    0xea9(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x8(%rbp)
jmp    12ac <main+0x14c>
lea    0xe9a(%rip),%rdi
call   1030 <puts@plt>
jmp    1182 <main+0x22>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe8b(%rip),%rdi
call   1030 <puts@plt>
lea    0xec7(%rip),%r15
lea    0xeeb(%rip),%r12
lea    0xf14(%rip),%r13
mov    0x2e52(%rip),%r14
lea    0xe(%rsp),%rbx
lea    0xf13(%rip),%rbp
jmp    11c3 <main+0x63>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xf49(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1060 <guess_binary_from_num@plt>
lea    0xe4b(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
call   1030 <puts@plt>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1050 <fgets@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1070 <atoi@plt>
cmp    $0x1,%eax
je     1230 <main+0xd0>
cmp    $0x2,%eax
je     11b0 <main+0x50>
cmp    $0x3,%eax
je     126d <main+0x10d>
lea    0xef7(%rip),%rdi
call   1030 <puts@plt>
jmp    11c3 <main+0x63>
nopl   0x0(%rax)
lea    0xe15(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1080 <guess_num_from_binary@plt>
test   %eax,%eax
je     125c <main+0xfc>
lea    0xe89(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11c3 <main+0x63>
lea    0xe62(%rip),%rdi
call   1030 <puts@plt>
jmp    11c3 <main+0x63>
lea    0xe9c(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"\09 The BitShape Game \00"
@.str.1 = [51 x i8] c"Enter a choice, which game you would like to play:\00"
@.str.2 = [43 x i8] c"1 - Guess a number from it's bit shape ...\00"
@.str.3 = [48 x i8] c"2 - Given an integer type in it's bit shape ...\00"
@.str.4 = [18 x i8] c"3 - Exit the game\00"
@stdin = global i32 0
@.str.5 = [16 x i8] c"Printing s: %s\0A\00"
@.str.6 = [40 x i8] c"Guess a number from it's bit shape ...\0A\00"
@.str.7 = [18 x i8] c"\0AThat's Correct!\0A\00"
@.str.8 = [41 x i8] c"\0AThat's Wrong! The correct answer is %d\0A\00"
@.str.9 = [16 x i8] c"Play version 2\0A\00"
@.str.10 = [9 x i8] c"Good bye\00"
@.str.11 = [33 x i8] c"Did not understand your input...\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [10 x i8]
store i32 0, i32* %1
store i32 1, i32* %2
%5 = call i32 @puts(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %39, %0
%7 = load i32, i32* %2
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %40
9: ; preds = %6
%10 = call i32 @puts(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @puts(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @puts(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%14 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%15 = load i32, i32* @stdin
%16 = call i32 @fgets(i8* %14, i32 10, i32 %15)
%17 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%20 = call i32 @atoi(i8* %19)
switch i32 %20, label %37 [
i32 1, label %21
i32 2, label %32
i32 3, label %35
]
21: ; preds = %9
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0))
%23 = call i32 (...) @guess_num_from_binary()
store i32 %23, i32* %3
%24 = load i32, i32* %3
%25 = icmp ne i32 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %21
%27 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
br label %31
28: ; preds = %21
%29 = load i32, i32* %3
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.8, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %28, %26
br label %39
32: ; preds = %9
%33 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0))
%34 = call i32 (...) @guess_binary_from_num()
br label %39
35: ; preds = %9
%36 = call i32 @puts(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0))
store i32 0, i32* %2
br label %39
37: ; preds = %9
%38 = call i32 @puts(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.11, i64 0, i64 0))
br label %39
39: ; preds = %37, %35, %32, %31
br label %6
40: ; preds = %6
ret i32 0
}

LLVM IR (-O2):
@.str = [21 x i8] c"\09 The BitShape Game \00"
@.str.1 = [51 x i8] c"Enter a choice, which game you would like to play:\00"
@.str.2 = [43 x i8] c"1 - Guess a number from it's bit shape ...\00"
@.str.3 = [48 x i8] c"2 - Given an integer type in it's bit shape ...\00"
@.str.4 = [18 x i8] c"3 - Exit the game\00"
@stdin = global i32 0
@.str.5 = [16 x i8] c"Printing s: %s\0A\00"
@.str.7 = [18 x i8] c"\0AThat's Correct!\0A\00"
@.str.8 = [41 x i8] c"\0AThat's Wrong! The correct answer is %d\0A\00"
@.str.9 = [16 x i8] c"Play version 2\0A\00"
@.str.10 = [9 x i8] c"Good bye\00"
@.str.11 = [33 x i8] c"Did not understand your input...\00"
@str = [39 x i8] c"Guess a number from it's bit shape ...\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %4
4: ; preds = %19, %0
%5 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0))
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%9 = load i32, i32* @stdin
%10 = call i32 @fgets(i8* %2, i32 10, i32 %9)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %2)
%12 = call i32 @atoi(i8* %2)
switch i32 %12, label %25 [
i32 1, label %13
i32 2, label %22
i32 3, label %27
]
13: ; preds = %4
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%15 = call i32 (...) @guess_num_from_binary()
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
br label %19
19: ; preds = %17, %20, %25, %22
br label %4
20: ; preds = %13
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.8, i64 0, i64 0), i32 %15)
br label %19
22: ; preds = %4
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0))
%24 = call i32 (...) @guess_binary_from_num()
br label %19
25: ; preds = %4
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.11, i64 0, i64 0))
br label %19
27: ; preds = %4
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0))
ret i32 0
}