#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*/ memcpy(double *, double *, int);
int /*<<< orphan*/ ms_gswap8a(double *);
int msr_unpack_float_64(double *fbuf, int num_samples, int req_samples,
                        double *databuff, int swapflag) {
  int nd = 0;
  double dtmp;
  if (num_samples < 0)
    return 0;
  if (req_samples < 0)
    return 0;
  for (nd = 0; nd < req_samples && nd < num_samples; nd++) {
    memcpy(&dtmp, &fbuf[nd], sizeof(double));
    if (swapflag)
      ms_gswap8a(&dtmp);
    databuff[nd] = dtmp;
  }
  return nd;
}


x86 assembly (clang, -O0):
<msr_unpack_float_64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1157 <msr_unpack_float_64+0x37>
movl   $0x0,-0x4(%rbp)
jmp    11f7 <msr_unpack_float_64+0xd7>
cmpl   $0x0,-0x18(%rbp)
jge    116d <msr_unpack_float_64+0x4d>
movl   $0x0,-0x4(%rbp)
jmp    11f7 <msr_unpack_float_64+0xd7>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%ecx
xor    %eax,%eax
cmp    -0x18(%rbp),%ecx
mov    %al,-0x31(%rbp)
jge    1191 <msr_unpack_float_64+0x71>
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
setl   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    11a1 <msr_unpack_float_64+0x81>
jmp    11f1 <msr_unpack_float_64+0xd1>
mov    -0x10(%rbp),%rsi
movslq -0x28(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
lea    -0x30(%rbp),%rdi
mov    $0x8,%edx
call   1040 <memcpy@plt>
cmpl   $0x0,-0x24(%rbp)
je     11d1 <msr_unpack_float_64+0xb1>
lea    -0x30(%rbp),%rdi
call   1030 <ms_gswap8a@plt>
movsd  -0x30(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1174 <msr_unpack_float_64+0x54>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<msr_unpack_float_64>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r12
xor    %eax,%eax
mov    %edx,%ecx
or     %esi,%ecx
js     11a9 <msr_unpack_float_64+0x89>
test   %edx,%edx
jle    11a9 <msr_unpack_float_64+0x89>
test   %esi,%esi
jle    11a9 <msr_unpack_float_64+0x89>
mov    %r8d,%r14d
mov    %rdi,%r13
add    $0xffffffff,%edx
add    $0xffffffff,%esi
cmp    %esi,%edx
cmovb  %edx,%esi
lea    0x1(%rsi),%eax
mov    %eax,0xc(%rsp)
lea    0x8(,%rsi,8),%rbp
xor    %r15d,%r15d
lea    0x10(%rsp),%rbx
jmp    1185 <msr_unpack_float_64+0x65>
nopl   0x0(%rax,%rax,1)
movsd  0x10(%rsp),%xmm0
movsd  %xmm0,(%r12,%r15,1)
add    $0x8,%r15
cmp    %r15,%rbp
je     11a5 <msr_unpack_float_64+0x85>
lea    (%r15,%r13,1),%rsi
mov    %rbx,%rdi
mov    $0x8,%edx
call   1040 <memcpy@plt>
test   %r14d,%r14d
je     1170 <msr_unpack_float_64+0x50>
mov    %rbx,%rdi
call   1030 <ms_gswap8a@plt>
jmp    1170 <msr_unpack_float_64+0x50>
mov    0xc(%rsp),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @msr_unpack_float_64(double* %0, i32 %1, i32 %2, double* %3, i32 %4) {
%6 = alloca i32
%7 = alloca double*
%8 = alloca i32
%9 = alloca i32
%10 = alloca double*
%11 = alloca i32
%12 = alloca i32
%13 = alloca double
store double* %0, double** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store double* %3, double** %10
store i32 %4, i32* %11
store i32 0, i32* %12
%14 = load i32, i32* %8
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %5
store i32 0, i32* %6
br label %53
17: ; preds = %5
%18 = load i32, i32* %9
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 0, i32* %6
br label %53
21: ; preds = %17
store i32 0, i32* %12
br label %22
22: ; preds = %48, %21
%23 = load i32, i32* %12
%24 = load i32, i32* %9
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = load i32, i32* %12
%28 = load i32, i32* %8
%29 = icmp slt i32 %27, %28
br label %30
30: ; preds = %26, %22
%31 = phi i1 [ false, %22 ], [ %29, %26 ]
br i1 %31, label %32, label %51
32: ; preds = %30
%33 = load double*, double** %7
%34 = load i32, i32* %12
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds double, double* %33, i64 %35
%37 = call i32 @memcpy(double* %13, double* %36, i32 8)
%38 = load i32, i32* %11
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %32
%41 = call i32 @ms_gswap8a(double* %13)
br label %42
42: ; preds = %40, %32
%43 = load double, double* %13
%44 = load double*, double** %10
%45 = load i32, i32* %12
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double, double* %44, i64 %46
store double %43, double* %47
br label %48
48: ; preds = %42
%49 = load i32, i32* %12
%50 = add nsw i32 %49, 1
store i32 %50, i32* %12
br label %22
51: ; preds = %30
%52 = load i32, i32* %12
store i32 %52, i32* %6
br label %53
53: ; preds = %51, %20, %16
%54 = load i32, i32* %6
ret i32 %54
}

LLVM IR (-O2):
define i32 @msr_unpack_float_64(double* %0, i32 %1, i32 %2, double* nocapture writeonly %3, i32 %4) {
%6 = alloca double
%7 = bitcast double* %6 to i8*
%8 = or i32 %2, %1
%9 = icmp sgt i32 %8, -1
br i1 %9, label %10, label %32
10: ; preds = %5
%11 = icmp sgt i32 %2, 0
%12 = icmp sgt i32 %1, 0
%13 = and i1 %11, %12
br i1 %13, label %14, label %32
14: ; preds = %10
%15 = icmp eq i32 %4, 0
%16 = add nsw i32 %2, -1
%17 = add nsw i32 %1, -1
%18 = call i32 @llvm.umin.i32(i32 %16, i32 %17)
%19 = add nuw nsw i32 %18, 1
%20 = zext i32 %19 to i64
br label %21
21: ; preds = %14, %27
%22 = phi i64 [ 0, %14 ], [ %30, %27 ]
%23 = getelementptr inbounds double, double* %0, i64 %22
%24 = call i32 @memcpy(double* %6, double* %23, i32 8)
br i1 %15, label %27, label %25
25: ; preds = %21
%26 = call i32 @ms_gswap8a(double* %6)
br label %27
27: ; preds = %25, %21
%28 = load double, double* %6
%29 = getelementptr inbounds double, double* %3, i64 %22
store double %28, double* %29
%30 = add nuw nsw i64 %22, 1
%31 = icmp eq i64 %30, %20
br i1 %31, label %32, label %21
32: ; preds = %27, %10, %5
%33 = phi i32 [ 0, %5 ], [ 0, %10 ], [ %19, %27 ]
ret i32 %33
}