#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);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, double *);
main() {
  int j;
  double h, x0, y, xf;
  printf("Escolha o passo de integração: ");
  scanf("%lf", &h);
  printf("\nInforme o valor inicial x0: ");
  scanf("%lf", &x0);
  printf("\nInforme o valor inicial y(x0):");
  scanf("%lf", &y);
  printf("   X        Y   \n");
  j = 0;
  while (x0 <= 40.0) {
    j++;
    x0 = x0 + h;
    y = y + h * f(y);
    printf("%d  %lf   %lf   \n", j, x0, y);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xed6(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <scanf@plt>
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb8(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <scanf@plt>
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe9a(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <scanf@plt>
lea    0xecc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x8(%rbp)
movsd  0xe4a(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     1231 <main+0x101>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
movsd  -0x18(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <f@plt>
movsd  -0x38(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%esi
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
lea    0xe59(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
jmp    11ae <main+0x7e>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
lea    0xeba(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xece(%rip),%rbx
lea    0x20(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
lea    0xebe(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
lea    0xec3(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
lea    0xeda(%rip),%rdi
call   1030 <puts@plt>
movsd  (%rsp),%xmm0
movsd  0xe4a(%rip),%xmm1
ucomisd %xmm0,%xmm1
jb     1233 <main+0xf3>
mov    $0x1,%ebx
lea    0xea4(%rip),%r14
nopl   0x0(%rax,%rax,1)
movsd  0x20(%rsp),%xmm1
movsd  %xmm1,0x18(%rsp)
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
call   1040 <f@plt>
movsd  0x18(%rsp),%xmm1
mulsd  %xmm0,%xmm1
addsd  0x10(%rsp),%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  (%rsp),%xmm0
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x2,%al
call   1050 <printf@plt>
movsd  0xddb(%rip),%xmm1
movsd  (%rsp),%xmm0
add    $0x1,%ebx
ucomisd %xmm0,%xmm1
jae    11d0 <main+0x90>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [34 x i8] c"Escolha o passo de integra\C3\A7\C3\A3o: \00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [30 x i8] c"\0AInforme o valor inicial x0: \00"
@.str.3 = [32 x i8] c"\0AInforme o valor inicial y(x0):\00"
@.str.4 = [18 x i8] c" X Y \0A\00"
@.str.5 = [18 x i8] c"%d %lf %lf \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %3)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %4)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %5)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %2
br label %14
14: ; preds = %17, %0
%15 = load double, double* %4
%16 = fcmp ole double %15, 4.000000e+01
br i1 %16, label %17, label %32
17: ; preds = %14
%18 = load i32, i32* %2
%19 = add nsw i32 %18, 1
store i32 %19, i32* %2
%20 = load double, double* %4
%21 = load double, double* %3
%22 = fadd double %20, %21
store double %22, double* %4
%23 = load double, double* %5
%24 = load double, double* %3
%25 = load double, double* %5
%26 = call double @f(double %25)
%27 = call double @llvm.fmuladd.f64(double %24, double %26, double %23)
store double %27, double* %5
%28 = load i32, i32* %2
%29 = load double, double* %4
%30 = load double, double* %5
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %28, double %29, double %30)
br label %14
32: ; preds = %14
%33 = load i32, i32* %1
ret i32 %33
}

LLVM IR (-O2):
@.str = [34 x i8] c"Escolha o passo de integra\C3\A7\C3\A3o: \00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [30 x i8] c"\0AInforme o valor inicial x0: \00"
@.str.3 = [32 x i8] c"\0AInforme o valor inicial y(x0):\00"
@.str.5 = [18 x i8] c"%d %lf %lf \0A\00"
@str = [17 x i8] c" X Y \00"
define i32 @main() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
%4 = bitcast double* %1 to i8*
%5 = bitcast double* %2 to i8*
%6 = bitcast double* %3 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %1)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %2)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %3)
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%14 = load double, double* %2
%15 = fcmp ugt double %14, 4.000000e+01
br i1 %15, label %29, label %16
16: ; preds = %0, %16
%17 = phi double [ %27, %16 ], [ %14, %0 ]
%18 = phi i32 [ %19, %16 ], [ 0, %0 ]
%19 = add nuw nsw i32 %18, 1
%20 = load double, double* %1
%21 = fadd double %17, %20
store double %21, double* %2
%22 = load double, double* %3
%23 = call double @f(double %22)
%24 = call double @llvm.fmuladd.f64(double %20, double %23, double %22)
store double %24, double* %3
%25 = load double, double* %2
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %19, double %25, double %24)
%27 = load double, double* %2
%28 = fcmp ugt double %27, 4.000000e+01
br i1 %28, label %29, label %16
29: ; preds = %16, %0
ret i32 0
}