#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*/ memcpy(unsigned char *, unsigned char *, int);
void stub1(unsigned char *, int, unsigned char *, int);
void IMAGE_STRETCH(unsigned char *dest_ptr, int dest_dx, int dest_dy,
                   int dest_pitch, int dest_bpp, unsigned char *src_ptr,
                   int src_dx, int src_dy, int src_pitch, int src_bpp,
                   void (*row_func)(unsigned char *, int, unsigned char *, int),
                   void (*row2x_func)(unsigned char *, unsigned char *,
                                      unsigned char *, int, unsigned char *,
                                      int)) {
  register unsigned char *d = dest_ptr;
  register unsigned char *s = src_ptr;
  register int dest_dx_bytes = dest_dx * dest_bpp;
  register int count = dest_dy;
  register int limit = dest_dy >> 1;
  register int step = src_dy;
  if (count) {
    goto start;
    do {
      if ((limit -= step) < 0) {
        limit += dest_dy;
      start:
        (*row_func)(d, dest_dx, s, src_dx);
        s += src_pitch;
        d += dest_pitch;
      } else {
        memcpy(d, d - dest_pitch, dest_dx_bytes);
        d += dest_pitch;
      }
    } while (--count);
  }
}


x86 assembly (clang, -O0):
<IMAGE_STRETCH>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x38(%rbp),%rax
mov    0x30(%rbp),%rax
mov    0x28(%rbp),%eax
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    %r9,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0xc(%rbp),%eax
imul   -0x18(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    0x18(%rbp),%eax
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x38(%rbp)
je     1220 <IMAGE_STRETCH+0x110>
jmp    119c <IMAGE_STRETCH+0x8c>
mov    -0x40(%rbp),%ecx
mov    -0x3c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x3c(%rbp)
cmp    $0x0,%eax
jge    11d7 <IMAGE_STRETCH+0xc7>
mov    -0x10(%rbp),%eax
add    -0x3c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    0x30(%rbp),%rax
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x30(%rbp),%rdx
mov    0x10(%rbp),%ecx
call   *%rax
mov    0x20(%rbp),%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    1204 <IMAGE_STRETCH+0xf4>
mov    -0x28(%rbp),%rdi
mov    -0x28(%rbp),%rsi
movslq -0x14(%rbp),%rcx
xor    %eax,%eax
sub    %rcx,%rax
add    %rax,%rsi
mov    -0x34(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x14(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    1209 <IMAGE_STRETCH+0xf9>
mov    -0x38(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x38(%rbp)
cmp    $0x0,%eax
jne    117f <IMAGE_STRETCH+0x6f>
jmp    1220 <IMAGE_STRETCH+0x110>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<IMAGE_STRETCH>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,0x10(%rsp)
mov    %esi,0xc(%rsp)
test   %edx,%edx
je     11f1 <IMAGE_STRETCH+0xe1>
mov    %r8d,%ebp
mov    %ecx,%r14d
mov    %rdi,%rbx
mov    %edx,%r15d
mov    0x60(%rsp),%ecx
mov    0xc(%rsp),%esi
mov    0x10(%rsp),%rdx
call   *0x80(%rsp)
mov    %r15d,%r13d
add    $0xffffffff,%r13d
je     11f1 <IMAGE_STRETCH+0xe1>
imul   0xc(%rsp),%ebp
movslq 0x70(%rsp),%rax
mov    %rax,0x20(%rsp)
movslq %r14d,%r14
mov    %r15d,%eax
mov    %r15d,%r12d
sar    %r12d
sub    0x68(%rsp),%eax
mov    %eax,0x1c(%rsp)
mov    $0x1,%eax
sub    %r13d,%eax
mov    0x20(%rsp),%rcx
add    %rcx,0x10(%rsp)
mov    %eax,%r13d
mov    %rbx,%rsi
mov    %r12d,%r15d
nopw   0x0(%rax,%rax,1)
lea    (%rsi,%r14,1),%rbx
sub    0x68(%rsp),%r15d
js     11d0 <IMAGE_STRETCH+0xc0>
add    $0x1,%r13d
mov    %rbx,%rdi
mov    %ebp,%edx
call   1030 <memcpy@plt>
mov    %rbx,%rsi
mov    %r15d,%r12d
cmp    $0x1,%r13d
jne    11a0 <IMAGE_STRETCH+0x90>
jmp    11f1 <IMAGE_STRETCH+0xe1>
nopw   0x0(%rax,%rax,1)
add    0x1c(%rsp),%r12d
mov    %rbx,%rdi
mov    0xc(%rsp),%esi
mov    0x10(%rsp),%rdx
mov    0x60(%rsp),%ecx
call   *0x80(%rsp)
neg    %r13d
jb     117f <IMAGE_STRETCH+0x6f>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @IMAGE_STRETCH(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4, i8* %5, i32 %6, i32 %7, i32 %8, i32 %9, void (i8*, i32, i8*, i32)* nocapture %10, void (i8*, i8*, i8*, i32, i8*, i32)* nocapture readnone %11) {
%13 = mul nsw i32 %4, %1
%14 = icmp eq i32 %2, 0
br i1 %14, label %43, label %15
15: ; preds = %12
tail call void %10(i8* %0, i32 %1, i8* %5, i32 %6)
%16 = sext i32 %8 to i64
%17 = sext i32 %3 to i64
%18 = add nsw i32 %2, -1
%19 = icmp eq i32 %18, 0
br i1 %19, label %43, label %20
20: ; preds = %15
%21 = ashr i32 %2, 1
br label %33
22: ; preds = %33, %39
%23 = phi i32 [ %34, %33 ], [ %41, %39 ]
%24 = phi i8* [ %36, %33 ], [ %26, %39 ]
%25 = phi i32 [ %37, %33 ], [ %27, %39 ]
%26 = getelementptr inbounds i8, i8* %24, i64 %17
%27 = sub nsw i32 %25, %7
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %39
29: ; preds = %22
%30 = add nsw i32 %27, %2
tail call void %10(i8* %26, i32 %1, i8* %38, i32 %6)
%31 = add nsw i32 %23, -1
%32 = icmp eq i32 %31, 0
br i1 %32, label %43, label %33
33: ; preds = %20, %29
%34 = phi i32 [ %31, %29 ], [ %18, %20 ]
%35 = phi i8* [ %38, %29 ], [ %5, %20 ]
%36 = phi i8* [ %26, %29 ], [ %0, %20 ]
%37 = phi i32 [ %30, %29 ], [ %21, %20 ]
%38 = getelementptr inbounds i8, i8* %35, i64 %16
br label %22
39: ; preds = %22
%40 = tail call i32 @memcpy(i8* %26, i8* %24, i32 %13)
%41 = add nsw i32 %23, -1
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %22
43: ; preds = %29, %39, %15, %12
ret void
}