#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 extract_nbit_words(void *, int, int, int *);
int /*<<< orphan*/ memcpy(void *, char *, int);
int extract_wgdos_row(char **packed_data, int ndata, int bits_per_value,
                      void *buffer, int *data) {
  int i;
  int status = 0;
  int nsus_to_read;
  if (bits_per_value == 0) {
    for (i = 0; i < ndata; i++) {
      data[i] = 0;
    }
  } else if (ndata > 0) {
    nsus_to_read = (((bits_per_value * ndata) + 32 - 1) / 32);
    memcpy(buffer, *packed_data, nsus_to_read * (32 / 8));
    *packed_data = *packed_data + nsus_to_read * (32 / 8);
    status = extract_nbit_words(buffer, bits_per_value, ndata, data);
  }
  return status;
}


x86 assembly (clang, -O0):
<extract_wgdos_row>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    1180 <extract_wgdos_row+0x60>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    117b <extract_wgdos_row+0x5b>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1152 <extract_wgdos_row+0x32>
jmp    11ec <extract_wgdos_row+0xcc>
cmpl   $0x0,-0xc(%rbp)
jle    11e7 <extract_wgdos_row+0xc7>
mov    -0x10(%rbp),%eax
imul   -0xc(%rbp),%eax
add    $0x20,%eax
sub    $0x1,%eax
mov    $0x20,%ecx
cltd
idiv   %ecx
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
mov    -0x2c(%rbp),%edx
shl    $0x2,%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
mov    -0x2c(%rbp),%eax
shl    $0x2,%eax
cltq
add    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x20(%rbp),%rcx
call   1030 <extract_nbit_words@plt>
mov    %eax,-0x28(%rbp)
jmp    11ec <extract_wgdos_row+0xcc>
mov    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_wgdos_row>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %esi,%r13d
test   %edx,%edx
je     119b <extract_wgdos_row+0x6b>
test   %r13d,%r13d
jle    11b1 <extract_wgdos_row+0x81>
mov    %rcx,%r15
mov    %edx,%ebx
mov    %rdi,%r12
mov    %edx,%ebp
imul   %r13d,%ebp
lea    0x1f(%rbp),%eax
add    $0x3e,%ebp
test   %eax,%eax
cmovns %eax,%ebp
sar    $0x5,%ebp
mov    (%rdi),%rsi
shl    $0x2,%ebp
mov    %rcx,%rdi
mov    %ebp,%edx
call   1050 <memcpy@plt>
movslq %ebp,%rax
add    %rax,(%r12)
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r13d,%edx
mov    %r14,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <extract_nbit_words@plt>
test   %r13d,%r13d
jle    11b1 <extract_wgdos_row+0x81>
mov    %r13d,%edx
shl    $0x2,%rdx
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @extract_wgdos_row(i8** nocapture %0, i32 %1, i32 %2, i8* %3, i32* %4) {
%6 = bitcast i32* %4 to i8*
%7 = icmp eq i32 %2, 0
%8 = icmp sgt i32 %1, 0
br i1 %7, label %9, label %13
9: ; preds = %5
br i1 %8, label %10, label %25
10: ; preds = %9
%11 = zext i32 %1 to i64
%12 = shl nuw nsw i64 %11, 2
br label %25
13: ; preds = %5
br i1 %8, label %14, label %25
14: ; preds = %13
%15 = mul nsw i32 %2, %1
%16 = add nsw i32 %15, 31
%17 = sdiv i32 %16, 32
%18 = load i8*, i8** %0
%19 = shl nsw i32 %17, 2
%20 = tail call i32 @memcpy(i8* %3, i8* %18, i32 %19)
%21 = load i8*, i8** %0
%22 = sext i32 %19 to i64
%23 = getelementptr inbounds i8, i8* %21, i64 %22
store i8* %23, i8** %0
%24 = tail call i32 @extract_nbit_words(i8* %3, i32 %2, i32 %1, i32* %4)
br label %25
25: ; preds = %10, %9, %13, %14
%26 = phi i32 [ %24, %14 ], [ 0, %13 ], [ 0, %9 ], [ 0, %10 ]
ret i32 %26
}