#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*/ Bisection(double, double);
int /*<<< orphan*/ FalsePosition(double, double);
int /*<<< orphan*/ NewtonRaphson(double);
int /*<<< orphan*/ OnePointIteration(double);
int /*<<< orphan*/ Secant(double, double);
int /*<<< orphan*/ TestBisection();
int /*<<< orphan*/ TestFalsePosition();
int /*<<< orphan*/ TestNewtonRaphson();
int /*<<< orphan*/ TestOnePointIteration();
int /*<<< orphan*/ TestSecant();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, double *);
void SelectMethod(int choice) {
  double a, b, x;
  switch (choice) {
  case 3:
  case 4:
    printf("Enter x value: ");
    scanf("%lf", &x);
    printf("\n");
    break;
  case 1:
  case 2:
  case 5:
    printf("Enter starting point: ");
    scanf("%lf", &a);
    printf("Enter ending point: ");
    scanf("%lf", &b);
    break;
  case 6:
    printf("======== TEST ALL METHODS =========\n");
    TestBisection();
    TestFalsePosition();
    TestOnePointIteration();
    TestNewtonRaphson();
    TestSecant();
    printf("===================================\n");
    break;
  }
  switch (choice) {
  case 1:
    printf("Bisection method, root = %lf\n", Bisection(a, b));
    break;
  case 2:
    printf("Bisection method, root = %lf\n", FalsePosition(a, b));
    break;
  case 3:
    printf("Bisection method, root = %lf\n", OnePointIteration(x));
    break;
  case 4:
    printf("Bisection method, root = %lf\n", NewtonRaphson(x));
    break;
  case 5:
    printf("Bisection method, root = %lf\n", Secant(a, b));
    break;
  }
}


