void texcoord(double t[3], double p[3]) {
  double x = -p[0] / 2;
  if (x < 0)
    x++;
  double y = -p[1] / 2;
  if (y < 0)
    y++;
  t[0] = x;
  t[1] = y;
  t[2] = 0;
}


x86 assembly (clang, -O0):
<texcoord>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xecd(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    115c <texcoord+0x5c>
movsd  0xeb6(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xe7c(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    11ad <texcoord+0xad>
movsd  0xe65(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x20(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,0x10(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<texcoord>:
movupd (%rsi),%xmm0
mulpd  0xef4(%rip),%xmm0
xorpd  %xmm1,%xmm1
movapd %xmm0,%xmm2
cmpltpd %xmm1,%xmm2
movapd %xmm2,%xmm1
andnpd %xmm0,%xmm1
addpd  0xee7(%rip),%xmm0
andpd  %xmm2,%xmm0
orpd   %xmm1,%xmm0
movupd %xmm0,(%rdi)
movq   $0x0,0x10(%rdi)
ret

LLVM IR (-O0):
define void @texcoord(double* %0, double* %1) {
%3 = alloca double*
%4 = alloca double*
%5 = alloca double
%6 = alloca double
store double* %0, double** %3
store double* %1, double** %4
%7 = load double*, double** %4
%8 = getelementptr inbounds double, double* %7, i64 0
%9 = load double, double* %8
%10 = fneg double %9
%11 = fdiv double %10, 2.000000e+00
store double %11, double* %5
%12 = load double, double* %5
%13 = fcmp olt double %12, 0.000000e+00
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load double, double* %5
%16 = fadd double %15, 1.000000e+00
store double %16, double* %5
br label %17
17: ; preds = %14, %2
%18 = load double*, double** %4
%19 = getelementptr inbounds double, double* %18, i64 1
%20 = load double, double* %19
%21 = fneg double %20
%22 = fdiv double %21, 2.000000e+00
store double %22, double* %6
%23 = load double, double* %6
%24 = fcmp olt double %23, 0.000000e+00
br i1 %24, label %25, label %28
25: ; preds = %17
%26 = load double, double* %6
%27 = fadd double %26, 1.000000e+00
store double %27, double* %6
br label %28
28: ; preds = %25, %17
%29 = load double, double* %5
%30 = load double*, double** %3
%31 = getelementptr inbounds double, double* %30, i64 0
store double %29, double* %31
%32 = load double, double* %6
%33 = load double*, double** %3
%34 = getelementptr inbounds double, double* %33, i64 1
store double %32, double* %34
%35 = load double*, double** %3
%36 = getelementptr inbounds double, double* %35, i64 2
store double 0.000000e+00, double* %36
ret void
}

LLVM IR (-O2):
define void @texcoord(double* nocapture writeonly %0, double* nocapture %1) {
%3 = bitcast double* %1 to <2 x double>*
%4 = load <2 x double>, <2 x double>* %3
%5 = fmul <2 x double> %4, <double -5.000000e-01, double -5.000000e-01>
%6 = fcmp olt <2 x double> %5, zeroinitializer
%7 = fadd <2 x double> %5, <double 1.000000e+00, double 1.000000e+00>
%8 = select <2 x i1> %6, <2 x double> %7, <2 x double> %5
%9 = bitcast double* %0 to <2 x double>*
store <2 x double> %8, <2 x double>* %9
%10 = getelementptr inbounds double, double* %0, i64 2
store double 0.000000e+00, double* %10
ret void
}