#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 singles2halfp(void *target, void *source, int numel) {
  unsigned short *hp = (unsigned short *)target;
  unsigned long *xp = (unsigned long *)source;
  unsigned short hs, he, hm;
  unsigned long x, xs, xe, xm;
  int hes;
  static int next;
  static int checkieee = 1;
  double one = 1.0;
  unsigned long *ip;
  if (checkieee) {
    ip = (unsigned long *)&one;
    if (*ip) {
      next = 0;
    } else {
      next = 1;
      ip++;
    }
    if (*ip != 0x3FF00000u) {
      return 1;
    }
    if (sizeof(short) != 2 || sizeof(long) != 4) {
      return 1;
    }
    checkieee = 0;
  }
  if (source == NULL || target == NULL) {
    return 0;
  }
  while (numel--) {
    x = *xp++;
    if ((x & 0x7FFFFFFFu) == 0) {
      *hp++ = (unsigned short)(x >> 16);
    } else {
      xs = x & 0x80000000u;
      xe = x & 0x7F800000u;
      xm = x & 0x007FFFFFu;
      if (xe == 0) {
        *hp++ = (unsigned short)(xs >> 16);
      } else if (xe == 0x7F800000u) {
        if (xm == 0) {
          *hp++ = (unsigned short)((xs >> 16) | 0x7C00u);
        } else {
          *hp++ = (unsigned short)0xFE00u;
        }
      } else {
        hs = (unsigned short)(xs >> 16);
        hes = ((int)(xe >> 23)) - 127 + 15;
        if (hes >= 0x1F) {
          *hp++ = (unsigned short)((xs >> 16) | 0x7C00u);
        } else if (hes <= 0) {
          if ((14 - hes) > 24) {
            hm = (unsigned short)0u;
          } else {
            xm |= 0x00800000u;
            hm = (unsigned short)(xm >> (14 - hes));
            if ((xm >> (13 - hes)) & 0x00000001u)
              hm += (unsigned short)1u;
          }
          *hp++ = (hs | hm);
        } else {
          he = (unsigned short)(hes << 10);
          hm = (unsigned short)(xm >> 13);
          if (xm & 0x00001000u)
            *hp++ = (hs | he | hm) + (unsigned short)1u;
          else
            *hp++ = (hs | he | hm);
        }
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<singles2halfp>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
movsd  0xed9(%rip),%xmm0
movsd  %xmm0,-0x68(%rbp)
cmpl   $0x0,0x2eed(%rip)
je     119d <singles2halfp+0x9d>
lea    -0x68(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rax
cmpq   $0x0,(%rax)
je     115e <singles2halfp+0x5e>
movl   $0x0,0x2ecf(%rip)
jmp    1174 <singles2halfp+0x74>
movl   $0x1,0x2ec0(%rip)
mov    -0x70(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rax
cmpq   $0x3ff00000,(%rax)
je     1191 <singles2halfp+0x91>
movl   $0x1,-0x4(%rbp)
jmp    1465 <singles2halfp+0x365>
movl   $0x1,-0x4(%rbp)
jmp    1465 <singles2halfp+0x365>
cmpq   $0x0,-0x18(%rbp)
je     11b3 <singles2halfp+0xb3>
cmpq   $0x0,-0x10(%rbp)
jne    11bf <singles2halfp+0xbf>
movl   $0x0,-0x4(%rbp)
jmp    1465 <singles2halfp+0x365>
jmp    11c4 <singles2halfp+0xc4>
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x1c(%rbp)
cmp    $0x0,%eax
je     145e <singles2halfp+0x35e>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x30(%rbp)
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
and    $0x7fffffff,%rax
cmp    $0x0,%rax
jne    1224 <singles2halfp+0x124>
mov    -0x40(%rbp),%rax
shr    $0x10,%rax
mov    %ax,%cx
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x2,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cx,(%rax)
jmp    1459 <singles2halfp+0x359>
movabs $0x80000000,%rax
and    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rax
and    $0x7f800000,%rax
mov    %rax,-0x50(%rbp)
mov    -0x40(%rbp),%rax
and    $0x7fffff,%rax
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    127f <singles2halfp+0x17f>
mov    -0x48(%rbp),%rax
shr    $0x10,%rax
mov    %ax,%cx
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x2,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cx,(%rax)
jmp    1454 <singles2halfp+0x354>
cmpq   $0x7f800000,-0x50(%rbp)
7f
jne    12d9 <singles2halfp+0x1d9>
cmpq   $0x0,-0x58(%rbp)
jne    12c0 <singles2halfp+0x1c0>
mov    -0x48(%rbp),%rax
shr    $0x10,%rax
or     $0x7c00,%rax
mov    %ax,%cx
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x2,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cx,(%rax)
jmp    12d4 <singles2halfp+0x1d4>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x2,%rcx
mov    %rcx,-0x28(%rbp)
movw   $0xfe00,(%rax)
jmp    144f <singles2halfp+0x34f>
mov    -0x48(%rbp),%rax
shr    $0x10,%rax
mov    %ax,-0x32(%rbp)
mov    -0x50(%rbp),%rax
shr    $0x17,%rax
sub    $0x7f,%eax
add    $0xf,%eax
mov    %eax,-0x5c(%rbp)
cmpl   $0x1f,-0x5c(%rbp)
jl     1328 <singles2halfp+0x228>
mov    -0x48(%rbp),%rax
shr    $0x10,%rax
or     $0x7c00,%rax
mov    %ax,%cx
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x2,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cx,(%rax)
jmp    144a <singles2halfp+0x34a>
cmpl   $0x0,-0x5c(%rbp)
jg     13c4 <singles2halfp+0x2c4>
mov    $0xe,%eax
sub    -0x5c(%rbp),%eax
cmp    $0x18,%eax
jle    134e <singles2halfp+0x24e>
movw   $0x0,-0x36(%rbp)
jmp    13a0 <singles2halfp+0x2a0>
mov    -0x58(%rbp),%rax
or     $0x800000,%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
mov    $0xe,%ecx
sub    -0x5c(%rbp),%ecx
mov    %ecx,%ecx
shr    %cl,%rax
mov    %ax,-0x36(%rbp)
mov    -0x58(%rbp),%rax
mov    $0xd,%ecx
sub    -0x5c(%rbp),%ecx
mov    %ecx,%ecx
shr    %cl,%rax
and    $0x1,%rax
cmp    $0x0,%rax
je     139b <singles2halfp+0x29b>
movzwl -0x36(%rbp),%eax
add    $0x1,%eax
mov    %ax,-0x36(%rbp)
jmp    13a0 <singles2halfp+0x2a0>
movzwl -0x32(%rbp),%eax
movzwl -0x36(%rbp),%ecx
or     %ecx,%eax
mov    %ax,%cx
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x2,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cx,(%rax)
jmp    1445 <singles2halfp+0x345>
mov    -0x5c(%rbp),%eax
shl    $0xa,%eax
mov    %ax,-0x34(%rbp)
mov    -0x58(%rbp),%rax
shr    $0xd,%rax
mov    %ax,-0x36(%rbp)
mov    -0x58(%rbp),%rax
and    $0x1000,%rax
cmp    $0x0,%rax
je     141b <singles2halfp+0x31b>
movzwl -0x32(%rbp),%eax
movzwl -0x34(%rbp),%ecx
or     %ecx,%eax
movzwl -0x36(%rbp),%ecx
or     %ecx,%eax
add    $0x1,%eax
mov    %ax,%cx
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x2,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cx,(%rax)
jmp    1440 <singles2halfp+0x340>
movzwl -0x32(%rbp),%eax
movzwl -0x34(%rbp),%ecx
or     %ecx,%eax
movzwl -0x36(%rbp),%ecx
or     %ecx,%eax
mov    %ax,%cx
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x2,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cx,(%rax)
jmp    1445 <singles2halfp+0x345>
jmp    144a <singles2halfp+0x34a>
jmp    144f <singles2halfp+0x34f>
jmp    1454 <singles2halfp+0x354>
jmp    1459 <singles2halfp+0x359>
jmp    11c4 <singles2halfp+0xc4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<singles2halfp>:
mov    $0x1,%eax
ret

LLVM IR (-O0):
@singles2halfp.next = internal global i32 0
@singles2halfp.checkieee = internal global i32 1
define i32 @singles2halfp(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i16*
%9 = alloca i64*
%10 = alloca i16
%11 = alloca i16
%12 = alloca i16
%13 = alloca i64
%14 = alloca i64
%15 = alloca i64
%16 = alloca i64
%17 = alloca i32
%18 = alloca double
%19 = alloca i64*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%20 = load i8*, i8** %5
%21 = bitcast i8* %20 to i16*
store i16* %21, i16** %8
%22 = load i8*, i8** %6
%23 = bitcast i8* %22 to i64*
store i64* %23, i64** %9
store double 1.000000e+00, double* %18
%24 = load i32, i32* @singles2halfp.checkieee
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %41
26: ; preds = %3
%27 = bitcast double* %18 to i64*
store i64* %27, i64** %19
%28 = load i64*, i64** %19
%29 = load i64, i64* %28
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %26
store i32 0, i32* @singles2halfp.next
br label %35
32: ; preds = %26
store i32 1, i32* @singles2halfp.next
%33 = load i64*, i64** %19
%34 = getelementptr inbounds i64, i64* %33, i32 1
store i64* %34, i64** %19
br label %35
35: ; preds = %32, %31
%36 = load i64*, i64** %19
%37 = load i64, i64* %36
%38 = icmp ne i64 %37, 1072693248
br i1 %38, label %39, label %40
39: ; preds = %35
store i32 1, i32* %4
br label %197
40: ; preds = %35
store i32 1, i32* %4
br label %197
41: ; preds = %3
%42 = load i8*, i8** %6
%43 = icmp eq i8* %42, null
br i1 %43, label %47, label %44
44: ; preds = %41
%45 = load i8*, i8** %5
%46 = icmp eq i8* %45, null
br i1 %46, label %47, label %48
47: ; preds = %44, %41
store i32 0, i32* %4
br label %197
48: ; preds = %44
br label %49
49: ; preds = %195, %48
%50 = load i32, i32* %7
%51 = add nsw i32 %50, -1
store i32 %51, i32* %7
%52 = icmp ne i32 %50, 0
br i1 %52, label %53, label %196
53: ; preds = %49
%54 = load i64*, i64** %9
%55 = getelementptr inbounds i64, i64* %54, i32 1
store i64* %55, i64** %9
%56 = load i64, i64* %54
store i64 %56, i64* %13
%57 = load i64, i64* %13
%58 = and i64 %57, 2147483647
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %66
60: ; preds = %53
%61 = load i64, i64* %13
%62 = lshr i64 %61, 16
%63 = trunc i64 %62 to i16
%64 = load i16*, i16** %8
%65 = getelementptr inbounds i16, i16* %64, i32 1
store i16* %65, i16** %8
store i16 %63, i16* %64
br label %195
66: ; preds = %53
%67 = load i64, i64* %13
%68 = and i64 %67, 2147483648
store i64 %68, i64* %14
%69 = load i64, i64* %13
%70 = and i64 %69, 2139095040
store i64 %70, i64* %15
%71 = load i64, i64* %13
%72 = and i64 %71, 8388607
store i64 %72, i64* %16
%73 = load i64, i64* %15
%74 = icmp eq i64 %73, 0
br i1 %74, label %75, label %81
75: ; preds = %66
%76 = load i64, i64* %14
%77 = lshr i64 %76, 16
%78 = trunc i64 %77 to i16
%79 = load i16*, i16** %8
%80 = getelementptr inbounds i16, i16* %79, i32 1
store i16* %80, i16** %8
store i16 %78, i16* %79
br label %194
81: ; preds = %66
%82 = load i64, i64* %15
%83 = icmp eq i64 %82, 2139095040
br i1 %83, label %84, label %98
84: ; preds = %81
%85 = load i64, i64* %16
%86 = icmp eq i64 %85, 0
br i1 %86, label %87, label %94
87: ; preds = %84
%88 = load i64, i64* %14
%89 = lshr i64 %88, 16
%90 = or i64 %89, 31744
%91 = trunc i64 %90 to i16
%92 = load i16*, i16** %8
%93 = getelementptr inbounds i16, i16* %92, i32 1
store i16* %93, i16** %8
store i16 %91, i16* %92
br label %97
94: ; preds = %84
%95 = load i16*, i16** %8
%96 = getelementptr inbounds i16, i16* %95, i32 1
store i16* %96, i16** %8
store i16 -512, i16* %95
br label %97
97: ; preds = %94, %87
br label %193
98: ; preds = %81
%99 = load i64, i64* %14
%100 = lshr i64 %99, 16
%101 = trunc i64 %100 to i16
store i16 %101, i16* %10
%102 = load i64, i64* %15
%103 = lshr i64 %102, 23
%104 = trunc i64 %103 to i32
%105 = sub nsw i32 %104, 127
%106 = add nsw i32 %105, 15
store i32 %106, i32* %17
%107 = load i32, i32* %17
%108 = icmp sge i32 %107, 31
br i1 %108, label %109, label %116
109: ; preds = %98
%110 = load i64, i64* %14
%111 = lshr i64 %110, 16
%112 = or i64 %111, 31744
%113 = trunc i64 %112 to i16
%114 = load i16*, i16** %8
%115 = getelementptr inbounds i16, i16* %114, i32 1
store i16* %115, i16** %8
store i16 %113, i16* %114
br label %192
116: ; preds = %98
%117 = load i32, i32* %17
%118 = icmp sle i32 %117, 0
br i1 %118, label %119, label %155
119: ; preds = %116
%120 = load i32, i32* %17
%121 = sub nsw i32 14, %120
%122 = icmp sgt i32 %121, 24
br i1 %122, label %123, label %124
123: ; preds = %119
store i16 0, i16* %12
br label %146
124: ; preds = %119
%125 = load i64, i64* %16
%126 = or i64 %125, 8388608
store i64 %126, i64* %16
%127 = load i64, i64* %16
%128 = load i32, i32* %17
%129 = sub nsw i32 14, %128
%130 = zext i32 %129 to i64
%131 = lshr i64 %127, %130
%132 = trunc i64 %131 to i16
store i16 %132, i16* %12
%133 = load i64, i64* %16
%134 = load i32, i32* %17
%135 = sub nsw i32 13, %134
%136 = zext i32 %135 to i64
%137 = lshr i64 %133, %136
%138 = and i64 %137, 1
%139 = icmp ne i64 %138, 0
br i1 %139, label %140, label %145
140: ; preds = %124
%141 = load i16, i16* %12
%142 = zext i16 %141 to i32
%143 = add nsw i32 %142, 1
%144 = trunc i32 %143 to i16
store i16 %144, i16* %12
br label %145
145: ; preds = %140, %124
br label %146
146: ; preds = %145, %123
%147 = load i16, i16* %10
%148 = zext i16 %147 to i32
%149 = load i16, i16* %12
%150 = zext i16 %149 to i32
%151 = or i32 %148, %150
%152 = trunc i32 %151 to i16
%153 = load i16*, i16** %8
%154 = getelementptr inbounds i16, i16* %153, i32 1
store i16* %154, i16** %8
store i16 %152, i16* %153
br label %191
155: ; preds = %116
%156 = load i32, i32* %17
%157 = shl i32 %156, 10
%158 = trunc i32 %157 to i16
store i16 %158, i16* %11
%159 = load i64, i64* %16
%160 = lshr i64 %159, 13
%161 = trunc i64 %160 to i16
store i16 %161, i16* %12
%162 = load i64, i64* %16
%163 = and i64 %162, 4096
%164 = icmp ne i64 %163, 0
br i1 %164, label %165, label %178
165: ; preds = %155
%166 = load i16, i16* %10
%167 = zext i16 %166 to i32
%168 = load i16, i16* %11
%169 = zext i16 %168 to i32
%170 = or i32 %167, %169
%171 = load i16, i16* %12
%172 = zext i16 %171 to i32
%173 = or i32 %170, %172
%174 = add nsw i32 %173, 1
%175 = trunc i32 %174 to i16
%176 = load i16*, i16** %8
%177 = getelementptr inbounds i16, i16* %176, i32 1
store i16* %177, i16** %8
store i16 %175, i16* %176
br label %190
178: ; preds = %155
%179 = load i16, i16* %10
%180 = zext i16 %179 to i32
%181 = load i16, i16* %11
%182 = zext i16 %181 to i32
%183 = or i32 %180, %182
%184 = load i16, i16* %12
%185 = zext i16 %184 to i32
%186 = or i32 %183, %185
%187 = trunc i32 %186 to i16
%188 = load i16*, i16** %8
%189 = getelementptr inbounds i16, i16* %188, i32 1
store i16* %189, i16** %8
store i16 %187, i16* %188
br label %190
190: ; preds = %178, %165
br label %191
191: ; preds = %190, %146
br label %192
192: ; preds = %191, %109
br label %193
193: ; preds = %192, %97
br label %194
194: ; preds = %193, %75
br label %195
195: ; preds = %194, %60
br label %49
196: ; preds = %49
store i32 0, i32* %4
br label %197
197: ; preds = %196, %47, %40, %39
%198 = load i32, i32* %4
ret i32 %198
}

LLVM IR (-O2):
define i32 @singles2halfp(i8* nocapture readnone %0, i8* nocapture readnone %1, i32 %2) {
ret i32 1
}