#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 */
typedef int /*<<< orphan*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ dc_shift_short(short *, int const, int const, int);
int /*<<< orphan*/ dct_8x8(short *);
int find_eob(short *);
int /*<<< orphan*/ huffman_enc_64(short *, int, int /*<<< orphan*/ **, int *,
                                  short *);
int /*<<< orphan*/ quant_8x8(short *, int);
int /*<<< orphan*/ zigzag_8x8(short *, short *);
void jpeg_encode_block(short *in, short *last_block, uint8_t **out,
                       int *out_length, int quality) {
  const int bwidth = 8;
  const int bheight = 8;
  short zz[64];
  dc_shift_short(in, bwidth, bheight, -128);
  dct_8x8(in);
  quant_8x8(in, quality);
  zigzag_8x8(in, zz);
  int zz_len = find_eob(zz);
  huffman_enc_64(zz, zz_len, out, out_length, last_block);
}


x86 assembly (clang, -O0):
<jpeg_encode_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movl   $0x8,-0x28(%rbp)
movl   $0x8,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x8,%edx
mov    $0xffffff80,%ecx
mov    %edx,%esi
call   1060 <dc_shift_short@plt>
mov    -0x8(%rbp),%rdi
call   1050 <dct_8x8@plt>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1070 <quant_8x8@plt>
mov    -0x8(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
call   1030 <zigzag_8x8@plt>
lea    -0xb0(%rbp),%rdi
call   1040 <find_eob@plt>
mov    %eax,-0xb4(%rbp)
lea    -0xb0(%rbp),%rdi
mov    -0xb4(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%r8
call   1080 <huffman_enc_64@plt>
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jpeg_encode_block>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80,%rsp
mov    %r8d,%ebp
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0x8,%esi
mov    $0x8,%edx
mov    $0xffffff80,%ecx
call   1060 <dc_shift_short@plt>
mov    %rbx,%rdi
call   1050 <dct_8x8@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1070 <quant_8x8@plt>
mov    %rsp,%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1030 <zigzag_8x8@plt>
mov    %rbp,%rdi
call   1040 <find_eob@plt>
mov    %rbp,%rdi
mov    %eax,%esi
mov    %r12,%rdx
mov    %r14,%rcx
mov    %r15,%r8
call   1080 <huffman_enc_64@plt>
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @jpeg_encode_block(i16* %0, i16* %1, i32** %2, i32* %3, i32 %4) {
%6 = alloca i16*
%7 = alloca i16*
%8 = alloca i32**
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca [64 x i16]
%14 = alloca i32
store i16* %0, i16** %6
store i16* %1, i16** %7
store i32** %2, i32*** %8
store i32* %3, i32** %9
store i32 %4, i32* %10
store i32 8, i32* %11
store i32 8, i32* %12
%15 = load i16*, i16** %6
%16 = call i32 @dc_shift_short(i16* %15, i32 8, i32 8, i32 -128)
%17 = load i16*, i16** %6
%18 = call i32 @dct_8x8(i16* %17)
%19 = load i16*, i16** %6
%20 = load i32, i32* %10
%21 = call i32 @quant_8x8(i16* %19, i32 %20)
%22 = load i16*, i16** %6
%23 = getelementptr inbounds [64 x i16], [64 x i16]* %13, i64 0, i64 0
%24 = call i32 @zigzag_8x8(i16* %22, i16* %23)
%25 = getelementptr inbounds [64 x i16], [64 x i16]* %13, i64 0, i64 0
%26 = call i32 @find_eob(i16* %25)
store i32 %26, i32* %14
%27 = getelementptr inbounds [64 x i16], [64 x i16]* %13, i64 0, i64 0
%28 = load i32, i32* %14
%29 = load i32**, i32*** %8
%30 = load i32*, i32** %9
%31 = load i16*, i16** %7
%32 = call i32 @huffman_enc_64(i16* %27, i32 %28, i32** %29, i32* %30, i16* %31)
ret void
}

LLVM IR (-O2):
define void @jpeg_encode_block(i16* %0, i16* %1, i32** %2, i32* %3, i32 %4) {
%6 = alloca [64 x i16]
%7 = bitcast [64 x i16]* %6 to i8*
%8 = tail call i32 @dc_shift_short(i16* %0, i32 8, i32 8, i32 -128)
%9 = tail call i32 @dct_8x8(i16* %0)
%10 = tail call i32 @quant_8x8(i16* %0, i32 %4)
%11 = getelementptr inbounds [64 x i16], [64 x i16]* %6, i64 0, i64 0
%12 = call i32 @zigzag_8x8(i16* %0, i16* %11)
%13 = call i32 @find_eob(i16* %11)
%14 = call i32 @huffman_enc_64(i16* %11, i32 %13, i32** %2, i32* %3, i16* %1)
ret void
}