#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 */
float f(float, float);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, float *, float *, float *, float *);
int main() {
  float x0, y0, h, x, k1, k2;
  int i;
  printf("Enter x0 y0 x and h: ");
  scanf("%f %f %f %f", &x0, &y0, &x, &h);
  int n = (x - x0) / h;
  for (i = 0; i <= n; i++) {
    k1 = h * f(x0, y0);
    k2 = h * f(x0 + h, y0 + k1);
    y0 += (k1 + k2) / 2;
    x0 += h;
  }
  printf("Result: %f", y0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec6(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x14(%rbp),%rcx
lea    -0x10(%rbp),%r8
call   1050 <scanf@plt>
movss  -0x14(%rbp),%xmm0
subss  -0x8(%rbp),%xmm0
divss  -0x10(%rbp),%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jg     122d <main+0xfd>
movss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x8(%rbp),%xmm0
movss  -0xc(%rbp),%xmm1
call   1030 <f@plt>
movaps %xmm0,%xmm1
movss  -0x2c(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x28(%rbp)
movss  -0x8(%rbp),%xmm0
addss  -0x10(%rbp),%xmm0
movss  -0xc(%rbp),%xmm1
addss  -0x18(%rbp),%xmm1
call   1030 <f@plt>
movaps %xmm0,%xmm1
movss  -0x28(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x18(%rbp),%xmm0
addss  -0x1c(%rbp),%xmm0
movss  0xdfe(%rip),%xmm1
divss  %xmm1,%xmm0
addss  -0xc(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0x10(%rbp),%xmm0
addss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x8(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1186 <main+0x56>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xde9(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
lea    0xec8(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed0(%rip),%rdi
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x1c(%rsp),%rcx
lea    0x14(%rsp),%r8
call   1050 <scanf@plt>
movss  0x1c(%rsp),%xmm1
movss  0xc(%rsp),%xmm0
subss  %xmm0,%xmm1
movss  0x14(%rsp),%xmm2
divss  %xmm2,%xmm1
cvttss2si %xmm1,%ebx
movss  0x8(%rsp),%xmm1
test   %ebx,%ebx
js     121d <main+0xed>
add    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movss  %xmm2,0x10(%rsp)
call   1030 <f@plt>
movaps %xmm0,%xmm2
mulss  0x10(%rsp),%xmm2
movss  %xmm2,0x18(%rsp)
movss  0x14(%rsp),%xmm1
movss  %xmm1,0x10(%rsp)
movss  0xc(%rsp),%xmm0
addss  %xmm1,%xmm0
movss  0x8(%rsp),%xmm1
addss  %xmm2,%xmm1
call   1030 <f@plt>
movaps %xmm0,%xmm1
mulss  0x10(%rsp),%xmm1
addss  0x18(%rsp),%xmm1
mulss  0xe0a(%rip),%xmm1
addss  0x8(%rsp),%xmm1
movss  %xmm1,0x8(%rsp)
movss  0x14(%rsp),%xmm2
movss  0xc(%rsp),%xmm0
addss  %xmm2,%xmm0
movss  %xmm0,0xc(%rsp)
add    $0xffffffff,%ebx
jne    11a0 <main+0x70>
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
lea    0xdfb(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Enter x0 y0 x and h: \00"
@.str.1 = [12 x i8] c"%f %f %f %f\00"
@.str.2 = [11 x i8] c"Result: %f\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), float* %2, float* %3, float* %5, float* %4)
%12 = load float, float* %5
%13 = load float, float* %2
%14 = fsub float %12, %13
%15 = load float, float* %4
%16 = fdiv float %14, %15
%17 = fptosi float %16 to i32
store i32 %17, i32* %9
store i32 0, i32* %8
br label %18
18: ; preds = %46, %0
%19 = load i32, i32* %8
%20 = load i32, i32* %9
%21 = icmp sle i32 %19, %20
br i1 %21, label %22, label %49
22: ; preds = %18
%23 = load float, float* %4
%24 = load float, float* %2
%25 = load float, float* %3
%26 = call float @f(float %24, float %25)
%27 = fmul float %23, %26
store float %27, float* %6
%28 = load float, float* %4
%29 = load float, float* %2
%30 = load float, float* %4
%31 = fadd float %29, %30
%32 = load float, float* %3
%33 = load float, float* %6
%34 = fadd float %32, %33
%35 = call float @f(float %31, float %34)
%36 = fmul float %28, %35
store float %36, float* %7
%37 = load float, float* %6
%38 = load float, float* %7
%39 = fadd float %37, %38
%40 = fdiv float %39, 2.000000e+00
%41 = load float, float* %3
%42 = fadd float %41, %40
store float %42, float* %3
%43 = load float, float* %4
%44 = load float, float* %2
%45 = fadd float %44, %43
store float %45, float* %2
br label %46
46: ; preds = %22
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 1
store i32 %48, i32* %8
br label %18
49: ; preds = %18
%50 = load float, float* %3
%51 = fpext float %50 to double
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), double %51)
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"Enter x0 y0 x and h: \00"
@.str.1 = [12 x i8] c"%f %f %f %f\00"
@.str.2 = [11 x i8] c"Result: %f\00"
define i32 @main() {
%1 = alloca float
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = bitcast float* %1 to i8*
%6 = bitcast float* %2 to i8*
%7 = bitcast float* %3 to i8*
%8 = bitcast float* %4 to i8*
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), float* %1, float* %2, float* %4, float* %3)
%11 = load float, float* %4
%12 = load float, float* %1
%13 = fsub float %11, %12
%14 = load float, float* %3
%15 = fdiv float %13, %14
%16 = fptosi float %15 to i32
%17 = icmp slt i32 %16, 0
%18 = load float, float* %2
br i1 %17, label %42, label %19
19: ; preds = %0, %19
%20 = phi float [ %36, %19 ], [ %18, %0 ]
%21 = phi float [ %39, %19 ], [ %12, %0 ]
%22 = phi float [ %37, %19 ], [ %14, %0 ]
%23 = phi i32 [ %40, %19 ], [ 0, %0 ]
%24 = call float @f(float %21, float %20)
%25 = fmul float %22, %24
%26 = load float, float* %3
%27 = load float, float* %1
%28 = fadd float %26, %27
%29 = load float, float* %2
%30 = fadd float %25, %29
%31 = call float @f(float %28, float %30)
%32 = fmul float %26, %31
%33 = fadd float %25, %32
%34 = fmul float %33, 5.000000e-01
%35 = load float, float* %2
%36 = fadd float %35, %34
store float %36, float* %2
%37 = load float, float* %3
%38 = load float, float* %1
%39 = fadd float %37, %38
store float %39, float* %1
%40 = add nuw i32 %23, 1
%41 = icmp eq i32 %23, %16
br i1 %41, label %42, label %19
42: ; preds = %19, %0
%43 = phi float [ %18, %0 ], [ %36, %19 ]
%44 = fpext float %43 to double
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), double %44)
ret i32 0
}