#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*/ uint64_t;

/* Variables and functions */
int /*<<< orphan*/ copy_in(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
void buffer_load(int flag, uint64_t *global_buf_A,
                 char part_buf_A[64][128 * ((512) / (64))],
                 uint64_t *global_buf_B,
                 char part_buf_B[64][128 * ((512) / (64))]) {
#pragma HLS INLINE off
  uint64_t large_A[64][128 * ((512) / (64)) / 8];
#pragma HLS ARRAY_PARTITION variable = large_A dim = 1 complete
  uint64_t large_B[64][128 * ((512) / (64)) / 8];
#pragma HLS ARRAY_PARTITION variable = large_B dim = 1 complete
  int i;
  if (flag) {
    for (i = 0; i < 64; i++) {
      memcpy(large_A[i], global_buf_A + i * (128 * ((512) / (64))) / 8,
             128 * ((512) / (64)));
    }
    for (i = 0; i < 64; i++) {
#pragma HLS UNROLL
      copy_in(large_A[i], part_buf_A[i]);
    }
    for (i = 0; i < 64; i++) {
      memcpy(large_B[i], global_buf_B + i * (128 * ((512) / (64))) / 8,
             128 * ((512) / (64)));
    }
    for (i = 0; i < 64; i++) {
#pragma HLS UNROLL
      copy_in(large_B[i], part_buf_B[i]);
    }
  }
  return;
}


x86 assembly (clang, -O0):
<buffer_load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10040,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     12cb <buffer_load+0x1ab>
movl   $0x0,-0x10034(%rbp)
cmpl   $0x40,-0x10034(%rbp)
jge    11b0 <buffer_load+0x90>
movslq -0x10034(%rbp),%rax
lea    -0x8030(%rbp),%rdi
shl    $0x9,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x10034(%rbp),%eax
shl    $0xa,%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cltq
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x400,%edx
call   1040 <memcpy@plt>
mov    -0x10034(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10034(%rbp)
jmp    1152 <buffer_load+0x32>
movl   $0x0,-0x10034(%rbp)
cmpl   $0x40,-0x10034(%rbp)
jge    1207 <buffer_load+0xe7>
movslq -0x10034(%rbp),%rax
lea    -0x8030(%rbp),%rdi
shl    $0x9,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
movslq -0x10034(%rbp),%rax
shl    $0xa,%rax
add    %rax,%rsi
call   1030 <copy_in@plt>
mov    -0x10034(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10034(%rbp)
jmp    11ba <buffer_load+0x9a>
movl   $0x0,-0x10034(%rbp)
cmpl   $0x40,-0x10034(%rbp)
jge    126f <buffer_load+0x14f>
movslq -0x10034(%rbp),%rax
lea    -0x10030(%rbp),%rdi
shl    $0x9,%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10034(%rbp),%eax
shl    $0xa,%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cltq
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x400,%edx
call   1040 <memcpy@plt>
mov    -0x10034(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10034(%rbp)
jmp    1211 <buffer_load+0xf1>
movl   $0x0,-0x10034(%rbp)
cmpl   $0x40,-0x10034(%rbp)
jge    12c6 <buffer_load+0x1a6>
movslq -0x10034(%rbp),%rax
lea    -0x10030(%rbp),%rdi
shl    $0x9,%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
movslq -0x10034(%rbp),%rax
shl    $0xa,%rax
add    %rax,%rsi
call   1030 <copy_in@plt>
mov    -0x10034(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10034(%rbp)
jmp    1279 <buffer_load+0x159>
jmp    12cb <buffer_load+0x1ab>
add    $0x10040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buffer_load>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10000,%rsp
test   %edi,%edi
je     1203 <buffer_load+0xe3>
mov    %r8,%r15
mov    %rcx,%r14
mov    %rdx,%r13
mov    %rsi,%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
lea    (%rsp,%rbx,1),%rdi
add    $0x8000,%rdi
lea    (%r12,%rbx,1),%rsi
mov    $0x400,%edx
call   1040 <memcpy@plt>
add    $0x200,%rbx
cmp    $0x8000,%rbx
jne    1150 <buffer_load+0x30>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
lea    (%rsp,%rbx,1),%rdi
add    $0x8000,%rdi
mov    %r13,%rsi
call   1030 <copy_in@plt>
add    $0x200,%rbx
add    $0x400,%r13
cmp    $0x8000,%rbx
jne    1180 <buffer_load+0x60>
xor    %ebx,%ebx
nopl   0x0(%rax)
lea    (%rsp,%rbx,1),%rdi
lea    (%r14,%rbx,1),%rsi
mov    $0x400,%edx
call   1040 <memcpy@plt>
add    $0x200,%rbx
cmp    $0x8000,%rbx
jne    11b0 <buffer_load+0x90>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    (%rsp,%rbx,1),%rdi
mov    %r15,%rsi
call   1030 <copy_in@plt>
add    $0x200,%rbx
add    $0x400,%r15
cmp    $0x8000,%rbx
jne    11e0 <buffer_load+0xc0>
add    $0x10000,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @buffer_load(i32 %0, i32* %1, [1024 x i8]* %2, i32* %3, [1024 x i8]* %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca [1024 x i8]*
%9 = alloca i32*
%10 = alloca [1024 x i8]*
%11 = alloca [64 x [128 x i32]]
%12 = alloca [64 x [128 x i32]]
%13 = alloca i32
store i32 %0, i32* %6
store i32* %1, i32** %7
store [1024 x i8]* %2, [1024 x i8]** %8
store i32* %3, i32** %9
store [1024 x i8]* %4, [1024 x i8]** %10
%14 = load i32, i32* %6
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %91
16: ; preds = %5
store i32 0, i32* %13
br label %17
17: ; preds = %32, %16
%18 = load i32, i32* %13
%19 = icmp slt i32 %18, 64
br i1 %19, label %20, label %35
20: ; preds = %17
%21 = load i32, i32* %13
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [64 x [128 x i32]], [64 x [128 x i32]]* %11, i64 0, i64 %22
%24 = getelementptr inbounds [128 x i32], [128 x i32]* %23, i64 0, i64 0
%25 = load i32*, i32** %7
%26 = load i32, i32* %13
%27 = mul nsw i32 %26, 1024
%28 = sdiv i32 %27, 8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %25, i64 %29
%31 = call i32 @memcpy(i32* %24, i32* %30, i32 1024)
br label %32
32: ; preds = %20
%33 = load i32, i32* %13
%34 = add nsw i32 %33, 1
store i32 %34, i32* %13
br label %17
35: ; preds = %17
store i32 0, i32* %13
br label %36
36: ; preds = %50, %35
%37 = load i32, i32* %13
%38 = icmp slt i32 %37, 64
br i1 %38, label %39, label %53
39: ; preds = %36
%40 = load i32, i32* %13
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [64 x [128 x i32]], [64 x [128 x i32]]* %11, i64 0, i64 %41
%43 = getelementptr inbounds [128 x i32], [128 x i32]* %42, i64 0, i64 0
%44 = load [1024 x i8]*, [1024 x i8]** %8
%45 = load i32, i32* %13
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %44, i64 %46
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %47, i64 0, i64 0
%49 = call i32 @copy_in(i32* %43, i8* %48)
br label %50
50: ; preds = %39
%51 = load i32, i32* %13
%52 = add nsw i32 %51, 1
store i32 %52, i32* %13
br label %36
53: ; preds = %36
store i32 0, i32* %13
br label %54
54: ; preds = %69, %53
%55 = load i32, i32* %13
%56 = icmp slt i32 %55, 64
br i1 %56, label %57, label %72
57: ; preds = %54
%58 = load i32, i32* %13
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [64 x [128 x i32]], [64 x [128 x i32]]* %12, i64 0, i64 %59
%61 = getelementptr inbounds [128 x i32], [128 x i32]* %60, i64 0, i64 0
%62 = load i32*, i32** %9
%63 = load i32, i32* %13
%64 = mul nsw i32 %63, 1024
%65 = sdiv i32 %64, 8
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i32, i32* %62, i64 %66
%68 = call i32 @memcpy(i32* %61, i32* %67, i32 1024)
br label %69
69: ; preds = %57
%70 = load i32, i32* %13
%71 = add nsw i32 %70, 1
store i32 %71, i32* %13
br label %54
72: ; preds = %54
store i32 0, i32* %13
br label %73
73: ; preds = %87, %72
%74 = load i32, i32* %13
%75 = icmp slt i32 %74, 64
br i1 %75, label %76, label %90
76: ; preds = %73
%77 = load i32, i32* %13
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds [64 x [128 x i32]], [64 x [128 x i32]]* %12, i64 0, i64 %78
%80 = getelementptr inbounds [128 x i32], [128 x i32]* %79, i64 0, i64 0
%81 = load [1024 x i8]*, [1024 x i8]** %10
%82 = load i32, i32* %13
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds [1024 x i8], [1024 x i8]* %81, i64 %83
%85 = getelementptr inbounds [1024 x i8], [1024 x i8]* %84, i64 0, i64 0
%86 = call i32 @copy_in(i32* %80, i8* %85)
br label %87
87: ; preds = %76
%88 = load i32, i32* %13
%89 = add nsw i32 %88, 1
store i32 %89, i32* %13
br label %73
90: ; preds = %73
br label %91
91: ; preds = %90, %5
ret void
}

LLVM IR (-O2):
define void @buffer_load(i32 %0, i32* %1, [1024 x i8]* %2, i32* %3, [1024 x i8]* %4) {
%6 = alloca [64 x [128 x i32]]
%7 = alloca [64 x [128 x i32]]
%8 = bitcast [64 x [128 x i32]]* %6 to i8*
%9 = bitcast [64 x [128 x i32]]* %7 to i8*
%10 = icmp eq i32 %0, 0
br i1 %10, label %41, label %11
11: ; preds = %5, %11
%12 = phi i64 [ %17, %11 ], [ 0, %5 ]
%13 = getelementptr inbounds [64 x [128 x i32]], [64 x [128 x i32]]* %6, i64 0, i64 %12, i64 0
%14 = shl nuw nsw i64 %12, 7
%15 = getelementptr inbounds i32, i32* %1, i64 %14
%16 = call i32 @memcpy(i32* %13, i32* %15, i32 1024)
%17 = add nuw nsw i64 %12, 1
%18 = icmp eq i64 %17, 64
br i1 %18, label %19, label %11
19: ; preds = %11, %19
%20 = phi i64 [ %24, %19 ], [ 0, %11 ]
%21 = getelementptr inbounds [64 x [128 x i32]], [64 x [128 x i32]]* %6, i64 0, i64 %20, i64 0
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 %20, i64 0
%23 = call i32 @copy_in(i32* %21, i8* %22)
%24 = add nuw nsw i64 %20, 1
%25 = icmp eq i64 %24, 64
br i1 %25, label %26, label %19
26: ; preds = %19, %26
%27 = phi i64 [ %32, %26 ], [ 0, %19 ]
%28 = getelementptr inbounds [64 x [128 x i32]], [64 x [128 x i32]]* %7, i64 0, i64 %27, i64 0
%29 = shl nuw nsw i64 %27, 7
%30 = getelementptr inbounds i32, i32* %3, i64 %29
%31 = call i32 @memcpy(i32* %28, i32* %30, i32 1024)
%32 = add nuw nsw i64 %27, 1
%33 = icmp eq i64 %32, 64
br i1 %33, label %34, label %26
34: ; preds = %26, %34
%35 = phi i64 [ %39, %34 ], [ 0, %26 ]
%36 = getelementptr inbounds [64 x [128 x i32]], [64 x [128 x i32]]* %7, i64 0, i64 %35, i64 0
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 %35, i64 0
%38 = call i32 @copy_in(i32* %36, i8* %37)
%39 = add nuw nsw i64 %35, 1
%40 = icmp eq i64 %39, 64
br i1 %40, label %41, label %34
41: ; preds = %34, %5
ret void
}