x86 assembly (clang, -O0):
<SelectMethod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
add    $0xffffffff,%eax
sub    $0x2,%eax
jb     1249 <SelectMethod+0x89>
jmp    11e2 <SelectMethod+0x22>
mov    -0x24(%rbp),%eax
add    $0xfffffffd,%eax
sub    $0x2,%eax
jb     1218 <SelectMethod+0x58>
jmp    11f6 <SelectMethod+0x36>
mov    -0x24(%rbp),%eax
sub    $0x5,%eax
je     1249 <SelectMethod+0x89>
jmp    1207 <SelectMethod+0x47>
mov    -0x24(%rbp),%eax
sub    $0x6,%eax
je     128a <SelectMethod+0xca>
jmp    12c9 <SelectMethod+0x109>
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdf7(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1090 <scanf@plt>
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12c9 <SelectMethod+0x109>
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdc6(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1090 <scanf@plt>
lea    0xdd1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xda8(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1090 <scanf@plt>
jmp    12c9 <SelectMethod+0x109>
lea    0xdc3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1080 <TestBisection@plt>
mov    $0x0,%al
call   1050 <TestFalsePosition@plt>
mov    $0x0,%al
call   1060 <TestOnePointIteration@plt>
mov    $0x0,%al
call   10d0 <TestNewtonRaphson@plt>
mov    $0x0,%al
call   10b0 <TestSecant@plt>
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x4,%eax
ja     1397 <SelectMethod+0x1d7>
mov    -0x30(%rbp),%rax
lea    0xd17(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   10a0 <Bisection@plt>
mov    %eax,%esi
lea    0xd94(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1397 <SelectMethod+0x1d7>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   1070 <FalsePosition@plt>
mov    %eax,%esi
lea    0xd70(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1397 <SelectMethod+0x1d7>
movsd  -0x20(%rbp),%xmm0
call   10c0 <OnePointIteration@plt>
mov    %eax,%esi
lea    0xd51(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1397 <SelectMethod+0x1d7>
movsd  -0x20(%rbp),%xmm0
call   1030 <NewtonRaphson@plt>
mov    %eax,%esi
lea    0xd32(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1397 <SelectMethod+0x1d7>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   10e0 <Secant@plt>
mov    %eax,%esi
lea    0xd0e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SelectMethod>:
push   %r14
push   %rbx
sub    $0x18,%rsp
cmp    $0x6,%edi
ja     1338 <SelectMethod+0x158>
mov    %edi,%ebx
mov    $0x26,%eax
bt     %edi,%eax
jb     1235 <SelectMethod+0x55>
mov    $0x18,%eax
bt     %ebx,%eax
jae    12a1 <SelectMethod+0xc1>
lea    0xe03(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe05(%rip),%rdi
lea    0x10(%rsp),%rsi
call   10b0 <scanf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1270 <SelectMethod+0x90>
lea    0xdec(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdda(%rip),%r14
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   10b0 <scanf@plt>
lea    0xde1(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rsp,%rsi
mov    %r14,%rdi
call   10b0 <scanf@plt>
add    $0xffffffff,%ebx
cmp    $0x4,%ebx
ja     1338 <SelectMethod+0x158>
lea    0xd7d(%rip),%rax
movslq (%rax,%rbx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
movsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm1
call   10c0 <Bisection@plt>
jmp    1328 <SelectMethod+0x148>
cmp    $0x6,%ebx
jne    1338 <SelectMethod+0x158>
lea    0xdc1(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   10a0 <TestBisection@plt>
xor    %eax,%eax
call   1070 <TestFalsePosition@plt>
xor    %eax,%eax
call   1080 <TestOnePointIteration@plt>
xor    %eax,%eax
call   10f0 <TestNewtonRaphson@plt>
xor    %eax,%eax
call   10d0 <TestSecant@plt>
lea    0xdb6(%rip),%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r14
jmp    1040 <puts@plt>
movsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm1
call   1090 <FalsePosition@plt>
jmp    1328 <SelectMethod+0x148>
movsd  0x10(%rsp),%xmm0
call   10e0 <OnePointIteration@plt>
jmp    1328 <SelectMethod+0x148>
movsd  0x10(%rsp),%xmm0
call   1050 <NewtonRaphson@plt>
jmp    1328 <SelectMethod+0x148>
movsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm1
call   1100 <Secant@plt>
lea    0xd25(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [16 x i8] c"Enter x value: \00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [23 x i8] c"Enter starting point: \00"
@.str.4 = [21 x i8] c"Enter ending point: \00"
@.str.5 = [37 x i8] c"======== TEST ALL METHODS =========\0A\00"
@.str.6 = [37 x i8] c"===================================\0A\00"
@.str.7 = [30 x i8] c"Bisection method, root = %lf\0A\00"
define void @SelectMethod(i32 %0) {
%2 = alloca i32
%3 = alloca double
%4 = alloca double
%5 = alloca double
store i32 %0, i32* %2
%6 = load i32, i32* %2
switch i32 %6, label %24 [
i32 3, label %7
i32 4, label %7
i32 1, label %11
i32 2, label %11
i32 5, label %11
i32 6, label %16
]
7: ; preds = %1, %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %5)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %24
11: ; preds = %1, %1, %1
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %3)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %4)
br label %24
16: ; preds = %1
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
%18 = call i32 (...) @TestBisection()
%19 = call i32 (...) @TestFalsePosition()
%20 = call i32 (...) @TestOnePointIteration()
%21 = call i32 (...) @TestNewtonRaphson()
%22 = call i32 (...) @TestSecant()
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0))
br label %24
24: ; preds = %1, %16, %11, %7
%25 = load i32, i32* %2
switch i32 %25, label %49 [
i32 1, label %26
i32 2, label %31
i32 3, label %36
i32 4, label %40
i32 5, label %44
]
26: ; preds = %24
%27 = load double, double* %3
%28 = load double, double* %4
%29 = call i32 @Bisection(double %27, double %28)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i32 %29)
br label %49
31: ; preds = %24
%32 = load double, double* %3
%33 = load double, double* %4
%34 = call i32 @FalsePosition(double %32, double %33)
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i32 %34)
br label %49
36: ; preds = %24
%37 = load double, double* %5
%38 = call i32 @OnePointIteration(double %37)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i32 %38)
br label %49
40: ; preds = %24
%41 = load double, double* %5
%42 = call i32 @NewtonRaphson(double %41)
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i32 %42)
br label %49
44: ; preds = %24
%45 = load double, double* %3
%46 = load double, double* %4
%47 = call i32 @Secant(double %45, double %46)
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %24, %44, %40, %36, %31, %26
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"Enter x value: \00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.3 = [23 x i8] c"Enter starting point: \00"
@.str.4 = [21 x i8] c"Enter ending point: \00"
@.str.7 = [30 x i8] c"Bisection method, root = %lf\0A\00"
@str = [36 x i8] c"======== TEST ALL METHODS =========\00"
@str.8 = [36 x i8] c"===================================\00"
define void @SelectMethod(i32 %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = bitcast double* %2 to i8*
%6 = bitcast double* %3 to i8*
%7 = bitcast double* %4 to i8*
switch i32 %0, label %49 [
i32 3, label %8
i32 4, label %8
i32 1, label %12
i32 2, label %12
i32 5, label %12
i32 6, label %17
]
8: ; preds = %1, %1
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %4)
%11 = call i32 @putchar(i32 10)
br label %25
12: ; preds = %1, %1, %1
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %2)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%16 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %3)
br label %25
17: ; preds = %1
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
%19 = tail call i32 (...) @TestBisection()
%20 = tail call i32 (...) @TestFalsePosition()
%21 = tail call i32 (...) @TestOnePointIteration()
%22 = tail call i32 (...) @TestNewtonRaphson()
%23 = tail call i32 (...) @TestSecant()
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.8, i64 0, i64 0))
br label %49
25: ; preds = %12, %8
switch i32 %0, label %49 [
i32 1, label %26
i32 2, label %31
i32 3, label %36
i32 4, label %40
i32 5, label %44
]
26: ; preds = %25
%27 = load double, double* %2
%28 = load double, double* %3
%29 = call i32 @Bisection(double %27, double %28)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i32 %29)
br label %49
31: ; preds = %25
%32 = load double, double* %2
%33 = load double, double* %3
%34 = call i32 @FalsePosition(double %32, double %33)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i32 %34)
br label %49
36: ; preds = %25
%37 = load double, double* %4
%38 = call i32 @OnePointIteration(double %37)
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i32 %38)
br label %49
40: ; preds = %25
%41 = load double, double* %4
%42 = call i32 @NewtonRaphson(double %41)
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i32 %42)
br label %49
44: ; preds = %25
%45 = load double, double* %2
%46 = load double, double* %3
%47 = call i32 @Secant(double %45, double %46)
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %17, %1, %25, %44, %40, %36, %31, %26
ret void
}