#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(float);
float fabs(double);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, float *);
main() {
  float x;
  float h;
  float erroA;
  float D;
  printf("Digite o valor de 'x' para ser derivado:\n");
  scanf("%f", &x);
  printf("Digite o valor de 'h':\n");
  scanf("%f", &h);
  D = 1.0 / (2 * h) * (f(x + h) - f(x - h));
  erroA = fabs(22.167168 - D);
  printf("\nO valor da derivada é %f", D);
  printf("\nO valor do erro absoluto é %f\n", erroA);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf11(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1060 <scanf@plt>
lea    0xed1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xef3(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
movss  0xe84(%rip),%xmm0
mulss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe6b(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movss  -0x4(%rbp),%xmm0
addss  -0x8(%rbp),%xmm0
call   1030 <f@plt>
movsd  %xmm0,-0x20(%rbp)
movss  -0x4(%rbp),%xmm0
subss  -0x8(%rbp),%xmm0
call   1030 <f@plt>
movsd  -0x20(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x18(%rbp),%xmm0
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe08(%rip),%xmm0
subsd  %xmm1,%xmm0
call   1050 <fabs@plt>
movss  %xmm0,-0xc(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe40(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe44(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
lea    0xef0(%rip),%rdi
call   1030 <puts@plt>
lea    0xec0(%rip),%rbx
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <scanf@plt>
lea    0xef9(%rip),%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <scanf@plt>
movss  0x8(%rsp),%xmm0
movaps %xmm0,%xmm1
addss  %xmm0,%xmm1
cvtss2sd %xmm1,%xmm1
movsd  0xe59(%rip),%xmm2
divsd  %xmm1,%xmm2
movsd  %xmm2,0x18(%rsp)
addss  0xc(%rsp),%xmm0
call   1040 <f@plt>
movsd  %xmm0,0x10(%rsp)
movss  0xc(%rsp),%xmm0
subss  0x8(%rsp),%xmm0
call   1040 <f@plt>
movsd  0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
mulsd  0x18(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
movsd  0xe09(%rip),%xmm0
subsd  %xmm1,%xmm0
call   1060 <fabs@plt>
movss  %xmm0,0x10(%rsp)
lea    0xdfb(%rip),%rdi
movsd  0x18(%rsp),%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
movss  0x10(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdf8(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [42 x i8] c"Digite o valor de 'x' para ser derivado:\0A\00"
@.str.1 = [3 x i8] c"%f\00"
@.str.2 = [24 x i8] c"Digite o valor de 'h':\0A\00"
@.str.3 = [27 x i8] c"\0AO valor da derivada \C3\A9 %f\00"
@.str.4 = [33 x i8] c"\0AO valor do erro absoluto \C3\A9 %f\0A\00"
define i32 @main() {
%1 = alloca float
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %1)
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %2)
%9 = load float, float* %2
%10 = fmul float 2.000000e+00, %9
%11 = fpext float %10 to double
%12 = fdiv double 1.000000e+00, %11
%13 = load float, float* %1
%14 = load float, float* %2
%15 = fadd float %13, %14
%16 = call double @f(float %15)
%17 = load float, float* %1
%18 = load float, float* %2
%19 = fsub float %17, %18
%20 = call double @f(float %19)
%21 = fsub double %16, %20
%22 = fmul double %12, %21
%23 = fptrunc double %22 to float
store float %23, float* %4
%24 = load float, float* %4
%25 = fpext float %24 to double
%26 = fsub double 0x40362ACB85A4F00F, %25
%27 = call float @fabs(double %26)
store float %27, float* %3
%28 = load float, float* %4
%29 = fpext float %28 to double
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), double %29)
%31 = load float, float* %3
%32 = fpext float %31 to double
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), double %32)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%f\00"
@.str.3 = [27 x i8] c"\0AO valor da derivada \C3\A9 %f\00"
@.str.4 = [33 x i8] c"\0AO valor do erro absoluto \C3\A9 %f\0A\00"
@str = [41 x i8] c"Digite o valor de 'x' para ser derivado:\00"
@str.5 = [23 x i8] c"Digite o valor de 'h':\00"
define i32 @main() {
%1 = alloca float
%2 = alloca float
%3 = bitcast float* %1 to i8*
%4 = bitcast float* %2 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %1)
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.5, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %2)
%9 = load float, float* %2
%10 = fmul float %9, 2.000000e+00
%11 = fpext float %10 to double
%12 = fdiv double 1.000000e+00, %11
%13 = load float, float* %1
%14 = fadd float %9, %13
%15 = call double @f(float %14)
%16 = load float, float* %1
%17 = load float, float* %2
%18 = fsub float %16, %17
%19 = call double @f(float %18)
%20 = fsub double %15, %19
%21 = fmul double %12, %20
%22 = fptrunc double %21 to float
%23 = fpext float %22 to double
%24 = fsub double 0x40362ACB85A4F00F, %23
%25 = call float @fabs(double %24)
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), double %23)
%27 = fpext float %25 to double
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), double %27)
ret i32 0
}