#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*/ get_filter(int);
scalar_t__ malloc(int);
int /*<<< orphan*/ zoom_image(unsigned char *, unsigned char *,
                              int /*<<< orphan*/, int, int, int, int, int, int,
                              int);
unsigned char *scale_image(unsigned char *image, int image_width,
                           int image_height, int x, int y, int width,
                           int height, int new_width, int new_height) {
  unsigned char *new_image =
      (unsigned char *)malloc(new_width * new_height * 3);
  unsigned char *image_start = image + (x + y * image_width) * 3;
  zoom_image(new_image, image_start, get_filter(2), 3, new_width, new_height,
             new_width * 3, width, height, image_width * 3);
  return new_image;
}


x86 assembly (clang, -O0):
<scale_image>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x68,%rsp
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
mov    0x18(%rbp),%eax
imul   0x20(%rbp),%eax
imul   $0x3,%eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%edx
imul   -0x14(%rbp),%edx
add    %edx,%ecx
imul   $0x3,%ecx,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    $0x2,%edi
call   1050 <get_filter@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
mov    0x18(%rbp),%r8d
mov    0x20(%rbp),%r9d
imul   $0x3,0x18(%rbp),%ebx
mov    -0x24(%rbp),%r11d
mov    0x10(%rbp),%r10d
imul   $0x3,-0x14(%rbp),%eax
mov    $0x3,%ecx
mov    %ebx,(%rsp)
mov    %r11d,0x8(%rsp)
mov    %r10d,0x10(%rsp)
mov    %eax,0x18(%rsp)
call   1030 <zoom_image@plt>
mov    -0x30(%rbp),%rax
add    $0x68,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<scale_image>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,(%rsp)
mov    %r8d,%ebp
mov    %ecx,%ebx
mov    %esi,%r15d
mov    %rdi,%r12
mov    0x48(%rsp),%ecx
lea    (%rcx,%rcx,2),%r14d
mov    %r14d,%edi
imul   0x50(%rsp),%edi
call   1040 <malloc@plt>
mov    %rax,%r13
imul   %r15d,%ebp
add    %ebx,%ebp
lea    0x0(%rbp,%rbp,2),%eax
movslq %eax,%rbx
add    %r12,%rbx
mov    $0x2,%edi
call   1050 <get_filter@plt>
lea    (%r15,%r15,2),%ebp
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
mov    $0x3,%ecx
mov    0x48(%rsp),%r8d
mov    0x50(%rsp),%r9d
push   %rbp
mov    0x48(%rsp),%eax
push   %rax
push   0x10(%rsp)
push   %r14
call   1030 <zoom_image@plt>
add    $0x20,%rsp
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @scale_image(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7, i32 %8) {
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i8*
%20 = alloca i8*
store i8* %0, i8** %10
store i32 %1, i32* %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
%21 = load i32, i32* %17
%22 = load i32, i32* %18
%23 = mul nsw i32 %21, %22
%24 = mul nsw i32 %23, 3
%25 = call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to i8*
store i8* %26, i8** %19
%27 = load i8*, i8** %10
%28 = load i32, i32* %13
%29 = load i32, i32* %14
%30 = load i32, i32* %11
%31 = mul nsw i32 %29, %30
%32 = add nsw i32 %28, %31
%33 = mul nsw i32 %32, 3
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %27, i64 %34
store i8* %35, i8** %20
%36 = load i8*, i8** %19
%37 = load i8*, i8** %20
%38 = call i32 @get_filter(i32 2)
%39 = load i32, i32* %17
%40 = load i32, i32* %18
%41 = load i32, i32* %17
%42 = mul nsw i32 %41, 3
%43 = load i32, i32* %15
%44 = load i32, i32* %16
%45 = load i32, i32* %11
%46 = mul nsw i32 %45, 3
%47 = call i32 @zoom_image(i8* %36, i8* %37, i32 %38, i32 3, i32 %39, i32 %40, i32 %42, i32 %43, i32 %44, i32 %46)
%48 = load i8*, i8** %19
ret i8* %48
}

LLVM IR (-O2):
define i8* @scale_image(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7, i32 %8) {
%10 = mul i32 %7, 3
%11 = mul i32 %10, %8
%12 = tail call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i8*
%14 = mul nsw i32 %4, %1
%15 = add nsw i32 %14, %3
%16 = mul nsw i32 %15, 3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = tail call i32 @get_filter(i32 2)
%20 = mul nsw i32 %1, 3
%21 = tail call i32 @zoom_image(i8* %13, i8* %18, i32 %19, i32 3, i32 %7, i32 %8, i32 %10, i32 %5, i32 %6, i32 %20)
ret i8* %13
}