#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() {
  int i, n;
  float x0, y0, x, y, h;
  printf("Enter x0 y0 x and h: ");
  scanf("%f %f %f %f", &x0, &y0, &x, &h);
  n = (x - x0) / h;
  x = x0;
  y = y0;
  for (i = 0; i <= n; i++) {
    y += h * f(x, y);
    x = x + h;
  }
  printf("The Result is: %f", y);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec2(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x18(%rbp),%rcx
lea    -0x20(%rbp),%r8
call   1050 <scanf@plt>
movss  -0x18(%rbp),%xmm0
subss  -0x10(%rbp),%xmm0
divss  -0x20(%rbp),%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0xc(%rbp)
movss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11f6 <main+0xc6>
movss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x18(%rbp),%xmm0
movss  -0x1c(%rbp),%xmm1
call   1030 <f@plt>
movaps %xmm0,%xmm2
movss  -0x24(%rbp),%xmm0
movss  -0x1c(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x18(%rbp),%xmm0
addss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    119a <main+0x6a>
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe1c(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
lea    0xec4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xecc(%rip),%rdi
lea    0x1c(%rsp),%rsi
lea    0x18(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0x10(%rsp),%r8
call   1050 <scanf@plt>
movss  0x8(%rsp),%xmm1
movss  0x1c(%rsp),%xmm0
subss  %xmm0,%xmm1
movss  0x10(%rsp),%xmm2
divss  %xmm2,%xmm1
cvttss2si %xmm1,%ebx
movss  %xmm0,0x8(%rsp)
movss  0x18(%rsp),%xmm1
test   %ebx,%ebx
js     11e2 <main+0xb2>
add    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movss  %xmm2,0x14(%rsp)
movss  %xmm1,0xc(%rsp)
movss  0xc(%rsp),%xmm1
call   1030 <f@plt>
movss  0xc(%rsp),%xmm1
mulss  0x14(%rsp),%xmm0
addss  %xmm0,%xmm1
movss  0x10(%rsp),%xmm2
movss  0x8(%rsp),%xmm0
addss  %xmm2,%xmm0
movss  %xmm0,0x8(%rsp)
add    $0xffffffff,%ebx
jne    11a0 <main+0x70>
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
lea    0xe32(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    $0x1,%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 = [18 x i8] c"The Result is: %f\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca float
store i32 0, i32* %1
%9 = call i32 (i8*, ...) @printf(i8* 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* %4, float* %5, float* %6, float* %8)
%11 = load float, float* %6
%12 = load float, float* %4
%13 = fsub float %11, %12
%14 = load float, float* %8
%15 = fdiv float %13, %14
%16 = fptosi float %15 to i32
store i32 %16, i32* %3
%17 = load float, float* %4
store float %17, float* %6
%18 = load float, float* %5
store float %18, float* %7
store i32 0, i32* %2
br label %19
19: ; preds = %33, %0
%20 = load i32, i32* %2
%21 = load i32, i32* %3
%22 = icmp sle i32 %20, %21
br i1 %22, label %23, label %36
23: ; preds = %19
%24 = load float, float* %8
%25 = load float, float* %6
%26 = load float, float* %7
%27 = call float @f(float %25, float %26)
%28 = load float, float* %7
%29 = call float @llvm.fmuladd.f32(float %24, float %27, float %28)
store float %29, float* %7
%30 = load float, float* %6
%31 = load float, float* %8
%32 = fadd float %30, %31
store float %32, float* %6
br label %33
33: ; preds = %23
%34 = load i32, i32* %2
%35 = add nsw i32 %34, 1
store i32 %35, i32* %2
br label %19
36: ; preds = %19
%37 = load float, float* %7
%38 = fpext float %37 to double
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), double %38)
ret i32 1
}

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 = [18 x i8] c"The Result is: %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* %3, float* %4)
%11 = load float, float* %3
%12 = load float, float* %1
%13 = fsub float %11, %12
%14 = load float, float* %4
%15 = fdiv float %13, %14
%16 = fptosi float %15 to i32
store float %12, float* %3
%17 = load float, float* %2
%18 = icmp slt i32 %16, 0
br i1 %18, label %31, label %19
19: ; preds = %0, %19
%20 = phi float [ %28, %19 ], [ %12, %0 ]
%21 = phi float [ %27, %19 ], [ %14, %0 ]
%22 = phi float [ %25, %19 ], [ %17, %0 ]
%23 = phi i32 [ %29, %19 ], [ 0, %0 ]
%24 = call float @f(float %20, float %22)
%25 = call float @llvm.fmuladd.f32(float %21, float %24, float %22)
%26 = load float, float* %3
%27 = load float, float* %4
%28 = fadd float %26, %27
store float %28, float* %3
%29 = add nuw i32 %23, 1
%30 = icmp eq i32 %23, %16
br i1 %30, label %31, label %19
31: ; preds = %19, %0
%32 = phi float [ %17, %0 ], [ %25, %19 ]
%33 = fpext float %32 to double
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), double %33)
ret i32 1
}