#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*/ copy_region(unsigned char *, unsigned char *, int, int, int,
                               int, int, int, int, int);
void tileimage(unsigned char *out, unsigned char **in, int w, int nrows,
               int ncols, int x1, int y1, int dx, int dy) {
  int col, row;
  for (row = 0; row < nrows; row++) {
    for (col = 0; col < ncols; col++) {
      copy_region(out, in[row * ncols + col], col * dx, row * dy, x1, y1, dx,
                  dy, ncols * dx, w);
    }
  }
}


x86 assembly (clang, -O0):
<tileimage>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x48,%rsp
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11d7 <tileimage+0xc7>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11c4 <tileimage+0xb4>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%ecx
imul   -0x24(%rbp),%ecx
add    -0x2c(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x2c(%rbp),%edx
imul   0x18(%rbp),%edx
mov    -0x30(%rbp),%ecx
imul   0x20(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    0x10(%rbp),%r9d
mov    0x18(%rbp),%ebx
mov    0x20(%rbp),%r11d
mov    -0x24(%rbp),%r10d
imul   0x18(%rbp),%r10d
mov    -0x1c(%rbp),%eax
mov    %ebx,(%rsp)
mov    %r11d,0x8(%rsp)
mov    %r10d,0x10(%rsp)
mov    %eax,0x18(%rsp)
call   1030 <copy_region@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1152 <tileimage+0x42>
jmp    11c9 <tileimage+0xb9>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    113f <tileimage+0x2f>
add    $0x48,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<tileimage>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r8d,0x4(%rsp)
test   %ecx,%ecx
jle    1229 <tileimage+0x119>
mov    %r9d,%ebp
mov    %edx,%r10d
mov    0x90(%rsp),%r15d
mov    0x88(%rsp),%r14d
mov    0x80(%rsp),%r9d
mov    %r14d,%r11d
mov    0x4(%rsp),%edx
imul   %edx,%r11d
movslq %edx,%rdx
mov    %ecx,%ecx
mov    %rcx,0x20(%rsp)
mov    %edx,%ecx
shl    $0x3,%rdx
mov    %rdx,0x28(%rsp)
xor    %edx,%edx
mov    %rdx,0x8(%rsp)
mov    %ebp,0x10(%rsp)
mov    %rdi,0x40(%rsp)
mov    %r11,0x38(%rsp)
mov    %rcx,0x30(%rsp)
jmp    11ad <tileimage+0x9d>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x8(%rsp),%rbx
add    $0x1,%rbx
add    0x28(%rsp),%rsi
mov    %rbx,%rdx
mov    %rbx,0x8(%rsp)
cmp    0x20(%rsp),%rbx
je     1229 <tileimage+0x119>
cmpl   $0x0,0x4(%rsp)
jle    1190 <tileimage+0x80>
mov    0x8(%rsp),%rdx
imul   %r15d,%edx
mov    %edx,0x14(%rsp)
xor    %r13d,%r13d
xor    %r12d,%r12d
mov    %rsi,0x18(%rsp)
nopl   0x0(%rax)
mov    0x18(%rsp),%rcx
mov    (%rcx,%r12,8),%rsi
mov    0x40(%rsp),%rdi
mov    %r13d,%edx
mov    0x14(%rsp),%ecx
mov    %ebp,%r8d
push   %r10
push   %r11
push   %r15
push   %r14
mov    %r10,%rbp
mov    %r9d,%ebx
call   1030 <copy_region@plt>
mov    0x50(%rsp),%rcx
mov    0x58(%rsp),%r11
mov    %ebx,%r9d
mov    0x38(%rsp),%rsi
mov    %rbp,%r10
mov    0x30(%rsp),%ebp
add    $0x20,%rsp
add    $0x1,%r12
add    %r14d,%r13d
cmp    %r12,%rcx
jne    11d0 <tileimage+0xc0>
jmp    1190 <tileimage+0x80>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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