#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 */
scalar_t__ calloc(int, int);
double f(double, double);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, double *);
void Runge_Kutta_2(double h, int n) {
  double *y, *x;
  int i;
  y = (double *)calloc(n + 1, sizeof(double));
  x = (double *)calloc(n + 1, sizeof(double));
  printf("\nValores Iniciais:\n");
  printf("Entre com x0: ");
  scanf("%lf", &x[0]);
  printf("Entre com y(x0): ");
  scanf("%lf", &y[0]);
  printf("\nIteracoes\n");
  for (i = 1; i <= n; i++) {
    x[i] += x[i - 1] + h;
  }
  for (i = 1; i <= n; i++) {
    y[i] = y[i - 1] +
           (h / 2) * (f(x[i - 1], y[i - 1]) +
                      f(x[i - 1] + h, y[i - 1] + h * f(x[i - 1], y[i - 1])));
    printf("y(%lf) = %lf\n", x[i], y[i]);
  }
}


x86 assembly (clang, -O0):
<Runge_Kutta_2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xe8c(%rip),%rdi
call   1060 <scanf@plt>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe6e(%rip),%rdi
call   1060 <scanf@plt>
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     121a <Runge_Kutta_2+0xda>
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x8(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11d7 <Runge_Kutta_2+0x97>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     136e <Runge_Kutta_2+0x22e>
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xdaf(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
call   1030 <f@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
call   1030 <f@plt>
movsd  -0x58(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x48(%rbp),%xmm0
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
call   1030 <f@plt>
movsd  -0x40(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm1
movaps %xmm0,%xmm3
movsd  -0x30(%rbp),%xmm0
addsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
lea    0xcf4(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1221 <Runge_Kutta_2+0xe1>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Runge_Kutta_2>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %edi,%r15d
movsd  %xmm0,(%rsp)
lea    0x1(%r15),%ebp
mov    %ebp,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,%r14
mov    %ebp,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,%rbx
lea    0xeae(%rip),%rdi
call   1030 <puts@plt>
lea    0xe6f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe70(%rip),%r12
mov    %r12,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
lea    0xe62(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   1070 <scanf@plt>
lea    0xe7c(%rip),%rdi
call   1030 <puts@plt>
test   %r15d,%r15d
jle    1345 <Runge_Kutta_2+0x1f5>
movsd  (%rsp),%xmm1
mov    %ebp,%r12d
movsd  (%rbx),%xmm0
lea    -0x1(%r12),%rdx
lea    -0x2(%r12),%rsi
mov    %edx,%eax
and    $0x3,%eax
mov    $0x1,%ecx
cmp    $0x3,%rsi
jb     125d <Runge_Kutta_2+0x10d>
and    $0xfffffffffffffffc,%rdx
xor    %ecx,%ecx
nopl   0x0(%rax)
addsd  %xmm1,%xmm0
addsd  0x8(%rbx,%rcx,8),%xmm0
movsd  %xmm0,0x8(%rbx,%rcx,8)
addsd  %xmm1,%xmm0
addsd  0x10(%rbx,%rcx,8),%xmm0
movsd  %xmm0,0x10(%rbx,%rcx,8)
addsd  %xmm1,%xmm0
addsd  0x18(%rbx,%rcx,8),%xmm0
movsd  %xmm0,0x18(%rbx,%rcx,8)
addsd  %xmm1,%xmm0
addsd  0x20(%rbx,%rcx,8),%xmm0
movsd  %xmm0,0x20(%rbx,%rcx,8)
add    $0x4,%rcx
cmp    %rcx,%rdx
jne    1210 <Runge_Kutta_2+0xc0>
add    $0x1,%rcx
test   %rax,%rax
je     1287 <Runge_Kutta_2+0x137>
lea    (%rbx,%rcx,8),%rcx
xor    %edx,%edx
nopl   0x0(%rax,%rax,1)
addsd  %xmm1,%xmm0
addsd  (%rcx,%rdx,8),%xmm0
movsd  %xmm0,(%rcx,%rdx,8)
add    $0x1,%rdx
cmp    %rdx,%rax
jne    1270 <Runge_Kutta_2+0x120>
test   %r15d,%r15d
jle    1345 <Runge_Kutta_2+0x1f5>
movsd  0xd68(%rip),%xmm0
mulsd  (%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
add    $0xffffffffffffffff,%r12
xor    %ebp,%ebp
lea    0xd7d(%rip),%r15
movsd  (%r14,%rbp,8),%xmm1
movsd  %xmm1,0x28(%rsp)
movsd  (%rbx,%rbp,8),%xmm0
call   1040 <f@plt>
movsd  %xmm0,0x20(%rsp)
movsd  (%rbx,%rbp,8),%xmm0
movapd %xmm0,%xmm1
addsd  (%rsp),%xmm1
movsd  %xmm1,0x18(%rsp)
movsd  (%r14,%rbp,8),%xmm1
movsd  %xmm1,0x10(%rsp)
call   1040 <f@plt>
mulsd  (%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  0x18(%rsp),%xmm0
call   1040 <f@plt>
movsd  0x20(%rsp),%xmm1
addsd  %xmm0,%xmm1
mulsd  0x8(%rsp),%xmm1
addsd  0x28(%rsp),%xmm1
movsd  %xmm1,0x8(%r14,%rbp,8)
movsd  0x8(%rbx,%rbp,8),%xmm0
mov    %r15,%rdi
mov    $0x2,%al
call   1050 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%r12
jne    12b0 <Runge_Kutta_2+0x160>
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"\0AValores Iniciais:\0A\00"
@.str.1 = [15 x i8] c"Entre com x0: \00"
@.str.2 = [4 x i8] c"%lf\00"
@.str.3 = [18 x i8] c"Entre com y(x0): \00"
@.str.4 = [12 x i8] c"\0AIteracoes\0A\00"
@.str.5 = [14 x i8] c"y(%lf) = %lf\0A\00"
define void @Runge_Kutta_2(double %0, i32 %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca double*
%6 = alloca double*
%7 = alloca i32
store double %0, double* %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = add nsw i32 %8, 1
%10 = call i64 @calloc(i32 %9, i32 8)
%11 = inttoptr i64 %10 to double*
store double* %11, double** %5
%12 = load i32, i32* %4
%13 = add nsw i32 %12, 1
%14 = call i64 @calloc(i32 %13, i32 8)
%15 = inttoptr i64 %14 to double*
store double* %15, double** %6
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%18 = load double*, double** %6
%19 = getelementptr inbounds double, double* %18, i64 0
%20 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %19)
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%22 = load double*, double** %5
%23 = getelementptr inbounds double, double* %22, i64 0
%24 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %23)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %7
br label %26
26: ; preds = %45, %2
%27 = load i32, i32* %7
%28 = load i32, i32* %4
%29 = icmp sle i32 %27, %28
br i1 %29, label %30, label %48
30: ; preds = %26
%31 = load double*, double** %6
%32 = load i32, i32* %7
%33 = sub nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double, double* %31, i64 %34
%36 = load double, double* %35
%37 = load double, double* %3
%38 = fadd double %36, %37
%39 = load double*, double** %6
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %39, i64 %41
%43 = load double, double* %42
%44 = fadd double %43, %38
store double %44, double* %42
br label %45
45: ; preds = %30
%46 = load i32, i32* %7
%47 = add nsw i32 %46, 1
store i32 %47, i32* %7
br label %26
48: ; preds = %26
store i32 1, i32* %7
br label %49
49: ; preds = %122, %48
%50 = load i32, i32* %7
%51 = load i32, i32* %4
%52 = icmp sle i32 %50, %51
br i1 %52, label %53, label %125
53: ; preds = %49
%54 = load double*, double** %5
%55 = load i32, i32* %7
%56 = sub nsw i32 %55, 1
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds double, double* %54, i64 %57
%59 = load double, double* %58
%60 = load double, double* %3
%61 = fdiv double %60, 2.000000e+00
%62 = load double*, double** %6
%63 = load i32, i32* %7
%64 = sub nsw i32 %63, 1
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds double, double* %62, i64 %65
%67 = load double, double* %66
%68 = load double*, double** %5
%69 = load i32, i32* %7
%70 = sub nsw i32 %69, 1
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds double, double* %68, i64 %71
%73 = load double, double* %72
%74 = call double @f(double %67, double %73)
%75 = load double*, double** %6
%76 = load i32, i32* %7
%77 = sub nsw i32 %76, 1
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds double, double* %75, i64 %78
%80 = load double, double* %79
%81 = load double, double* %3
%82 = fadd double %80, %81
%83 = load double*, double** %5
%84 = load i32, i32* %7
%85 = sub nsw i32 %84, 1
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds double, double* %83, i64 %86
%88 = load double, double* %87
%89 = load double, double* %3
%90 = load double*, double** %6
%91 = load i32, i32* %7
%92 = sub nsw i32 %91, 1
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds double, double* %90, i64 %93
%95 = load double, double* %94
%96 = load double*, double** %5
%97 = load i32, i32* %7
%98 = sub nsw i32 %97, 1
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds double, double* %96, i64 %99
%101 = load double, double* %100
%102 = call double @f(double %95, double %101)
%103 = call double @llvm.fmuladd.f64(double %89, double %102, double %88)
%104 = call double @f(double %82, double %103)
%105 = fadd double %74, %104
%106 = call double @llvm.fmuladd.f64(double %61, double %105, double %59)
%107 = load double*, double** %5
%108 = load i32, i32* %7
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds double, double* %107, i64 %109
store double %106, double* %110
%111 = load double*, double** %6
%112 = load i32, i32* %7
%113 = sext i32 %112 to i64
%114 = getelementptr inbounds double, double* %111, i64 %113
%115 = load double, double* %114
%116 = load double*, double** %5
%117 = load i32, i32* %7
%118 = sext i32 %117 to i64
%119 = getelementptr inbounds double, double* %116, i64 %118
%120 = load double, double* %119
%121 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), double %115, double %120)
br label %122
122: ; preds = %53
%123 = load i32, i32* %7
%124 = add nsw i32 %123, 1
store i32 %124, i32* %7
br label %49
125: ; preds = %49
ret void
}

LLVM IR (-O2):
@.str.1 = [15 x i8] c"Entre com x0: \00"
@.str.2 = [4 x i8] c"%lf\00"
@.str.3 = [18 x i8] c"Entre com y(x0): \00"
@.str.5 = [14 x i8] c"y(%lf) = %lf\0A\00"
@str = [19 x i8] c"\0AValores Iniciais:\00"
@str.6 = [11 x i8] c"\0AIteracoes\00"
define void @Runge_Kutta_2(double %0, i32 %1) {
%3 = add i32 %1, 1
%4 = tail call i64 @calloc(i32 %3, i32 8)
%5 = inttoptr i64 %4 to double*
%6 = tail call i64 @calloc(i32 %3, i32 8)
%7 = inttoptr i64 %6 to double*
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %7)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%12 = tail call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %5)
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.6, i64 0, i64 0))
%14 = icmp slt i32 %1, 1
br i1 %14, label %91, label %15
15: ; preds = %2
%16 = zext i32 %3 to i64
%17 = load double, double* %7
%18 = add nsw i64 %16, -1
%19 = add nsw i64 %16, -2
%20 = and i64 %18, 3
%21 = icmp ult i64 %19, 3
br i1 %21, label %24, label %22
22: ; preds = %15
%23 = and i64 %18, -4
br label %43
24: ; preds = %43, %15
%25 = phi double [ %17, %15 ], [ %65, %43 ]
%26 = phi i64 [ 1, %15 ], [ %66, %43 ]
%27 = icmp eq i64 %20, 0
br i1 %27, label %39, label %28
28: ; preds = %24, %28
%29 = phi double [ %35, %28 ], [ %25, %24 ]
%30 = phi i64 [ %36, %28 ], [ %26, %24 ]
%31 = phi i64 [ %37, %28 ], [ 0, %24 ]
%32 = fadd double %29, %0
%33 = getelementptr inbounds double, double* %7, i64 %30
%34 = load double, double* %33
%35 = fadd double %34, %32
store double %35, double* %33
%36 = add nuw nsw i64 %30, 1
%37 = add i64 %31, 1
%38 = icmp eq i64 %37, %20
br i1 %38, label %39, label %28
39: ; preds = %28, %24
br i1 %14, label %91, label %40
40: ; preds = %39
%41 = fmul double %0, 5.000000e-01
%42 = zext i32 %3 to i64
br label %69
43: ; preds = %43, %22
%44 = phi double [ %17, %22 ], [ %65, %43 ]
%45 = phi i64 [ 1, %22 ], [ %66, %43 ]
%46 = phi i64 [ 0, %22 ], [ %67, %43 ]
%47 = fadd double %44, %0
%48 = getelementptr inbounds double, double* %7, i64 %45
%49 = load double, double* %48
%50 = fadd double %49, %47
store double %50, double* %48
%51 = add nuw nsw i64 %45, 1
%52 = fadd double %50, %0
%53 = getelementptr inbounds double, double* %7, i64 %51
%54 = load double, double* %53
%55 = fadd double %54, %52
store double %55, double* %53
%56 = add nuw nsw i64 %45, 2
%57 = fadd double %55, %0
%58 = getelementptr inbounds double, double* %7, i64 %56
%59 = load double, double* %58
%60 = fadd double %59, %57
store double %60, double* %58
%61 = add nuw nsw i64 %45, 3
%62 = fadd double %60, %0
%63 = getelementptr inbounds double, double* %7, i64 %61
%64 = load double, double* %63
%65 = fadd double %64, %62
store double %65, double* %63
%66 = add nuw nsw i64 %45, 4
%67 = add i64 %46, 4
%68 = icmp eq i64 %67, %23
br i1 %68, label %24, label %43
69: ; preds = %40, %69
%70 = phi i64 [ 1, %40 ], [ %89, %69 ]
%71 = add nsw i64 %70, -1
%72 = getelementptr inbounds double, double* %5, i64 %71
%73 = load double, double* %72
%74 = getelementptr inbounds double, double* %7, i64 %71
%75 = load double, double* %74
%76 = tail call double @f(double %75, double %73)
%77 = load double, double* %74
%78 = fadd double %77, %0
%79 = load double, double* %72
%80 = tail call double @f(double %77, double %79)
%81 = tail call double @llvm.fmuladd.f64(double %0, double %80, double %79)
%82 = tail call double @f(double %78, double %81)
%83 = fadd double %76, %82
%84 = tail call double @llvm.fmuladd.f64(double %41, double %83, double %73)
%85 = getelementptr inbounds double, double* %5, i64 %70
store double %84, double* %85
%86 = getelementptr inbounds double, double* %7, i64 %70
%87 = load double, double* %86
%88 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), double %87, double %84)
%89 = add nuw nsw i64 %70, 1
%90 = icmp eq i64 %89, %42
br i1 %90, label %91, label %69
91: ; preds = %69, %2, %39
ret void
}