#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 c40_getchar();
int /*<<< orphan*/ c40_printf(char *, ...);
unsigned int get_dram(void) {
  c40_printf("\n");
  c40_printf("1) 1 MWords\n2) 4 MWords\n3) 16 MWords\n\n");
  c40_printf("Selection => ");
  while (1) {
    switch (c40_getchar()) {
    case '1':
      c40_printf("\n");
      return ((unsigned long)1);
      break;
    case '2':
      c40_printf("\n");
      return ((unsigned long)4);
      break;
    case '3':
      c40_printf("\n");
      return ((unsigned long)16);
      break;
    default:
      c40_printf("%c", 7);
      break;
    }
  }
}


x86 assembly (clang, -O0):
<get_dram>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xef6(%rip),%rdi
mov    $0x0,%al
call   1040 <c40_printf@plt>
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1040 <c40_printf@plt>
lea    0xedc(%rip),%rdi
mov    $0x0,%al
call   1040 <c40_printf@plt>
xor    %eax,%eax
call   1030 <c40_getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0x8(%rbp)
sub    $0x31,%eax
je     118e <get_dram+0x6e>
jmp    116c <get_dram+0x4c>
mov    -0x8(%rbp),%eax
sub    $0x32,%eax
je     11a8 <get_dram+0x88>
jmp    117d <get_dram+0x5d>
mov    -0x8(%rbp),%eax
sub    $0x33,%eax
je     11c2 <get_dram+0xa2>
jmp    11dc <get_dram+0xbc>
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1040 <c40_printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f4 <get_dram+0xd4>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1040 <c40_printf@plt>
movl   $0x4,-0x4(%rbp)
jmp    11f4 <get_dram+0xd4>
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1040 <c40_printf@plt>
movl   $0x10,-0x4(%rbp)
jmp    11f4 <get_dram+0xd4>
lea    0xe52(%rip),%rdi
mov    $0x7,%esi
mov    $0x0,%al
call   1040 <c40_printf@plt>
jmp    1152 <get_dram+0x32>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_dram>:
push   %rbx
lea    0xefd(%rip),%rdi
xor    %eax,%eax
call   1040 <c40_printf@plt>
lea    0xeca(%rip),%rdi
xor    %eax,%eax
call   1040 <c40_printf@plt>
lea    0xee3(%rip),%rdi
xor    %eax,%eax
call   1040 <c40_printf@plt>
lea    0xee3(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <c40_getchar@plt>
add    $0xffffffcf,%eax
cmp    $0x3,%eax
jb     1180 <get_dram+0x60>
mov    %rbx,%rdi
mov    $0x7,%esi
xor    %eax,%eax
call   1040 <c40_printf@plt>
jmp    1160 <get_dram+0x40>
cltq
lea    0xeaf(%rip),%rcx
mov    (%rcx,%rax,4),%ebx
lea    0xe92(%rip),%rdi
xor    %eax,%eax
call   1040 <c40_printf@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [39 x i8] c"1) 1 MWords\0A2) 4 MWords\0A3) 16 MWords\0A\0A\00"
@.str.2 = [14 x i8] c"Selection => \00"
@.str.3 = [3 x i8] c"%c\00"
define i32 @get_dram() {
%1 = alloca i32
%2 = call i32 (i8*, ...) @c40_printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = call i32 (i8*, ...) @c40_printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32 (i8*, ...) @c40_printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %5
5: ; preds = %0, %15
%6 = call i32 (...) @c40_getchar()
switch i32 %6, label %13 [
i32 49, label %7
i32 50, label %9
i32 51, label %11
]
7: ; preds = %5
%8 = call i32 (i8*, ...) @c40_printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %16
9: ; preds = %5
%10 = call i32 (i8*, ...) @c40_printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 4, i32* %1
br label %16
11: ; preds = %5
%12 = call i32 (i8*, ...) @c40_printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 16, i32* %1
br label %16
13: ; preds = %5
%14 = call i32 (i8*, ...) @c40_printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 7)
br label %15
15: ; preds = %13
br label %5
16: ; preds = %11, %9, %7
%17 = load i32, i32* %1
ret i32 %17
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [39 x i8] c"1) 1 MWords\0A2) 4 MWords\0A3) 16 MWords\0A\0A\00"
@.str.2 = [14 x i8] c"Selection => \00"
@.str.3 = [3 x i8] c"%c\00"
@switch.table.get_dram = [3 x i32] [i32 1, i32 4, i32 16]
define i32 @get_dram() {
%1 = tail call i32 (i8*, ...) @c40_printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 (i8*, ...) @c40_printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32 (i8*, ...) @c40_printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %4
4: ; preds = %0, %8
%5 = tail call i32 (...) @c40_getchar()
%6 = add i32 %5, -49
%7 = icmp ult i32 %6, 3
br i1 %7, label %10, label %8
8: ; preds = %4
%9 = tail call i32 (i8*, ...) @c40_printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 7)
br label %4
10: ; preds = %4
%11 = sext i32 %6 to i64
%12 = getelementptr inbounds [3 x i32], [3 x i32]* @switch.table.get_dram, i64 0, i64 %11
%13 = load i32, i32* %12
%14 = tail call i32 (i8*, ...) @c40_printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
ret i32 %13
}