#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*/ DFP(int, int, double, double);
int /*<<< orphan*/ SD(int, int, double, double);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ stdin;
int main() {
  int n, met, fun;
  double prec, h;
  while (1) {
    do {
      printf("\nPlease select the methord(1 or 2 , 0 to quit): \n");
      printf(" 0: quit \n 1: SD(steepest descent) \n 2: DFP \n");
      printf("Your selected methord: ");
      fflush(stdin);
      scanf("%d", &met);
    } while (met < 0 || met > 2);
    if (met == 0)
      break;
    do {
      printf("\nPlease select the function(1 or 2): \n");
      printf(" 1: f1=¦²[x^2-10*cos(2*¦Ð*x)+10] \n");
      printf(" 2: f2=(¦²x^2)/4000-¡Çcos(x/i)+1] \n");
      printf("Your selected function: ");
      fflush(stdin);
      scanf("%d", &fun);
    } while (fun < 1 || fun > 2);
    do {
      printf("\nPlease input the precision(prec>0): ");
      fflush(stdin);
      scanf("%lf", &prec);
    } while (prec <= 0);
    do {
      printf("Please input the step size(h>0): ");
      fflush(stdin);
      scanf("%lf", &h);
    } while (prec <= 0);
    do {
      printf("\nPlease input the dimension(n>=1): ");
      fflush(stdin);
      scanf("%d", &n);
    } while (n < 1);
    switch (met) {
    case 1:
      SD(fun, n, prec, h);
      break;
    case 2:
      DFP(fun, n, prec, h);
      break;
    default:
      break;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
jmp    1164 <main+0x14>
lea    0xe95(%rip),%rdi
call   1040 <printf@plt>
lea    0xebb(%rip),%rdi
call   1040 <printf@plt>
lea    0xedd(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
lea    0xedb(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    $0x1,%al
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0x21(%rbp)
jl     11c1 <main+0x71>
cmpl   $0x2,-0xc(%rbp)
setg   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1164 <main+0x14>
cmpl   $0x0,-0xc(%rbp)
jne    11db <main+0x8b>
jmp    1370 <main+0x220>
jmp    11e0 <main+0x90>
lea    0xe94(%rip),%rdi
call   1040 <printf@plt>
lea    0xeaf(%rip),%rdi
call   1040 <printf@plt>
lea    0xeca(%rip),%rdi
call   1040 <printf@plt>
lea    0xee6(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
lea    0xe53(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    $0x1,%al
cmpl   $0x1,-0x10(%rbp)
mov    %al,-0x22(%rbp)
jl     1249 <main+0xf9>
cmpl   $0x2,-0x10(%rbp)
setg   %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
test   $0x1,%al
jne    11e0 <main+0x90>
jmp    1259 <main+0x109>
lea    0xeaa(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
lea    0xeb6(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jae    1259 <main+0x109>
jmp    1298 <main+0x148>
lea    0xe95(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d3d(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
lea    0xe77(%rip),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jae    1298 <main+0x148>
jmp    12d7 <main+0x187>
lea    0xe78(%rip),%rdi
call   1040 <printf@plt>
mov    0x2cfe(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
lea    0xd80(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
cmpl   $0x1,-0x8(%rbp)
jl     12d7 <main+0x187>
mov    -0xc(%rbp),%eax
mov    %eax,-0x28(%rbp)
sub    $0x1,%eax
je     1332 <main+0x1e2>
jmp    1321 <main+0x1d1>
mov    -0x28(%rbp),%eax
sub    $0x2,%eax
je     134c <main+0x1fc>
jmp    1366 <main+0x216>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%esi
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
call   1030 <SD@plt>
jmp    136b <main+0x21b>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%esi
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
call   1050 <DFP@plt>
jmp    136b <main+0x21b>
jmp    136b <main+0x21b>
jmp    115f <main+0xf>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    0x2e73(%rip),%r14
lea    0xe9c(%rip),%r13
lea    0xfa5(%rip),%rbx
lea    0xe91(%rip),%r15
lea    0x8(%rsp),%r12
jmp    11c0 <main+0x60>
mov    0x8(%rsp),%edi
movsd  0x10(%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
call   1060 <DFP@plt>
lea    0xf7b(%rip),%rbx
lea    0xe67(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xedd(%rip),%rdi
call   1040 <puts@plt>
lea    0xf02(%rip),%rdi
call   1040 <puts@plt>
lea    0xe21(%rip),%rdi
call   1050 <printf@plt>
mov    (%r14),%edi
call   1070 <fflush@plt>
mov    %r13,%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x2,%eax
ja     11c0 <main+0x60>
test   %eax,%eax
je     1363 <main+0x203>
mov    %r13,%rbp
lea    0xeec(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
lea    0xf17(%rip),%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
call   1050 <printf@plt>
mov    (%r14),%edi
call   1070 <fflush@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
mov    0x8(%rsp),%eax
add    $0xfffffffd,%eax
cmp    $0xfffffffe,%eax
jb     1220 <main+0xc0>
lea    0xdc8(%rip),%rbx
lea    0xde7(%rip),%r13
lea    0x10(%rsp),%r12
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    (%r14),%edi
call   1070 <fflush@plt>
mov    %r13,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
xorpd  %xmm0,%xmm0
ucomisd 0x10(%rsp),%xmm0
jae    1280 <main+0x120>
lea    0x8(%rsp),%r12
lea    0xda9(%rip),%rbx
lea    0x20(%rsp),%rbp
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    (%r14),%edi
call   1070 <fflush@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
xorpd  %xmm0,%xmm0
ucomisd 0x10(%rsp),%xmm0
jae    12c0 <main+0x160>
lea    0xd90(%rip),%rbx
lea    0x1c(%rsp),%rbp
lea    0xd1c(%rip),%r13
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    (%r14),%edi
call   1070 <fflush@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
mov    0x1c(%rsp),%esi
test   %esi,%esi
jle    1300 <main+0x1a0>
mov    0xc(%rsp),%eax
cmp    $0x2,%eax
je     1191 <main+0x31>
cmp    $0x1,%eax
lea    0xdec(%rip),%rbx
lea    0xcd8(%rip),%r15
jne    11c0 <main+0x60>
mov    0x8(%rsp),%edi
movsd  0x10(%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
call   1030 <SD@plt>
jmp    11c0 <main+0x60>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [50 x i8] c"\0APlease select the methord(1 or 2 , 0 to quit): \0A\00"
@.str.1 = [46 x i8] c" 0: quit \0A 1: SD(steepest descent) \0A 2: DFP \0A\00"
@.str.2 = [24 x i8] c"Your selected methord: \00"
@stdin = global i32 0
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [39 x i8] c"\0APlease select the function(1 or 2): \0A\00"
@.str.5 = [39 x i8] c" 1: f1=\C2\A6\C2\B2[x^2-10*cos(2*\C2\A6\C3\90*x)+10] \0A\00"
@.str.6 = [40 x i8] c" 2: f2=(\C2\A6\C2\B2x^2)/4000-\C2\A1\C3\87cos(x/i)+1] \0A\00"
@.str.7 = [25 x i8] c"Your selected function: \00"
@.str.8 = [38 x i8] c"\0APlease input the precision(prec>0): \00"
@.str.9 = [4 x i8] c"%lf\00"
@.str.10 = [34 x i8] c"Please input the step size(h>0): \00"
@.str.11 = [36 x i8] c"\0APlease input the dimension(n>=1): \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
%6 = alloca double
store i32 0, i32* %1
br label %7
7: ; preds = %0, %86
br label %8
8: ; preds = %21, %7
%9 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%12 = load i32, i32* @stdin
%13 = call i32 @fflush(i32 %12)
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
br label %15
15: ; preds = %8
%16 = load i32, i32* %3
%17 = icmp slt i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = load i32, i32* %3
%20 = icmp sgt i32 %19, 2
br label %21
21: ; preds = %18, %15
%22 = phi i1 [ true, %15 ], [ %20, %18 ]
br i1 %22, label %8, label %23
23: ; preds = %21
%24 = load i32, i32* %3
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %23
br label %87
27: ; preds = %23
br label %28
28: ; preds = %42, %27
%29 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
%30 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0))
%31 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0))
%32 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0))
%33 = load i32, i32* @stdin
%34 = call i32 @fflush(i32 %33)
%35 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %4)
br label %36
36: ; preds = %28
%37 = load i32, i32* %4
%38 = icmp slt i32 %37, 1
br i1 %38, label %42, label %39
39: ; preds = %36
%40 = load i32, i32* %4
%41 = icmp sgt i32 %40, 2
br label %42
42: ; preds = %39, %36
%43 = phi i1 [ true, %36 ], [ %41, %39 ]
br i1 %43, label %28, label %44
44: ; preds = %42
br label %45
45: ; preds = %50, %44
%46 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0))
%47 = load i32, i32* @stdin
%48 = call i32 @fflush(i32 %47)
%49 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), double* %5)
br label %50
50: ; preds = %45
%51 = load double, double* %5
%52 = fcmp ole double %51, 0.000000e+00
br i1 %52, label %45, label %53
53: ; preds = %50
br label %54
54: ; preds = %59, %53
%55 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.10, i64 0, i64 0))
%56 = load i32, i32* @stdin
%57 = call i32 @fflush(i32 %56)
%58 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), double* %6)
br label %59
59: ; preds = %54
%60 = load double, double* %5
%61 = fcmp ole double %60, 0.000000e+00
br i1 %61, label %54, label %62
62: ; preds = %59
br label %63
63: ; preds = %68, %62
%64 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.11, i64 0, i64 0))
%65 = load i32, i32* @stdin
%66 = call i32 @fflush(i32 %65)
%67 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
br label %68
68: ; preds = %63
%69 = load i32, i32* %2
%70 = icmp slt i32 %69, 1
br i1 %70, label %63, label %71
71: ; preds = %68
%72 = load i32, i32* %3
switch i32 %72, label %85 [
i32 1, label %73
i32 2, label %79
]
73: ; preds = %71
%74 = load i32, i32* %4
%75 = load i32, i32* %2
%76 = load double, double* %5
%77 = load double, double* %6
%78 = call i32 @SD(i32 %74, i32 %75, double %76, double %77)
br label %86
79: ; preds = %71
%80 = load i32, i32* %4
%81 = load i32, i32* %2
%82 = load double, double* %5
%83 = load double, double* %6
%84 = call i32 @DFP(i32 %80, i32 %81, double %82, double %83)
br label %86
85: ; preds = %71
br label %86
86: ; preds = %85, %79, %73
br label %7
87: ; preds = %26
%88 = load i32, i32* %1
ret i32 %88
}

