#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 M_PI;
int acos(double);
int atan2(double, double);
double sqrt(double);
void texcoord(double t[3], double p[3]) {
  t[0] = (atan2(p[0], p[1]) + M_PI) / (2 * M_PI);
  t[1] = acos(p[2] / sqrt(p[0] * p[0] + p[1] * p[1] + p[2] * p[2])) / M_PI;
  t[2] = 0;
}


x86 assembly (clang, -O0):
<texcoord>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm1
call   1030 <atan2@plt>
mov    0x2e8b(%rip),%rcx
add    (%rcx),%eax
mov    0x2e82(%rip),%rcx
mov    (%rcx),%ecx
shl    $0x1,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
divsd  %xmm1,%xmm0
call   1040 <acos@plt>
mov    0x2dff(%rip),%rcx
cltd
idivl  (%rcx)
cvtsi2sd %eax,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,0x10(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<texcoord>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
movsd  (%rsi),%xmm0
movsd  0x8(%rsi),%xmm1
call   1030 <atan2@plt>
mov    0x2e94(%rip),%r15
mov    (%r15),%ecx
add    %ecx,%eax
add    %ecx,%ecx
cltd
idiv   %ecx
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,(%r14)
movsd  0x10(%rbx),%xmm2
movsd  (%rbx),%xmm1
movsd  0x8(%rbx),%xmm0
mulsd  %xmm0,%xmm0
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movapd %xmm2,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11a0 <texcoord+0x70>
sqrtsd %xmm0,%xmm0
jmp    11b1 <texcoord+0x81>
movsd  %xmm2,0x8(%rsp)
call   1050 <sqrt@plt>
movsd  0x8(%rsp),%xmm2
divsd  %xmm0,%xmm2
movapd %xmm2,%xmm0
call   1040 <acos@plt>
cltd
idivl  (%r15)
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x8(%r14)
movq   $0x0,0x10(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@M_PI = global i32 0
define void @texcoord(double* %0, double* %1) {
%3 = alloca double*
%4 = alloca double*
store double* %0, double** %3
store double* %1, double** %4
%5 = load double*, double** %4
%6 = getelementptr inbounds double, double* %5, i64 0
%7 = load double, double* %6
%8 = load double*, double** %4
%9 = getelementptr inbounds double, double* %8, i64 1
%10 = load double, double* %9
%11 = call i32 @atan2(double %7, double %10)
%12 = load i32, i32* @M_PI
%13 = add nsw i32 %11, %12
%14 = load i32, i32* @M_PI
%15 = mul nsw i32 2, %14
%16 = sdiv i32 %13, %15
%17 = sitofp i32 %16 to double
%18 = load double*, double** %3
%19 = getelementptr inbounds double, double* %18, i64 0
store double %17, double* %19
%20 = load double*, double** %4
%21 = getelementptr inbounds double, double* %20, i64 2
%22 = load double, double* %21
%23 = load double*, double** %4
%24 = getelementptr inbounds double, double* %23, i64 0
%25 = load double, double* %24
%26 = load double*, double** %4
%27 = getelementptr inbounds double, double* %26, i64 0
%28 = load double, double* %27
%29 = load double*, double** %4
%30 = getelementptr inbounds double, double* %29, i64 1
%31 = load double, double* %30
%32 = load double*, double** %4
%33 = getelementptr inbounds double, double* %32, i64 1
%34 = load double, double* %33
%35 = fmul double %31, %34
%36 = call double @llvm.fmuladd.f64(double %25, double %28, double %35)
%37 = load double*, double** %4
%38 = getelementptr inbounds double, double* %37, i64 2
%39 = load double, double* %38
%40 = load double*, double** %4
%41 = getelementptr inbounds double, double* %40, i64 2
%42 = load double, double* %41
%43 = call double @llvm.fmuladd.f64(double %39, double %42, double %36)
%44 = call double @sqrt(double %43)
%45 = fdiv double %22, %44
%46 = call i32 @acos(double %45)
%47 = load i32, i32* @M_PI
%48 = sdiv i32 %46, %47
%49 = sitofp i32 %48 to double
%50 = load double*, double** %3
%51 = getelementptr inbounds double, double* %50, i64 1
store double %49, double* %51
%52 = load double*, double** %3
%53 = getelementptr inbounds double, double* %52, i64 2
store double 0.000000e+00, double* %53
ret void
}

LLVM IR (-O2):
@M_PI = global i32 0
define void @texcoord(double* nocapture writeonly %0, double* nocapture %1) {
%3 = load double, double* %1
%4 = getelementptr inbounds double, double* %1, i64 1
%5 = load double, double* %4
%6 = tail call i32 @atan2(double %3, double %5)
%7 = load i32, i32* @M_PI
%8 = add nsw i32 %7, %6
%9 = shl nsw i32 %7, 1
%10 = sdiv i32 %8, %9
%11 = sitofp i32 %10 to double
store double %11, double* %0
%12 = getelementptr inbounds double, double* %1, i64 2
%13 = load double, double* %12
%14 = load double, double* %1
%15 = load double, double* %4
%16 = fmul double %15, %15
%17 = tail call double @llvm.fmuladd.f64(double %14, double %14, double %16)
%18 = tail call double @llvm.fmuladd.f64(double %13, double %13, double %17)
%19 = tail call double @sqrt(double %18)
%20 = fdiv double %13, %19
%21 = tail call i32 @acos(double %20)
%22 = load i32, i32* @M_PI
%23 = sdiv i32 %21, %22
%24 = sitofp i32 %23 to double
%25 = getelementptr inbounds double, double* %0, i64 1
store double %24, double* %25
%26 = getelementptr inbounds double, double* %0, i64 2
store double 0.000000e+00, double* %26
ret void
}