#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 */
unsigned long IJGWrite(unsigned char *, long, unsigned char *, unsigned long,
                       int, long, long, int);
int /*<<< orphan*/ free(char *);
char *textureResample(char *, long, long, int, int, int /*<<< orphan*/);
unsigned long MakeJPG(char *destBuf, char *srcBuf, long width, long height,
                      int quality) {
  unsigned long jpgsize = 0;
  char *textureData = NULL;
  textureData = textureResample(srcBuf, width, height, 32, 24, 0);
  if (!textureData)
    return 0;
  jpgsize = IJGWrite((unsigned char *)textureData, width * height * 3, NULL, 0,
                     quality, width, height, 3);
  if (!destBuf) {
    free(textureData);
    return jpgsize;
  }
  IJGWrite((unsigned char *)textureData, width * height * 3,
           (unsigned char *)destBuf, jpgsize, quality, width, height, 3);
  free(textureData);
  return jpgsize;
}


x86 assembly (clang, -O0):
<MakeJPG>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    $0x20,%ecx
mov    $0x18,%r8d
xor    %r9d,%r9d
call   1040 <textureResample@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1197 <MakeJPG+0x67>
movq   $0x0,-0x8(%rbp)
jmp    1236 <MakeJPG+0x106>
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rax
imul   -0x28(%rbp),%rax
imul   $0x3,%rax,%rsi
mov    -0x2c(%rbp),%r8d
mov    -0x20(%rbp),%r9
mov    -0x28(%rbp),%rax
xor    %ecx,%ecx
mov    %rcx,%rdx
mov    %rax,(%rsp)
movl   $0x3,0x8(%rsp)
call   1050 <IJGWrite@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ef <MakeJPG+0xbf>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1236 <MakeJPG+0x106>
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rax
imul   -0x28(%rbp),%rax
imul   $0x3,%rax,%rsi
mov    -0x10(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    -0x2c(%rbp),%r8d
mov    -0x20(%rbp),%r9
mov    -0x28(%rbp),%rax
mov    %rax,(%rsp)
movl   $0x3,0x8(%rsp)
call   1050 <IJGWrite@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MakeJPG>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,0x4(%rsp)
mov    %rcx,%r12
mov    %rdx,%rbp
mov    %rdi,%r15
xor    %r13d,%r13d
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %rcx,%rdx
mov    $0x20,%ecx
mov    $0x18,%r8d
xor    %r9d,%r9d
call   1040 <textureResample@plt>
test   %rax,%rax
je     11cb <MakeJPG+0x9b>
mov    %rax,%rbx
mov    %rbp,%rax
imul   %r12,%rax
lea    (%rax,%rax,2),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    0x4(%rsp),%r8d
mov    %rbp,%r9
push   $0x3
push   %r12
call   1050 <IJGWrite@plt>
add    $0x10,%rsp
mov    %rax,%r13
test   %r15,%r15
je     11c3 <MakeJPG+0x93>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r13,%rcx
mov    0x4(%rsp),%r8d
mov    %rbp,%r9
push   $0x3
push   %r12
call   1050 <IJGWrite@plt>
add    $0x10,%rsp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i64 @MakeJPG(i8* %0, i8* %1, i64 %2, i64 %3, i32 %4) {
%6 = tail call i8* @textureResample(i8* %1, i64 %2, i64 %3, i32 32, i32 24, i32 0)
%7 = icmp eq i8* %6, null
br i1 %7, label %17, label %8
8: ; preds = %5
%9 = mul i64 %2, 3
%10 = mul i64 %9, %3
%11 = tail call i64 @IJGWrite(i8* %6, i64 %10, i8* null, i64 0, i32 %4, i64 %2, i64 %3, i32 3)
%12 = icmp eq i8* %0, null
br i1 %12, label %15, label %13
13: ; preds = %8
%14 = tail call i64 @IJGWrite(i8* %6, i64 %10, i8* %0, i64 %11, i32 %4, i64 %2, i64 %3, i32 3)
br label %15
15: ; preds = %8, %13
%16 = tail call i32 @free(i8* %6)
br label %17
17: ; preds = %15, %5
%18 = phi i64 [ 0, %5 ], [ %11, %15 ]
ret i64 %18
}