#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_out(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
void buffer_store(int flag, uint64_t *global_buf_A,
                  char part_buf_A[64][(128 + 128) * ((512) / (64))],
                  uint64_t *global_buf_B,
                  char part_buf_B[64][(128 + 128) * ((512) / (64))]) {
#pragma HLS INLINE off
  uint64_t large_A[64][(128 + 128) * ((512) / (64)) / 8];
#pragma HLS ARRAY_PARTITION variable = large_A dim = 1 complete
  uint64_t large_B[64][(128 + 128) * ((512) / (64)) / 8];
#pragma HLS ARRAY_PARTITION variable = large_B dim = 1 complete
  int i;
  if (flag) {
    for (i = 0; i < 64; i++) {
#pragma HLS UNROLL
      copy_out(large_A[i], part_buf_A[i]);
    }
    for (i = 0; i < 64; i++) {
      memcpy(global_buf_A + i * ((128 + 128) * ((512) / (64))) / 64, large_A[i],
             (128 + 128) * ((512) / (64)));
    }
    for (i = 0; i < 64; i++) {
#pragma HLS UNROLL
      copy_out(large_B[i], part_buf_B[i]);
    }
    for (i = 0; i < 64; i++) {
      memcpy(global_buf_B + i * ((128 + 128) * ((512) / (64))) / 64, large_B[i],
             (128 + 128) * ((512) / (64)));
    }
  }
  return;
}


x86 assembly (clang, -O0):
<buffer_store>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20040,%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_store+0x1ab>
movl   $0x0,-0x20034(%rbp)
cmpl   $0x40,-0x20034(%rbp)
jge    119f <buffer_store+0x7f>
movslq -0x20034(%rbp),%rax
lea    -0x10030(%rbp),%rdi
shl    $0xa,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
movslq -0x20034(%rbp),%rax
shl    $0xb,%rax
add    %rax,%rsi
call   1040 <copy_out@plt>
mov    -0x20034(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20034(%rbp)
jmp    1152 <buffer_store+0x32>
movl   $0x0,-0x20034(%rbp)
cmpl   $0x40,-0x20034(%rbp)
jge    1207 <buffer_store+0xe7>
mov    -0x10(%rbp),%rdi
mov    -0x20034(%rbp),%eax
shl    $0xb,%eax
mov    $0x40,%ecx
cltd
idiv   %ecx
cltq
shl    $0x2,%rax
add    %rax,%rdi
movslq -0x20034(%rbp),%rax
lea    -0x10030(%rbp),%rsi
shl    $0xa,%rax
add    %rax,%rsi
mov    $0x800,%edx
call   1030 <memcpy@plt>
mov    -0x20034(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20034(%rbp)
jmp    11a9 <buffer_store+0x89>
movl   $0x0,-0x20034(%rbp)
cmpl   $0x40,-0x20034(%rbp)
jge    125e <buffer_store+0x13e>
movslq -0x20034(%rbp),%rax
lea    -0x20030(%rbp),%rdi
shl    $0xa,%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
movslq -0x20034(%rbp),%rax
shl    $0xb,%rax
add    %rax,%rsi
call   1040 <copy_out@plt>
mov    -0x20034(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20034(%rbp)
jmp    1211 <buffer_store+0xf1>
movl   $0x0,-0x20034(%rbp)
cmpl   $0x40,-0x20034(%rbp)
jge    12c6 <buffer_store+0x1a6>
mov    -0x20(%rbp),%rdi
mov    -0x20034(%rbp),%eax
shl    $0xb,%eax
mov    $0x40,%ecx
cltd
idiv   %ecx
cltq
shl    $0x2,%rax
add    %rax,%rdi
movslq -0x20034(%rbp),%rax
lea    -0x20030(%rbp),%rsi
shl    $0xa,%rax
add    %rax,%rsi
mov    $0x800,%edx
call   1030 <memcpy@plt>
mov    -0x20034(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20034(%rbp)
jmp    1268 <buffer_store+0x148>
jmp    12cb <buffer_store+0x1ab>
add    $0x20040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buffer_store>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20000,%rsp
test   %edi,%edi
je     1215 <buffer_store+0xf5>
mov    %r8,%r12
mov    %rcx,%r14
mov    %rdx,%r13
mov    %rsi,%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
lea    (%rsp,%rbx,1),%rdi
add    $0x10000,%rdi
mov    %r13,%rsi
call   1040 <copy_out@plt>
add    $0x400,%rbx
add    $0x800,%r13
cmp    $0x10000,%rbx
jne    1150 <buffer_store+0x30>
lea    0x10000(%rsp),%r13
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    (%r15,%rbx,1),%rdi
mov    %r13,%rsi
mov    $0x800,%edx
call   1030 <memcpy@plt>
sub    $0xffffffffffffff80,%rbx
add    $0x400,%r13
cmp    $0x2000,%rbx
jne    1190 <buffer_store+0x70>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
lea    (%rsp,%rbx,1),%rdi
mov    %r12,%rsi
call   1040 <copy_out@plt>
add    $0x400,%rbx
add    $0x800,%r12
cmp    $0x10000,%rbx
jne    11c0 <buffer_store+0xa0>
mov    %rsp,%r15
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
lea    (%r14,%rbx,1),%rdi
mov    %r15,%rsi
mov    $0x800,%edx
call   1030 <memcpy@plt>
sub    $0xffffffffffffff80,%rbx
add    $0x400,%r15
cmp    $0x2000,%rbx
jne    11f0 <buffer_store+0xd0>
add    $0x20000,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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