#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 /*<<< orphan*/ apply_periodic_boundary(void *, int, int);
int /*<<< orphan*/ free(void *);
void *malloc(int);
int /*<<< orphan*/ memcpy(char **, void *, int);
int /*<<< orphan*/ repeat_mem(char *, int const, void *, int);
void stripe_cem_matrix(void **matrix, int n_rows, int n_cols, int itemsize,
                       void *stripe, int nitems) {
  const int offset_to_left = (n_cols / 4) * itemsize;
  const int width = (n_cols / 2) * itemsize;
  void *row = malloc(itemsize * n_cols);
  int i;
  repeat_mem((char *)row + offset_to_left, width, stripe, nitems * itemsize);
  apply_periodic_boundary(row, itemsize, n_cols);
  for (i = 0; i < n_rows; i++) {
    memcpy((char **)matrix[i], row, itemsize * n_cols);
  }
  free(row);
}


x86 assembly (clang, -O0):
<stripe_cem_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
imul   -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
imul   -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%edi
imul   -0x10(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
movslq -0x28(%rbp),%rax
add    %rax,%rdi
mov    -0x2c(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
imul   -0x14(%rbp),%ecx
call   1040 <repeat_mem@plt>
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1070 <apply_periodic_boundary@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    120b <stripe_cem_matrix+0xbb>
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x14(%rbp),%edx
imul   -0x10(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11d5 <stripe_cem_matrix+0x85>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stripe_cem_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebx
lea    0x3(%rbx),%ebp
test   %edx,%edx
cmovns %edx,%ebp
mov    %r9d,0x8(%rsp)
mov    %r8,0x10(%rsp)
mov    %ecx,%r13d
mov    %esi,0xc(%rsp)
mov    %rdi,%r14
sar    $0x2,%ebp
mov    %ecx,0x4(%rsp)
imul   %ecx,%ebp
mov    %edx,%r12d
shr    $0x1f,%r12d
add    %edx,%r12d
sar    %r12d
imul   %ecx,%r12d
imul   %edx,%r13d
mov    %r13d,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
movslq %ebp,%rdi
add    %rax,%rdi
mov    0x8(%rsp),%ecx
mov    0x4(%rsp),%ebp
imul   %ebp,%ecx
mov    %r12d,%esi
mov    0x10(%rsp),%rdx
call   1040 <repeat_mem@plt>
mov    %r15,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1070 <apply_periodic_boundary@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    11f8 <stripe_cem_matrix+0xa8>
mov    %eax,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    (%r14,%rbx,8),%rdi
mov    %r15,%rsi
mov    %r13d,%edx
call   1050 <memcpy@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11e0 <stripe_cem_matrix+0x90>
mov    %r15,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

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

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