#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 CalculateTaxDue(double);
char EOF;
int EXIT_SUCCESS;
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int scanf(char *, double *);
int main(void) {
  double income = 0.0;
  double taxdue = 0.0;
  int isInputValid = 0;
  while (!isInputValid) {
    printf("Please enter the amount of taxable income: ");
    if (scanf("%lf", &income) == 1) {
      if (income < 0.0) {
        puts("Income cannot be negative. Please try again.");
      } else {
        isInputValid = 1;
      }
    } else {
      puts("Invalid input. Please try again.");
    }
    char c = '\0';
    while ((c = getchar()) != '\n' && c != EOF)
      continue;
  }
  taxdue = CalculateTaxDue(income);
  printf("Income: $%.2lf\n", income);
  printf("Tax due: $%.2lf\n", taxdue);
  getchar();
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    118c <main+0x3c>
jmp    1239 <main+0xe9>
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe8b(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1070 <scanf@plt>
cmp    $0x1,%eax
jne    11de <main+0x8e>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11d2 <main+0x82>
lea    0xe68(%rip),%rdi
call   1030 <puts@plt>
jmp    11d9 <main+0x89>
movl   $0x1,-0x1c(%rbp)
jmp    11ea <main+0x9a>
lea    0xe78(%rip),%rdi
call   1030 <puts@plt>
movb   $0x0,-0x1d(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x1d(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x1e(%rbp)
je     121f <main+0xcf>
movsbl -0x1d(%rbp),%eax
mov    0x2dd4(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x1e(%rbp)
mov    -0x1e(%rbp),%al
test   $0x1,%al
jne    122f <main+0xdf>
jmp    1234 <main+0xe4>
jmp    11ee <main+0x9e>
jmp    1176 <main+0x26>
movsd  -0x10(%rbp),%xmm0
call   1060 <CalculateTaxDue@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
lea    0xe2a(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  -0x18(%rbp),%xmm0
lea    0xe27(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    0x2d5c(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x8(%rsp)
lea    0xe9a(%rip),%r14
lea    0xebf(%rip),%r15
lea    0x8(%rsp),%r12
lea    0xee4(%rip),%rbx
mov    0x2e60(%rip),%rbp
jmp    1195 <main+0x45>
nopw   0x0(%rax,%rax,1)
test   %r13b,%r13b
je     11f2 <main+0xa2>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1070 <scanf@plt>
mov    %rbx,%rdi
cmp    $0x1,%eax
jne    11c5 <main+0x75>
xorpd  %xmm0,%xmm0
ucomisd 0x8(%rsp),%xmm0
lea    0xe75(%rip),%rdi
jbe    11d0 <main+0x80>
call   1030 <puts@plt>
mov    $0x1,%r13b
jmp    11e0 <main+0x90>
nop
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
je     1190 <main+0x40>
cmp    0x0(%rbp),%al
jne    11e0 <main+0x90>
jmp    1190 <main+0x40>
movsd  0x8(%rsp),%xmm0
call   1060 <CalculateTaxDue@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
lea    0xe76(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xe78(%rip),%rdi
movsd  0x10(%rsp),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2d9f(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"Please enter the amount of taxable income: \00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [45 x i8] c"Income cannot be negative. Please try again.\00"
@.str.3 = [33 x i8] c"Invalid input. Please try again.\00"
@EOF = global i8 0
@.str.4 = [16 x i8] c"Income: $%.2lf\0A\00"
@.str.5 = [17 x i8] c"Tax due: $%.2lf\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca i32
%5 = alloca i8
store i32 0, i32* %1
store double 0.000000e+00, double* %2
store double 0.000000e+00, double* %3
store i32 0, i32* %4
br label %6
6: ; preds = %37, %0
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 0
%9 = xor i1 %8, true
br i1 %9, label %10, label %38
10: ; preds = %6
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %2)
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %21
14: ; preds = %10
%15 = load double, double* %2
%16 = fcmp olt double %15, 0.000000e+00
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @puts(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
br label %20
19: ; preds = %14
store i32 1, i32* %4
br label %20
20: ; preds = %19, %17
br label %23
21: ; preds = %10
%22 = call i32 @puts(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %21, %20
store i8 0, i8* %5
br label %24
24: ; preds = %36, %23
%25 = call signext i8 (...) @getchar()
store i8 %25, i8* %5
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 10
br i1 %27, label %28, label %34
28: ; preds = %24
%29 = load i8, i8* %5
%30 = sext i8 %29 to i32
%31 = load i8, i8* @EOF
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %30, %32
br label %34
34: ; preds = %28, %24
%35 = phi i1 [ false, %24 ], [ %33, %28 ]
br i1 %35, label %36, label %37
36: ; preds = %34
br label %24
37: ; preds = %34
br label %6
38: ; preds = %6
%39 = load double, double* %2
%40 = call double @CalculateTaxDue(double %39)
store double %40, double* %3
%41 = load double, double* %2
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), double %41)
%43 = load double, double* %3
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), double %43)
%45 = call signext i8 (...) @getchar()
%46 = load i32, i32* @EXIT_SUCCESS
ret i32 %46
}

LLVM IR (-O2):
@.str = [44 x i8] c"Please enter the amount of taxable income: \00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [45 x i8] c"Income cannot be negative. Please try again.\00"
@.str.3 = [33 x i8] c"Invalid input. Please try again.\00"
@EOF = global i8 0
@.str.4 = [16 x i8] c"Income: $%.2lf\0A\00"
@.str.5 = [17 x i8] c"Tax due: $%.2lf\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca double
%2 = bitcast double* %1 to i8*
store double 0.000000e+00, double* %1
br label %4
3: ; preds = %16
br i1 %15, label %4, label %22
4: ; preds = %0, %3
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %1)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %11
8: ; preds = %4
%9 = load double, double* %1
%10 = fcmp olt double %9, 0.000000e+00
br i1 %10, label %11, label %14
11: ; preds = %4, %8
%12 = phi i8* [ getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), %8 ], [ getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), %4 ]
%13 = call i32 @puts(i8* dereferenceable(1) %12)
br label %14
14: ; preds = %11, %8
%15 = phi i1 [ false, %8 ], [ true, %11 ]
br label %16
16: ; preds = %16, %14
%17 = call signext i8 (...) @getchar()
%18 = icmp ne i8 %17, 10
%19 = load i8, i8* @EOF
%20 = icmp ne i8 %17, %19
%21 = select i1 %18, i1 %20, i1 false
br i1 %21, label %16, label %3
22: ; preds = %3
%23 = load double, double* %1
%24 = call double @CalculateTaxDue(double %23)
%25 = load double, double* %1
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), double %25)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), double %24)
%28 = call signext i8 (...) @getchar()
%29 = load i32, i32* @EXIT_SUCCESS
ret i32 %29
}