#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_decode_float64(double *input, int samplecount, double *output,
                       int outputlength, int swapflag) {
  double sample;
  int idx;
  if (samplecount <= 0)
    return 0;
  if (!input || !output || outputlength <= 0)
    return -1;
  for (idx = 0; idx < samplecount && outputlength >= (int)sizeof(double);
       idx++) {
    memcpy(&sample, &input[idx], sizeof(double));
    if (swapflag)
      ms_gswap8a(&sample);
    output[idx] = sample;
    outputlength -= sizeof(double);
  }
  return idx;
}


x86 assembly (clang, -O0):
<msr_decode_float64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     1150 <msr_decode_float64+0x30>
movl   $0x0,-0x4(%rbp)
jmp    120f <msr_decode_float64+0xef>
cmpq   $0x0,-0x10(%rbp)
je     1170 <msr_decode_float64+0x50>
cmpq   $0x0,-0x20(%rbp)
je     1170 <msr_decode_float64+0x50>
cmpl   $0x0,-0x24(%rbp)
jg     117c <msr_decode_float64+0x5c>
movl   $0xffffffff,-0x4(%rbp)
jmp    120f <msr_decode_float64+0xef>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%ecx
xor    %eax,%eax
cmp    -0x14(%rbp),%ecx
mov    %al,-0x35(%rbp)
jge    119e <msr_decode_float64+0x7e>
cmpl   $0x8,-0x24(%rbp)
setge  %al
mov    %al,-0x35(%rbp)
mov    -0x35(%rbp),%al
test   $0x1,%al
jne    11ae <msr_decode_float64+0x8e>
jmp    1209 <msr_decode_float64+0xe9>
mov    -0x10(%rbp),%rsi
movslq -0x34(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
lea    -0x30(%rbp),%rdi
mov    $0x8,%edx
call   1040 <memcpy@plt>
cmpl   $0x0,-0x28(%rbp)
je     11de <msr_decode_float64+0xbe>
lea    -0x30(%rbp),%rdi
call   1030 <ms_gswap8a@plt>
movsd  -0x30(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movslq -0x24(%rbp),%rax
sub    $0x8,%rax
mov    %eax,-0x24(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1183 <msr_decode_float64+0x63>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<msr_decode_float64>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,0xc(%rsp)
xor    %ebx,%ebx
test   %esi,%esi
jle    11b6 <msr_decode_float64+0x96>
mov    %rdi,%rbp
mov    $0xffffffff,%ebx
test   %rdi,%rdi
je     11b6 <msr_decode_float64+0x96>
mov    %rdx,%r15
test   %rdx,%rdx
je     11b6 <msr_decode_float64+0x96>
mov    %ecx,%r12d
test   %ecx,%ecx
jle    11b6 <msr_decode_float64+0x96>
mov    $0x0,%ebx
cmp    $0x8,%r12d
jb     11b6 <msr_decode_float64+0x96>
mov    %esi,%r14d
xor    %ebx,%ebx
lea    0x10(%rsp),%r13
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %rbp,%rsi
mov    $0x8,%edx
call   1040 <memcpy@plt>
cmpl   $0x0,0xc(%rsp)
je     118f <msr_decode_float64+0x6f>
mov    %r13,%rdi
call   1030 <ms_gswap8a@plt>
movsd  0x10(%rsp),%xmm0
movsd  %xmm0,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %r14,%rbx
jae    11b6 <msr_decode_float64+0x96>
lea    -0x8(%r12),%eax
add    $0x8,%rbp
cmp    $0xf,%r12d
mov    %eax,%r12d
jg     1170 <msr_decode_float64+0x50>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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