int *ScaleMatrix(Numerator, Denominator, LongFlag, Matrix)
int Numerator;
int Denominator;
int LongFlag;
int *Matrix;
{
  static char RoutineName[] = "ScaleMatrix";
  int *Temp, *tptr;
  int Limit;
  Limit = ((LongFlag) ? 65535 : 255);
  if (!(Temp = (int *)calloc(64, sizeof(int)))) {
    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, 470);
    printf("Cannot allocate space for new matrix.\n");
    exit(12);
  }
  for (tptr = Temp; tptr < Temp + 64; tptr++) {
    *tptr = (*(Matrix++) * Numerator) / Denominator;
    if (*tptr > Limit)
      *tptr = Limit;
    else if (*tptr < 1)
      *tptr = 1;
  }
  return (Temp);
}


x86 assembly (clang, -O0):
<ScaleMatrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0xc(%rbp),%edx
mov    $0xff,%eax
mov    $0xffff,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    $0x40,%edi
mov    $0x4,%esi
call   1040 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11b1 <ScaleMatrix+0x81>
lea    0xe81(%rip),%rdi
lea    0xe8b(%rip),%rsi
lea    0x2eab(%rip),%rdx
mov    $0x1d6,%ecx
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xefe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xc,%edi
call   1050 <exit@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
add    $0x100,%rcx
cmp    %rcx,%rax
jae    1241 <ScaleMatrix+0x111>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%eax
imul   -0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
cmp    -0x2c(%rbp),%eax
jle    120f <ScaleMatrix+0xdf>
mov    -0x2c(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
jmp    122b <ScaleMatrix+0xfb>
mov    -0x28(%rbp),%rax
cmpl   $0x1,(%rax)
jge    1226 <ScaleMatrix+0xf6>
mov    -0x28(%rbp),%rax
movl   $0x1,(%rax)
jmp    122b <ScaleMatrix+0xfb>
jmp    1230 <ScaleMatrix+0x100>
mov    -0x28(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x28(%rbp)
jmp    11b9 <ScaleMatrix+0x89>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ScaleMatrix>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %esi,%r15d
mov    %edi,%ebx
test   %edx,%edx
mov    $0xff,%eax
mov    $0xffff,%ebp
cmove  %eax,%ebp
mov    $0x40,%edi
mov    $0x4,%esi
call   1050 <calloc@plt>
test   %rax,%rax
je     11ba <ScaleMatrix+0x7a>
mov    %rax,%rcx
xor    %esi,%esi
jmp    118d <ScaleMatrix+0x4d>
nopl   0x0(%rax)
mov    %edx,(%rcx,%rsi,4)
add    $0x1,%rsi
cmp    $0x40,%rsi
je     11ac <ScaleMatrix+0x6c>
mov    (%r14,%rsi,4),%eax
imul   %ebx,%eax
cltd
idiv   %r15d
mov    %eax,(%rcx,%rsi,4)
mov    %ebp,%edx
cmp    %ebp,%eax
jg     1180 <ScaleMatrix+0x40>
test   %eax,%eax
jg     1183 <ScaleMatrix+0x43>
mov    $0x1,%edx
jmp    1180 <ScaleMatrix+0x40>
mov    %rcx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe3f(%rip),%rdi
lea    0xe49(%rip),%rsi
lea    0x2e71(%rip),%rdx
mov    $0x1d6,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xebc(%rip),%rdi
call   1030 <puts@plt>
mov    $0xc,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@ScaleMatrix.RoutineName = internal global [12 x i8] c"ScaleMatrix\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 = [39 x i8] c"Cannot allocate space for new matrix.\0A\00"
define i32* @ScaleMatrix(i32 %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32* %3, i32** %8
%12 = load i32, i32* %7
%13 = icmp ne i32 %12, 0
%14 = zext i1 %13 to i64
%15 = select i1 %13, i32 65535, i32 255
store i32 %15, i32* %11
%16 = call i8* @calloc(i64 64, i64 4)
%17 = bitcast i8* %16 to i32*
store i32* %17, i32** %9
%18 = icmp ne i32* %17, null
br i1 %18, label %22, label %19
19: ; preds = %4
%20 = 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 ([12 x i8], [12 x i8]* @ScaleMatrix.RoutineName, i64 0, i64 0), i32 470)
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
unreachable
22: ; preds = %4
%23 = load i32*, i32** %9
store i32* %23, i32** %10
br label %24
24: ; preds = %53, %22
%25 = load i32*, i32** %10
%26 = load i32*, i32** %9
%27 = getelementptr inbounds i32, i32* %26, i64 64
%28 = icmp ult i32* %25, %27
br i1 %28, label %29, label %56
29: ; preds = %24
%30 = load i32*, i32** %8
%31 = getelementptr inbounds i32, i32* %30, i32 1
store i32* %31, i32** %8
%32 = load i32, i32* %30
%33 = load i32, i32* %5
%34 = mul nsw i32 %32, %33
%35 = load i32, i32* %6
%36 = sdiv i32 %34, %35
%37 = load i32*, i32** %10
store i32 %36, i32* %37
%38 = load i32*, i32** %10
%39 = load i32, i32* %38
%40 = load i32, i32* %11
%41 = icmp sgt i32 %39, %40
br i1 %41, label %42, label %45
42: ; preds = %29
%43 = load i32, i32* %11
%44 = load i32*, i32** %10
store i32 %43, i32* %44
br label %52
45: ; preds = %29
%46 = load i32*, i32** %10
%47 = load i32, i32* %46
%48 = icmp slt i32 %47, 1
br i1 %48, label %49, label %51
49: ; preds = %45
%50 = load i32*, i32** %10
store i32 1, i32* %50
br label %51
51: ; preds = %49, %45
br label %52
52: ; preds = %51, %42
br label %53
53: ; preds = %52
%54 = load i32*, i32** %10
%55 = getelementptr inbounds i32, i32* %54, i32 1
store i32* %55, i32** %10
br label %24
56: ; preds = %24
%57 = load i32*, i32** %9
ret i32* %57
}

LLVM IR (-O2):
@ScaleMatrix.RoutineName = internal global [12 x i8] c"ScaleMatrix\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 = [38 x i8] c"Cannot allocate space for new matrix.\00"
define noalias i32* @ScaleMatrix(i32 %0, i32 %1, i32 %2, i32* nocapture %3) {
%5 = icmp eq i32 %2, 0
%6 = select i1 %5, i32 255, i32 65535
%7 = tail call dereferenceable_or_null(256) i8* @calloc(i64 64, i64 4)
%8 = bitcast i8* %7 to i32*
%9 = icmp eq i8* %7, null
br i1 %9, label %10, label %13
10: ; preds = %4
%11 = 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 ([12 x i8], [12 x i8]* @ScaleMatrix.RoutineName, i64 0, i64 0), i32 470)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
tail call void @exit(i32 12)
unreachable
13: ; preds = %4, %26
%14 = phi i32* [ %28, %26 ], [ %8, %4 ]
%15 = phi i32* [ %17, %26 ], [ %3, %4 ]
%16 = phi i64 [ %27, %26 ], [ 0, %4 ]
%17 = getelementptr inbounds i32, i32* %15, i64 1
%18 = load i32, i32* %15
%19 = mul nsw i32 %18, %0
%20 = sdiv i32 %19, %1
store i32 %20, i32* %14
%21 = icmp sgt i32 %20, %6
br i1 %21, label %24, label %22
22: ; preds = %13
%23 = icmp slt i32 %20, 1
br i1 %23, label %24, label %26
24: ; preds = %22, %13
%25 = phi i32 [ %6, %13 ], [ 1, %22 ]
store i32 %25, i32* %14
br label %26
26: ; preds = %24, %22
%27 = add nuw nsw i64 %16, 1
%28 = getelementptr inbounds i32, i32* %8, i64 %27
%29 = icmp eq i64 %27, 64
br i1 %29, label %30, label %13
30: ; preds = %26
ret i32* %8
}