#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 */
double compound_interest(double, double, int);
int /*<<< orphan*/ get_capital(double *);
int /*<<< orphan*/ get_rate(double *);
int /*<<< orphan*/ get_time(int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
double simple_interest(double, double, int);
int main(void) {
  printf("\t--- Menu ---\n");
  printf("1 - Calculate simple interest\n");
  printf("2 - Calculate compound interest\n");
  printf("Please enter your selection: ");
  char choice;
  scanf(" %c", &choice);
  double capital;
  double rate;
  int time;
  double earnings;
  switch (choice) {
  case '1':
    get_capital(&capital);
    get_rate(&rate);
    get_time(&time);
    earnings = simple_interest(capital, rate, time);
    printf("Earnings: %.2f\n", earnings);
    break;
  case '2':
    get_capital(&capital);
    get_rate(&rate);
    get_time(&time);
    earnings = compound_interest(capital, rate, time);
    printf("Earnings: %.2f\n", earnings);
    break;
  default:
    printf("Unimplemetned option!\n");
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x2d(%rbp)
call   1060 <printf@plt>
mov    -0x2d(%rbp),%al
lea    0xe75(%rip),%rdi
call   1060 <printf@plt>
mov    -0x2d(%rbp),%al
lea    0xe85(%rip),%rdi
call   1060 <printf@plt>
mov    -0x2d(%rbp),%al
lea    0xe97(%rip),%rdi
call   1060 <printf@plt>
lea    0xea9(%rip),%rdi
lea    -0x5(%rbp),%rsi
call   1090 <scanf@plt>
movsbl -0x5(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x31,%eax
je     11f3 <main+0x83>
jmp    11e2 <main+0x72>
mov    -0x2c(%rbp),%eax
sub    $0x32,%eax
je     123d <main+0xcd>
jmp    1287 <main+0x117>
lea    -0x10(%rbp),%rdi
call   1040 <get_capital@plt>
lea    -0x18(%rbp),%rdi
call   1030 <get_rate@plt>
lea    -0x1c(%rbp),%rdi
call   1070 <get_time@plt>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mov    -0x1c(%rbp),%edi
call   1050 <simple_interest@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
lea    0xe40(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
jmp    1295 <main+0x125>
lea    -0x10(%rbp),%rdi
call   1040 <get_capital@plt>
lea    -0x18(%rbp),%rdi
call   1030 <get_rate@plt>
lea    -0x1c(%rbp),%rdi
call   1070 <get_time@plt>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mov    -0x1c(%rbp),%edi
call   1080 <compound_interest@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
lea    0xdf6(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
jmp    1295 <main+0x125>
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0xea7(%rip),%rdi
call   1050 <puts@plt>
lea    0xea9(%rip),%rdi
call   1050 <puts@plt>
lea    0xebb(%rip),%rdi
call   1050 <puts@plt>
lea    0xe51(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe61(%rip),%rdi
lea    0x3(%rsp),%rsi
call   10a0 <scanf@plt>
movsbl 0x3(%rsp),%eax
cmp    $0x32,%eax
je     120b <main+0x8b>
cmp    $0x31,%eax
jne    124e <main+0xce>
lea    0x10(%rsp),%rdi
call   1040 <get_capital@plt>
lea    0x8(%rsp),%rdi
call   1030 <get_rate@plt>
lea    0x4(%rsp),%rdi
call   1080 <get_time@plt>
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mov    0x4(%rsp),%edi
call   1060 <simple_interest@plt>
jmp    123e <main+0xbe>
lea    0x10(%rsp),%rdi
call   1040 <get_capital@plt>
lea    0x8(%rsp),%rdi
call   1030 <get_rate@plt>
lea    0x4(%rsp),%rdi
call   1080 <get_time@plt>
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mov    0x4(%rsp),%edi
call   1090 <compound_interest@plt>
lea    0xddd(%rip),%rdi
mov    $0x1,%al
call   1070 <printf@plt>
jmp    125a <main+0xda>
lea    0xe29(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"\09--- Menu ---\0A\00"
@.str.1 = [31 x i8] c"1 - Calculate simple interest\0A\00"
@.str.2 = [33 x i8] c"2 - Calculate compound interest\0A\00"
@.str.3 = [30 x i8] c"Please enter your selection: \00"
@.str.4 = [4 x i8] c" %c\00"
@.str.5 = [16 x i8] c"Earnings: %.2f\0A\00"
@.str.6 = [23 x i8] c"Unimplemetned option!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca double
%4 = alloca double
%5 = alloca i32
%6 = alloca double
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %2)
%12 = load i8, i8* %2
%13 = sext i8 %12 to i32
switch i32 %13, label %34 [
i32 49, label %14
i32 50, label %24
]
14: ; preds = %0
%15 = call i32 @get_capital(double* %3)
%16 = call i32 @get_rate(double* %4)
%17 = call i32 @get_time(i32* %5)
%18 = load double, double* %3
%19 = load double, double* %4
%20 = load i32, i32* %5
%21 = call double @simple_interest(double %18, double %19, i32 %20)
store double %21, double* %6
%22 = load double, double* %6
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), double %22)
br label %36
24: ; preds = %0
%25 = call i32 @get_capital(double* %3)
%26 = call i32 @get_rate(double* %4)
%27 = call i32 @get_time(i32* %5)
%28 = load double, double* %3
%29 = load double, double* %4
%30 = load i32, i32* %5
%31 = call double @compound_interest(double %28, double %29, i32 %30)
store double %31, double* %6
%32 = load double, double* %6
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), double %32)
br label %36
34: ; preds = %0
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
br label %36
36: ; preds = %34, %24, %14
ret i32 0
}

LLVM IR (-O2):
@.str.3 = [30 x i8] c"Please enter your selection: \00"
@.str.4 = [4 x i8] c" %c\00"
@.str.5 = [16 x i8] c"Earnings: %.2f\0A\00"
@str = [14 x i8] c"\09--- Menu ---\00"
@str.7 = [30 x i8] c"1 - Calculate simple interest\00"
@str.8 = [32 x i8] c"2 - Calculate compound interest\00"
@str.9 = [22 x i8] c"Unimplemetned option!\00"
define i32 @main() {
%1 = alloca i8
%2 = alloca double
%3 = alloca double
%4 = alloca i32
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.7, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.8, i64 0, i64 0))
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %1)
%10 = bitcast double* %2 to i8*
%11 = bitcast double* %3 to i8*
%12 = bitcast i32* %4 to i8*
%13 = load i8, i8* %1
%14 = sext i8 %13 to i32
switch i32 %14, label %33 [
i32 49, label %15
i32 50, label %24
]
15: ; preds = %0
%16 = call i32 @get_capital(double* %2)
%17 = call i32 @get_rate(double* %3)
%18 = call i32 @get_time(i32* %4)
%19 = load double, double* %2
%20 = load double, double* %3
%21 = load i32, i32* %4
%22 = call double @simple_interest(double %19, double %20, i32 %21)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), double %22)
br label %35
24: ; preds = %0
%25 = call i32 @get_capital(double* %2)
%26 = call i32 @get_rate(double* %3)
%27 = call i32 @get_time(i32* %4)
%28 = load double, double* %2
%29 = load double, double* %3
%30 = load i32, i32* %4
%31 = call double @compound_interest(double %28, double %29, i32 %30)
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), double %31)
br label %35
33: ; preds = %0
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.9, i64 0, i64 0))
br label %35
35: ; preds = %33, %24, %15
ret i32 0
}