LLVM IR (-O2):
@.str.2 = [24 x i8] c"Your selected methord: \00"
@stdin = global i32 0
@.str.3 = [3 x i8] c"%d\00"
@.str.7 = [25 x i8] c"Your selected function: \00"
@.str.8 = [38 x i8] c"\0APlease input the precision(prec>0): \00"
@.str.9 = [4 x i8] c"%lf\00"
@.str.10 = [34 x i8] c"Please input the step size(h>0): \00"
@.str.11 = [36 x i8] c"\0APlease input the dimension(n>=1): \00"
@str = [49 x i8] c"\0APlease select the methord(1 or 2 , 0 to quit): \00"
@str.12 = [45 x i8] c" 0: quit \0A 1: SD(steepest descent) \0A 2: DFP \00"
@str.13 = [38 x i8] c"\0APlease select the function(1 or 2): \00"
@str.14 = [38 x i8] c" 1: f1=\C2\A6\C2\B2[x^2-10*cos(2*\C2\A6\C3\90*x)+10] \00"
@str.15 = [39 x i8] c" 2: f2=(\C2\A6\C2\B2x^2)/4000-\C2\A1\C3\87cos(x/i)+1] \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
%5 = alloca double
%6 = bitcast i32* %1 to i8*
%7 = bitcast i32* %2 to i8*
%8 = bitcast i32* %3 to i8*
%9 = bitcast double* %4 to i8*
%10 = bitcast double* %5 to i8*
br label %11
11: ; preds = %20, %0
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str, i64 0, i64 0))
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.12, i64 0, i64 0))
%14 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%15 = load i32, i32* @stdin
%16 = call i32 @fflush(i32 %15)
%17 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%18 = load i32, i32* %2
%19 = icmp ugt i32 %18, 2
br i1 %19, label %20, label %21
20: ; preds = %11, %55, %62, %57
br label %11
21: ; preds = %11
%22 = icmp eq i32 %18, 0
br i1 %22, label %67, label %23
23: ; preds = %21, %23
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.13, i64 0, i64 0))
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.14, i64 0, i64 0))
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.15, i64 0, i64 0))
%27 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0))
%28 = load i32, i32* @stdin
%29 = call i32 @fflush(i32 %28)
%30 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%31 = load i32, i32* %3
%32 = add i32 %31, -3
%33 = icmp ult i32 %32, -2
br i1 %33, label %23, label %34
34: ; preds = %23, %34
%35 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0))
%36 = load i32, i32* @stdin
%37 = call i32 @fflush(i32 %36)
%38 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), double* %4)
%39 = load double, double* %4
%40 = fcmp ugt double %39, 0.000000e+00
br i1 %40, label %41, label %34
41: ; preds = %34, %41
%42 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.10, i64 0, i64 0))
%43 = load i32, i32* @stdin
%44 = call i32 @fflush(i32 %43)
%45 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), double* %5)
%46 = load double, double* %4
%47 = fcmp ugt double %46, 0.000000e+00
br i1 %47, label %48, label %41
48: ; preds = %41, %48
%49 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.11, i64 0, i64 0))
%50 = load i32, i32* @stdin
%51 = call i32 @fflush(i32 %50)
%52 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%53 = load i32, i32* %1
%54 = icmp slt i32 %53, 1
br i1 %54, label %48, label %55
55: ; preds = %48
%56 = load i32, i32* %2
switch i32 %56, label %20 [
i32 1, label %57
i32 2, label %62
]
57: ; preds = %55
%58 = load i32, i32* %3
%59 = load double, double* %4
%60 = load double, double* %5
%61 = call i32 @SD(i32 %58, i32 %53, double %59, double %60)
br label %20
62: ; preds = %55
%63 = load i32, i32* %3
%64 = load double, double* %4
%65 = load double, double* %5
%66 = call i32 @DFP(i32 %63, i32 %53, double %64, double %65)
br label %20
67: ; preds = %21
ret i32 0
}