#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 doubles2halfp(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;
  }
  xp += next;
  if (source == NULL || target == NULL) {
    return 0;
  }
  while (numel--) {
    x = *xp++;
    xp++;
    if ((x & 0x7FFFFFFFu) == 0) {
      *hp++ = (unsigned short)(x >> 16);
    } else {
      xs = x & 0x80000000u;
      xe = x & 0x7FF00000u;
      xm = x & 0x000FFFFFu;
      if (xe == 0) {
        *hp++ = (unsigned short)(xs >> 16);
      } else if (xe == 0x7FF00000u) {
        if (xm == 0) {
          *hp++ = (unsigned short)((xs >> 16) | 0x7C00u);
        } else {
          *hp++ = (unsigned short)0xFE00u;
        }
      } else {
        hs = (unsigned short)(xs >> 16);
        hes = ((int)(xe >> 20)) - 1023 + 15;
        if (hes >= 0x1F) {
          *hp++ = (unsigned short)((xs >> 16) | 0x7C00u);
        } else if (hes <= 0) {
          if ((10 - hes) > 21) {
            hm = (unsigned short)0u;
          } else {
            xm |= 0x00100000u;
            hm = (unsigned short)(xm >> (11 - hes));
            if ((xm >> (10 - hes)) & 0x00000001u)
              hm += (unsigned short)1u;
          }
          *hp++ = (hs | hm);
        } else {
          he = (unsigned short)(hes << 10);
          hm = (unsigned short)(xm >> 10);
          if (xm & 0x00000200u)
            *hp++ = (hs | he | hm) + (unsigned short)1u;
          else
            *hp++ = (hs | he | hm);
        }
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<doubles2halfp>:
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 <doubles2halfp+0x9d>
lea    -0x68(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rax
cmpq   $0x0,(%rax)
je     115e <doubles2halfp+0x5e>
movl   $0x0,0x2ecf(%rip)
jmp    1174 <doubles2halfp+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 <doubles2halfp+0x91>
movl   $0x1,-0x4(%rbp)
jmp    148b <doubles2halfp+0x38b>
movl   $0x1,-0x4(%rbp)
jmp    148b <doubles2halfp+0x38b>
mov    0x2e85(%rip),%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11cb <doubles2halfp+0xcb>
cmpq   $0x0,-0x10(%rbp)
jne    11d7 <doubles2halfp+0xd7>
movl   $0x0,-0x4(%rbp)
jmp    148b <doubles2halfp+0x38b>
jmp    11dc <doubles2halfp+0xdc>
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x1c(%rbp)
cmp    $0x0,%eax
je     1484 <doubles2halfp+0x384>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x30(%rbp)
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x30(%rbp)
mov    -0x40(%rbp),%rax
and    $0x7fffffff,%rax
cmp    $0x0,%rax
jne    1248 <doubles2halfp+0x148>
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    147f <doubles2halfp+0x37f>
movabs $0x80000000,%rax
and    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rax
and    $0x7ff00000,%rax
mov    %rax,-0x50(%rbp)
mov    -0x40(%rbp),%rax
and    $0xfffff,%rax
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    12a3 <doubles2halfp+0x1a3>
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    147a <doubles2halfp+0x37a>
cmpq   $0x7ff00000,-0x50(%rbp)
7f
jne    12fd <doubles2halfp+0x1fd>
cmpq   $0x0,-0x58(%rbp)
jne    12e4 <doubles2halfp+0x1e4>
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    12f8 <doubles2halfp+0x1f8>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x2,%rcx
mov    %rcx,-0x28(%rbp)
movw   $0xfe00,(%rax)
jmp    1475 <doubles2halfp+0x375>
mov    -0x48(%rbp),%rax
shr    $0x10,%rax
mov    %ax,-0x32(%rbp)
mov    -0x50(%rbp),%rax
shr    $0x14,%rax
sub    $0x3ff,%eax
add    $0xf,%eax
mov    %eax,-0x5c(%rbp)
cmpl   $0x1f,-0x5c(%rbp)
jl     134e <doubles2halfp+0x24e>
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    1470 <doubles2halfp+0x370>
cmpl   $0x0,-0x5c(%rbp)
jg     13ea <doubles2halfp+0x2ea>
mov    $0xa,%eax
sub    -0x5c(%rbp),%eax
cmp    $0x15,%eax
jle    1374 <doubles2halfp+0x274>
movw   $0x0,-0x36(%rbp)
jmp    13c6 <doubles2halfp+0x2c6>
mov    -0x58(%rbp),%rax
or     $0x100000,%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
mov    $0xb,%ecx
sub    -0x5c(%rbp),%ecx
mov    %ecx,%ecx
shr    %cl,%rax
mov    %ax,-0x36(%rbp)
mov    -0x58(%rbp),%rax
mov    $0xa,%ecx
sub    -0x5c(%rbp),%ecx
mov    %ecx,%ecx
shr    %cl,%rax
and    $0x1,%rax
cmp    $0x0,%rax
je     13c1 <doubles2halfp+0x2c1>
movzwl -0x36(%rbp),%eax
add    $0x1,%eax
mov    %ax,-0x36(%rbp)
jmp    13c6 <doubles2halfp+0x2c6>
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    146b <doubles2halfp+0x36b>
mov    -0x5c(%rbp),%eax
shl    $0xa,%eax
mov    %ax,-0x34(%rbp)
mov    -0x58(%rbp),%rax
shr    $0xa,%rax
mov    %ax,-0x36(%rbp)
mov    -0x58(%rbp),%rax
and    $0x200,%rax
cmp    $0x0,%rax
je     1441 <doubles2halfp+0x341>
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    1466 <doubles2halfp+0x366>
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    146b <doubles2halfp+0x36b>
jmp    1470 <doubles2halfp+0x370>
jmp    1475 <doubles2halfp+0x375>
jmp    147a <doubles2halfp+0x37a>
jmp    147f <doubles2halfp+0x37f>
jmp    11dc <doubles2halfp+0xdc>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

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

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

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