void Quantize(matrix, qmatrix) int *matrix;
int *qmatrix;
{
  static char RoutineName[] = "Quantize";
  int *mptr;
  if (!qmatrix) {
    printf("F>%s:R>%s:L>%d: ",
           "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/aaalgo/ljpeg/refs/heads/master/jpegdir/"
           "transform.c",
           RoutineName, 283);
    printf("No quantization matrix specified!\n");
    exit(1);
  }
  for (mptr = matrix; mptr < matrix + 64; mptr++) {
    if (*mptr > 0) {
      *mptr = (*mptr + *qmatrix / 2) / (*qmatrix);
      qmatrix++;
    } else {
      *mptr = (*mptr - *qmatrix / 2) / (*qmatrix);
      qmatrix++;
    }
  }
}


x86 assembly (clang, -O0):
<Quantize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1174 <Quantize+0x54>
lea    0xebe(%rip),%rdi
lea    0xec8(%rip),%rsi
lea    0x2ee0(%rip),%rdx
mov    $0x11b,%ecx
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf3b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
add    $0x100,%rcx
cmp    %rcx,%rax
jae    122e <Quantize+0x10e>
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jle    11df <Quantize+0xbf>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
mov    -0x10(%rbp),%rcx
cltd
idivl  (%rcx)
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
jmp    1218 <Quantize+0xf8>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
sub    %ecx,%eax
mov    -0x10(%rbp),%rcx
cltd
idivl  (%rcx)
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
jmp    121d <Quantize+0xfd>
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
jmp    117c <Quantize+0x5c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Quantize>:
push   %rax
test   %rsi,%rsi
je     1175 <Quantize+0x45>
xor    %ecx,%ecx
nopl   0x0(%rax,%rax,1)
mov    (%rdi,%rcx,4),%r9d
xor    %eax,%eax
test   %r9d,%r9d
setg   %al
mov    (%rsi,%rcx,4),%r8d
lea    -0x2(,%rax,4),%r10d
ff
mov    %r8d,%eax
cltd
idiv   %r10d
add    %r9d,%eax
cltd
idiv   %r8d
mov    %eax,(%rdi,%rcx,4)
add    $0x1,%rcx
cmp    $0x40,%rcx
jne    1140 <Quantize+0x10>
pop    %rax
ret
lea    0xe84(%rip),%rdi
lea    0xe8e(%rip),%rsi
lea    0x2eae(%rip),%rdx
mov    $0x11b,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf01(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@Quantize.RoutineName = internal global [9 x i8] c"Quantize\00"
@.str = [17 x i8] c"F>%s:R>%s:L>%d: \00"
@.str.1 = [141 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/aaalgo/ljpeg/refs/heads/master/jpegdir/transform.c\00"
@.str.2 = [35 x i8] c"No quantization matrix specified!\0A\00"
define void @Quantize(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
store i32* %0, i32** %3
store i32* %1, i32** %4
%6 = load i32*, i32** %4
%7 = icmp ne i32* %6, null
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([141 x i8], [141 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @Quantize.RoutineName, i64 0, i64 0), i32 283)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
unreachable
11: ; preds = %2
%12 = load i32*, i32** %3
store i32* %12, i32** %5
br label %13
13: ; preds = %49, %11
%14 = load i32*, i32** %5
%15 = load i32*, i32** %3
%16 = getelementptr inbounds i32, i32* %15, i64 64
%17 = icmp ult i32* %14, %16
br i1 %17, label %18, label %52
18: ; preds = %13
%19 = load i32*, i32** %5
%20 = load i32, i32* %19
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %35
22: ; preds = %18
%23 = load i32*, i32** %5
%24 = load i32, i32* %23
%25 = load i32*, i32** %4
%26 = load i32, i32* %25
%27 = sdiv i32 %26, 2
%28 = add nsw i32 %24, %27
%29 = load i32*, i32** %4
%30 = load i32, i32* %29
%31 = sdiv i32 %28, %30
%32 = load i32*, i32** %5
store i32 %31, i32* %32
%33 = load i32*, i32** %4
%34 = getelementptr inbounds i32, i32* %33, i32 1
store i32* %34, i32** %4
br label %48
35: ; preds = %18
%36 = load i32*, i32** %5
%37 = load i32, i32* %36
%38 = load i32*, i32** %4
%39 = load i32, i32* %38
%40 = sdiv i32 %39, 2
%41 = sub nsw i32 %37, %40
%42 = load i32*, i32** %4
%43 = load i32, i32* %42
%44 = sdiv i32 %41, %43
%45 = load i32*, i32** %5
store i32 %44, i32* %45
%46 = load i32*, i32** %4
%47 = getelementptr inbounds i32, i32* %46, i32 1
store i32* %47, i32** %4
br label %48
48: ; preds = %35, %22
br label %49
49: ; preds = %48
%50 = load i32*, i32** %5
%51 = getelementptr inbounds i32, i32* %50, i32 1
store i32* %51, i32** %5
br label %13
52: ; preds = %13
ret void
}

LLVM IR (-O2):
@Quantize.RoutineName = internal global [9 x i8] c"Quantize\00"
@.str = [17 x i8] c"F>%s:R>%s:L>%d: \00"
@.str.1 = [141 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/aaalgo/ljpeg/refs/heads/master/jpegdir/transform.c\00"
@str = [34 x i8] c"No quantization matrix specified!\00"
define void @Quantize(i32* nocapture %0, i32* %1) {
%3 = icmp eq i32* %1, null
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([141 x i8], [141 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @Quantize.RoutineName, i64 0, i64 0), i32 283)
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
tail call void @exit(i32 1)
unreachable
7: ; preds = %2, %7
%8 = phi i32* [ %20, %7 ], [ %0, %2 ]
%9 = phi i64 [ %19, %7 ], [ 0, %2 ]
%10 = phi i32* [ %18, %7 ], [ %1, %2 ]
%11 = load i32, i32* %8
%12 = icmp sgt i32 %11, 0
%13 = load i32, i32* %10
%14 = select i1 %12, i32 2, i32 -2
%15 = sdiv i32 %13, %14
%16 = add i32 %15, %11
%17 = sdiv i32 %16, %13
store i32 %17, i32* %8
%18 = getelementptr inbounds i32, i32* %10, i64 1
%19 = add nuw nsw i64 %9, 1
%20 = getelementptr inbounds i32, i32* %0, i64 %19
%21 = icmp eq i64 %19, 64
br i1 %21, label %22, label %7
22: ; preds = %7
ret void
}