#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*/ memmove(unsigned char *, unsigned char *, unsigned short);
int /*<<< orphan*/ memset(unsigned char *, unsigned char, int);
void expand_maps(unsigned char *cgb_map, unsigned char *cgb_atr,
                 unsigned short rows, unsigned short columns, unsigned char chr,
                 char status) {
  unsigned char *dst, *src;
  if (status)
    return;
  do {
    columns--;
    src = &cgb_map[columns * rows];
    dst = &cgb_map[columns * 32];
    memmove(dst, src, rows);
    memset((dst + rows), chr, 32 - rows);
    src = &cgb_atr[columns * rows];
    dst = &cgb_atr[columns * 32];
    memmove(dst, src, rows);
    memset((dst + rows), 0, 32 - rows);
  } while (columns > 0);
}


x86 assembly (clang, -O0):
<expand_maps>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %r8d,-0x3c(%rbp)
mov    %ecx,%eax
mov    -0x3c(%rbp),%ecx
mov    %eax,-0x38(%rbp)
mov    %edx,%eax
mov    -0x38(%rbp),%edx
mov    %eax,-0x34(%rbp)
mov    %rsi,%rax
mov    -0x34(%rbp),%esi
mov    %rax,-0x30(%rbp)
mov    %rdi,%r8
mov    -0x30(%rbp),%rdi
mov    %r9b,%al
mov    %r8,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %si,-0x12(%rbp)
mov    %dx,-0x14(%rbp)
mov    %cl,-0x15(%rbp)
mov    %al,-0x16(%rbp)
cmpb   $0x0,-0x16(%rbp)
je     1175 <expand_maps+0x55>
jmp    1259 <expand_maps+0x139>
jmp    117a <expand_maps+0x5a>
mov    -0x14(%rbp),%ax
add    $0xffff,%ax
mov    %ax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movzwl -0x14(%rbp),%ecx
movzwl -0x12(%rbp),%edx
imul   %edx,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movzwl -0x14(%rbp),%ecx
shl    $0x5,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x12(%rbp),%ax
movzwl %ax,%edx
call   1040 <memmove@plt>
mov    -0x20(%rbp),%rdi
movzwl -0x12(%rbp),%eax
cltq
add    %rax,%rdi
mov    -0x15(%rbp),%al
movzwl -0x12(%rbp),%ecx
mov    $0x20,%edx
sub    %ecx,%edx
movzbl %al,%esi
call   1030 <memset@plt>
mov    -0x10(%rbp),%rax
movzwl -0x14(%rbp),%ecx
movzwl -0x12(%rbp),%edx
imul   %edx,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movzwl -0x14(%rbp),%ecx
shl    $0x5,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x12(%rbp),%ax
movzwl %ax,%edx
call   1040 <memmove@plt>
mov    -0x20(%rbp),%rdi
movzwl -0x12(%rbp),%eax
cltq
add    %rax,%rdi
movzwl -0x12(%rbp),%eax
mov    $0x20,%edx
sub    %eax,%edx
xor    %esi,%esi
call   1030 <memset@plt>
movzwl -0x14(%rbp),%eax
cmp    $0x0,%eax
jg     117a <expand_maps+0x5a>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expand_maps>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,0x18(%rsp)
test   %r9b,%r9b
jne    11dd <expand_maps+0xbd>
movzwl %dx,%edx
mov    $0x20,%eax
sub    %edx,%eax
mov    %eax,(%rsp)
lea    -0x1(%rcx),%eax
movzwl %ax,%ebx
mov    %rdx,0x8(%rsp)
mov    %edx,%r12d
imul   %ebx,%r12d
shl    $0x5,%ebx
movzbl %r8b,%eax
mov    %eax,0x4(%rsp)
mov    %rdi,0x10(%rsp)
mov    0x8(%rsp),%rbp
mov    %rcx,0x20(%rsp)
mov    %r12d,%r13d
lea    (%rdi,%r13,1),%rsi
mov    %ebx,%r14d
lea    (%rdi,%r14,1),%r15
mov    %r15,%rdi
mov    %ebp,%edx
call   1040 <memmove@plt>
add    %rbp,%r15
mov    %r15,%rdi
mov    0x18(%rsp),%r15
mov    0x4(%rsp),%esi
mov    (%rsp),%edx
call   1030 <memset@plt>
add    %r15,%r13
add    %r15,%r14
mov    %r14,%rdi
mov    %r13,%rsi
mov    %ebp,%edx
call   1040 <memmove@plt>
add    %rbp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    (%rsp),%edx
call   1030 <memset@plt>
mov    0x10(%rsp),%rdi
mov    0x20(%rsp),%rcx
add    $0xffffffe0,%ebx
sub    %ebp,%r12d
add    $0xffff,%cx
jne    1170 <expand_maps+0x50>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @expand_maps(i8* %0, i8* %1, i16 zeroext %2, i16 zeroext %3, i8 zeroext %4, i8 signext %5) {
%7 = icmp eq i8 %5, 0
br i1 %7, label %8, label %31
8: ; preds = %6
%9 = zext i16 %2 to i32
%10 = zext i16 %2 to i64
%11 = sub nsw i32 32, %9
br label %12
12: ; preds = %8, %12
%13 = phi i16 [ %14, %12 ], [ %3, %8 ]
%14 = add i16 %13, -1
%15 = zext i16 %14 to i32
%16 = mul nuw nsw i32 %15, %9
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = shl nuw nsw i32 %15, 5
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %0, i64 %20
%22 = tail call i32 @memmove(i8* %21, i8* %18, i16 zeroext %2)
%23 = getelementptr inbounds i8, i8* %21, i64 %10
%24 = tail call i32 @memset(i8* %23, i8 zeroext %4, i32 %11)
%25 = getelementptr inbounds i8, i8* %1, i64 %17
%26 = getelementptr inbounds i8, i8* %1, i64 %20
%27 = tail call i32 @memmove(i8* %26, i8* %25, i16 zeroext %2)
%28 = getelementptr inbounds i8, i8* %26, i64 %10
%29 = tail call i32 @memset(i8* %28, i8 zeroext 0, i32 %11)
%30 = icmp eq i16 %14, 0
br i1 %30, label %31, label %12
31: ; preds = %12, %6
ret void
}