#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);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, float *);
main() {
  float x;
  float h;
  float fx;
  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);
  fx = f(x);
  D = 1.0 / (2 * h) * (f(x - 2 * h) - 4 * f(x - h) + 3 * f(x));
  printf("\nO valor de f(x) é %f", fx);
  printf("\nO valor da derivada é %f", D);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xecd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf15(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1050 <scanf@plt>
lea    0xed9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xef7(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
movss  -0x4(%rbp),%xmm0
call   1030 <f@plt>
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  0xe79(%rip),%xmm0
mulss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe60(%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  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe35(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe35(%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    0xeee(%rip),%rdi
call   1030 <puts@plt>
lea    0xec4(%rip),%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
lea    0xef7(%rip),%rdi
call   1030 <puts@plt>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
movss  0x8(%rsp),%xmm0
call   1040 <f@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  %xmm0,0x1c(%rsp)
movss  0xc(%rsp),%xmm1
addss  %xmm1,%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
movsd  0xe51(%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
movss  %xmm0,0x10(%rsp)
movss  0x1c(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdf0(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movss  0x10(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdef(%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 = [23 x i8] c"\0AO valor de f(x) \C3\A9 %f\00"
@.str.4 = [27 x i8] c"\0AO valor da derivada \C3\A9 %f\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* %1
%10 = call i32 @f(float %9)
%11 = sitofp i32 %10 to float
store float %11, float* %3
%12 = load float, float* %2
%13 = fmul float 2.000000e+00, %12
%14 = fpext float %13 to double
%15 = fdiv double 1.000000e+00, %14
%16 = load float, float* %1
%17 = load float, float* %2
%18 = call float @llvm.fmuladd.f32(float -2.000000e+00, float %17, float %16)
%19 = call i32 @f(float %18)
%20 = load float, float* %1
%21 = load float, float* %2
%22 = fsub float %20, %21
%23 = call i32 @f(float %22)
%24 = mul nsw i32 4, %23
%25 = sub nsw i32 %19, %24
%26 = load float, float* %1
%27 = call i32 @f(float %26)
%28 = mul nsw i32 3, %27
%29 = add nsw i32 %25, %28
%30 = sitofp i32 %29 to double
%31 = fmul double %15, %30
%32 = fptrunc double %31 to float
store float %32, float* %4
%33 = load float, float* %3
%34 = fpext float %33 to double
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), double %34)
%36 = load float, float* %4
%37 = fpext float %36 to double
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), double %37)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%f\00"
@.str.3 = [23 x i8] c"\0AO valor de f(x) \C3\A9 %f\00"
@.str.4 = [27 x i8] c"\0AO valor da derivada \C3\A9 %f\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* %1
%10 = call i32 @f(float %9)
%11 = sitofp i32 %10 to float
%12 = load float, float* %2
%13 = fmul float %12, 2.000000e+00
%14 = fpext float %13 to double
%15 = fdiv double 1.000000e+00, %14
%16 = load float, float* %1
%17 = call float @llvm.fmuladd.f32(float %12, float -2.000000e+00, float %16)
%18 = call i32 @f(float %17)
%19 = load float, float* %1
%20 = load float, float* %2
%21 = fsub float %19, %20
%22 = call i32 @f(float %21)
%23 = mul i32 %22, -4
%24 = add i32 %23, %18
%25 = load float, float* %1
%26 = call i32 @f(float %25)
%27 = mul nsw i32 %26, 3
%28 = add nsw i32 %24, %27
%29 = sitofp i32 %28 to double
%30 = fmul double %15, %29
%31 = fptrunc double %30 to float
%32 = fpext float %11 to double
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), double %32)
%34 = fpext float %31 to double
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), double %34)
ret i32 0
}