#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 *, ...);
int main() {
  float integral(float low_limit, float upper_limit, float (*p)(float x));
  float func1(float x);
  float func2(float x);
  float func3(float x);
  float func4(float x);
  float func5(float x);
  float low_limit, upper_limit, result;
  int choice;
  printf("integral wich funciotn f(x)|(low_limit,upper_limit)\n");
  printf("input low_limit and upper_limit:\n");
  scanf("%f,%f", &low_limit, &upper_limit);
  printf("choose function "
         "f(x)\n\t1-->f(x)=1+x\n\t2-->f(x)=2*x+1\n\t3-->f(x)=e^x+1\n\t4-->f(x)="
         "(1+x)^2\n\t5-->f(x)=x^3\n");
  scanf("%d", &choice);
  switch (choice) {
  case 1:
    result = integral(low_limit, upper_limit, func1);
    break;
  case 2:
    result = integral(low_limit, upper_limit, func2);
    break;
  case 3:
    result = integral(low_limit, upper_limit, func3);
    break;
  case 4:
    result = integral(low_limit, upper_limit, func4);
    break;
  case 5:
    result = integral(low_limit, upper_limit, func5);
    break;
  default:
    printf("please choice the right func.");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xece(%rip),%rdi
call   1040 <printf@plt>
lea    0xef7(%rip),%rdi
call   1040 <printf@plt>
lea    0xf0d(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x21(%rbp)
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1050 <scanf@plt>
lea    0xefa(%rip),%rdi
call   1040 <printf@plt>
mov    -0x21(%rbp),%al
lea    0xf4f(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x4,%eax
ja     1258 <main+0x128>
mov    -0x20(%rbp),%rax
lea    0xe51(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movss  -0x8(%rbp),%xmm0
movss  -0xc(%rbp),%xmm1
mov    0x2dff(%rip),%rdi
call   1030 <integral@plt>
movss  %xmm0,-0x10(%rbp)
jmp    1264 <main+0x134>
movss  -0x8(%rbp),%xmm0
movss  -0xc(%rbp),%xmm1
mov    0x2dff(%rip),%rdi
call   1030 <integral@plt>
movss  %xmm0,-0x10(%rbp)
jmp    1264 <main+0x134>
movss  -0x8(%rbp),%xmm0
movss  -0xc(%rbp),%xmm1
mov    0x2daf(%rip),%rdi
call   1030 <integral@plt>
movss  %xmm0,-0x10(%rbp)
jmp    1264 <main+0x134>
movss  -0x8(%rbp),%xmm0
movss  -0xc(%rbp),%xmm1
mov    0x2db7(%rip),%rdi
call   1030 <integral@plt>
movss  %xmm0,-0x10(%rbp)
jmp    1264 <main+0x134>
movss  -0x8(%rbp),%xmm0
movss  -0xc(%rbp),%xmm1
mov    0x2d77(%rip),%rdi
call   1030 <integral@plt>
movss  %xmm0,-0x10(%rbp)
jmp    1264 <main+0x134>
lea    0xe79(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0xef0(%rip),%rdi
call   1030 <puts@plt>
lea    0xf18(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb1(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
lea    0xf15(%rip),%rdi
call   1030 <puts@plt>
lea    0xe93(%rip),%rdi
lea    0x14(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0x14(%rsp),%eax
add    $0xffffffff,%eax
cmp    $0x4,%eax
ja     11c4 <main+0x84>
lea    0xe5a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movss  0x10(%rsp),%xmm0
movss  0xc(%rsp),%xmm1
mov    0x2e06(%rip),%rdi
jmp    1224 <main+0xe4>
lea    0xe52(%rip),%rdi
call   1050 <printf@plt>
jmp    1229 <main+0xe9>
movss  0x10(%rsp),%xmm0
movss  0xc(%rsp),%xmm1
mov    0x2e03(%rip),%rdi
jmp    1224 <main+0xe4>
movss  0x10(%rsp),%xmm0
movss  0xc(%rsp),%xmm1
mov    0x2dbe(%rip),%rdi
jmp    1224 <main+0xe4>
movss  0x10(%rsp),%xmm0
movss  0xc(%rsp),%xmm1
mov    0x2dd1(%rip),%rdi
jmp    1224 <main+0xe4>
movss  0x10(%rsp),%xmm0
movss  0xc(%rsp),%xmm1
mov    0x2d9c(%rip),%rdi
call   1040 <integral@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [53 x i8] c"integral wich funciotn f(x)|(low_limit,upper_limit)\0A\00"
@.str.1 = [34 x i8] c"input low_limit and upper_limit:\0A\00"
@.str.2 = [6 x i8] c"%f,%f\00"
@.str.3 = [100 x i8] c"choose function f(x)\0A\091-->f(x)=1+x\0A\092-->f(x)=2*x+1\0A\093-->f(x)=e^x+1\0A\094-->f(x)=(1+x)^2\0A\095-->f(x)=x^3\0A\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [30 x i8] c"please choice the right func.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), float* %2, float* %3)
%9 = call i32 @printf(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @.str.3, i64 0, i64 0))
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %5)
%11 = load i32, i32* %5
switch i32 %11, label %32 [
i32 1, label %12
i32 2, label %16
i32 3, label %20
i32 4, label %24
i32 5, label %28
]
12: ; preds = %0
%13 = load float, float* %2
%14 = load float, float* %3
%15 = call float @integral(float %13, float %14, float (float)* @func1)
store float %15, float* %4
br label %34
16: ; preds = %0
%17 = load float, float* %2
%18 = load float, float* %3
%19 = call float @integral(float %17, float %18, float (float)* @func2)
store float %19, float* %4
br label %34
20: ; preds = %0
%21 = load float, float* %2
%22 = load float, float* %3
%23 = call float @integral(float %21, float %22, float (float)* @func3)
store float %23, float* %4
br label %34
24: ; preds = %0
%25 = load float, float* %2
%26 = load float, float* %3
%27 = call float @integral(float %25, float %26, float (float)* @func4)
store float %27, float* %4
br label %34
28: ; preds = %0
%29 = load float, float* %2
%30 = load float, float* %3
%31 = call float @integral(float %29, float %30, float (float)* @func5)
store float %31, float* %4
br label %34
32: ; preds = %0
%33 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
br label %34
34: ; preds = %32, %28, %24, %20, %16, %12
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [6 x i8] c"%f,%f\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [30 x i8] c"please choice the right func.\00"
@str = [52 x i8] c"integral wich funciotn f(x)|(low_limit,upper_limit)\00"
@str.6 = [33 x i8] c"input low_limit and upper_limit:\00"
@str.7 = [99 x i8] c"choose function f(x)\0A\091-->f(x)=1+x\0A\092-->f(x)=2*x+1\0A\093-->f(x)=e^x+1\0A\094-->f(x)=(1+x)^2\0A\095-->f(x)=x^3\00"
define i32 @main() {
%1 = alloca float
%2 = alloca float
%3 = alloca i32
%4 = bitcast float* %1 to i8*
%5 = bitcast float* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.6, i64 0, i64 0))
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), float* %1, float* %2)
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([99 x i8], [99 x i8]* @str.7, i64 0, i64 0))
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%12 = load i32, i32* %3
switch i32 %12, label %33 [
i32 1, label %13
i32 2, label %17
i32 3, label %21
i32 4, label %25
i32 5, label %29
]
13: ; preds = %0
%14 = load float, float* %1
%15 = load float, float* %2
%16 = call float @integral(float %14, float %15, float (float)* @func1)
br label %35
17: ; preds = %0
%18 = load float, float* %1
%19 = load float, float* %2
%20 = call float @integral(float %18, float %19, float (float)* @func2)
br label %35
21: ; preds = %0
%22 = load float, float* %1
%23 = load float, float* %2
%24 = call float @integral(float %22, float %23, float (float)* @func3)
br label %35
25: ; preds = %0
%26 = load float, float* %1
%27 = load float, float* %2
%28 = call float @integral(float %26, float %27, float (float)* @func4)
br label %35
29: ; preds = %0
%30 = load float, float* %1
%31 = load float, float* %2
%32 = call float @integral(float %30, float %31, float (float)* @func5)
br label %35
33: ; preds = %0
%34 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
br label %35
35: ; preds = %33, %29, %25, %21, %17, %13
ret i32 0
}