#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 */
double f(double, double, int);
void euler(double a, double b, int n, double *w, int func) {
  double h = (b - a) / n;
  int i;
  if (n > 10000)
    return;
  w[0] = 1;
  for (i = 0; i < n; i++) {
    double ti = a + i * h;
    double tnext = a + (i + 1) * h;
    w[i + 1] = w[i] + h / 2 *
                          (f(ti, w[i], func) +
                           f(tnext, w[i] + h * f(ti, w[i], func), func));
  }
}


x86 assembly (clang, -O0):
<euler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %edx,-0x24(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
cmpl   $0x2710,-0x14(%rbp)
jle    1159 <euler+0x49>
jmp    12a0 <euler+0x190>
mov    -0x20(%rbp),%rax
movsd  0xe9b(%rip),%xmm0
movsd  %xmm0,(%rax)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12a0 <euler+0x190>
movsd  -0x8(%rbp),%xmm1
cvtsi2sdl -0x34(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x8(%rbp),%xmm1
mov    -0x34(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  -0x30(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xe30(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x40(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x24(%rbp),%edi
call   1030 <f@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x40(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x24(%rbp),%edi
call   1030 <f@plt>
movsd  -0x78(%rbp),%xmm1
movsd  -0x70(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x68(%rbp),%xmm0
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
mov    -0x24(%rbp),%edi
call   1030 <f@plt>
movsd  -0x60(%rbp),%xmm2
movsd  -0x58(%rbp),%xmm1
movaps %xmm0,%xmm3
movsd  -0x50(%rbp),%xmm0
addsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1170 <euler+0x60>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<euler>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
cmp    $0x2710,%edi
jg     1231 <euler+0x121>
mov    %rsi,%r14
movabs $0x3ff0000000000000,%rax
mov    %rax,(%rsi)
test   %edi,%edi
jle    1231 <euler+0x121>
mov    %edx,%r12d
movapd %xmm0,%xmm2
subsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %edi,%xmm0
divsd  %xmm0,%xmm1
movsd  0xea2(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %edi,%r15d
movsd  0xe95(%rip),%xmm3
xor    %ebx,%ebx
movsd  %xmm1,(%rsp)
movsd  %xmm2,0x10(%rsp)
movsd  %xmm3,0x38(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
mulsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
movsd  %xmm0,0x20(%rsp)
lea    0x1(%rbx),%rbp
xorps  %xmm4,%xmm4
cvtsi2sd %ebp,%xmm4
mulsd  %xmm1,%xmm4
addsd  %xmm2,%xmm4
movsd  %xmm4,0x28(%rsp)
movapd %xmm3,%xmm1
mov    %r12d,%edi
call   1030 <f@plt>
movsd  %xmm0,0x30(%rsp)
movsd  (%r14,%rbx,8),%xmm1
movsd  %xmm1,0x18(%rsp)
movsd  0x20(%rsp),%xmm0
mov    %r12d,%edi
call   1030 <f@plt>
mulsd  (%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  0x28(%rsp),%xmm0
mov    %r12d,%edi
call   1030 <f@plt>
movsd  0x38(%rsp),%xmm3
movsd  0x10(%rsp),%xmm2
movsd  (%rsp),%xmm1
addsd  0x30(%rsp),%xmm0
mulsd  0x8(%rsp),%xmm0
addsd  %xmm0,%xmm3
movsd  %xmm3,0x8(%r14,%rbx,8)
mov    %rbp,%rbx
cmp    %rbp,%r15
jne    1180 <euler+0x70>
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @euler(double %0, double %1, i32 %2, double* %3, i32 %4) {
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca double*
%10 = alloca i32
%11 = alloca double
%12 = alloca i32
%13 = alloca double
%14 = alloca double
store double %0, double* %6
store double %1, double* %7
store i32 %2, i32* %8
store double* %3, double** %9
store i32 %4, i32* %10
%15 = load double, double* %7
%16 = load double, double* %6
%17 = fsub double %15, %16
%18 = load i32, i32* %8
%19 = sitofp i32 %18 to double
%20 = fdiv double %17, %19
store double %20, double* %11
%21 = load i32, i32* %8
%22 = icmp sgt i32 %21, 10000
br i1 %22, label %23, label %24
23: ; preds = %5
br label %86
24: ; preds = %5
%25 = load double*, double** %9
%26 = getelementptr inbounds double, double* %25, i64 0
store double 1.000000e+00, double* %26
store i32 0, i32* %12
br label %27
27: ; preds = %83, %24
%28 = load i32, i32* %12
%29 = load i32, i32* %8
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %86
31: ; preds = %27
%32 = load double, double* %6
%33 = load i32, i32* %12
%34 = sitofp i32 %33 to double
%35 = load double, double* %11
%36 = call double @llvm.fmuladd.f64(double %34, double %35, double %32)
store double %36, double* %13
%37 = load double, double* %6
%38 = load i32, i32* %12
%39 = add nsw i32 %38, 1
%40 = sitofp i32 %39 to double
%41 = load double, double* %11
%42 = call double @llvm.fmuladd.f64(double %40, double %41, double %37)
store double %42, double* %14
%43 = load double*, double** %9
%44 = load i32, i32* %12
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double, double* %43, i64 %45
%47 = load double, double* %46
%48 = load double, double* %11
%49 = fdiv double %48, 2.000000e+00
%50 = load double, double* %13
%51 = load double*, double** %9
%52 = load i32, i32* %12
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds double, double* %51, i64 %53
%55 = load double, double* %54
%56 = load i32, i32* %10
%57 = call double @f(double %50, double %55, i32 %56)
%58 = load double, double* %14
%59 = load double*, double** %9
%60 = load i32, i32* %12
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds double, double* %59, i64 %61
%63 = load double, double* %62
%64 = load double, double* %11
%65 = load double, double* %13
%66 = load double*, double** %9
%67 = load i32, i32* %12
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds double, double* %66, i64 %68
%70 = load double, double* %69
%71 = load i32, i32* %10
%72 = call double @f(double %65, double %70, i32 %71)
%73 = call double @llvm.fmuladd.f64(double %64, double %72, double %63)
%74 = load i32, i32* %10
%75 = call double @f(double %58, double %73, i32 %74)
%76 = fadd double %57, %75
%77 = call double @llvm.fmuladd.f64(double %49, double %76, double %47)
%78 = load double*, double** %9
%79 = load i32, i32* %12
%80 = add nsw i32 %79, 1
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds double, double* %78, i64 %81
store double %77, double* %82
br label %83
83: ; preds = %31
%84 = load i32, i32* %12
%85 = add nsw i32 %84, 1
store i32 %85, i32* %12
br label %27
86: ; preds = %23, %27
ret void
}

LLVM IR (-O2):
define void @euler(double %0, double %1, i32 %2, double* nocapture %3, i32 %4) {
%6 = fsub double %1, %0
%7 = sitofp i32 %2 to double
%8 = fdiv double %6, %7
%9 = icmp sgt i32 %2, 10000
br i1 %9, label %35, label %10
10: ; preds = %5
store double 1.000000e+00, double* %3
%11 = icmp sgt i32 %2, 0
br i1 %11, label %12, label %35
12: ; preds = %10
%13 = fmul double %8, 5.000000e-01
%14 = zext i32 %2 to i64
br label %15
15: ; preds = %12, %15
%16 = phi double [ 1.000000e+00, %12 ], [ %32, %15 ]
%17 = phi i64 [ 0, %12 ], [ %21, %15 ]
%18 = trunc i64 %17 to i32
%19 = sitofp i32 %18 to double
%20 = tail call double @llvm.fmuladd.f64(double %19, double %8, double %0)
%21 = add nuw nsw i64 %17, 1
%22 = trunc i64 %21 to i32
%23 = sitofp i32 %22 to double
%24 = tail call double @llvm.fmuladd.f64(double %23, double %8, double %0)
%25 = getelementptr inbounds double, double* %3, i64 %17
%26 = tail call double @f(double %20, double %16, i32 %4)
%27 = load double, double* %25
%28 = tail call double @f(double %20, double %27, i32 %4)
%29 = tail call double @llvm.fmuladd.f64(double %8, double %28, double %27)
%30 = tail call double @f(double %24, double %29, i32 %4)
%31 = fadd double %26, %30
%32 = tail call double @llvm.fmuladd.f64(double %13, double %31, double %16)
%33 = getelementptr inbounds double, double* %3, i64 %21
store double %32, double* %33
%34 = icmp eq i64 %21, %14
br i1 %34, label %35, label %15
35: ; preds = %15, %10, %5
ret void
}