#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 calculate_discriminant(double, double, double);
int /*<<< orphan*/ print_data_size();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, double *);
double sqrt(double);
int main() {
  double a, b, c, discriminant;
  double x1, x2;
  print_data_size();
  printf("Program to solve quadratic equation a * x^2 + b * x + c = 0\n");
  printf("Enter the a: ");
  scanf("%f", &a);
  printf("Enter the b: ");
  scanf("%f", &b);
  printf("Enter the c: ");
  scanf("%f", &c);
  discriminant = calculate_discriminant(a, b, c);
  if (discriminant > 0) {
    x1 = (-b + sqrt(discriminant)) / 2 * c;
    x2 = (-b - sqrt(discriminant)) / 2 * c;
    printf("x1 is: %lf\n", x1);
    printf("x2 is: %lf\n", x2);
  } else {
    printf("The equation has no real roots\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <print_data_size@plt>
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeca(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1060 <scanf@plt>
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeac(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <scanf@plt>
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe8e(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <scanf@plt>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
call   1040 <calculate_discriminant@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    12be <main+0x16e>
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   1070 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  0xdc8(%rip),%xmm1
divsd  %xmm1,%xmm0
mulsd  -0x20(%rbp),%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   1070 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  0xd7b(%rip),%xmm1
divsd  %xmm1,%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
lea    0xdd3(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x38(%rbp),%xmm0
lea    0xdcc(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    12cc <main+0x17c>
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
xor    %eax,%eax
call   1060 <print_data_size@plt>
lea    0xef2(%rip),%rdi
call   1030 <puts@plt>
lea    0xea1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea1(%rip),%rbx
lea    0x38(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <scanf@plt>
lea    0xe90(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x18(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <scanf@plt>
lea    0xe83(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <scanf@plt>
movsd  0x38(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
movsd  0x10(%rsp),%xmm2
call   1050 <calculate_discriminant@plt>
movapd %xmm0,%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm2
jbe    12c9 <main+0x169>
movsd  0x18(%rsp),%xmm0
sqrtsd %xmm2,%xmm3
movapd %xmm3,%xmm1
jae    123a <main+0xda>
movsd  %xmm0,0x30(%rsp)
movapd %xmm2,%xmm0
movsd  %xmm2,0x20(%rsp)
movsd  %xmm3,0x8(%rsp)
call   1080 <sqrt@plt>
movsd  0x8(%rsp),%xmm3
movsd  0x20(%rsp),%xmm2
movapd %xmm0,%xmm1
movsd  0x30(%rsp),%xmm0
subsd  %xmm0,%xmm1
mulsd  0xdba(%rip),%xmm1
mulsd  0x10(%rsp),%xmm1
movsd  0x18(%rsp),%xmm0
xorpd  0xdb6(%rip),%xmm0
movapd %xmm0,0x20(%rsp)
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm2
jae    1283 <main+0x123>
movapd %xmm2,%xmm0
movsd  %xmm1,0x8(%rsp)
call   1080 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
movapd %xmm0,%xmm3
movapd 0x20(%rsp),%xmm0
subsd  %xmm3,%xmm0
mulsd  0xd6b(%rip),%xmm0
mulsd  0x10(%rsp),%xmm0
movapd %xmm0,0x20(%rsp)
lea    0xda5(%rip),%rdi
movapd %xmm1,%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xd9f(%rip),%rdi
movapd 0x20(%rsp),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
jmp    12d5 <main+0x175>
lea    0xdd1(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [61 x i8] c"Program to solve quadratic equation a * x^2 + b * x + c = 0\0A\00"
@.str.1 = [14 x i8] c"Enter the a: \00"
@.str.2 = [3 x i8] c"%f\00"
@.str.3 = [14 x i8] c"Enter the b: \00"
@.str.4 = [14 x i8] c"Enter the c: \00"
@.str.5 = [12 x i8] c"x1 is: %lf\0A\00"
@.str.6 = [12 x i8] c"x2 is: %lf\0A\00"
@.str.7 = [32 x i8] c"The equation has no real roots\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 (...) @print_data_size()
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), double* %2)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), double* %3)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), double* %4)
%16 = load double, double* %2
%17 = load double, double* %3
%18 = load double, double* %4
%19 = call double @calculate_discriminant(double %16, double %17, double %18)
store double %19, double* %5
%20 = load double, double* %5
%21 = fcmp ogt double %20, 0.000000e+00
br i1 %21, label %22, label %43
22: ; preds = %0
%23 = load double, double* %3
%24 = fneg double %23
%25 = load double, double* %5
%26 = call double @sqrt(double %25)
%27 = fadd double %24, %26
%28 = fdiv double %27, 2.000000e+00
%29 = load double, double* %4
%30 = fmul double %28, %29
store double %30, double* %6
%31 = load double, double* %3
%32 = fneg double %31
%33 = load double, double* %5
%34 = call double @sqrt(double %33)
%35 = fsub double %32, %34
%36 = fdiv double %35, 2.000000e+00
%37 = load double, double* %4
%38 = fmul double %36, %37
store double %38, double* %7
%39 = load double, double* %6
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), double %39)
%41 = load double, double* %7
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), double %41)
br label %45
43: ; preds = %0
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0))
br label %45
45: ; preds = %43, %22
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [14 x i8] c"Enter the a: \00"
@.str.2 = [3 x i8] c"%f\00"
@.str.3 = [14 x i8] c"Enter the b: \00"
@.str.4 = [14 x i8] c"Enter the c: \00"
@.str.5 = [12 x i8] c"x1 is: %lf\0A\00"
@.str.6 = [12 x i8] c"x2 is: %lf\0A\00"
@str = [60 x i8] c"Program to solve quadratic equation a * x^2 + b * x + c = 0\00"
@str.8 = [31 x i8] c"The equation has no real roots\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 (...) @print_data_size()
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), double* %1)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), double* %2)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), double* %3)
%15 = load double, double* %1
%16 = load double, double* %2
%17 = load double, double* %3
%18 = call double @calculate_discriminant(double %15, double %16, double %17)
%19 = fcmp ogt double %18, 0.000000e+00
br i1 %19, label %20, label %36
20: ; preds = %0
%21 = load double, double* %2
%22 = call double @sqrt(double %18)
%23 = fsub double %22, %21
%24 = fmul double %23, 5.000000e-01
%25 = load double, double* %3
%26 = fmul double %25, %24
%27 = load double, double* %2
%28 = fneg double %27
%29 = call double @sqrt(double %18)
%30 = fsub double %28, %29
%31 = fmul double %30, 5.000000e-01
%32 = load double, double* %3
%33 = fmul double %32, %31
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), double %26)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), double %33)
br label %38
36: ; preds = %0
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.8, i64 0, i64 0))
br label %38
38: ; preds = %36, %20
ret i32 0
}