#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 */
char EOF;
int /*<<< orphan*/ decode();
int /*<<< orphan*/ encode();
char fgetc(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
int main() {
  char answer, dumchar;
  do {
    printf("What do you want to do?\n");
    printf("a) Encode a message in a bmp file\n");
    printf("b) Retrieve a message from a bmp file\n");
    answer = fgetc(stdin);
    while ((dumchar = fgetc(stdin)) != EOF) {
      if (dumchar == '\n') {
        break;
      }
    }
    if ((answer != 'a') && (answer != 'b')) {
      printf("Not a valid option, try again\n\n");
    }
  } while ((answer != 'a') && (answer != 'b'));
  if (answer == 'a') {
    encode();
  } else if (answer == 'b') {
    decode();
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
call   1040 <printf@plt>
lea    0xeb7(%rip),%rdi
call   1040 <printf@plt>
lea    0xece(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
call   1050 <fgetc@plt>
mov    %al,-0x5(%rbp)
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
call   1050 <fgetc@plt>
mov    %al,-0x6(%rbp)
movsbl %al,%eax
mov    0x2e41(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11c1 <main+0x81>
movsbl -0x6(%rbp),%eax
cmp    $0xa,%eax
jne    11bc <main+0x7c>
jmp    11c1 <main+0x81>
jmp    1184 <main+0x44>
movsbl -0x5(%rbp),%eax
cmp    $0x61,%eax
je     11e7 <main+0xa7>
movsbl -0x5(%rbp),%eax
cmp    $0x62,%eax
je     11e7 <main+0xa7>
lea    0xe81(%rip),%rdi
call   1040 <printf@plt>
jmp    11ec <main+0xac>
movsbl -0x5(%rbp),%ecx
xor    %eax,%eax
cmp    $0x61,%ecx
mov    %al,-0x7(%rbp)
je     120b <main+0xcb>
movsbl -0x5(%rbp),%eax
cmp    $0x62,%eax
setne  %al
mov    %al,-0x7(%rbp)
mov    -0x7(%rbp),%al
test   $0x1,%al
jne    114f <main+0xf>
movsbl -0x5(%rbp),%eax
cmp    $0x61,%eax
jne    122f <main+0xef>
mov    $0x0,%al
call   1030 <encode@plt>
jmp    1248 <main+0x108>
movsbl -0x5(%rbp),%eax
cmp    $0x62,%eax
jne    1243 <main+0x103>
mov    $0x0,%al
call   1060 <decode@plt>
jmp    1248 <main+0x108>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xec6(%rip),%r15
lea    0xee1(%rip),%r12
mov    0x2e88(%rip),%rbp
mov    0x2e79(%rip),%r14
lea    0xef2(%rip),%r13
xchg   %ax,%ax
lea    0xe89(%rip),%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
call   1040 <puts@plt>
mov    0x0(%rbp),%edi
call   1050 <fgetc@plt>
mov    %eax,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    0x0(%rbp),%edi
call   1050 <fgetc@plt>
cmp    $0xa,%al
je     11b1 <main+0x71>
cmp    (%r14),%al
jne    11a0 <main+0x60>
lea    -0x63(%rbx),%eax
cmp    $0xfd,%al
ja     11c2 <main+0x82>
mov    %r13,%rdi
call   1040 <puts@plt>
jmp    1170 <main+0x30>
cmp    $0x62,%bl
je     11d5 <main+0x95>
cmp    $0x61,%bl
jne    11dc <main+0x9c>
xor    %eax,%eax
call   1030 <encode@plt>
jmp    11dc <main+0x9c>
xor    %eax,%eax
call   1060 <decode@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"What do you want to do?\0A\00"
@.str.1 = [35 x i8] c"a) Encode a message in a bmp file\0A\00"
@.str.2 = [39 x i8] c"b) Retrieve a message from a bmp file\0A\00"
@stdin = global i32 0
@EOF = global i8 0
@.str.3 = [32 x i8] c"Not a valid option, try again\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i8
store i32 0, i32* %1
br label %4
4: ; preds = %42, %0
%5 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
%8 = load i32, i32* @stdin
%9 = call signext i8 @fgetc(i32 %8)
store i8 %9, i8* %2
br label %10
10: ; preds = %22, %4
%11 = load i32, i32* @stdin
%12 = call signext i8 @fgetc(i32 %11)
store i8 %12, i8* %3
%13 = sext i8 %12 to i32
%14 = load i8, i8* @EOF
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %13, %15
br i1 %16, label %17, label %23
17: ; preds = %10
%18 = load i8, i8* %3
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 10
br i1 %20, label %21, label %22
21: ; preds = %17
br label %23
22: ; preds = %17
br label %10
23: ; preds = %21, %10
%24 = load i8, i8* %2
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 97
br i1 %26, label %27, label %33
27: ; preds = %23
%28 = load i8, i8* %2
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 98
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
br label %33
33: ; preds = %31, %27, %23
br label %34
34: ; preds = %33
%35 = load i8, i8* %2
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 97
br i1 %37, label %38, label %42
38: ; preds = %34
%39 = load i8, i8* %2
%40 = sext i8 %39 to i32
%41 = icmp ne i32 %40, 98
br label %42
42: ; preds = %38, %34
%43 = phi i1 [ false, %34 ], [ %41, %38 ]
br i1 %43, label %4, label %44
44: ; preds = %42
%45 = load i8, i8* %2
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 97
br i1 %47, label %48, label %50
48: ; preds = %44
%49 = call i32 (...) @encode()
br label %57
50: ; preds = %44
%51 = load i8, i8* %2
%52 = sext i8 %51 to i32
%53 = icmp eq i32 %52, 98
br i1 %53, label %54, label %56
54: ; preds = %50
%55 = call i32 (...) @decode()
br label %56
56: ; preds = %54, %50
br label %57
57: ; preds = %56, %48
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@EOF = global i8 0
@str = [24 x i8] c"What do you want to do?\00"
@str.4 = [34 x i8] c"a) Encode a message in a bmp file\00"
@str.5 = [38 x i8] c"b) Retrieve a message from a bmp file\00"
@str.6 = [31 x i8] c"Not a valid option, try again\0A\00"
define i32 @main() {
br label %1
1: ; preds = %17, %0
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.4, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.5, i64 0, i64 0))
%5 = load i32, i32* @stdin
%6 = tail call signext i8 @fgetc(i32 %5)
br label %7
7: ; preds = %7, %1
%8 = load i32, i32* @stdin
%9 = tail call signext i8 @fgetc(i32 %8)
%10 = load i8, i8* @EOF
%11 = icmp eq i8 %9, %10
%12 = icmp eq i8 %9, 10
%13 = or i1 %12, %11
br i1 %13, label %14, label %7
14: ; preds = %7
%15 = add i8 %6, -99
%16 = icmp ult i8 %15, -2
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.6, i64 0, i64 0))
br label %1
19: ; preds = %14
switch i8 %6, label %24 [
i8 97, label %20
i8 98, label %22
]
20: ; preds = %19
%21 = tail call i32 (...) @encode()
br label %24
22: ; preds = %19
%23 = tail call i32 (...) @decode()
br label %24
24: ; preds = %19, %22, %20
ret i32 0
}