#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 */
scalar_t__ sqrt(double);
void GetIndexTernary(int *ix, int *iy, double *x, double *y, int itriangle,
                     int K) {
  *ix = (int)sqrt((double)itriangle);
  *iy = itriangle - ((*ix) * (*ix));
  *x = (1 + (*iy / 2) * 3 + (*iy % 2)) / (3. * K);
  *y = (1 + (K - 1 - *ix) * 3 + (*iy % 2)) / (3. * K);
}


x86 assembly (clang, -O0):
<GetIndexTernary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
cvtsi2sdl -0x24(%rbp),%xmm0
call   1030 <sqrt@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x24(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    -0x8(%rbp),%rdx
imul   (%rdx),%eax
sub    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
imul   $0x3,%eax,%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x30(%rbp),%eax
add    %edx,%eax
cvtsi2sd %eax,%xmm0
cvtsi2sdl -0x28(%rbp),%xmm2
movsd  0xe6b(%rip),%xmm1
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x28(%rbp),%eax
sub    $0x1,%eax
mov    -0x8(%rbp),%rcx
sub    (%rcx),%eax
imul   $0x3,%eax,%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x2c(%rbp),%eax
add    %edx,%eax
cvtsi2sd %eax,%xmm0
cvtsi2sdl -0x28(%rbp),%xmm2
movsd  0xe22(%rip),%xmm1
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetIndexTernary>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,%r12d
mov    %r8d,%ebx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%r13
cvtsi2sd %r8d,%xmm0
call   1030 <sqrt@plt>
mov    %eax,0x0(%r13)
imul   %eax,%eax
sub    %eax,%ebx
mov    %ebx,0x0(%rbp)
mov    %ebx,%eax
shr    $0x1f,%eax
add    %ebx,%eax
mov    %eax,%ecx
sar    %ecx
lea    (%rcx,%rcx,2),%ecx
and    $0xfffffffe,%eax
sub    %eax,%ebx
lea    (%rbx,%rcx,1),%eax
add    $0x1,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
cvtsi2sd %r12d,%xmm1
mulsd  0xe90(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,(%r15)
mov    0x0(%r13),%eax
not    %eax
add    %r12d,%eax
lea    (%rax,%rax,2),%eax
add    %ebx,%eax
add    $0x1,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @GetIndexTernary(i32* nocapture %0, i32* nocapture %1, double* nocapture writeonly %2, double* nocapture writeonly %3, i32 %4, i32 %5) {
%7 = sitofp i32 %4 to double
%8 = tail call i64 @sqrt(double %7)
%9 = trunc i64 %8 to i32
store i32 %9, i32* %0
%10 = mul nsw i32 %9, %9
%11 = sub nsw i32 %4, %10
store i32 %11, i32* %1
%12 = sdiv i32 %11, 2
%13 = mul nsw i32 %12, 3
%14 = srem i32 %11, 2
%15 = add nsw i32 %14, 1
%16 = add i32 %15, %13
%17 = sitofp i32 %16 to double
%18 = sitofp i32 %5 to double
%19 = fmul double %18, 3.000000e+00
%20 = fdiv double %17, %19
store double %20, double* %2
%21 = load i32, i32* %0
%22 = xor i32 %21, -1
%23 = add i32 %22, %5
%24 = mul nsw i32 %23, 3
%25 = add i32 %15, %24
%26 = sitofp i32 %25 to double
%27 = fdiv double %26, %19
store double %27, double* %3
ret void
}