#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 */
short ENDSWAP_16(short);
void bes2d_array(short *src, int count, double *dest, double normfact) {
  short value;
  while (--count >= 0) {
    value = src[count];
    value = ENDSWAP_16(value);
    dest[count] = ((double)value) * normfact;
  };
}


x86 assembly (clang, -O0):
<bes2d_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jl     1176 <bes2d_array+0x66>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,2),%ax
mov    %ax,-0x22(%rbp)
movswl -0x22(%rbp),%edi
call   1030 <ENDSWAP_16@plt>
mov    %ax,-0x22(%rbp)
movswl -0x22(%rbp),%eax
cvtsi2sd %eax,%xmm0
mulsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    1128 <bes2d_array+0x18>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bes2d_array>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    115f <bes2d_array+0x4f>
mov    %rdx,%r14
mov    %rdi,%r15
mov    %esi,%ebx
add    $0x1,%rbx
movsd  %xmm0,(%rsp)
nopl   (%rax)
lea    -0x2(%rbx),%r12d
movswl (%r15,%r12,2),%edi
call   1030 <ENDSWAP_16@plt>
movsd  (%rsp),%xmm0
cwtl
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%r14,%r12,8)
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     1130 <bes2d_array+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @bes2d_array(i16* %0, i32 %1, double* %2, double %3) {
%5 = alloca i16*
%6 = alloca i32
%7 = alloca double*
%8 = alloca double
%9 = alloca i16
store i16* %0, i16** %5
store i32 %1, i32* %6
store double* %2, double** %7
store double %3, double* %8
br label %10
10: ; preds = %14, %4
%11 = load i32, i32* %6
%12 = add nsw i32 %11, -1
store i32 %12, i32* %6
%13 = icmp sge i32 %12, 0
br i1 %13, label %14, label %30
14: ; preds = %10
%15 = load i16*, i16** %5
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i16, i16* %15, i64 %17
%19 = load i16, i16* %18
store i16 %19, i16* %9
%20 = load i16, i16* %9
%21 = call signext i16 @ENDSWAP_16(i16 signext %20)
store i16 %21, i16* %9
%22 = load i16, i16* %9
%23 = sitofp i16 %22 to double
%24 = load double, double* %8
%25 = fmul double %23, %24
%26 = load double*, double** %7
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
store double %25, double* %29
br label %10
30: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @bes2d_array(i16* nocapture %0, i32 %1, double* nocapture writeonly %2, double %3) {
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %19
6: ; preds = %4
%7 = zext i32 %1 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ %7, %6 ], [ %10, %8 ]
%10 = add nsw i64 %9, -1
%11 = and i64 %10, 4294967295
%12 = getelementptr inbounds i16, i16* %0, i64 %11
%13 = load i16, i16* %12
%14 = tail call signext i16 @ENDSWAP_16(i16 signext %13)
%15 = sitofp i16 %14 to double
%16 = fmul double %15, %3
%17 = getelementptr inbounds double, double* %2, i64 %11
store double %16, double* %17
%18 = icmp ugt i64 %9, 1
br i1 %18, label %8, label %19
19: ; preds = %8, %4
ret void
}