#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*/ integral(int, double, double, double, double, double);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
double strtod(char *, char **);
int main(void) {
  double in[5];
  char *ins[5] = {"wspolczynnik a", "wspolczynnik b", "wspolczynnik c",
                  "lewa granice calkowania", "prawa granice calkowania"};
  char s[100], *er;
  for (int i = 0; i < 5; ++i) {
    printf("Wprowadz %s:\n", ins[i]);
    scanf("%s", s);
    in[i] = strtod(s, &er);
    if (*er) {
      printf("Blednie wprowadzone dane!\n");
      --i;
    }
  }
  if (in[3] > in[4]) {
    printf("\n\nUWAGA! Lewa granica większa od prawej, wynaczona wartosc "
           "może byc przeciwnoscia spodziewanej!\n\n");
  }
  printf("Calka z (%.3lf*cos(%.3lf*x)+%.3lf)*dx od %.3lf do %.3lf obliczona "
         "metoda trapezow (dla n trapezow) to w zaleznosci od n:\n",
         in[0], in[1], in[2], in[3], in[4]);
  for (int n = 3; n < 100000; n *= 1.35)
    printf("%i: %.5lf\n", n, integral(n, in[3], in[4], in[0], in[1], in[2]));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1060 <memset@plt>
lea    0xe8f(%rip),%rax
mov    %rax,-0x60(%rbp)
lea    0xe93(%rip),%rax
mov    %rax,-0x58(%rbp)
lea    0xe97(%rip),%rax
mov    %rax,-0x50(%rbp)
lea    0xe9b(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    0xea8(%rip),%rax
mov    %rax,-0x40(%rbp)
movl   $0x0,-0xdc(%rbp)
cmpl   $0x5,-0xdc(%rbp)
jge    1253 <main+0x103>
movslq -0xdc(%rbp),%rax
mov    -0x60(%rbp,%rax,8),%rsi
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0xd0(%rbp),%rsi
lea    0xe8c(%rip),%rdi
call   1070 <scanf@plt>
lea    -0xd0(%rbp),%rdi
lea    -0xd8(%rbp),%rsi
call   1030 <strtod@plt>
movslq -0xdc(%rbp),%rax
movsd  %xmm0,-0x30(%rbp,%rax,8)
mov    -0xd8(%rbp),%rax
cmpb   $0x0,(%rax)
je     123a <main+0xea>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xdc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xdc(%rbp)
jmp    123f <main+0xef>
mov    -0xdc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xdc(%rbp)
jmp    11b3 <main+0x63>
movsd  -0x18(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1271 <main+0x121>
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movsd  -0x30(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm3
movsd  -0x10(%rbp),%xmm4
lea    0xe65(%rip),%rdi
mov    $0x5,%al
call   1050 <printf@plt>
movl   $0x3,-0xe0(%rbp)
cmpl   $0x186a0,-0xe0(%rbp)
jge    131b <main+0x1cb>
mov    -0xe0(%rbp),%eax
mov    %eax,-0xe4(%rbp)
mov    -0xe0(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm3
movsd  -0x20(%rbp),%xmm4
call   1040 <integral@plt>
mov    -0xe4(%rbp),%esi
mov    %eax,%edx
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cvtsi2sdl -0xe0(%rbp),%xmm0
ff
movsd  0xcf8(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0xe0(%rbp)
jmp    12a2 <main+0x152>
xor    %eax,%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xf8,%rsp
lea    0xea0(%rip),%rsi
mov    %rsi,0x30(%rsp)
lea    0xea3(%rip),%rax
mov    %rax,0x38(%rsp)
lea    0xea6(%rip),%rax
mov    %rax,0x40(%rsp)
lea    0xea9(%rip),%rax
mov    %rax,0x48(%rsp)
lea    0xeb5(%rip),%rax
mov    %rax,0x50(%rsp)
lea    0xec2(%rip),%r14
lea    0xec9(%rip),%r15
lea    0x90(%rsp),%rbx
lea    0x28(%rsp),%r12
xor    %ebp,%ebp
jmp    11d4 <main+0x84>
nopl   0x0(%rax)
lea    0xf98(%rip),%rdi
call   1030 <puts@plt>
movslq %ebp,%rax
mov    0x30(%rsp,%rax,8),%rsi
movslq %ebp,%r13
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <strtod@plt>
movsd  %xmm0,0x60(%rsp,%r13,8)
mov    0x28(%rsp),%rax
cmpb   $0x0,(%rax)
jne    11c0 <main+0x70>
cmp    $0x3,%ebp
jg     1212 <main+0xc2>
add    $0x1,%ebp
jmp    11cc <main+0x7c>
movsd  0x78(%rsp),%xmm3
movsd  0x80(%rsp),%xmm4
ucomisd %xmm4,%xmm3
movsd  %xmm3,0x8(%rsp)
movsd  %xmm4,(%rsp)
jbe    1249 <main+0xf9>
lea    0xec3(%rip),%rdi
call   1030 <puts@plt>
movsd  (%rsp),%xmm4
movsd  0x8(%rsp),%xmm3
movsd  0x60(%rsp),%xmm0
movsd  0x68(%rsp),%xmm1
movsd  0x70(%rsp),%xmm2
lea    0xe15(%rip),%rdi
movsd  %xmm0,0x20(%rsp)
movsd  %xmm1,0x18(%rsp)
movsd  %xmm2,0x10(%rsp)
mov    $0x5,%al
call   1060 <printf@plt>
mov    $0x3,%ebp
lea    0xe6a(%rip),%rbx
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
movsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm1
movsd  0x20(%rsp),%xmm2
movsd  0x18(%rsp),%xmm3
movsd  0x10(%rsp),%xmm4
call   1050 <integral@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  0xd2f(%rip),%xmm0
cvttsd2si %xmm0,%ebp
cmp    $0x186a0,%ebp
jl     1290 <main+0x140>
xor    %eax,%eax
add    $0xf8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"wspolczynnik a\00"
@.str.1 = [15 x i8] c"wspolczynnik b\00"
@.str.2 = [15 x i8] c"wspolczynnik c\00"
@.str.3 = [24 x i8] c"lewa granice calkowania\00"
@.str.4 = [25 x i8] c"prawa granice calkowania\00"
@.str.5 = [14 x i8] c"Wprowadz %s:\0A\00"
@.str.6 = [3 x i8] c"%s\00"
@.str.7 = [27 x i8] c"Blednie wprowadzone dane!\0A\00"
@.str.8 = [100 x i8] c"\0A\0AUWAGA! Lewa granica wi\C4\99ksza od prawej, wynaczona wartosc mo\C5\BCe byc przeciwnoscia spodziewanej!\0A\0A\00"
@.str.9 = [122 x i8] c"Calka z (%.3lf*cos(%.3lf*x)+%.3lf)*dx od %.3lf do %.3lf obliczona metoda trapezow (dla n trapezow) to w zaleznosci od n:\0A\00"
@.str.10 = [11 x i8] c"%i: %.5lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [5 x double]
%3 = alloca [5 x i8*]
%4 = alloca [100 x i8]
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = bitcast [5 x i8*]* %3 to i8*
%9 = bitcast i8* %8 to [5 x i8*]*
%10 = getelementptr inbounds [5 x i8*], [5 x i8*]* %9, i32 0, i32 0
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i32 0, i32 0), i8** %10
%11 = getelementptr inbounds [5 x i8*], [5 x i8*]* %9, i32 0, i32 1
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i32 0, i32 0), i8** %11
%12 = getelementptr inbounds [5 x i8*], [5 x i8*]* %9, i32 0, i32 2
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i32 0, i32 0), i8** %12
%13 = getelementptr inbounds [5 x i8*], [5 x i8*]* %9, i32 0, i32 3
store i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i32 0, i32 0), i8** %13
%14 = getelementptr inbounds [5 x i8*], [5 x i8*]* %9, i32 0, i32 4
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i32 0, i32 0), i8** %14
store i32 0, i32* %6
br label %15
15: ; preds = %39, %0
%16 = load i32, i32* %6
%17 = icmp slt i32 %16, 5
br i1 %17, label %18, label %42
18: ; preds = %15
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 %20
%22 = load i8*, i8** %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %22)
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %24)
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%27 = call double @strtod(i8* %26, i8** %5)
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [5 x double], [5 x double]* %2, i64 0, i64 %29
store double %27, double* %30
%31 = load i8*, i8** %5
%32 = load i8, i8* %31
%33 = icmp ne i8 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %18
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
%36 = load i32, i32* %6
%37 = add nsw i32 %36, -1
store i32 %37, i32* %6
br label %38
38: ; preds = %34, %18
br label %39
39: ; preds = %38
%40 = load i32, i32* %6
%41 = add nsw i32 %40, 1
store i32 %41, i32* %6
br label %15
42: ; preds = %15
%43 = getelementptr inbounds [5 x double], [5 x double]* %2, i64 0, i64 3
%44 = load double, double* %43
%45 = getelementptr inbounds [5 x double], [5 x double]* %2, i64 0, i64 4
%46 = load double, double* %45
%47 = fcmp ogt double %44, %46
br i1 %47, label %48, label %50
48: ; preds = %42
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @.str.8, i64 0, i64 0))
br label %50
50: ; preds = %48, %42
%51 = getelementptr inbounds [5 x double], [5 x double]* %2, i64 0, i64 0
%52 = load double, double* %51
%53 = getelementptr inbounds [5 x double], [5 x double]* %2, i64 0, i64 1
%54 = load double, double* %53
%55 = getelementptr inbounds [5 x double], [5 x double]* %2, i64 0, i64 2
%56 = load double, double* %55
%57 = getelementptr inbounds [5 x double], [5 x double]* %2, i64 0, i64 3
%58 = load double, double* %57
%59 = getelementptr inbounds [5 x double], [5 x double]* %2, i64 0, i64 4
%60 = load double, double* %59
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([122 x i8], [122 x i8]* @.str.9, i64 0, i64 0), double %52, double %54, double %56, double %58, double %60)
store i32 3, i32* %7
br label %62
62: ; preds = %80, %50
%63 = load i32, i32* %7
%64 = icmp slt i32 %63, 100000
br i1 %64, label %65, label %85
65: ; preds = %62
%66 = load i32, i32* %7
%67 = load i32, i32* %7
%68 = getelementptr inbounds [5 x double], [5 x double]* %2, i64 0, i64 3
%69 = load double, double* %68
%70 = getelementptr inbounds [5 x double], [5 x double]* %2, i64 0, i64 4
%71 = load double, double* %70
%72 = getelementptr inbounds [5 x double], [5 x double]* %2, i64 0, i64 0
%73 = load double, double* %72
%74 = getelementptr inbounds [5 x double], [5 x double]* %2, i64 0, i64 1
%75 = load double, double* %74
%76 = getelementptr inbounds [5 x double], [5 x double]* %2, i64 0, i64 2
%77 = load double, double* %76
%78 = call i32 @integral(i32 %67, double %69, double %71, double %73, double %75, double %77)
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0), i32 %66, i32 %78)
br label %80
80: ; preds = %65
%81 = load i32, i32* %7
%82 = sitofp i32 %81 to double
%83 = fmul double %82, 1.350000e+00
%84 = fptosi double %83 to i32
store i32 %84, i32* %7
br label %62
85: ; preds = %62
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"wspolczynnik a\00"
@.str.1 = [15 x i8] c"wspolczynnik b\00"
@.str.2 = [15 x i8] c"wspolczynnik c\00"
@.str.3 = [24 x i8] c"lewa granice calkowania\00"
@.str.4 = [25 x i8] c"prawa granice calkowania\00"
@.str.5 = [14 x i8] c"Wprowadz %s:\0A\00"
@.str.6 = [3 x i8] c"%s\00"
@.str.9 = [122 x i8] c"Calka z (%.3lf*cos(%.3lf*x)+%.3lf)*dx od %.3lf do %.3lf obliczona metoda trapezow (dla n trapezow) to w zaleznosci od n:\0A\00"
@.str.10 = [11 x i8] c"%i: %.5lf\0A\00"
@str = [99 x i8] c"\0A\0AUWAGA! Lewa granica wi\C4\99ksza od prawej, wynaczona wartosc mo\C5\BCe byc przeciwnoscia spodziewanej!\0A\00"
@str.11 = [26 x i8] c"Blednie wprowadzone dane!\00"
define i32 @main() {
%1 = alloca [5 x double]
%2 = alloca [5 x i8*]
%3 = alloca [100 x i8]
%4 = alloca i8*
%5 = bitcast [5 x double]* %1 to i8*
%6 = bitcast [5 x i8*]* %2 to i8*
%7 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 0
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %7
%8 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 1
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8** %8
%9 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 2
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 3
store i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8** %10
%11 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 4
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8** %11
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%13 = bitcast i8** %4 to i8*
br label %20
14: ; preds = %33
%15 = getelementptr inbounds [5 x double], [5 x double]* %1, i64 0, i64 3
%16 = load double, double* %15
%17 = getelementptr inbounds [5 x double], [5 x double]* %1, i64 0, i64 4
%18 = load double, double* %17
%19 = fcmp ogt double %16, %18
br i1 %19, label %41, label %43
20: ; preds = %36, %0
%21 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), %0 ], [ %40, %36 ]
%22 = phi i32 [ 0, %0 ], [ %37, %36 ]
%23 = sext i32 %22 to i64
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %21)
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %12)
%26 = call double @strtod(i8* %12, i8** %4)
%27 = getelementptr inbounds [5 x double], [5 x double]* %1, i64 0, i64 %23
store double %26, double* %27
%28 = load i8*, i8** %4
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %20
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.11, i64 0, i64 0))
br label %36
33: ; preds = %20
%34 = add nsw i32 %22, 1
%35 = icmp slt i32 %22, 4
br i1 %35, label %36, label %14
36: ; preds = %31, %33
%37 = phi i32 [ %22, %31 ], [ %34, %33 ]
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 %38
%40 = load i8*, i8** %39
br label %20
41: ; preds = %14
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([99 x i8], [99 x i8]* @str, i64 0, i64 0))
br label %43
43: ; preds = %41, %14
%44 = getelementptr inbounds [5 x double], [5 x double]* %1, i64 0, i64 0
%45 = load double, double* %44
%46 = getelementptr inbounds [5 x double], [5 x double]* %1, i64 0, i64 1
%47 = load double, double* %46
%48 = getelementptr inbounds [5 x double], [5 x double]* %1, i64 0, i64 2
%49 = load double, double* %48
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([122 x i8], [122 x i8]* @.str.9, i64 0, i64 0), double %45, double %47, double %49, double %16, double %18)
br label %52
51: ; preds = %52
ret i32 0
52: ; preds = %43, %52
%53 = phi i32 [ 3, %43 ], [ %58, %52 ]
%54 = call i32 @integral(i32 %53, double %16, double %18, double %45, double %47, double %49)
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0), i32 %53, i32 %54)
%56 = sitofp i32 %53 to double
%57 = fmul double %56, 1.350000e+00
%58 = fptosi double %57 to i32
%59 = icmp slt i32 %58, 100000
br i1 %59, label %52, label %51
}