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

/* Variables and functions */
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
void reshape_cifar_image(uint8_t *image_data, int num_bytes) {
  uint8_t temp_data[3072];
  memcpy(temp_data, image_data, num_bytes);
  int k = 0;
  for (int i = 0; i < 1024; i++) {
    int r_ind = 0 + i;
    int g_ind = 1024 + i;
    int b_ind = (1024 * 2) + i;
    image_data[k] = temp_data[r_ind];
    k++;
    image_data[k] = temp_data[g_ind];
    k++;
    image_data[k] = temp_data[b_ind];
    k++;
  }
}


x86 assembly (clang, -O0):
<reshape_cifar_image>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3030,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x3010(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <memcpy@plt>
movl   $0x0,-0x3014(%rbp)
movl   $0x0,-0x3018(%rbp)
cmpl   $0x400,-0x3018(%rbp)
jge    121f <reshape_cifar_image+0x10f>
mov    -0x3018(%rbp),%eax
add    $0x0,%eax
mov    %eax,-0x301c(%rbp)
mov    -0x3018(%rbp),%eax
add    $0x400,%eax
mov    %eax,-0x3020(%rbp)
mov    -0x3018(%rbp),%eax
add    $0x800,%eax
mov    %eax,-0x3024(%rbp)
movslq -0x301c(%rbp),%rax
mov    -0x3010(%rbp,%rax,4),%edx
mov    -0x8(%rbp),%rax
movslq -0x3014(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x3014(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3014(%rbp)
movslq -0x3020(%rbp),%rax
mov    -0x3010(%rbp,%rax,4),%edx
mov    -0x8(%rbp),%rax
movslq -0x3014(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x3014(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3014(%rbp)
movslq -0x3024(%rbp),%rax
mov    -0x3010(%rbp,%rax,4),%edx
mov    -0x8(%rbp),%rax
movslq -0x3014(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x3014(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3014(%rbp)
mov    -0x3018(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3018(%rbp)
jmp    1149 <reshape_cifar_image+0x39>
add    $0x3030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reshape_cifar_image>:
push   %rbx
sub    $0x3000,%rsp
mov    %esi,%edx
mov    %rdi,%rbx
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1030 <memcpy@plt>
add    $0x8,%rbx
mov    $0xfffffffffffffc00,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x1000(%rsp,%rax,4),%ecx
mov    %ecx,-0x8(%rbx)
mov    0x2000(%rsp,%rax,4),%ecx
mov    %ecx,-0x4(%rbx)
mov    0x3000(%rsp,%rax,4),%ecx
mov    %ecx,(%rbx)
add    $0xc,%rbx
inc    %rax
jne    1140 <reshape_cifar_image+0x30>
add    $0x3000,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
define void @reshape_cifar_image(i32* %0, i32 %1) {
%3 = alloca [3072 x i32]
%4 = bitcast [3072 x i32]* %3 to i8*
%5 = getelementptr inbounds [3072 x i32], [3072 x i32]* %3, i64 0, i64 0
%6 = call i32 @memcpy(i32* %5, i32* %0, i32 %1)
br label %8
7: ; preds = %8
ret void
8: ; preds = %2, %8
%9 = phi i64 [ 0, %2 ], [ %25, %8 ]
%10 = phi i64 [ 0, %2 ], [ %24, %8 ]
%11 = add nuw nsw i64 %9, 1024
%12 = add nuw nsw i64 %9, 2048
%13 = getelementptr inbounds [3072 x i32], [3072 x i32]* %3, i64 0, i64 %9
%14 = load i32, i32* %13
%15 = getelementptr inbounds i32, i32* %0, i64 %10
store i32 %14, i32* %15
%16 = add nuw nsw i64 %10, 1
%17 = getelementptr inbounds [3072 x i32], [3072 x i32]* %3, i64 0, i64 %11
%18 = load i32, i32* %17
%19 = getelementptr inbounds i32, i32* %0, i64 %16
store i32 %18, i32* %19
%20 = add nuw nsw i64 %10, 2
%21 = getelementptr inbounds [3072 x i32], [3072 x i32]* %3, i64 0, i64 %12
%22 = load i32, i32* %21
%23 = getelementptr inbounds i32, i32* %0, i64 %20
store i32 %22, i32* %23
%24 = add nuw nsw i64 %10, 3
%25 = add nuw nsw i64 %9, 1
%26 = icmp eq i64 %25, 1024
br i1 %26, label %7, label %8
}