#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 CHAR_BIT;
int /*<<< orphan*/ hsfc2d(unsigned int *, unsigned int *, unsigned int *);
void THSFC2d(double coord[], unsigned add_step, unsigned *nkey,
             unsigned key[]) {
  const unsigned imax =
      ((unsigned)(((sizeof(unsigned) * CHAR_BIT) <= 32)
                      ? ~(0u)
                      : (0xffffffff << ((sizeof(unsigned) * CHAR_BIT) - 32))));
  const double c0 = (coord[0] <= 0) ? 0 : imax * coord[0];
  const double c1 = (coord[1] <= 0) ? 0 : imax * coord[1];
  unsigned c[2];
  c[0] = (unsigned)((imax < c0) ? imax : c0);
  c[1] = (unsigned)((imax < c1) ? imax : c1);
  unsigned nk = (*nkey) - 1;
  key[2] = add_step;
  hsfc2d(c, &nk, key);
}


x86 assembly (clang, -O0):
<THSFC2d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    0x2eb2(%rip),%rax
movslq (%rax),%rax
shl    $0x2,%rax
cmp    $0x20,%rax
ja     114c <THSFC2d+0x3c>
mov    $0xffffffff,%eax
mov    %eax,-0x48(%rbp)
jmp    116a <THSFC2d+0x5a>
mov    0x2e8d(%rip),%rax
movslq (%rax),%rax
shl    $0x2,%rax
sub    $0x20,%rax
mov    %eax,%ecx
mov    $0xffffffff,%eax
shl    %cl,%eax
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
ucomisd (%rax),%xmm0
jb     118e <THSFC2d+0x7e>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
jmp    11a3 <THSFC2d+0x93>
mov    -0x24(%rbp),%eax
cvtsi2sd %rax,%xmm0
mov    -0x8(%rbp),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
ucomisd 0x8(%rax),%xmm0
jb     11cc <THSFC2d+0xbc>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
jmp    11e2 <THSFC2d+0xd2>
mov    -0x24(%rbp),%eax
cvtsi2sd %rax,%xmm0
mov    -0x8(%rbp),%rax
mulsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x24(%rbp),%eax
cvtsi2sd %rax,%xmm1
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1215 <THSFC2d+0x105>
mov    -0x24(%rbp),%eax
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x60(%rbp)
jmp    121f <THSFC2d+0x10f>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
cvttsd2si %xmm0,%rax
mov    %eax,-0x40(%rbp)
mov    -0x24(%rbp),%eax
cvtsi2sd %rax,%xmm1
movsd  -0x38(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1255 <THSFC2d+0x145>
mov    -0x24(%rbp),%eax
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x68(%rbp)
jmp    125f <THSFC2d+0x14f>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x68(%rbp),%xmm0
cvttsd2si %xmm0,%rax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
sub    $0x1,%eax
mov    %eax,-0x44(%rbp)
mov    -0xc(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x8(%rax)
lea    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    -0x44(%rbp),%rsi
call   1030 <hsfc2d@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<THSFC2d>:
sub    $0x18,%rsp
mov    %rcx,%r8
mov    0x2ec2(%rip),%rax
movslq (%rax),%rcx
shl    $0x2,%rcx
mov    $0xffffffff,%eax
shl    %cl,%eax
cmp    $0x21,%rcx
jb     1139 <THSFC2d+0x29>
cvtsi2sd %rax,%xmm0
jmp    1141 <THSFC2d+0x31>
movsd  0xebf(%rip),%xmm0
movsd  (%rdi),%xmm1
movsd  0x8(%rdi),%xmm2
movapd %xmm1,%xmm3
mulsd  %xmm0,%xmm3
xorpd  %xmm4,%xmm4
cmpnlesd %xmm4,%xmm1
andpd  %xmm3,%xmm1
movapd %xmm2,%xmm3
mulsd  %xmm0,%xmm3
cmpnlesd %xmm4,%xmm2
andpd  %xmm3,%xmm2
movapd %xmm0,%xmm3
minsd  %xmm1,%xmm3
cvttsd2si %xmm3,%rax
mov    %eax,0x10(%rsp)
minsd  %xmm2,%xmm0
cvttsd2si %xmm0,%rax
mov    %eax,0x14(%rsp)
mov    (%rdx),%eax
add    $0xffffffff,%eax
mov    %eax,0xc(%rsp)
mov    %esi,0x8(%r8)
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rsi
mov    %r8,%rdx
call   1030 <hsfc2d@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
@CHAR_BIT = global i32 0
define void @THSFC2d(double* %0, i32 %1, i32* %2, i32* %3) {
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = alloca [2 x i32]
%13 = alloca i32
store double* %0, double** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%14 = load i32, i32* @CHAR_BIT
%15 = sext i32 %14 to i64
%16 = mul i64 4, %15
%17 = icmp ule i64 %16, 32
br i1 %17, label %18, label %19
18: ; preds = %4
br label %26
19: ; preds = %4
%20 = load i32, i32* @CHAR_BIT
%21 = sext i32 %20 to i64
%22 = mul i64 4, %21
%23 = sub i64 %22, 32
%24 = trunc i64 %23 to i32
%25 = shl i32 -1, %24
br label %26
26: ; preds = %19, %18
%27 = phi i32 [ -1, %18 ], [ %25, %19 ]
store i32 %27, i32* %9
%28 = load double*, double** %5
%29 = getelementptr inbounds double, double* %28, i64 0
%30 = load double, double* %29
%31 = fcmp ole double %30, 0.000000e+00
br i1 %31, label %32, label %33
32: ; preds = %26
br label %40
33: ; preds = %26
%34 = load i32, i32* %9
%35 = uitofp i32 %34 to double
%36 = load double*, double** %5
%37 = getelementptr inbounds double, double* %36, i64 0
%38 = load double, double* %37
%39 = fmul double %35, %38
br label %40
40: ; preds = %33, %32
%41 = phi double [ 0.000000e+00, %32 ], [ %39, %33 ]
store double %41, double* %10
%42 = load double*, double** %5
%43 = getelementptr inbounds double, double* %42, i64 1
%44 = load double, double* %43
%45 = fcmp ole double %44, 0.000000e+00
br i1 %45, label %46, label %47
46: ; preds = %40
br label %54
47: ; preds = %40
%48 = load i32, i32* %9
%49 = uitofp i32 %48 to double
%50 = load double*, double** %5
%51 = getelementptr inbounds double, double* %50, i64 1
%52 = load double, double* %51
%53 = fmul double %49, %52
br label %54
54: ; preds = %47, %46
%55 = phi double [ 0.000000e+00, %46 ], [ %53, %47 ]
store double %55, double* %11
%56 = load i32, i32* %9
%57 = uitofp i32 %56 to double
%58 = load double, double* %10
%59 = fcmp olt double %57, %58
br i1 %59, label %60, label %63
60: ; preds = %54
%61 = load i32, i32* %9
%62 = uitofp i32 %61 to double
br label %65
63: ; preds = %54
%64 = load double, double* %10
br label %65
65: ; preds = %63, %60
%66 = phi double [ %62, %60 ], [ %64, %63 ]
%67 = fptoui double %66 to i32
%68 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
store i32 %67, i32* %68
%69 = load i32, i32* %9
%70 = uitofp i32 %69 to double
%71 = load double, double* %11
%72 = fcmp olt double %70, %71
br i1 %72, label %73, label %76
73: ; preds = %65
%74 = load i32, i32* %9
%75 = uitofp i32 %74 to double
br label %78
76: ; preds = %65
%77 = load double, double* %11
br label %78
78: ; preds = %76, %73
%79 = phi double [ %75, %73 ], [ %77, %76 ]
%80 = fptoui double %79 to i32
%81 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 1
store i32 %80, i32* %81
%82 = load i32*, i32** %7
%83 = load i32, i32* %82
%84 = sub i32 %83, 1
store i32 %84, i32* %13
%85 = load i32, i32* %6
%86 = load i32*, i32** %8
%87 = getelementptr inbounds i32, i32* %86, i64 2
store i32 %85, i32* %87
%88 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%89 = load i32*, i32** %8
%90 = call i32 @hsfc2d(i32* %88, i32* %13, i32* %89)
ret void
}

LLVM IR (-O2):
@CHAR_BIT = global i32 0
define void @THSFC2d(double* nocapture %0, i32 %1, i32* nocapture %2, i32* %3) {
%5 = alloca [2 x i32]
%6 = alloca i32
%7 = load i32, i32* @CHAR_BIT
%8 = sext i32 %7 to i64
%9 = shl nsw i64 %8, 2
%10 = icmp ult i64 %9, 33
%11 = trunc i64 %9 to i32
%12 = add i32 %11, -32
%13 = shl nsw i32 -1, %12
%14 = load double, double* %0
%15 = fcmp ugt double %14, 0.000000e+00
%16 = uitofp i32 %13 to double
%17 = select i1 %10, double 0x41EFFFFFFFE00000, double %16
%18 = fmul double %14, %17
%19 = select i1 %15, double %18, double 0.000000e+00
%20 = getelementptr inbounds double, double* %0, i64 1
%21 = load double, double* %20
%22 = fcmp ugt double %21, 0.000000e+00
%23 = fmul double %21, %17
%24 = select i1 %22, double %23, double 0.000000e+00
%25 = bitcast [2 x i32]* %5 to i8*
%26 = fcmp ogt double %19, %17
%27 = select i1 %26, double %17, double %19
%28 = fptoui double %27 to i32
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
store i32 %28, i32* %29
%30 = fcmp ogt double %24, %17
%31 = select i1 %30, double %17, double %24
%32 = fptoui double %31 to i32
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
store i32 %32, i32* %33
%34 = bitcast i32* %6 to i8*
%35 = load i32, i32* %2
%36 = add i32 %35, -1
store i32 %36, i32* %6
%37 = getelementptr inbounds i32, i32* %3, i64 2
store i32 %1, i32* %37
%38 = call i32 @hsfc2d(i32* %29, i32* %6, i32* %3)
ret void
}