#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, ...);
int solve_cubic(int, int, int, float *);
void cubic_test(void) {
  float x[3];
  int count = solve_cubic(-6, 11, -6, x);
  printf("%d cubic solutions\n", count);
  for (int i = 0; i != count; ++i) {
    printf("cubic solution %d: %f\n", i, x[i]);
  }
  count = solve_cubic(-3, 1, -3, x);
  printf("%d cubic solutions\n", count);
  for (int i = 0; i != count; ++i) {
    printf("cubic solution %d: %f\n", i, x[i]);
  }
  count = solve_cubic(-5, 100, -15625, x);
  printf("%d cubic solutions\n", count);
  for (int i = 0; i != count; ++i) {
    printf("cubic solution %d: %f\n", i, x[i]);
  }
}


x86 assembly (clang, -O0):
<cubic_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0xc(%rbp),%rcx
mov    $0xfffffffa,%edx
mov    $0xb,%esi
mov    %edx,%edi
call   1030 <solve_cubic@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
je     1191 <cubic_test+0x71>
mov    -0x14(%rbp),%esi
movslq -0x14(%rbp),%rax
movss  -0xc(%rbp,%rax,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe98(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1158 <cubic_test+0x38>
lea    -0xc(%rbp),%rcx
mov    $0xfffffffd,%edx
mov    $0x1,%esi
mov    %edx,%edi
call   1030 <solve_cubic@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
je     11fa <cubic_test+0xda>
mov    -0x18(%rbp),%esi
movslq -0x18(%rbp),%rax
movss  -0xc(%rbp,%rax,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe2f(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11c1 <cubic_test+0xa1>
lea    -0xc(%rbp),%rcx
mov    $0xfffffffb,%edi
mov    $0x64,%esi
mov    $0xffffc2f7,%edx
call   1030 <solve_cubic@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
je     1266 <cubic_test+0x146>
mov    -0x1c(%rbp),%esi
movslq -0x1c(%rbp),%rax
movss  -0xc(%rbp,%rax,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdc3(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    122d <cubic_test+0x10d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cubic_test>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0x4(%rsp),%rcx
mov    $0xfffffffa,%edi
mov    $0xb,%esi
mov    $0xfffffffa,%edx
call   1030 <solve_cubic@plt>
mov    %eax,%ebx
lea    0xeb5(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebx,%ebx
je     118f <cubic_test+0x6f>
mov    %ebx,%r15d
xor    %ebx,%ebx
lea    0xeb0(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movss  0x4(%rsp,%rbx,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x1,%al
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1170 <cubic_test+0x50>
lea    0x4(%rsp),%rcx
mov    $0xfffffffd,%edi
mov    $0x1,%esi
mov    $0xfffffffd,%edx
call   1030 <solve_cubic@plt>
mov    %eax,%ebx
lea    0xe4f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebx,%ebx
je     11ef <cubic_test+0xcf>
mov    %ebx,%r15d
xor    %ebx,%ebx
lea    0xe4a(%rip),%r14
nopw   0x0(%rax,%rax,1)
movss  0x4(%rsp,%rbx,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x1,%al
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    11d0 <cubic_test+0xb0>
lea    0x4(%rsp),%rcx
mov    $0xfffffffb,%edi
mov    $0x64,%esi
mov    $0xffffc2f7,%edx
call   1030 <solve_cubic@plt>
mov    %eax,%ebx
lea    0xdef(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebx,%ebx
je     124f <cubic_test+0x12f>
mov    %ebx,%r15d
xor    %ebx,%ebx
lea    0xdea(%rip),%r14
nopw   0x0(%rax,%rax,1)
movss  0x4(%rsp,%rbx,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x1,%al
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1230 <cubic_test+0x110>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [20 x i8] c"%d cubic solutions\0A\00"
@.str.1 = [23 x i8] c"cubic solution %d: %f\0A\00"
define void @cubic_test() {
%1 = alloca [3 x float]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = getelementptr inbounds [3 x float], [3 x float]* %1, i64 0, i64 0
%7 = call i32 @solve_cubic(i32 -6, i32 11, i32 -6, float* %6)
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 0, i32* %3
br label %10
10: ; preds = %22, %0
%11 = load i32, i32* %3
%12 = load i32, i32* %2
%13 = icmp ne i32 %11, %12
br i1 %13, label %14, label %25
14: ; preds = %10
%15 = load i32, i32* %3
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [3 x float], [3 x float]* %1, i64 0, i64 %17
%19 = load float, float* %18
%20 = fpext float %19 to double
%21 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %15, double %20)
br label %22
22: ; preds = %14
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
br label %10
25: ; preds = %10
%26 = getelementptr inbounds [3 x float], [3 x float]* %1, i64 0, i64 0
%27 = call i32 @solve_cubic(i32 -3, i32 1, i32 -3, float* %26)
store i32 %27, i32* %2
%28 = load i32, i32* %2
%29 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %28)
store i32 0, i32* %4
br label %30
30: ; preds = %42, %25
%31 = load i32, i32* %4
%32 = load i32, i32* %2
%33 = icmp ne i32 %31, %32
br i1 %33, label %34, label %45
34: ; preds = %30
%35 = load i32, i32* %4
%36 = load i32, i32* %4
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [3 x float], [3 x float]* %1, i64 0, i64 %37
%39 = load float, float* %38
%40 = fpext float %39 to double
%41 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %35, double %40)
br label %42
42: ; preds = %34
%43 = load i32, i32* %4
%44 = add nsw i32 %43, 1
store i32 %44, i32* %4
br label %30
45: ; preds = %30
%46 = getelementptr inbounds [3 x float], [3 x float]* %1, i64 0, i64 0
%47 = call i32 @solve_cubic(i32 -5, i32 100, i32 -15625, float* %46)
store i32 %47, i32* %2
%48 = load i32, i32* %2
%49 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %48)
store i32 0, i32* %5
br label %50
50: ; preds = %62, %45
%51 = load i32, i32* %5
%52 = load i32, i32* %2
%53 = icmp ne i32 %51, %52
br i1 %53, label %54, label %65
54: ; preds = %50
%55 = load i32, i32* %5
%56 = load i32, i32* %5
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [3 x float], [3 x float]* %1, i64 0, i64 %57
%59 = load float, float* %58
%60 = fpext float %59 to double
%61 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %55, double %60)
br label %62
62: ; preds = %54
%63 = load i32, i32* %5
%64 = add nsw i32 %63, 1
store i32 %64, i32* %5
br label %50
65: ; preds = %50
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"%d cubic solutions\0A\00"
@.str.1 = [23 x i8] c"cubic solution %d: %f\0A\00"
define void @cubic_test() {
%1 = alloca [3 x float]
%2 = bitcast [3 x float]* %1 to i8*
%3 = getelementptr inbounds [3 x float], [3 x float]* %1, i64 0, i64 0
%4 = call i32 @solve_cubic(i32 -6, i32 11, i32 -6, float* %3)
%5 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp eq i32 %4, 0
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = zext i32 %4 to i64
br label %15
9: ; preds = %15, %0
%10 = call i32 @solve_cubic(i32 -3, i32 1, i32 -3, float* %3)
%11 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = icmp eq i32 %10, 0
br i1 %12, label %24, label %13
13: ; preds = %9
%14 = zext i32 %10 to i64
br label %30
15: ; preds = %7, %15
%16 = phi i64 [ 0, %7 ], [ %22, %15 ]
%17 = getelementptr inbounds [3 x float], [3 x float]* %1, i64 0, i64 %16
%18 = load float, float* %17
%19 = fpext float %18 to double
%20 = trunc i64 %16 to i32
%21 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %20, double %19)
%22 = add nuw nsw i64 %16, 1
%23 = icmp eq i64 %22, %8
br i1 %23, label %9, label %15
24: ; preds = %30, %9
%25 = call i32 @solve_cubic(i32 -5, i32 100, i32 -15625, float* %3)
%26 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %25)
%27 = icmp eq i32 %25, 0
br i1 %27, label %39, label %28
28: ; preds = %24
%29 = zext i32 %25 to i64
br label %40
30: ; preds = %13, %30
%31 = phi i64 [ 0, %13 ], [ %37, %30 ]
%32 = getelementptr inbounds [3 x float], [3 x float]* %1, i64 0, i64 %31
%33 = load float, float* %32
%34 = fpext float %33 to double
%35 = trunc i64 %31 to i32
%36 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %35, double %34)
%37 = add nuw nsw i64 %31, 1
%38 = icmp eq i64 %37, %14
br i1 %38, label %24, label %30
39: ; preds = %40, %24
ret void
40: ; preds = %28, %40
%41 = phi i64 [ 0, %28 ], [ %47, %40 ]
%42 = getelementptr inbounds [3 x float], [3 x float]* %1, i64 0, i64 %41
%43 = load float, float* %42
%44 = fpext float %43 to double
%45 = trunc i64 %41 to i32
%46 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %45, double %44)
%47 = add nuw nsw i64 %41, 1
%48 = icmp eq i64 %47, %29
br i1 %48, label %39, label %40
}