#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 floor(int /*<<< orphan*/);
int /*<<< orphan*/ sqrt(double);
void k_combination2(unsigned long pos, unsigned long *a, unsigned long *b) {
  double s;
  double i = floor(sqrt(2.0 * pos)) - 1.0;
  if (i <= 1.0) {
    i = 1.0;
  }
  s = i * (i - 1.0) / 2.0;
  while (pos - s >= i) {
    s += i;
    i += 1;
  }
  *a = (unsigned long)(pos - s);
  *b = (unsigned long)(i);
}


x86 assembly (clang, -O0):
<k_combination2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movaps 0xee5(%rip),%xmm0
movq   -0x8(%rbp),%xmm1
punpckldq %xmm0,%xmm1
movapd 0xee4(%rip),%xmm0
subpd  %xmm0,%xmm1
movaps %xmm1,%xmm0
unpckhpd %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0xea5(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
mov    %eax,%edi
call   1040 <floor@plt>
movsd  0xe85(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe74(%rip),%xmm0
ucomisd -0x28(%rbp),%xmm0
jb     11a4 <k_combination2+0x84>
movsd  0xe61(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0xe4a(%rip),%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe42(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movaps 0xe4a(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xe49(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
subsd  -0x20(%rbp),%xmm0
ucomisd -0x28(%rbp),%xmm0
jb     122c <k_combination2+0x10c>
movsd  -0x28(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xde3(%rip),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11cf <k_combination2+0xaf>
movaps 0xded(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xdec(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x20(%rbp),%xmm1
subsd  %xmm1,%xmm0
movaps %xmm0,%xmm1
cvttsd2si %xmm1,%rcx
mov    %rcx,%rdx
sar    $0x3f,%rdx
movsd  0xd9d(%rip),%xmm2
subsd  %xmm2,%xmm0
cvttsd2si %xmm0,%rax
and    %rdx,%rax
or     %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movsd  -0x28(%rbp),%xmm0
movaps %xmm0,%xmm1
subsd  %xmm2,%xmm1
cvttsd2si %xmm1,%rax
cvttsd2si %xmm0,%rcx
mov    %rcx,%rdx
sar    $0x3f,%rdx
and    %rdx,%rax
or     %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<k_combination2>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movq   %rdi,%xmm0
punpckldq 0xecc(%rip),%xmm0
subpd  0xed4(%rip),%xmm0
mov    %rdx,%r14
mov    %rsi,%rbx
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,(%rsp)
movapd %xmm1,%xmm0
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
mov    %eax,%edi
call   1040 <floor@plt>
movapd (%rsp),%xmm4
movsd  0xeac(%rip),%xmm2
addsd  %xmm2,%xmm0
movsd  0xea8(%rip),%xmm3
movapd %xmm3,%xmm1
maxsd  %xmm0,%xmm1
addsd  %xmm1,%xmm2
mulsd  %xmm1,%xmm2
mulsd  0xe98(%rip),%xmm2
nopl   0x0(%rax,%rax,1)
movapd %xmm4,%xmm0
subsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jb     11b8 <k_combination2+0x98>
addsd  %xmm1,%xmm2
addsd  %xmm3,%xmm1
jmp    11a0 <k_combination2+0x80>
movsd  0xe78(%rip),%xmm2
cvttsd2si %xmm0,%rax
subsd  %xmm2,%xmm0
cvttsd2si %xmm0,%rcx
mov    %rax,%rdx
sar    $0x3f,%rdx
and    %rcx,%rdx
or     %rax,%rdx
cvttsd2si %xmm1,%rax
mov    %rdx,(%rbx)
subsd  %xmm2,%xmm1
cvttsd2si %xmm1,%rcx
mov    %rax,%rdx
sar    $0x3f,%rdx
and    %rcx,%rdx
or     %rax,%rdx
mov    %rdx,(%r14)
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @k_combination2(i64 %0, i64* %1, i64* %2) {
%4 = alloca i64
%5 = alloca i64*
%6 = alloca i64*
%7 = alloca double
%8 = alloca double
store i64 %0, i64* %4
store i64* %1, i64** %5
store i64* %2, i64** %6
%9 = load i64, i64* %4
%10 = uitofp i64 %9 to double
%11 = fmul double 2.000000e+00, %10
%12 = call i32 @sqrt(double %11)
%13 = call double @floor(i32 %12)
%14 = fsub double %13, 1.000000e+00
store double %14, double* %8
%15 = load double, double* %8
%16 = fcmp ole double %15, 1.000000e+00
br i1 %16, label %17, label %18
17: ; preds = %3
store double 1.000000e+00, double* %8
br label %18
18: ; preds = %17, %3
%19 = load double, double* %8
%20 = load double, double* %8
%21 = fsub double %20, 1.000000e+00
%22 = fmul double %19, %21
%23 = fdiv double %22, 2.000000e+00
store double %23, double* %7
br label %24
24: ; preds = %31, %18
%25 = load i64, i64* %4
%26 = uitofp i64 %25 to double
%27 = load double, double* %7
%28 = fsub double %26, %27
%29 = load double, double* %8
%30 = fcmp oge double %28, %29
br i1 %30, label %31, label %37
31: ; preds = %24
%32 = load double, double* %8
%33 = load double, double* %7
%34 = fadd double %33, %32
store double %34, double* %7
%35 = load double, double* %8
%36 = fadd double %35, 1.000000e+00
store double %36, double* %8
br label %24
37: ; preds = %24
%38 = load i64, i64* %4
%39 = uitofp i64 %38 to double
%40 = load double, double* %7
%41 = fsub double %39, %40
%42 = fptoui double %41 to i64
%43 = load i64*, i64** %5
store i64 %42, i64* %43
%44 = load double, double* %8
%45 = fptoui double %44 to i64
%46 = load i64*, i64** %6
store i64 %45, i64* %46
ret void
}

LLVM IR (-O2):
define void @k_combination2(i64 %0, i64* nocapture writeonly %1, i64* nocapture writeonly %2) {
%4 = uitofp i64 %0 to double
%5 = fmul double %4, 2.000000e+00
%6 = tail call i32 @sqrt(double %5)
%7 = tail call double @floor(i32 %6)
%8 = fadd double %7, -1.000000e+00
%9 = fcmp ole double %8, 1.000000e+00
%10 = select i1 %9, double 1.000000e+00, double %8
%11 = fadd double %10, -1.000000e+00
%12 = fmul double %10, %11
%13 = fmul double %12, 5.000000e-01
%14 = fsub double %4, %13
%15 = fcmp ult double %14, %10
br i1 %15, label %23, label %16
16: ; preds = %3, %16
%17 = phi double [ %20, %16 ], [ %10, %3 ]
%18 = phi double [ %19, %16 ], [ %13, %3 ]
%19 = fadd double %18, %17
%20 = fadd double %17, 1.000000e+00
%21 = fsub double %4, %19
%22 = fcmp ult double %21, %20
br i1 %22, label %23, label %16
23: ; preds = %16, %3
%24 = phi double [ %10, %3 ], [ %20, %16 ]
%25 = phi double [ %14, %3 ], [ %21, %16 ]
%26 = fptoui double %25 to i64
store i64 %26, i64* %1
%27 = fptoui double %24 to i64
store i64 %27, i64* %2
ret void
}