#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 */
int 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 - 2 * h) - 4 * f(x - h) + 3 * f(x));
  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    $0x30,%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,-0x20(%rbp)
movss  -0x4(%rbp),%xmm0
movss  -0x8(%rbp),%xmm1
addss  %xmm1,%xmm1
subss  %xmm1,%xmm0
call   1030 <f@plt>
mov    %eax,-0x24(%rbp)
movss  -0x4(%rbp),%xmm0
subss  -0x8(%rbp),%xmm0
call   1030 <f@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
shl    $0x2,%ecx
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
movss  -0x4(%rbp),%xmm0
call   1030 <f@plt>
movsd  -0x20(%rbp),%xmm0
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
imul   $0x3,%ecx,%ecx
add    %ecx,%eax
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xde9(%rip),%xmm0
subsd  %xmm1,%xmm0
call   1050 <fabs@plt>
movss  %xmm0,-0xc(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe21(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe25(%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    0xef0(%rip),%rdi
call   1030 <puts@plt>
lea    0xec0(%rip),%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <scanf@plt>
lea    0xef9(%rip),%rdi
call   1030 <puts@plt>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <scanf@plt>
movss  0xc(%rsp),%xmm1
addss  %xmm1,%xmm1
cvtss2sd %xmm1,%xmm0
movsd  0xe5c(%rip),%xmm2
divsd  %xmm0,%xmm2
movsd  %xmm2,0x10(%rsp)
movss  0x8(%rsp),%xmm0
subss  %xmm1,%xmm0
call   1040 <f@plt>
mov    %eax,%ebx
movss  0x8(%rsp),%xmm0
subss  0xc(%rsp),%xmm0
call   1040 <f@plt>
shl    $0x2,%eax
sub    %eax,%ebx
movss  0x8(%rsp),%xmm0
call   1040 <f@plt>
lea    (%rax,%rax,2),%eax
add    %ebx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0x10(%rsp),%xmm0
cvtsd2ss %xmm0,%xmm0
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  0xdfd(%rip),%xmm0
subsd  %xmm1,%xmm0
call   1060 <fabs@plt>
movss  %xmm0,0x1c(%rsp)
lea    0xdef(%rip),%rdi
movsd  0x10(%rsp),%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
movss  0x1c(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdec(%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 = call float @llvm.fmuladd.f32(float -2.000000e+00, float %14, float %13)
%16 = call i32 @f(float %15)
%17 = load float, float* %1
%18 = load float, float* %2
%19 = fsub float %17, %18
%20 = call i32 @f(float %19)
%21 = mul nsw i32 4, %20
%22 = sub nsw i32 %16, %21
%23 = load float, float* %1
%24 = call i32 @f(float %23)
%25 = mul nsw i32 3, %24
%26 = add nsw i32 %22, %25
%27 = sitofp i32 %26 to double
%28 = fmul double %12, %27
%29 = fptrunc double %28 to float
store float %29, float* %4
%30 = load float, float* %4
%31 = fpext float %30 to double
%32 = fsub double 0x40362ACB85A4F00F, %31
%33 = call float @fabs(double %32)
store float %33, float* %3
%34 = load float, float* %4
%35 = fpext float %34 to double
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), double %35)
%37 = load float, float* %3
%38 = fpext float %37 to double
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), double %38)
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 = call float @llvm.fmuladd.f32(float %9, float -2.000000e+00, float %13)
%15 = call i32 @f(float %14)
%16 = load float, float* %1
%17 = load float, float* %2
%18 = fsub float %16, %17
%19 = call i32 @f(float %18)
%20 = mul i32 %19, -4
%21 = add i32 %20, %15
%22 = load float, float* %1
%23 = call i32 @f(float %22)
%24 = mul nsw i32 %23, 3
%25 = add nsw i32 %21, %24
%26 = sitofp i32 %25 to double
%27 = fmul double %12, %26
%28 = fptrunc double %27 to float
%29 = fpext float %28 to double
%30 = fsub double 0x40362ACB85A4F00F, %29
%31 = call float @fabs(double %30)
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), double %29)
%33 = fpext float %31 to double
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), double %33)
ret i32 0
}