#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 const mat_Dabs(double const);
int check_spin(const double spin_j, const double spin_k, const int sign,
               const double symprec) {
  if (sign == 0) {
    if (mat_Dabs(spin_j - spin_k) < symprec) {
      return 1;
    }
    if (mat_Dabs(spin_j + spin_k) < symprec) {
      return -1;
    }
    return 0;
  } else {
    if (mat_Dabs(spin_j - spin_k * sign) < symprec) {
      return sign;
    } else {
      return 0;
    }
  }
}


x86 assembly (clang, -O0):
<check_spin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %edi,-0x1c(%rbp)
movsd  %xmm2,-0x28(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    119a <check_spin+0x8a>
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
call   1030 <mat_Dabs@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1161 <check_spin+0x51>
movl   $0x1,-0x4(%rbp)
jmp    11f1 <check_spin+0xe1>
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
call   1030 <mat_Dabs@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    118e <check_spin+0x7e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f1 <check_spin+0xe1>
movl   $0x0,-0x4(%rbp)
jmp    11f1 <check_spin+0xe1>
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <mat_Dabs@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11ea <check_spin+0xda>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f1 <check_spin+0xe1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_spin>:
push   %rbx
sub    $0x20,%rsp
movsd  %xmm2,0x8(%rsp)
test   %edi,%edi
je     1146 <check_spin+0x36>
mov    %edi,%ebx
xorps  %xmm2,%xmm2
cvtsi2sd %edi,%xmm2
mulsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
call   1030 <mat_Dabs@plt>
xor    %eax,%eax
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
cmova  %ebx,%eax
jmp    118e <check_spin+0x7e>
movsd  %xmm0,0x18(%rsp)
movsd  %xmm1,0x10(%rsp)
subsd  %xmm1,%xmm0
call   1030 <mat_Dabs@plt>
mov    $0x1,%eax
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
ja     118e <check_spin+0x7e>
movsd  0x18(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
call   1030 <mat_Dabs@plt>
xor    %eax,%eax
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
seta   %al
neg    %eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @check_spin(double %0, double %1, i32 %2, double %3) {
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca double
store double %0, double* %6
store double %1, double* %7
store i32 %2, i32* %8
store double %3, double* %9
%10 = load i32, i32* %8
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %29
12: ; preds = %4
%13 = load double, double* %6
%14 = load double, double* %7
%15 = fsub double %13, %14
%16 = call double @mat_Dabs(double %15)
%17 = load double, double* %9
%18 = fcmp olt double %16, %17
br i1 %18, label %19, label %20
19: ; preds = %12
store i32 1, i32* %5
br label %42
20: ; preds = %12
%21 = load double, double* %6
%22 = load double, double* %7
%23 = fadd double %21, %22
%24 = call double @mat_Dabs(double %23)
%25 = load double, double* %9
%26 = fcmp olt double %24, %25
br i1 %26, label %27, label %28
27: ; preds = %20
store i32 -1, i32* %5
br label %42
28: ; preds = %20
store i32 0, i32* %5
br label %42
29: ; preds = %4
%30 = load double, double* %6
%31 = load double, double* %7
%32 = load i32, i32* %8
%33 = sitofp i32 %32 to double
%34 = fneg double %31
%35 = call double @llvm.fmuladd.f64(double %34, double %33, double %30)
%36 = call double @mat_Dabs(double %35)
%37 = load double, double* %9
%38 = fcmp olt double %36, %37
br i1 %38, label %39, label %41
39: ; preds = %29
%40 = load i32, i32* %8
store i32 %40, i32* %5
br label %42
41: ; preds = %29
store i32 0, i32* %5
br label %42
42: ; preds = %41, %39, %28, %27, %19
%43 = load i32, i32* %5
ret i32 %43
}

LLVM IR (-O2):
define i32 @check_spin(double %0, double %1, i32 %2, double %3) {
%5 = icmp eq i32 %2, 0
br i1 %5, label %6, label %15
6: ; preds = %4
%7 = fsub double %0, %1
%8 = tail call double @mat_Dabs(double %7)
%9 = fcmp olt double %8, %3
br i1 %9, label %22, label %10
10: ; preds = %6
%11 = fadd double %0, %1
%12 = tail call double @mat_Dabs(double %11)
%13 = fcmp olt double %12, %3
%14 = sext i1 %13 to i32
br label %22
15: ; preds = %4
%16 = sitofp i32 %2 to double
%17 = fneg double %1
%18 = tail call double @llvm.fmuladd.f64(double %17, double %16, double %0)
%19 = tail call double @mat_Dabs(double %18)
%20 = fcmp olt double %19, %3
%21 = select i1 %20, i32 %2, i32 0
br label %22
22: ; preds = %15, %10, %6
%23 = phi i32 [ 1, %6 ], [ %14, %10 ], [ %21, %15 ]
ret i32 %23
}