#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 /*<<< orphan*/ getch();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, float *, float *, float *);
float sqrt(float);
int main() {
  float a, b, c, D, x1, x2;
  printf("Quadratic Equations - Roots Calculator \n");
  printf("General form: ax2 + bx + c = 0 \n");
  printf("Enter the value of a, b, c (space separated): ");
  scanf("%f %f %f", &a, &b, &c);
  D = b * b - 4 * a * c;
  if (D < 0)
    printf("The value of the discriminant is %f < zero, hence no real roots "
           "exist.",
           D);
  else {
    printf("The value of the discriminant is %f ", D);
    x1 = (-b + sqrt(D)) / (2 * a);
    x2 = (-b - sqrt(D)) / (2 * a);
    printf("\nThe roots of the equation are %f and %f ", x1, x2);
  }
  getch();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf01(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
call   1040 <scanf@plt>
movss  -0xc(%rbp),%xmm0
movss  -0xc(%rbp),%xmm2
movss  0xe5d(%rip),%xmm1
mulss  -0x8(%rbp),%xmm1
mulss  -0x10(%rbp),%xmm1
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0x14(%rbp),%xmm0
jbe    11f0 <main+0xb0>
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xea6(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    12ad <main+0x16d>
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xed1(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movss  -0xc(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x14(%rbp),%xmm0
call   1060 <sqrt@plt>
movaps %xmm0,%xmm1
movss  -0x24(%rbp),%xmm0
addss  %xmm1,%xmm0
movss  0xdc8(%rip),%xmm1
mulss  -0x8(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0xc(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x14(%rbp),%xmm0
call   1060 <sqrt@plt>
movaps %xmm0,%xmm1
movss  -0x20(%rbp),%xmm0
subss  %xmm1,%xmm0
movss  0xd85(%rip),%xmm1
mulss  -0x8(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x1c(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xe50(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <getch@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x38,%rsp
lea    0xf93(%rip),%rdi
call   1030 <puts@plt>
lea    0xfaf(%rip),%rdi
call   1030 <puts@plt>
lea    0xead(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xece(%rip),%rdi
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0x1c(%rsp),%rcx
call   1050 <scanf@plt>
movss  0x10(%rsp),%xmm1
movss  0x14(%rsp),%xmm0
mulss  0xe57(%rip),%xmm0
mulss  0x1c(%rsp),%xmm0
mulss  %xmm1,%xmm1
addss  %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomiss %xmm1,%xmm0
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
jbe    11d9 <main+0x89>
lea    0xe8b(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    12a8 <main+0x158>
lea    0xebf(%rip),%rdi
mov    $0x1,%al
movss  %xmm1,0xc(%rsp)
call   1040 <printf@plt>
movss  0xc(%rsp),%xmm1
movss  0x10(%rsp),%xmm0
sqrtss %xmm1,%xmm3
ucomiss 0xe00(%rip),%xmm1
movaps %xmm3,%xmm2
jae    1232 <main+0xe2>
movss  %xmm0,0x18(%rsp)
movaps %xmm1,%xmm0
movss  %xmm3,0x20(%rsp)
call   1070 <sqrt@plt>
movss  0x20(%rsp),%xmm3
movss  0xc(%rsp),%xmm1
movaps %xmm0,%xmm2
movss  0x18(%rsp),%xmm0
subss  %xmm0,%xmm2
movss  0x14(%rsp),%xmm0
addss  %xmm0,%xmm0
movss  0x10(%rsp),%xmm4
xorps  0xdc3(%rip),%xmm4
divss  %xmm0,%xmm2
xorps  %xmm0,%xmm0
ucomiss %xmm0,%xmm1
jae    127a <main+0x12a>
movaps %xmm1,%xmm0
movss  %xmm2,0xc(%rsp)
movaps %xmm4,0x20(%rsp)
call   1070 <sqrt@plt>
movaps 0x20(%rsp),%xmm4
movss  0xc(%rsp),%xmm2
movaps %xmm0,%xmm3
subss  %xmm3,%xmm4
movss  0x14(%rsp),%xmm0
addss  %xmm0,%xmm0
divss  %xmm0,%xmm4
xorps  %xmm0,%xmm0
cvtss2sd %xmm2,%xmm0
xorps  %xmm1,%xmm1
cvtss2sd %xmm4,%xmm1
lea    0xe23(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <getch@plt>
xor    %eax,%eax
add    $0x38,%rsp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"Quadratic Equations - Roots Calculator \0A\00"
@.str.1 = [33 x i8] c"General form: ax2 + bx + c = 0 \0A\00"
@.str.2 = [47 x i8] c"Enter the value of a, b, c (space separated): \00"
@.str.3 = [9 x i8] c"%f %f %f\00"
@.str.4 = [71 x i8] c"The value of the discriminant is %f < zero, hence no real roots exist.\00"
@.str.5 = [37 x i8] c"The value of the discriminant is %f \00"
@.str.6 = [42 x i8] c"\0AThe roots of the equation are %f and %f \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca float
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), float* %2, float* %3, float* %4)
%12 = load float, float* %3
%13 = load float, float* %3
%14 = load float, float* %2
%15 = fmul float 4.000000e+00, %14
%16 = load float, float* %4
%17 = fmul float %15, %16
%18 = fneg float %17
%19 = call float @llvm.fmuladd.f32(float %12, float %13, float %18)
store float %19, float* %5
%20 = load float, float* %5
%21 = fcmp olt float %20, 0.000000e+00
br i1 %21, label %22, label %26
22: ; preds = %0
%23 = load float, float* %5
%24 = fpext float %23 to double
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.4, i64 0, i64 0), double %24)
br label %51
26: ; preds = %0
%27 = load float, float* %5
%28 = fpext float %27 to double
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), double %28)
%30 = load float, float* %3
%31 = fneg float %30
%32 = load float, float* %5
%33 = call float @sqrt(float %32)
%34 = fadd float %31, %33
%35 = load float, float* %2
%36 = fmul float 2.000000e+00, %35
%37 = fdiv float %34, %36
store float %37, float* %6
%38 = load float, float* %3
%39 = fneg float %38
%40 = load float, float* %5
%41 = call float @sqrt(float %40)
%42 = fsub float %39, %41
%43 = load float, float* %2
%44 = fmul float 2.000000e+00, %43
%45 = fdiv float %42, %44
store float %45, float* %7
%46 = load float, float* %6
%47 = fpext float %46 to double
%48 = load float, float* %7
%49 = fpext float %48 to double
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0), double %47, double %49)
br label %51
51: ; preds = %26, %22
%52 = call i32 (...) @getch()
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [47 x i8] c"Enter the value of a, b, c (space separated): \00"
@.str.3 = [9 x i8] c"%f %f %f\00"
@.str.4 = [71 x i8] c"The value of the discriminant is %f < zero, hence no real roots exist.\00"
@.str.5 = [37 x i8] c"The value of the discriminant is %f \00"
@.str.6 = [42 x i8] c"\0AThe roots of the equation are %f and %f \00"
@str = [40 x i8] c"Quadratic Equations - Roots Calculator \00"
@str.7 = [32 x i8] c"General form: ax2 + bx + c = 0 \00"
define i32 @main() {
%1 = alloca float
%2 = alloca float
%3 = alloca float
%4 = bitcast float* %1 to i8*
%5 = bitcast float* %2 to i8*
%6 = bitcast float* %3 to i8*
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.7, i64 0, i64 0))
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), float* %1, float* %2, float* %3)
%11 = load float, float* %2
%12 = load float, float* %1
%13 = load float, float* %3
%14 = fmul float %12, -4.000000e+00
%15 = fmul float %14, %13
%16 = call float @llvm.fmuladd.f32(float %11, float %11, float %15)
%17 = fcmp olt float %16, 0.000000e+00
%18 = fpext float %16 to double
br i1 %17, label %19, label %21
19: ; preds = %0
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @.str.4, i64 0, i64 0), double %18)
br label %39
21: ; preds = %0
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), double %18)
%23 = load float, float* %2
%24 = call float @sqrt(float %16)
%25 = fsub float %24, %23
%26 = load float, float* %1
%27 = fmul float %26, 2.000000e+00
%28 = fdiv float %25, %27
%29 = load float, float* %2
%30 = fneg float %29
%31 = call float @sqrt(float %16)
%32 = fsub float %30, %31
%33 = load float, float* %1
%34 = fmul float %33, 2.000000e+00
%35 = fdiv float %32, %34
%36 = fpext float %28 to double
%37 = fpext float %35 to double
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0), double %36, double %37)
br label %39
39: ; preds = %21, %19
%40 = call i32 (...) @getch()
ret i32 0
}