#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 /*<<< orphan*/ memset(void *, int /*<<< orphan*/, int);
int /*<<< orphan*/ ms_gswap8(double *);
int msr_pack_float_64(double *packed, double *data, int ns, int max_bytes,
                      int pad, int *pnbytes, int *pnsamples, int swapflag) {
  int points_remaining = ns;
  int i = 0;
  while (points_remaining > 0 && max_bytes >= 8) {
    *packed = data[i];
    if (swapflag)
      ms_gswap8(packed);
    packed++;
    max_bytes -= 8;
    points_remaining--;
    i++;
  }
  *pnbytes = (ns - points_remaining) * 8;
  if (pad) {
    memset((void *)packed, 0, max_bytes);
    *pnbytes += max_bytes;
  }
  *pnsamples = ns - points_remaining;
  return 0;
}


x86 assembly (clang, -O0):
<msr_pack_float_64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x2c(%rbp)
mov    %al,-0x31(%rbp)
jle    116b <msr_pack_float_64+0x4b>
cmpl   $0x8,-0x18(%rbp)
setge  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    117b <msr_pack_float_64+0x5b>
jmp    11cf <msr_pack_float_64+0xaf>
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
cmpl   $0x0,0x18(%rbp)
je     11a3 <msr_pack_float_64+0x83>
mov    -0x8(%rbp),%rdi
call   1040 <ms_gswap8@plt>
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%eax
sub    $0x8,%eax
mov    %eax,-0x18(%rbp)
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1152 <msr_pack_float_64+0x32>
mov    -0x14(%rbp),%ecx
sub    -0x2c(%rbp),%ecx
shl    $0x3,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
cmpl   $0x0,-0x1c(%rbp)
je     1201 <msr_pack_float_64+0xe1>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x18(%rbp),%ecx
mov    -0x28(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x14(%rbp),%ecx
sub    -0x2c(%rbp),%ecx
mov    0x10(%rbp),%rax
mov    %ecx,(%rax)
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<msr_pack_float_64>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%ebp
mov    %rdi,%rbx
test   %edx,%edx
mov    %r9,0x10(%rsp)
mov    %rdx,0x8(%rsp)
mov    %r8d,0x4(%rsp)
jle    119a <msr_pack_float_64+0x7a>
cmp    $0x8,%ebp
jl     119a <msr_pack_float_64+0x7a>
mov    %rsi,%r12
mov    0x58(%rsp),%r14d
mov    %rdx,%r15
cs nopw 0x0(%rax,%rax,1)
movsd  (%r12),%xmm0
movsd  %xmm0,(%rbx)
test   %r14d,%r14d
je     1177 <msr_pack_float_64+0x57>
mov    %rbx,%rdi
call   1040 <ms_gswap8@plt>
add    $0x8,%rbx
lea    -0x8(%rbp),%r13d
lea    -0x1(%r15),%eax
cmp    $0x2,%r15d
jl     119f <msr_pack_float_64+0x7f>
add    $0x8,%r12
mov    %eax,%r15d
cmp    $0xf,%ebp
mov    %r13d,%ebp
jg     1160 <msr_pack_float_64+0x40>
jmp    119f <msr_pack_float_64+0x7f>
mov    %ebp,%r13d
mov    %edx,%eax
mov    0x50(%rsp),%r14
mov    0x8(%rsp),%rbp
sub    %eax,%ebp
lea    0x0(,%rbp,8),%eax
mov    0x10(%rsp),%r15
mov    %eax,(%r15)
cmpl   $0x0,0x4(%rsp)
je     11d1 <msr_pack_float_64+0xb1>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r13d,%edx
call   1030 <memset@plt>
add    %r13d,(%r15)
mov    %ebp,(%r14)
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @msr_pack_float_64(double* %0, double* %1, i32 %2, i32 %3, i32 %4, i32* %5, i32* %6, i32 %7) {
%9 = alloca double*
%10 = alloca double*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
store double* %0, double** %9
store double* %1, double** %10
store i32 %2, i32* %11
store i32 %3, i32* %12
store i32 %4, i32* %13
store i32* %5, i32** %14
store i32* %6, i32** %15
store i32 %7, i32* %16
%19 = load i32, i32* %11
store i32 %19, i32* %17
store i32 0, i32* %18
br label %20
20: ; preds = %40, %8
%21 = load i32, i32* %17
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* %12
%25 = icmp sge i32 %24, 8
br label %26
26: ; preds = %23, %20
%27 = phi i1 [ false, %20 ], [ %25, %23 ]
br i1 %27, label %28, label %49
28: ; preds = %26
%29 = load double*, double** %10
%30 = load i32, i32* %18
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double, double* %29, i64 %31
%33 = load double, double* %32
%34 = load double*, double** %9
store double %33, double* %34
%35 = load i32, i32* %16
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %28
%38 = load double*, double** %9
%39 = call i32 @ms_gswap8(double* %38)
br label %40
40: ; preds = %37, %28
%41 = load double*, double** %9
%42 = getelementptr inbounds double, double* %41, i32 1
store double* %42, double** %9
%43 = load i32, i32* %12
%44 = sub nsw i32 %43, 8
store i32 %44, i32* %12
%45 = load i32, i32* %17
%46 = add nsw i32 %45, -1
store i32 %46, i32* %17
%47 = load i32, i32* %18
%48 = add nsw i32 %47, 1
store i32 %48, i32* %18
br label %20
49: ; preds = %26
%50 = load i32, i32* %11
%51 = load i32, i32* %17
%52 = sub nsw i32 %50, %51
%53 = mul nsw i32 %52, 8
%54 = load i32*, i32** %14
store i32 %53, i32* %54
%55 = load i32, i32* %13
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %66
57: ; preds = %49
%58 = load double*, double** %9
%59 = bitcast double* %58 to i8*
%60 = load i32, i32* %12
%61 = call i32 @memset(i8* %59, i32 0, i32 %60)
%62 = load i32, i32* %12
%63 = load i32*, i32** %14
%64 = load i32, i32* %63
%65 = add nsw i32 %64, %62
store i32 %65, i32* %63
br label %66
66: ; preds = %57, %49
%67 = load i32, i32* %11
%68 = load i32, i32* %17
%69 = sub nsw i32 %67, %68
%70 = load i32*, i32** %15
store i32 %69, i32* %70
ret i32 0
}

LLVM IR (-O2):
define i32 @msr_pack_float_64(double* %0, double* nocapture %1, i32 %2, i32 %3, i32 %4, i32* nocapture %5, i32* nocapture writeonly %6, i32 %7) {
%9 = icmp sgt i32 %2, 0
%10 = icmp sgt i32 %3, 7
%11 = and i1 %9, %10
br i1 %11, label %12, label %31
12: ; preds = %8
%13 = icmp eq i32 %7, 0
br label %14
14: ; preds = %12, %23
%15 = phi i64 [ 0, %12 ], [ %27, %23 ]
%16 = phi i32 [ %2, %12 ], [ %26, %23 ]
%17 = phi double* [ %0, %12 ], [ %24, %23 ]
%18 = phi i32 [ %3, %12 ], [ %25, %23 ]
%19 = getelementptr inbounds double, double* %1, i64 %15
%20 = load double, double* %19
store double %20, double* %17
br i1 %13, label %23, label %21
21: ; preds = %14
%22 = tail call i32 @ms_gswap8(double* %17)
br label %23
23: ; preds = %21, %14
%24 = getelementptr inbounds double, double* %17, i64 1
%25 = add nsw i32 %18, -8
%26 = add nsw i32 %16, -1
%27 = add nuw nsw i64 %15, 1
%28 = icmp sgt i32 %16, 1
%29 = icmp sgt i32 %18, 15
%30 = select i1 %28, i1 %29, i1 false
br i1 %30, label %14, label %31
31: ; preds = %23, %8
%32 = phi i32 [ %3, %8 ], [ %25, %23 ]
%33 = phi double* [ %0, %8 ], [ %24, %23 ]
%34 = phi i32 [ %2, %8 ], [ %26, %23 ]
%35 = sub nsw i32 %2, %34
%36 = shl nsw i32 %35, 3
store i32 %36, i32* %5
%37 = icmp eq i32 %4, 0
br i1 %37, label %43, label %38
38: ; preds = %31
%39 = bitcast double* %33 to i8*
%40 = tail call i32 @memset(i8* %39, i32 0, i32 %32)
%41 = load i32, i32* %5
%42 = add nsw i32 %41, %32
store i32 %42, i32* %5
br label %43
43: ; preds = %38, %31
store i32 %35, i32* %6
ret i32 0
}