#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);
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 + h) - f(x - h));
  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    $0x20,%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>
cvtsd2ss %xmm0,%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,-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  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe54(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe54(%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    0xeee(%rip),%rdi
call   1030 <puts@plt>
lea    0xec4(%rip),%rbx
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
lea    0xef9(%rip),%rdi
call   1030 <puts@plt>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
movss  (%rsp),%xmm0
call   1040 <f@plt>
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x14(%rsp)
movss  0x4(%rsp),%xmm0
movaps %xmm0,%xmm1
addss  %xmm0,%xmm1
cvtss2sd %xmm1,%xmm1
movsd  0xe57(%rip),%xmm2
divsd  %xmm1,%xmm2
movsd  %xmm2,0x8(%rsp)
addss  (%rsp),%xmm0
call   1040 <f@plt>
movsd  %xmm0,0x18(%rsp)
movss  (%rsp),%xmm0
subss  0x4(%rsp),%xmm0
call   1040 <f@plt>
movsd  0x18(%rsp),%xmm1
subsd  %xmm0,%xmm1
mulsd  0x8(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
movss  %xmm0,0x8(%rsp)
movss  0x14(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe07(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movss  0x8(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe06(%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 double @f(float %9)
%11 = fptrunc double %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 = fadd float %16, %17
%19 = call double @f(float %18)
%20 = load float, float* %1
%21 = load float, float* %2
%22 = fsub float %20, %21
%23 = call double @f(float %22)
%24 = fsub double %19, %23
%25 = fmul double %15, %24
%26 = fptrunc double %25 to float
store float %26, float* %4
%27 = load float, float* %3
%28 = fpext float %27 to double
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), double %28)
%30 = load float, float* %4
%31 = fpext float %30 to double
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), double %31)
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 double @f(float %9)
%11 = fptrunc double %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 = fadd float %12, %16
%18 = call double @f(float %17)
%19 = load float, float* %1
%20 = load float, float* %2
%21 = fsub float %19, %20
%22 = call double @f(float %21)
%23 = fsub double %18, %22
%24 = fmul double %15, %23
%25 = fptrunc double %24 to float
%26 = fpext float %11 to double
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), double %26)
%28 = fpext float %25 to double
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), double %28)
ret i32 0
}