#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, double *, double *, double *);
double sqrt(double);
int main() {
  double a, b, c, D, alpha, beta;
  printf("Enter the coefficients of x^2 (a), x (b) and the constant (c) of the "
         "quad eq: \n");
  scanf("%lf %lf %lf", &a, &b, &c);
  D = b * b - 4 * a * c;
  if (D > 0) {
    alpha = (-b + sqrt(D)) / (2 * a);
    beta = (-b - sqrt(D)) / (2 * a);
    printf("Roots: %.3lf and %.3lf\n", alpha, beta);
  } else if (D == 0) {
    alpha = beta = -b / (2 * a);
    printf("Roots: %.3lf and %.3lf\n", alpha, beta);
  } else
    printf("Imaginary roots. Imaginary part = %.3lf\n", D);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf0c(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1040 <scanf@plt>
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  0xe89(%rip),%xmm1
mulsd  -0x10(%rbp),%xmm1
mulsd  -0x20(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    126e <main+0x13e>
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  0xe12(%rip),%xmm1
mulsd  -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  0xdc5(%rip),%xmm1
mulsd  -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
lea    0xe0a(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
jmp    12f2 <main+0x1c2>
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    12da <main+0x1aa>
jp     12da <main+0x1aa>
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xd5e(%rip),%xmm1
mulsd  -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
lea    0xd9e(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
jmp    12ed <main+0x1bd>
movsd  -0x28(%rbp),%xmm0
lea    0xd9e(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    12f2 <main+0x1c2>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x48,%rsp
lea    0xf22(%rip),%rdi
call   1030 <puts@plt>
lea    0xec9(%rip),%rdi
mov    %rsp,%rsi
lea    0x8(%rsp),%rdx
lea    0x40(%rsp),%rcx
call   1050 <scanf@plt>
movsd  0x8(%rsp),%xmm3
movsd  (%rsp),%xmm0
movsd  0xe84(%rip),%xmm1
mulsd  %xmm0,%xmm1
mulsd  0x40(%rsp),%xmm1
movapd %xmm3,%xmm2
mulsd  %xmm3,%xmm2
addsd  %xmm1,%xmm2
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm2
jbe    1247 <main+0x107>
sqrtsd %xmm2,%xmm4
movapd %xmm4,%xmm5
jae    11db <main+0x9b>
movapd %xmm2,%xmm0
movapd %xmm2,0x20(%rsp)
movapd %xmm3,0x10(%rsp)
movsd  %xmm4,0x38(%rsp)
call   1060 <sqrt@plt>
movsd  0x38(%rsp),%xmm4
movapd 0x10(%rsp),%xmm3
movapd 0x20(%rsp),%xmm2
movapd %xmm0,%xmm5
subsd  %xmm3,%xmm5
movsd  (%rsp),%xmm0
addsd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm1
xorpd  0xe1a(%rip),%xmm1
divsd  %xmm0,%xmm5
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm2
jae    1229 <main+0xe9>
movapd %xmm2,%xmm0
movsd  %xmm5,0x20(%rsp)
movapd %xmm1,0x10(%rsp)
call   1060 <sqrt@plt>
movapd 0x10(%rsp),%xmm1
movsd  0x20(%rsp),%xmm5
movapd %xmm0,%xmm4
subsd  %xmm4,%xmm1
movsd  (%rsp),%xmm0
addsd  %xmm0,%xmm0
divsd  %xmm0,%xmm1
lea    0xdeb(%rip),%rdi
movapd %xmm5,%xmm0
jmp    126a <main+0x12a>
jne    1273 <main+0x133>
jp     1273 <main+0x133>
xorpd  0xdbd(%rip),%xmm3
addsd  %xmm0,%xmm0
divsd  %xmm0,%xmm3
lea    0xdca(%rip),%rdi
movapd %xmm3,%xmm0
movapd %xmm3,%xmm1
mov    $0x2,%al
call   1040 <printf@plt>
jmp    1285 <main+0x145>
lea    0xdca(%rip),%rdi
movapd %xmm2,%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x48,%rsp
ret

LLVM IR (-O0):
@.str = [80 x i8] c"Enter the coefficients of x^2 (a), x (b) and the constant (c) of the quad eq: \0A\00"
@.str.1 = [12 x i8] c"%lf %lf %lf\00"
@.str.2 = [24 x i8] c"Roots: %.3lf and %.3lf\0A\00"
@.str.3 = [41 x i8] c"Imaginary roots. Imaginary part = %.3lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), double* %2, double* %3, double* %4)
%10 = load double, double* %3
%11 = load double, double* %3
%12 = load double, double* %2
%13 = fmul double 4.000000e+00, %12
%14 = load double, double* %4
%15 = fmul double %13, %14
%16 = fneg double %15
%17 = call double @llvm.fmuladd.f64(double %10, double %11, double %16)
store double %17, double* %5
%18 = load double, double* %5
%19 = fcmp ogt double %18, 0.000000e+00
br i1 %19, label %20, label %40
20: ; preds = %0
%21 = load double, double* %3
%22 = fneg double %21
%23 = load double, double* %5
%24 = call double @sqrt(double %23)
%25 = fadd double %22, %24
%26 = load double, double* %2
%27 = fmul double 2.000000e+00, %26
%28 = fdiv double %25, %27
store double %28, double* %6
%29 = load double, double* %3
%30 = fneg double %29
%31 = load double, double* %5
%32 = call double @sqrt(double %31)
%33 = fsub double %30, %32
%34 = load double, double* %2
%35 = fmul double 2.000000e+00, %34
%36 = fdiv double %33, %35
store double %36, double* %7
%37 = load double, double* %6
%38 = load double, double* %7
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), double %37, double %38)
br label %56
40: ; preds = %0
%41 = load double, double* %5
%42 = fcmp oeq double %41, 0.000000e+00
br i1 %42, label %43, label %52
43: ; preds = %40
%44 = load double, double* %3
%45 = fneg double %44
%46 = load double, double* %2
%47 = fmul double 2.000000e+00, %46
%48 = fdiv double %45, %47
store double %48, double* %7
store double %48, double* %6
%49 = load double, double* %6
%50 = load double, double* %7
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), double %49, double %50)
br label %55
52: ; preds = %40
%53 = load double, double* %5
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), double %53)
br label %55
55: ; preds = %52, %43
br label %56
56: ; preds = %55, %20
%57 = load i32, i32* %1
ret i32 %57
}

