#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*/ free(void *);
void *malloc(int);
void *scale2x_align_ptr(void *);
unsigned int scale2x_align_size(int);
int /*<<< orphan*/ scale4x_buf(void *, unsigned int, void *, unsigned int,
                               void const *, unsigned int, unsigned int,
                               unsigned int, unsigned int, unsigned int);
void scale4x(void *void_dst, unsigned dst_slice, const void *void_src,
             unsigned src_slice, unsigned pixel, unsigned width,
             unsigned height, unsigned opt) {
  unsigned mid_slice;
  void *mid_ptr;
  void *mid_alloc;
  mid_slice = scale2x_align_size(2 * pixel * width);
  mid_alloc = malloc(6 * mid_slice + (16 - 1));
  if (!mid_alloc)
    return;
  mid_ptr = scale2x_align_ptr(mid_alloc);
  scale4x_buf(void_dst, dst_slice, mid_ptr, mid_slice, void_src, src_slice,
              pixel, width, height, opt);
  free(mid_alloc);
}


x86 assembly (clang, -O0):
<scale4x>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x58,%rsp
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    -0x28(%rbp),%edi
shl    $0x1,%edi
imul   -0x2c(%rbp),%edi
call   1040 <scale2x_align_size@plt>
mov    %eax,-0x30(%rbp)
imul   $0x6,-0x30(%rbp),%edi
add    $0xf,%edi
call   1060 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11a7 <scale4x+0x57>
jmp    11f7 <scale4x+0xa7>
mov    -0x40(%rbp),%rdi
call   1070 <scale2x_align_ptr@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%ecx
mov    -0x20(%rbp),%r8
mov    -0x24(%rbp),%r9d
mov    -0x28(%rbp),%ebx
mov    -0x2c(%rbp),%r11d
mov    0x10(%rbp),%r10d
mov    0x18(%rbp),%eax
mov    %ebx,(%rsp)
mov    %r11d,0x8(%rsp)
mov    %r10d,0x10(%rsp)
mov    %eax,0x18(%rsp)
call   1050 <scale4x_buf@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
add    $0x58,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<scale4x>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9d,%ebx
mov    %r8d,%r14d
mov    %ecx,0xc(%rsp)
mov    %rdx,0x18(%rsp)
mov    %esi,%r13d
mov    %rdi,%r15
mov    0x68(%rsp),%eax
mov    %rax,0x10(%rsp)
mov    0x60(%rsp),%eax
mov    %rax,0x20(%rsp)
mov    %r8d,%edi
imul   %r9d,%edi
add    %edi,%edi
call   1040 <scale2x_align_size@plt>
mov    %eax,%r12d
lea    (%r12,%r12,2),%eax
lea    (%rax,%rax,1),%edi
add    $0xf,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11f5 <scale4x+0xa5>
mov    %rax,%rbp
mov    %rax,%rdi
call   1070 <scale2x_align_ptr@plt>
mov    %r15,%rdi
mov    %r13d,%esi
mov    %rax,%rdx
mov    %r12d,%ecx
mov    0x18(%rsp),%r8
mov    0xc(%rsp),%r9d
push   0x10(%rsp)
push   0x28(%rsp)
push   %rbx
push   %r14
call   1050 <scale4x_buf@plt>
add    $0x20,%rsp
mov    %rbp,%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @scale4x(i8* %0, i32 %1, i8* %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7) {
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i8*
%19 = alloca i8*
store i8* %0, i8** %9
store i32 %1, i32* %10
store i8* %2, i8** %11
store i32 %3, i32* %12
store i32 %4, i32* %13
store i32 %5, i32* %14
store i32 %6, i32* %15
store i32 %7, i32* %16
%20 = load i32, i32* %13
%21 = mul i32 2, %20
%22 = load i32, i32* %14
%23 = mul i32 %21, %22
%24 = call i32 @scale2x_align_size(i32 %23)
store i32 %24, i32* %17
%25 = load i32, i32* %17
%26 = mul i32 6, %25
%27 = add i32 %26, 15
%28 = call i8* @malloc(i32 %27)
store i8* %28, i8** %19
%29 = load i8*, i8** %19
%30 = icmp ne i8* %29, null
br i1 %30, label %32, label %31
31: ; preds = %8
br label %48
32: ; preds = %8
%33 = load i8*, i8** %19
%34 = call i8* @scale2x_align_ptr(i8* %33)
store i8* %34, i8** %18
%35 = load i8*, i8** %9
%36 = load i32, i32* %10
%37 = load i8*, i8** %18
%38 = load i32, i32* %17
%39 = load i8*, i8** %11
%40 = load i32, i32* %12
%41 = load i32, i32* %13
%42 = load i32, i32* %14
%43 = load i32, i32* %15
%44 = load i32, i32* %16
%45 = call i32 @scale4x_buf(i8* %35, i32 %36, i8* %37, i32 %38, i8* %39, i32 %40, i32 %41, i32 %42, i32 %43, i32 %44)
%46 = load i8*, i8** %19
%47 = call i32 @free(i8* %46)
br label %48
48: ; preds = %32, %31
ret void
}

LLVM IR (-O2):
define void @scale4x(i8* %0, i32 %1, i8* %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7) {
%9 = shl i32 %4, 1
%10 = mul i32 %9, %5
%11 = tail call i32 @scale2x_align_size(i32 %10)
%12 = mul i32 %11, 6
%13 = add i32 %12, 15
%14 = tail call i8* @malloc(i32 %13)
%15 = icmp eq i8* %14, null
br i1 %15, label %20, label %16
16: ; preds = %8
%17 = tail call i8* @scale2x_align_ptr(i8* %14)
%18 = tail call i32 @scale4x_buf(i8* %0, i32 %1, i8* %17, i32 %11, i8* %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7)
%19 = tail call i32 @free(i8* %14)
br label %20
20: ; preds = %8, %16
ret void
}