#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 asin(int /*<<< orphan*/);
int /*<<< orphan*/ sinth0(double *, double *, void (*)(double *, double *));
double th2in(double *X0, double *X, void (*vofx)(double *, double *)) {
  double V[(4)];
  double V0[(4)];
  double Vc0[(4)];
  double Xc0[(4)];
  double Xcmid[(4)];
  double Vcmid[(4)];
  int j;
  double res;
  double th0;
  for (j = 0; j < (4); j++)
    Xc0[j] = X[j];
  Xc0[2] = X0[2];
  vofx(Xc0, Vc0);
  for (j = 0; j < (4); j++)
    Xcmid[j] = X[j];
  Xcmid[2] = 0;
  vofx(Xcmid, Vcmid);
  vofx(X0, V0);
  vofx(X, V);
  th0 = asin(sinth0(X0, X, vofx));
  res = (V[2] - Vc0[2]) / (Vcmid[2] - Vc0[2]) * (Vcmid[2] - th0) + th0;
  return (res);
}


x86 assembly (clang, -O0):
<th2in>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0xe4(%rbp)
cmpl   $0x4,-0xe4(%rbp)
jge    1182 <th2in+0x62>
mov    -0x10(%rbp),%rax
movslq -0xe4(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movslq -0xe4(%rbp),%rax
movsd  %xmm0,-0xa0(%rbp,%rax,8)
ff ff
mov    -0xe4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xe4(%rbp)
jmp    1141 <th2in+0x21>
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
mov    -0x18(%rbp),%rax
lea    -0xa0(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   *%rax
movl   $0x0,-0xe4(%rbp)
cmpl   $0x4,-0xe4(%rbp)
jge    11ef <th2in+0xcf>
mov    -0x10(%rbp),%rax
movslq -0xe4(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movslq -0xe4(%rbp),%rax
movsd  %xmm0,-0xc0(%rbp,%rax,8)
ff ff
mov    -0xe4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xe4(%rbp)
jmp    11ae <th2in+0x8e>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0xb0(%rbp)
ff
mov    -0x18(%rbp),%rax
lea    -0xc0(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
call   *%rax
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   *%rax
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   *%rax
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <sinth0@plt>
mov    %eax,%edi
call   1040 <asin@plt>
movsd  %xmm0,-0xf8(%rbp)
ff
movsd  -0x30(%rbp),%xmm0
subsd  -0x70(%rbp),%xmm0
movsd  -0xd0(%rbp),%xmm1
ff
subsd  -0x70(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  -0xd0(%rbp),%xmm2
ff
subsd  -0xf8(%rbp),%xmm2
ff
movsd  -0xf8(%rbp),%xmm1
ff
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0xf0(%rbp)
ff
movsd  -0xf0(%rbp),%xmm0
ff
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<th2in>:
push   %r15
push   %r14
push   %rbx
sub    $0xc0,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
movups (%rsi),%xmm0
movups 0x10(%rsi),%xmm1
movaps %xmm0,0x20(%rsp)
movaps %xmm1,0x30(%rsp)
movsd  0x10(%rdi),%xmm0
movsd  %xmm0,0x30(%rsp)
lea    0x20(%rsp),%rdi
lea    0x60(%rsp),%rsi
call   *%rdx
movupd (%rbx),%xmm0
movups 0x10(%rbx),%xmm1
movaps %xmm1,0x10(%rsp)
movapd %xmm0,(%rsp)
movq   $0x0,0x10(%rsp)
mov    %rsp,%rdi
lea    0x40(%rsp),%rsi
call   *%r14
lea    0xa0(%rsp),%rsi
mov    %r15,%rdi
call   *%r14
lea    0x80(%rsp),%rsi
mov    %rbx,%rdi
call   *%r14
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <sinth0@plt>
mov    %eax,%edi
call   1040 <asin@plt>
movsd  0x90(%rsp),%xmm1
movsd  0x70(%rsp),%xmm2
subsd  %xmm2,%xmm1
movsd  0x50(%rsp),%xmm3
movapd %xmm3,%xmm4
subsd  %xmm2,%xmm4
divsd  %xmm4,%xmm1
subsd  %xmm0,%xmm3
mulsd  %xmm1,%xmm3
addsd  %xmm3,%xmm0
add    $0xc0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @th2in(double* %0, double* %1, void (double*, double*)* %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca void (double*, double*)*
%7 = alloca [4 x double]
%8 = alloca [4 x double]
%9 = alloca [4 x double]
%10 = alloca [4 x double]
%11 = alloca [4 x double]
%12 = alloca [4 x double]
%13 = alloca i32
%14 = alloca double
%15 = alloca double
store double* %0, double** %4
store double* %1, double** %5
store void (double*, double*)* %2, void (double*, double*)** %6
store i32 0, i32* %13
br label %16
16: ; preds = %28, %3
%17 = load i32, i32* %13
%18 = icmp slt i32 %17, 4
br i1 %18, label %19, label %31
19: ; preds = %16
%20 = load double*, double** %5
%21 = load i32, i32* %13
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double, double* %20, i64 %22
%24 = load double, double* %23
%25 = load i32, i32* %13
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [4 x double], [4 x double]* %10, i64 0, i64 %26
store double %24, double* %27
br label %28
28: ; preds = %19
%29 = load i32, i32* %13
%30 = add nsw i32 %29, 1
store i32 %30, i32* %13
br label %16
31: ; preds = %16
%32 = load double*, double** %4
%33 = getelementptr inbounds double, double* %32, i64 2
%34 = load double, double* %33
%35 = getelementptr inbounds [4 x double], [4 x double]* %10, i64 0, i64 2
store double %34, double* %35
%36 = load void (double*, double*)*, void (double*, double*)** %6
%37 = getelementptr inbounds [4 x double], [4 x double]* %10, i64 0, i64 0
%38 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 0
store i32 0, i32* %13
br label %39
39: ; preds = %51, %31
%40 = load i32, i32* %13
%41 = icmp slt i32 %40, 4
br i1 %41, label %42, label %54
42: ; preds = %39
%43 = load double*, double** %5
%44 = load i32, i32* %13
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double, double* %43, i64 %45
%47 = load double, double* %46
%48 = load i32, i32* %13
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [4 x double], [4 x double]* %11, i64 0, i64 %49
store double %47, double* %50
br label %51
51: ; preds = %42
%52 = load i32, i32* %13
%53 = add nsw i32 %52, 1
store i32 %53, i32* %13
br label %39
54: ; preds = %39
%55 = getelementptr inbounds [4 x double], [4 x double]* %11, i64 0, i64 2
store double 0.000000e+00, double* %55
%56 = load void (double*, double*)*, void (double*, double*)** %6
%57 = getelementptr inbounds [4 x double], [4 x double]* %11, i64 0, i64 0
%58 = getelementptr inbounds [4 x double], [4 x double]* %12, i64 0, i64 0
%59 = load void (double*, double*)*, void (double*, double*)** %6
%60 = load double*, double** %4
%61 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 0
%62 = load void (double*, double*)*, void (double*, double*)** %6
%63 = load double*, double** %5
%64 = getelementptr inbounds [4 x double], [4 x double]* %7, i64 0, i64 0
%65 = load double*, double** %4
%66 = load double*, double** %5
%67 = load void (double*, double*)*, void (double*, double*)** %6
%68 = call i32 @sinth0(double* %65, double* %66, void (double*, double*)* %67)
%69 = call double @asin(i32 %68)
store double %69, double* %15
%70 = getelementptr inbounds [4 x double], [4 x double]* %7, i64 0, i64 2
%71 = load double, double* %70
%72 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 2
%73 = load double, double* %72
%74 = fsub double %71, %73
%75 = getelementptr inbounds [4 x double], [4 x double]* %12, i64 0, i64 2
%76 = load double, double* %75
%77 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 2
%78 = load double, double* %77
%79 = fsub double %76, %78
%80 = fdiv double %74, %79
%81 = getelementptr inbounds [4 x double], [4 x double]* %12, i64 0, i64 2
%82 = load double, double* %81
%83 = load double, double* %15
%84 = fsub double %82, %83
%85 = load double, double* %15
%86 = call double @llvm.fmuladd.f64(double %80, double %84, double %85)
store double %86, double* %14
%87 = load double, double* %14
ret double %87
}

LLVM IR (-O2):
define double @th2in(double* %0, double* %1, void (double*, double*)* %2) {
%4 = bitcast double* %1 to i8*
%5 = alloca [4 x double]
%6 = alloca [4 x double]
%7 = alloca [4 x double]
%8 = alloca [4 x double]
%9 = bitcast [4 x double]* %8 to i8*
%10 = alloca [4 x double]
%11 = bitcast [4 x double]* %10 to i8*
%12 = alloca [4 x double]
%13 = bitcast [4 x double]* %5 to i8*
%14 = bitcast [4 x double]* %6 to i8*
%15 = bitcast [4 x double]* %7 to i8*
%16 = bitcast [4 x double]* %12 to i8*
%17 = getelementptr inbounds double, double* %0, i64 2
%18 = load double, double* %17
%19 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 2
store double %18, double* %19
%20 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 0
%21 = getelementptr inbounds [4 x double], [4 x double]* %7, i64 0, i64 0
%22 = getelementptr inbounds [4 x double], [4 x double]* %10, i64 0, i64 2
store double 0.000000e+00, double* %22
%23 = getelementptr inbounds [4 x double], [4 x double]* %10, i64 0, i64 0
%24 = getelementptr inbounds [4 x double], [4 x double]* %12, i64 0, i64 0
%25 = getelementptr inbounds [4 x double], [4 x double]* %6, i64 0, i64 0
%26 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 0
%27 = call i32 @sinth0(double* %0, double* %1, void (double*, double*)* %2)
%28 = call double @asin(i32 %27)
%29 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 2
%30 = load double, double* %29
%31 = getelementptr inbounds [4 x double], [4 x double]* %7, i64 0, i64 2
%32 = load double, double* %31
%33 = fsub double %30, %32
%34 = getelementptr inbounds [4 x double], [4 x double]* %12, i64 0, i64 2
%35 = load double, double* %34
%36 = fsub double %35, %32
%37 = fdiv double %33, %36
%38 = fsub double %35, %28
%39 = call double @llvm.fmuladd.f64(double %37, double %38, double %28)
ret double %39
}