#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ DCT(int **);
int /*<<< orphan*/ add_to_output_matrix(int **, int /*<<< orphan*/ *, int **,
                                        int, int);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ print_8x8_matrix(int **);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ un_zig_zag(int **);
void read_block(FILE *input_fileHandle, int quant_matrix[8][8],
                int **output_matrix) {
  int x_offset, y_offset;
  int input_block[8][8];
  fscanf(input_fileHandle, "%d", &x_offset);
  fscanf(input_fileHandle, "%d", &y_offset);
  int i, j;
  for (i = 0; i < 8; i += 1) {
    for (j = 0; j < 8; j += 1) {
      fscanf(input_fileHandle, "%d", &input_block[i][j]);
      input_block[i][j] -= 127;
      input_block[i][j] = (input_block[i][j] * quant_matrix[i][j]);
    }
  }
  printf("%d %d \n\n", x_offset, y_offset);
  print_8x8_matrix(input_block);
  DCT(input_block);
  un_zig_zag(input_block);
  add_to_output_matrix(input_block, input_fileHandle, output_matrix, x_offset,
                       y_offset);
}


x86 assembly (clang, -O0):
<read_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe7e(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1060 <fscanf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe6a(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1060 <fscanf@plt>
movl   $0x0,-0x124(%rbp)
cmpl   $0x8,-0x124(%rbp)
jge    12ad <read_block+0x14d>
movl   $0x0,-0x128(%rbp)
cmpl   $0x8,-0x128(%rbp)
jge    1294 <read_block+0x134>
mov    -0x8(%rbp),%rdi
movslq -0x124(%rbp),%rax
lea    -0x120(%rbp),%rdx
shl    $0x5,%rax
add    %rax,%rdx
movslq -0x128(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xe05(%rip),%rsi
call   1060 <fscanf@plt>
movslq -0x124(%rbp),%rcx
lea    -0x120(%rbp),%rax
shl    $0x5,%rcx
add    %rcx,%rax
movslq -0x128(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
sub    $0x7f,%edx
mov    %edx,(%rax,%rcx,4)
movslq -0x124(%rbp),%rcx
lea    -0x120(%rbp),%rax
shl    $0x5,%rcx
add    %rcx,%rax
movslq -0x128(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x10(%rbp),%rax
movslq -0x124(%rbp),%rcx
shl    $0x5,%rcx
add    %rcx,%rax
movslq -0x128(%rbp),%rcx
imul   (%rax,%rcx,4),%edx
movslq -0x124(%rbp),%rcx
lea    -0x120(%rbp),%rax
shl    $0x5,%rcx
add    %rcx,%rax
movslq -0x128(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x128(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x128(%rbp)
jmp    11c0 <read_block+0x60>
jmp    1299 <read_block+0x139>
mov    -0x124(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x124(%rbp)
jmp    11a9 <read_block+0x49>
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xd49(%rip),%rdi
call   1040 <printf@plt>
lea    -0x120(%rbp),%rdi
call   1030 <print_8x8_matrix@plt>
lea    -0x120(%rbp),%rdi
call   1070 <DCT@plt>
lea    -0x120(%rbp),%rdi
call   1080 <un_zig_zag@plt>
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
call   1050 <add_to_output_matrix@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_block>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x110,%rsp
mov    %rdx,%r14
mov    %rsi,%r13
mov    %rdi,%r15
lea    0xe80(%rip),%r12
lea    0xc(%rsp),%rdx
mov    %r12,%rsi
call   1060 <fscanf@plt>
lea    0x8(%rsp),%rdx
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <fscanf@plt>
xor    %ebx,%ebx
nop
lea    (%rsp,%rbx,1),%rdx
add    $0x10,%rdx
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <fscanf@plt>
mov    0x10(%rsp,%rbx,1),%eax
add    $0xffffff81,%eax
imul   0x0(%r13,%rbx,1),%eax
mov    %eax,0x10(%rsp,%rbx,1)
lea    (%rsp,%rbx,1),%rdx
add    $0x14,%rdx
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <fscanf@plt>
mov    0x14(%rsp,%rbx,1),%eax
add    $0xffffff81,%eax
imul   0x4(%r13,%rbx,1),%eax
mov    %eax,0x14(%rsp,%rbx,1)
lea    (%rsp,%rbx,1),%rdx
add    $0x18,%rdx
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <fscanf@plt>
mov    0x18(%rsp,%rbx,1),%eax
add    $0xffffff81,%eax
imul   0x8(%r13,%rbx,1),%eax
mov    %eax,0x18(%rsp,%rbx,1)
lea    (%rsp,%rbx,1),%rdx
add    $0x1c,%rdx
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <fscanf@plt>
mov    0x1c(%rsp,%rbx,1),%eax
add    $0xffffff81,%eax
imul   0xc(%r13,%rbx,1),%eax
mov    %eax,0x1c(%rsp,%rbx,1)
lea    (%rsp,%rbx,1),%rdx
add    $0x20,%rdx
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <fscanf@plt>
mov    0x20(%rsp,%rbx,1),%eax
add    $0xffffff81,%eax
imul   0x10(%r13,%rbx,1),%eax
mov    %eax,0x20(%rsp,%rbx,1)
lea    (%rsp,%rbx,1),%rdx
add    $0x24,%rdx
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <fscanf@plt>
mov    0x24(%rsp,%rbx,1),%eax
add    $0xffffff81,%eax
imul   0x14(%r13,%rbx,1),%eax
mov    %eax,0x24(%rsp,%rbx,1)
lea    (%rsp,%rbx,1),%rdx
add    $0x28,%rdx
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <fscanf@plt>
mov    0x28(%rsp,%rbx,1),%eax
add    $0xffffff81,%eax
imul   0x18(%r13,%rbx,1),%eax
mov    %eax,0x28(%rsp,%rbx,1)
lea    (%rsp,%rbx,1),%rdx
add    $0x2c,%rdx
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <fscanf@plt>
mov    0x2c(%rsp,%rbx,1),%eax
add    $0xffffff81,%eax
imul   0x1c(%r13,%rbx,1),%eax
mov    %eax,0x2c(%rsp,%rbx,1)
add    $0x20,%rbx
cmp    $0x100,%rbx
jne    11a0 <read_block+0x40>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
lea    0xd23(%rip),%rdi
call   1040 <printf@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <print_8x8_matrix@plt>
mov    %rbx,%rdi
call   1070 <DCT@plt>
mov    %rbx,%rdi
call   1080 <un_zig_zag@plt>
mov    0xc(%rsp),%ecx
mov    0x8(%rsp),%r8d
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1050 <add_to_output_matrix@plt>
add    $0x110,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [9 x i8] c"%d %d \0A\0A\00"
define void @read_block(i32* %0, [8 x i32]* nocapture %1, i32** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca [8 x [8 x i32]]
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = bitcast [8 x [8 x i32]]* %6 to i8*
%10 = call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%11 = call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
br label %12
12: ; preds = %3, %12
%13 = phi i64 [ 0, %3 ], [ %70, %12 ]
%14 = getelementptr inbounds [8 x [8 x i32]], [8 x [8 x i32]]* %6, i64 0, i64 %13, i64 0
%15 = call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %14)
%16 = load i32, i32* %14
%17 = add nsw i32 %16, -127
%18 = getelementptr inbounds [8 x i32], [8 x i32]* %1, i64 %13, i64 0
%19 = load i32, i32* %18
%20 = mul nsw i32 %19, %17
store i32 %20, i32* %14
%21 = getelementptr inbounds [8 x [8 x i32]], [8 x [8 x i32]]* %6, i64 0, i64 %13, i64 1
%22 = call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %21)
%23 = load i32, i32* %21
%24 = add nsw i32 %23, -127
%25 = getelementptr inbounds [8 x i32], [8 x i32]* %1, i64 %13, i64 1
%26 = load i32, i32* %25
%27 = mul nsw i32 %26, %24
store i32 %27, i32* %21
%28 = getelementptr inbounds [8 x [8 x i32]], [8 x [8 x i32]]* %6, i64 0, i64 %13, i64 2
%29 = call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %28)
%30 = load i32, i32* %28
%31 = add nsw i32 %30, -127
%32 = getelementptr inbounds [8 x i32], [8 x i32]* %1, i64 %13, i64 2
%33 = load i32, i32* %32
%34 = mul nsw i32 %33, %31
store i32 %34, i32* %28
%35 = getelementptr inbounds [8 x [8 x i32]], [8 x [8 x i32]]* %6, i64 0, i64 %13, i64 3
%36 = call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %35)
%37 = load i32, i32* %35
%38 = add nsw i32 %37, -127
%39 = getelementptr inbounds [8 x i32], [8 x i32]* %1, i64 %13, i64 3
%40 = load i32, i32* %39
%41 = mul nsw i32 %40, %38
store i32 %41, i32* %35
%42 = getelementptr inbounds [8 x [8 x i32]], [8 x [8 x i32]]* %6, i64 0, i64 %13, i64 4
%43 = call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %42)
%44 = load i32, i32* %42
%45 = add nsw i32 %44, -127
%46 = getelementptr inbounds [8 x i32], [8 x i32]* %1, i64 %13, i64 4
%47 = load i32, i32* %46
%48 = mul nsw i32 %47, %45
store i32 %48, i32* %42
%49 = getelementptr inbounds [8 x [8 x i32]], [8 x [8 x i32]]* %6, i64 0, i64 %13, i64 5
%50 = call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %49)
%51 = load i32, i32* %49
%52 = add nsw i32 %51, -127
%53 = getelementptr inbounds [8 x i32], [8 x i32]* %1, i64 %13, i64 5
%54 = load i32, i32* %53
%55 = mul nsw i32 %54, %52
store i32 %55, i32* %49
%56 = getelementptr inbounds [8 x [8 x i32]], [8 x [8 x i32]]* %6, i64 0, i64 %13, i64 6
%57 = call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %56)
%58 = load i32, i32* %56
%59 = add nsw i32 %58, -127
%60 = getelementptr inbounds [8 x i32], [8 x i32]* %1, i64 %13, i64 6
%61 = load i32, i32* %60
%62 = mul nsw i32 %61, %59
store i32 %62, i32* %56
%63 = getelementptr inbounds [8 x [8 x i32]], [8 x [8 x i32]]* %6, i64 0, i64 %13, i64 7
%64 = call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %63)
%65 = load i32, i32* %63
%66 = add nsw i32 %65, -127
%67 = getelementptr inbounds [8 x i32], [8 x i32]* %1, i64 %13, i64 7
%68 = load i32, i32* %67
%69 = mul nsw i32 %68, %66
store i32 %69, i32* %63
%70 = add nuw nsw i64 %13, 1
%71 = icmp eq i64 %70, 8
br i1 %71, label %72, label %12
72: ; preds = %12
%73 = load i32, i32* %4
%74 = load i32, i32* %5
%75 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %73, i32 %74)
%76 = bitcast [8 x [8 x i32]]* %6 to i32**
%77 = call i32 @print_8x8_matrix(i32** %76)
%78 = call i32 @DCT(i32** %76)
%79 = call i32 @un_zig_zag(i32** %76)
%80 = load i32, i32* %4
%81 = load i32, i32* %5
%82 = call i32 @add_to_output_matrix(i32** %76, i32* %0, i32** %2, i32 %80, i32 %81)
ret void
}