#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 EXIT_SUCCESS;
double Fn(double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int scanf(char *, double *);
int /*<<< orphan*/ stderr;
int main(void) {
  double x = 0.0;
  double result = 0.0;
  char c = '\0';
  printf("This program will calculate the value of: "
         "3x^5 + 2x^4 - 5x^3 - x^2 + 7x - 6\n");
  printf("Please enter the value of x: ");
  while (scanf("%Lf", &x) != 1) {
    fprintf(stderr, "Input invalid. Please try again.\n");
    while ((c = getchar()) != '\n' && c != EOF)
      continue;
  }
  while ((c = getchar()) != '\n' && c != EOF)
    continue;
  result = Fn(x);
  printf("= %g\n", result);
  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)
movb   $0x0,-0x19(%rbp)
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xed5(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1070 <scanf@plt>
cmp    $0x1,%eax
je     1208 <main+0xb8>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
lea    0xeb7(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x19(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x1a(%rbp)
je     11ee <main+0x9e>
movsbl -0x19(%rbp),%eax
mov    0x2e05(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%al
test   $0x1,%al
jne    11fe <main+0xae>
jmp    1203 <main+0xb3>
jmp    11bd <main+0x6d>
jmp    118f <main+0x3f>
jmp    120d <main+0xbd>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x19(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x1b(%rbp)
je     123e <main+0xee>
movsbl -0x19(%rbp),%eax
mov    0x2db5(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x1b(%rbp)
mov    -0x1b(%rbp),%al
test   $0x1,%al
jne    124e <main+0xfe>
jmp    1253 <main+0x103>
jmp    120d <main+0xbd>
movsd  -0x10(%rbp),%xmm0
call   1030 <Fn@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
lea    0xe23(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    0x2d4d(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
lea    0xecd(%rip),%rdi
call   1040 <puts@plt>
lea    0xe77(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe87(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1080 <scanf@plt>
cmp    $0x1,%eax
jne    11fd <main+0x9d>
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0xa,%al
je     11c6 <main+0x66>
mov    0x2e26(%rip),%rcx
cmp    (%rcx),%al
jne    11b0 <main+0x50>
movsd  0x8(%rsp),%xmm0
call   1030 <Fn@plt>
lea    0xe6c(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2dd4(%rip),%r12
lea    0xe17(%rip),%r14
mov    0x2dd6(%rip),%rbx
lea    0xe05(%rip),%r15
lea    0x8(%rsp),%r13
jmp    1230 <main+0xd0>
mov    %r15,%rdi
mov    %r13,%rsi
call   1080 <scanf@plt>
cmp    $0x1,%eax
je     11b0 <main+0x50>
mov    (%r12),%edi
mov    %r14,%rsi
call   1070 <fprintf@plt>
nopl   0x0(%rax)
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0xa,%al
je     1220 <main+0xc0>
cmp    (%rbx),%al
jne    1240 <main+0xe0>
jmp    1220 <main+0xc0>

LLVM IR (-O0):
@.str = [77 x i8] c"This program will calculate the value of: 3x^5 + 2x^4 - 5x^3 - x^2 + 7x - 6\0A\00"
@.str.1 = [30 x i8] c"Please enter the value of x: \00"
@.str.2 = [4 x i8] c"%Lf\00"
@stderr = global i32 0
@.str.3 = [34 x i8] c"Input invalid. Please try again.\0A\00"
@EOF = global i8 0
@.str.4 = [6 x i8] c"= %g\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca i8
store i32 0, i32* %1
store double 0.000000e+00, double* %2
store double 0.000000e+00, double* %3
store i8 0, i8* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %7
7: ; preds = %26, %0
%8 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %2)
%9 = icmp ne i32 %8, 1
br i1 %9, label %10, label %27
10: ; preds = %7
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
br label %13
13: ; preds = %25, %10
%14 = call signext i8 (...) @getchar()
store i8 %14, i8* %4
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 10
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = load i8, i8* %4
%19 = sext i8 %18 to i32
%20 = load i8, i8* @EOF
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %19, %21
br label %23
23: ; preds = %17, %13
%24 = phi i1 [ false, %13 ], [ %22, %17 ]
br i1 %24, label %25, label %26
25: ; preds = %23
br label %13
26: ; preds = %23
br label %7
27: ; preds = %7
br label %28
28: ; preds = %40, %27
%29 = call signext i8 (...) @getchar()
store i8 %29, i8* %4
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 10
br i1 %31, label %32, label %38
32: ; preds = %28
%33 = load i8, i8* %4
%34 = sext i8 %33 to i32
%35 = load i8, i8* @EOF
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %34, %36
br label %38
38: ; preds = %32, %28
%39 = phi i1 [ false, %28 ], [ %37, %32 ]
br i1 %39, label %40, label %41
40: ; preds = %38
br label %28
41: ; preds = %38
%42 = load double, double* %2
%43 = call double @Fn(double %42)
store double %43, double* %3
%44 = load double, double* %3
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), double %44)
%46 = call signext i8 (...) @getchar()
%47 = load i32, i32* @EXIT_SUCCESS
ret i32 %47
}

LLVM IR (-O2):
@.str.1 = [30 x i8] c"Please enter the value of x: \00"
@.str.2 = [4 x i8] c"%Lf\00"
@stderr = global i32 0
@.str.3 = [34 x i8] c"Input invalid. Please try again.\0A\00"
@EOF = global i8 0
@.str.4 = [6 x i8] c"= %g\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [76 x i8] c"This program will calculate the value of: 3x^5 + 2x^4 - 5x^3 - x^2 + 7x - 6\00"
define i32 @main() {
%1 = alloca double
%2 = bitcast double* %1 to i8*
store double 0.000000e+00, double* %1
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([76 x i8], [76 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %1)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %11
7: ; preds = %8, %0
br label %20
8: ; preds = %14
%9 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %1)
%10 = icmp eq i32 %9, 1
br i1 %10, label %7, label %11
11: ; preds = %0, %8
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
br label %14
14: ; preds = %14, %11
%15 = call signext i8 (...) @getchar()
%16 = icmp ne i8 %15, 10
%17 = load i8, i8* @EOF
%18 = icmp ne i8 %15, %17
%19 = select i1 %16, i1 %18, i1 false
br i1 %19, label %14, label %8
20: ; preds = %7, %20
%21 = call signext i8 (...) @getchar()
%22 = icmp ne i8 %21, 10
%23 = load i8, i8* @EOF
%24 = icmp ne i8 %21, %23
%25 = select i1 %22, i1 %24, i1 false
br i1 %25, label %20, label %26
26: ; preds = %20
%27 = load double, double* %1
%28 = call double @Fn(double %27)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), double %28)
%30 = call signext i8 (...) @getchar()
%31 = load i32, i32* @EXIT_SUCCESS
ret i32 %31
}