#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*/ printf(char *, ...);
void test_2x2_quantization() {
  int qp = 6;
  int coeff[2][2] = {{-765, -19}, {-21, 1}};
  int dclevel[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  int dcrun[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  int aclevel[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  int acrun[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  int leveloffset[4][4] = {
      {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}};
  int coeff_cost = 0;
  printf("before\n");
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      printf("%5d   ", coeff[i][j]);
    }
    printf("\n");
  }
  printf("\n");
  printf("after\n");
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      printf("%5d   ", coeff[i][j]);
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<test_2x2_quantization>:
push   %rbp
mov    %rsp,%rbp
sub    $0x180,%rsp
movl   $0x6,-0x4(%rbp)
mov    0xec7(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xec4(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1040 <memset@plt>
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1040 <memset@plt>
lea    -0xe0(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1040 <memset@plt>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1040 <memset@plt>
lea    -0x160(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1040 <memset@plt>
movl   $0x0,-0x164(%rbp)
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x168(%rbp)
cmpl   $0x2,-0x168(%rbp)
jge    124a <test_2x2_quantization+0x12a>
movl   $0x0,-0x16c(%rbp)
cmpl   $0x2,-0x16c(%rbp)
jge    1228 <test_2x2_quantization+0x108>
movslq -0x168(%rbp),%rcx
lea    -0x20(%rbp),%rax
shl    $0x3,%rcx
add    %rcx,%rax
movslq -0x16c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x16c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x16c(%rbp)
jmp    11dd <test_2x2_quantization+0xbd>
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x168(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x168(%rbp)
jmp    11c6 <test_2x2_quantization+0xa6>
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x170(%rbp)
cmpl   $0x2,-0x170(%rbp)
jge    12f4 <test_2x2_quantization+0x1d4>
movl   $0x0,-0x174(%rbp)
cmpl   $0x2,-0x174(%rbp)
jge    12d2 <test_2x2_quantization+0x1b2>
movslq -0x170(%rbp),%rcx
lea    -0x20(%rbp),%rax
shl    $0x3,%rcx
add    %rcx,%rax
movslq -0x174(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xd61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x174(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x174(%rbp)
jmp    1287 <test_2x2_quantization+0x167>
lea    0xd3d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x170(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x170(%rbp)
jmp    1270 <test_2x2_quantization+0x150>
add    $0x180,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_2x2_quantization>:
push   %rbx
lea    0xecf(%rip),%rdi
call   1040 <puts@plt>
lea    0xebc(%rip),%rbx
mov    %rbx,%rdi
mov    $0xfffffd03,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0xffffffed,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
mov    $0xffffffeb,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe69(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    $0xfffffd03,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0xffffffed,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
mov    $0xffffffeb,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
pop    %rbx
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@__const.test_2x2_quantization.coeff = [2 x [2 x i32]] [[2 x i32] [i32 -765, i32 -19], [2 x i32] [i32 -21, i32 1]]
@.str = [8 x i8] c"before\0A\00"
@.str.1 = [7 x i8] c"%5d \00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [7 x i8] c"after\0A\00"
define void @test_2x2_quantization() {
%1 = alloca i32
%2 = alloca [2 x [2 x i32]]
%3 = alloca [16 x i32]
%4 = alloca [16 x i32]
%5 = alloca [16 x i32]
%6 = alloca [16 x i32]
%7 = alloca [4 x [4 x i32]]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 6, i32* %1
%13 = bitcast [2 x [2 x i32]]* %2 to i8*
%14 = bitcast [16 x i32]* %3 to i8*
%15 = bitcast [16 x i32]* %4 to i8*
%16 = bitcast [16 x i32]* %5 to i8*
%17 = bitcast [16 x i32]* %6 to i8*
%18 = bitcast [4 x [4 x i32]]* %7 to i8*
store i32 0, i32* %8
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %9
br label %20
20: ; preds = %41, %0
%21 = load i32, i32* %9
%22 = icmp slt i32 %21, 2
br i1 %22, label %23, label %44
23: ; preds = %20
store i32 0, i32* %10
br label %24
24: ; preds = %36, %23
%25 = load i32, i32* %10
%26 = icmp slt i32 %25, 2
br i1 %26, label %27, label %39
27: ; preds = %24
%28 = load i32, i32* %9
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %2, i64 0, i64 %29
%31 = load i32, i32* %10
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %30, i64 0, i64 %32
%34 = load i32, i32* %33
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %27
%37 = load i32, i32* %10
%38 = add nsw i32 %37, 1
store i32 %38, i32* %10
br label %24
39: ; preds = %24
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %41
41: ; preds = %39
%42 = load i32, i32* %9
%43 = add nsw i32 %42, 1
store i32 %43, i32* %9
br label %20
44: ; preds = %20
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %11
br label %47
47: ; preds = %68, %44
%48 = load i32, i32* %11
%49 = icmp slt i32 %48, 2
br i1 %49, label %50, label %71
50: ; preds = %47
store i32 0, i32* %12
br label %51
51: ; preds = %63, %50
%52 = load i32, i32* %12
%53 = icmp slt i32 %52, 2
br i1 %53, label %54, label %66
54: ; preds = %51
%55 = load i32, i32* %11
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %2, i64 0, i64 %56
%58 = load i32, i32* %12
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [2 x i32], [2 x i32]* %57, i64 0, i64 %59
%61 = load i32, i32* %60
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %61)
br label %63
63: ; preds = %54
%64 = load i32, i32* %12
%65 = add nsw i32 %64, 1
store i32 %65, i32* %12
br label %51
66: ; preds = %51
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %68
68: ; preds = %66
%69 = load i32, i32* %11
%70 = add nsw i32 %69, 1
store i32 %70, i32* %11
br label %47
71: ; preds = %47
ret void
}

LLVM IR (-O2):
@.str.1 = [7 x i8] c"%5d \00"
@str = [7 x i8] c"before\00"
@str.4 = [6 x i8] c"after\00"
define void @test_2x2_quantization() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 -765)
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 -19)
%4 = tail call i32 @putchar(i32 10)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 -21)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 1)
%7 = tail call i32 @putchar(i32 10)
%8 = tail call i32 @putchar(i32 10)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.4, i64 0, i64 0))
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 -765)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 -19)
%12 = tail call i32 @putchar(i32 10)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 -21)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 1)
%15 = tail call i32 @putchar(i32 10)
ret void
}