#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 */
typedef int /*<<< orphan*/ int32_t;

/* Variables and functions */
int /*<<< orphan*/ ms_gswap4a(int /*<<< orphan*/ *);
int msr_unpack_int_32(int32_t *ibuf, int num_samples, int req_samples,
                      int32_t *databuff, int swapflag) {
  int nd = 0;
  int32_t itmp;
  if (num_samples < 0)
    return 0;
  if (req_samples < 0)
    return 0;
  for (nd = 0; nd < req_samples && nd < num_samples; nd++) {
    itmp = ibuf[nd];
    if (swapflag)
      ms_gswap4a(&itmp);
    databuff[nd] = itmp;
  }
  return nd;
}


x86 assembly (clang, -O0):
<msr_unpack_int_32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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    1147 <msr_unpack_int_32+0x37>
movl   $0x0,-0x4(%rbp)
jmp    11d4 <msr_unpack_int_32+0xc4>
cmpl   $0x0,-0x18(%rbp)
jge    115d <msr_unpack_int_32+0x4d>
movl   $0x0,-0x4(%rbp)
jmp    11d4 <msr_unpack_int_32+0xc4>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%ecx
xor    %eax,%eax
cmp    -0x18(%rbp),%ecx
mov    %al,-0x2d(%rbp)
jge    1181 <msr_unpack_int_32+0x71>
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
setl   %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    1191 <msr_unpack_int_32+0x81>
jmp    11ce <msr_unpack_int_32+0xbe>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11b2 <msr_unpack_int_32+0xa2>
lea    -0x2c(%rbp),%rdi
call   1030 <ms_gswap4a@plt>
mov    -0x2c(%rbp),%edx
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1164 <msr_unpack_int_32+0x54>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<msr_unpack_int_32>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %ebp,%ebp
mov    %edx,%eax
or     %esi,%eax
js     1179 <msr_unpack_int_32+0x69>
test   %edx,%edx
jle    1179 <msr_unpack_int_32+0x69>
test   %esi,%esi
jle    1179 <msr_unpack_int_32+0x69>
mov    %r8d,%r14d
mov    %rcx,%r15
mov    %rdi,%r13
add    $0xffffffff,%edx
add    $0xffffffff,%esi
cmp    %esi,%edx
cmovb  %edx,%esi
mov    %esi,%ebp
add    $0x1,%ebp
xor    %ebx,%ebx
lea    0x4(%rsp),%r12
jmp    115d <msr_unpack_int_32+0x4d>
nopl   (%rax)
mov    %eax,(%r15,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%rbp
je     1179 <msr_unpack_int_32+0x69>
mov    0x0(%r13,%rbx,4),%eax
mov    %eax,0x4(%rsp)
test   %r14d,%r14d
je     1150 <msr_unpack_int_32+0x40>
mov    %r12,%rdi
call   1030 <ms_gswap4a@plt>
mov    0x4(%rsp),%eax
jmp    1150 <msr_unpack_int_32+0x40>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @msr_unpack_int_32(i32* %0, i32 %1, i32 %2, i32* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32* %0, i32** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32* %3, i32** %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 i32*, i32** %7
%34 = load i32, i32* %12
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
%37 = load i32, i32* %36
store i32 %37, i32* %13
%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_gswap4a(i32* %13)
br label %42
42: ; preds = %40, %32
%43 = load i32, i32* %13
%44 = load i32*, i32** %10
%45 = load i32, i32* %12
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32, i32* %44, i64 %46
store i32 %43, i32* %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_int_32(i32* nocapture %0, i32 %1, i32 %2, i32* nocapture writeonly %3, i32 %4) {
%6 = alloca i32
%7 = bitcast i32* %6 to i8*
%8 = or i32 %2, %1
%9 = icmp sgt i32 %8, -1
br i1 %9, label %10, label %33
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 %33
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, %28
%22 = phi i64 [ 0, %14 ], [ %31, %28 ]
%23 = getelementptr inbounds i32, i32* %0, i64 %22
%24 = load i32, i32* %23
store i32 %24, i32* %6
br i1 %15, label %28, label %25
25: ; preds = %21
%26 = call i32 @ms_gswap4a(i32* %6)
%27 = load i32, i32* %6
br label %28
28: ; preds = %25, %21
%29 = phi i32 [ %27, %25 ], [ %24, %21 ]
%30 = getelementptr inbounds i32, i32* %3, i64 %22
store i32 %29, i32* %30
%31 = add nuw nsw i64 %22, 1
%32 = icmp eq i64 %31, %20
br i1 %32, label %33, label %21
33: ; preds = %28, %10, %5
%34 = phi i32 [ 0, %5 ], [ 0, %10 ], [ %19, %28 ]
ret i32 %34
}