#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 */
unsigned int DIV_ROUND_CLOSEST(unsigned int, int);
void jpeg_scale_quant_table(unsigned char *q_tab, const unsigned char *tab,
                            int scale) {
  unsigned int temp;
  int i;
  for (i = 0; i < 64; i++) {
    temp = DIV_ROUND_CLOSEST((unsigned int)tab[i] * scale, 100);
    if (temp <= 0)
      temp = 1;
    if (temp > 255)
      temp = 255;
    q_tab[i] = (unsigned char)temp;
  }
}


x86 assembly (clang, -O0):
<jpeg_scale_quant_table>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x40,-0x1c(%rbp)
jge    1194 <jpeg_scale_quant_table+0x84>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
imul   -0x14(%rbp),%edi
mov    $0x64,%esi
call   1030 <DIV_ROUND_CLOSEST@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
ja     1162 <jpeg_scale_quant_table+0x52>
movl   $0x1,-0x18(%rbp)
cmpl   $0xff,-0x18(%rbp)
jbe    1176 <jpeg_scale_quant_table+0x66>
movl   $0xff,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112a <jpeg_scale_quant_table+0x1a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jpeg_scale_quant_table>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbp
xor    %ebx,%ebx
jmp    113e <jpeg_scale_quant_table+0x2e>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %cl,0x0(%rbp,%rbx,1)
add    $0x1,%rbx
cmp    $0x40,%rbx
je     116b <jpeg_scale_quant_table+0x5b>
movzbl (%r15,%rbx,1),%edi
imul   %r14d,%edi
mov    $0x64,%esi
call   1030 <DIV_ROUND_CLOSEST@plt>
mov    $0x1,%ecx
test   %eax,%eax
je     115c <jpeg_scale_quant_table+0x4c>
mov    %eax,%ecx
cmp    $0xff,%ecx
jb     1130 <jpeg_scale_quant_table+0x20>
mov    $0xff,%ecx
jmp    1130 <jpeg_scale_quant_table+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @jpeg_scale_quant_table(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %8
br label %9
9: ; preds = %36, %3
%10 = load i32, i32* %8
%11 = icmp slt i32 %10, 64
br i1 %11, label %12, label %39
12: ; preds = %9
%13 = load i8*, i8** %5
%14 = load i32, i32* %8
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
%19 = load i32, i32* %6
%20 = mul i32 %18, %19
%21 = call i32 @DIV_ROUND_CLOSEST(i32 %20, i32 100)
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = icmp ule i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %12
store i32 1, i32* %7
br label %25
25: ; preds = %24, %12
%26 = load i32, i32* %7
%27 = icmp ugt i32 %26, 255
br i1 %27, label %28, label %29
28: ; preds = %25
store i32 255, i32* %7
br label %29
29: ; preds = %28, %25
%30 = load i32, i32* %7
%31 = trunc i32 %30 to i8
%32 = load i8*, i8** %4
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 %31, i8* %35
br label %36
36: ; preds = %29
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
store i32 %38, i32* %8
br label %9
39: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @jpeg_scale_quant_table(i8* nocapture writeonly %0, i8* nocapture %1, i32 %2) {
br label %4
4: ; preds = %3, %4
%5 = phi i64 [ 0, %3 ], [ %17, %4 ]
%6 = getelementptr inbounds i8, i8* %1, i64 %5
%7 = load i8, i8* %6
%8 = zext i8 %7 to i32
%9 = mul i32 %8, %2
%10 = tail call i32 @DIV_ROUND_CLOSEST(i32 %9, i32 100)
%11 = icmp eq i32 %10, 0
%12 = select i1 %11, i32 1, i32 %10
%13 = icmp ult i32 %12, 255
%14 = select i1 %13, i32 %12, i32 255
%15 = trunc i32 %14 to i8
%16 = getelementptr inbounds i8, i8* %0, i64 %5
store i8 %15, i8* %16
%17 = add nuw nsw i64 %5, 1
%18 = icmp eq i64 %17, 64
br i1 %18, label %19, label %4
19: ; preds = %4
ret void
}