LLVM IR (-O2):
@.str.1 = [12 x i8] c"%lf %lf %lf\00"
@.str.2 = [24 x i8] c"Roots: %.3lf and %.3lf\0A\00"
@.str.3 = [41 x i8] c"Imaginary roots. Imaginary part = %.3lf\0A\00"
@str = [79 x i8] c"Enter the coefficients of x^2 (a), x (b) and the constant (c) of the quad eq: \00"
define i32 @main() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
%4 = bitcast double* %1 to i8*
%5 = bitcast double* %2 to i8*
%6 = bitcast double* %3 to i8*
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([79 x i8], [79 x i8]* @str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), double* %1, double* %2, double* %3)
%9 = load double, double* %2
%10 = load double, double* %1
%11 = load double, double* %3
%12 = fmul double %10, -4.000000e+00
%13 = fmul double %12, %11
%14 = call double @llvm.fmuladd.f64(double %9, double %9, double %13)
%15 = fcmp ogt double %14, 0.000000e+00
br i1 %15, label %16, label %30
16: ; preds = %0
%17 = call double @sqrt(double %14)
%18 = fsub double %17, %9
%19 = load double, double* %1
%20 = fmul double %19, 2.000000e+00
%21 = fdiv double %18, %20
%22 = load double, double* %2
%23 = fneg double %22
%24 = call double @sqrt(double %14)
%25 = fsub double %23, %24
%26 = load double, double* %1
%27 = fmul double %26, 2.000000e+00
%28 = fdiv double %25, %27
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), double %21, double %28)
br label %39
30: ; preds = %0
%31 = fcmp oeq double %14, 0.000000e+00
br i1 %31, label %32, label %37
32: ; preds = %30
%33 = fneg double %9
%34 = fmul double %10, 2.000000e+00
%35 = fdiv double %33, %34
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), double %35, double %35)
br label %39
37: ; preds = %30
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), double %14)
br label %39
39: ; preds = %32, %37, %16
ret i32 0
}