#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 */
typedef double x;

/* Variables and functions */
double f2_dashed2(double);
double sqrt(double);
void hillcar_f(double *state, double action, double *f) {
  double x, q, p, acc;
  x = state[0];
  q = (((x) < 0.0) ? (2.0 * (x) + 1.0) : f2_dashed2(x));
  p = 1.0 + (q * q);
  acc = (action / (1.0 * sqrt(p))) - (9.81 * q / p);
  f[0] = state[1];
  f[1] = acc;
}


x86 assembly (clang, -O0):
<hillcar_f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    116f <hillcar_f+0x4f>
movsd  -0x20(%rbp),%xmm0
addsd  %xmm0,%xmm0
movsd  0xe9f(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    117e <hillcar_f+0x5e>
movsd  -0x20(%rbp),%xmm0
call   1040 <f2_dashed2@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe62(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1030 <sqrt@plt>
movaps %xmm0,%xmm2
movsd  -0x48(%rbp),%xmm0
movsd  0xe35(%rip),%xmm1
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  0xe2d(%rip),%xmm1
mulsd  -0x28(%rbp),%xmm1
divsd  -0x30(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x38(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x8(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hillcar_f>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
movsd  %xmm0,0x10(%rsp)
mov    %rdi,%rbx
movsd  (%rdi),%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm2,%xmm0
jbe    114f <hillcar_f+0x2f>
addsd  %xmm2,%xmm2
addsd  0xeb3(%rip),%xmm2
jmp    115c <hillcar_f+0x3c>
movapd %xmm2,%xmm0
call   1040 <f2_dashed2@plt>
movapd %xmm0,%xmm2
movapd %xmm2,%xmm3
mulsd  %xmm2,%xmm3
addsd  0xe94(%rip),%xmm3
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm3
jb     117f <hillcar_f+0x5f>
xorps  %xmm0,%xmm0
sqrtsd %xmm3,%xmm0
jmp    119e <hillcar_f+0x7e>
movapd %xmm3,%xmm0
movsd  %xmm2,0x8(%rsp)
movsd  %xmm3,(%rsp)
call   1030 <sqrt@plt>
movsd  (%rsp),%xmm3
movsd  0x8(%rsp),%xmm2
movsd  0x10(%rsp),%xmm1
divsd  %xmm0,%xmm1
mulsd  0xe58(%rip),%xmm2
divsd  %xmm3,%xmm2
addsd  %xmm1,%xmm2
movsd  0x8(%rbx),%xmm0
movsd  %xmm0,(%r14)
movsd  %xmm2,0x8(%r14)
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @hillcar_f(double* %0, double %1, double* %2) {
%4 = alloca double*
%5 = alloca double
%6 = alloca double*
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
store double* %0, double** %4
store double %1, double* %5
store double* %2, double** %6
%11 = load double*, double** %4
%12 = getelementptr inbounds double, double* %11, i64 0
%13 = load double, double* %12
store double %13, double* %7
%14 = load double, double* %7
%15 = fcmp olt double %14, 0.000000e+00
br i1 %15, label %16, label %19
16: ; preds = %3
%17 = load double, double* %7
%18 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %17, double 1.000000e+00)
br label %22
19: ; preds = %3
%20 = load double, double* %7
%21 = call double @f2_dashed2(double %20)
br label %22
22: ; preds = %19, %16
%23 = phi double [ %18, %16 ], [ %21, %19 ]
store double %23, double* %8
%24 = load double, double* %8
%25 = load double, double* %8
%26 = call double @llvm.fmuladd.f64(double %24, double %25, double 1.000000e+00)
store double %26, double* %9
%27 = load double, double* %5
%28 = load double, double* %9
%29 = call double @sqrt(double %28)
%30 = fmul double 1.000000e+00, %29
%31 = fdiv double %27, %30
%32 = load double, double* %8
%33 = fmul double 9.810000e+00, %32
%34 = load double, double* %9
%35 = fdiv double %33, %34
%36 = fsub double %31, %35
store double %36, double* %10
%37 = load double*, double** %4
%38 = getelementptr inbounds double, double* %37, i64 1
%39 = load double, double* %38
%40 = load double*, double** %6
%41 = getelementptr inbounds double, double* %40, i64 0
store double %39, double* %41
%42 = load double, double* %10
%43 = load double*, double** %6
%44 = getelementptr inbounds double, double* %43, i64 1
store double %42, double* %44
ret void
}

LLVM IR (-O2):
define void @hillcar_f(double* nocapture %0, double %1, double* nocapture writeonly %2) {
%4 = load double, double* %0
%5 = fcmp olt double %4, 0.000000e+00
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call double @llvm.fmuladd.f64(double %4, double 2.000000e+00, double 1.000000e+00)
br label %10
8: ; preds = %3
%9 = tail call double @f2_dashed2(double %4)
br label %10
10: ; preds = %8, %6
%11 = phi double [ %7, %6 ], [ %9, %8 ]
%12 = tail call double @llvm.fmuladd.f64(double %11, double %11, double 1.000000e+00)
%13 = tail call double @sqrt(double %12)
%14 = fdiv double %1, %13
%15 = fmul double %11, 9.810000e+00
%16 = fdiv double %15, %12
%17 = fsub double %14, %16
%18 = getelementptr inbounds double, double* %0, i64 1
%19 = load double, double* %18
store double %19, double* %2
%20 = getelementptr inbounds double, double* %2, i64 1
store double %17, double* %20
ret void
}