#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 read_se(unsigned char *, int *, int *);
void skip_scaling_List(int sizeOfScalingList, unsigned char *rbsp,
                       int *bits_offset, int *total_bits) {
  const unsigned char ZZ_SCAN[16] = {0, 1,  4,  8,  5, 2,  3,  6,
                                     9, 12, 13, 10, 7, 11, 14, 15};
  const unsigned char ZZ_SCAN8[64] = {
      0,  1,  8,  16, 9,  2,  3,  10, 17, 24, 32, 25, 18, 11, 4,  5,
      12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6,  7,  14, 21, 28,
      35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51,
      58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63};
  int scalingList[64];
  int j, scanj;
  int delta_scale, lastScale, nextScale;
  lastScale = 8;
  nextScale = 8;
  for (j = 0; j < sizeOfScalingList; j++) {
    scanj = (sizeOfScalingList == 16) ? ZZ_SCAN[j] : ZZ_SCAN8[j];
    if (nextScale != 0) {
      delta_scale = read_se(rbsp, bits_offset, total_bits);
      nextScale = (lastScale + delta_scale + 256) % 256;
    }
    scalingList[scanj] = (nextScale == 0) ? lastScale : nextScale;
    lastScale = scalingList[scanj];
  }
}


x86 assembly (clang, -O0):
<skip_scaling_List>:
push   %rbp
mov    %rsp,%rbp
sub    $0x190,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    0xebf(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xebc(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    -0x70(%rbp),%rdi
lea    0xeb5(%rip),%rsi
mov    $0x40,%edx
call   1030 <memcpy@plt>
movl   $0x8,-0x180(%rbp)
movl   $0x8,-0x184(%rbp)
movl   $0x0,-0x174(%rbp)
mov    -0x174(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    127a <skip_scaling_List+0x15a>
cmpl   $0x10,-0x4(%rbp)
jne    11b3 <skip_scaling_List+0x93>
movslq -0x174(%rbp),%rax
movzbl -0x30(%rbp,%rax,1),%eax
mov    %eax,-0x188(%rbp)
jmp    11c5 <skip_scaling_List+0xa5>
movslq -0x174(%rbp),%rax
movzbl -0x70(%rbp,%rax,1),%eax
mov    %eax,-0x188(%rbp)
mov    -0x188(%rbp),%eax
mov    %eax,-0x178(%rbp)
cmpl   $0x0,-0x184(%rbp)
je     1214 <skip_scaling_List+0xf4>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <read_se@plt>
mov    %eax,-0x17c(%rbp)
mov    -0x180(%rbp),%eax
add    -0x17c(%rbp),%eax
add    $0x100,%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %edx,-0x184(%rbp)
cmpl   $0x0,-0x184(%rbp)
jne    1232 <skip_scaling_List+0x112>
mov    -0x180(%rbp),%eax
mov    %eax,-0x18c(%rbp)
jmp    123e <skip_scaling_List+0x11e>
mov    -0x184(%rbp),%eax
mov    %eax,-0x18c(%rbp)
mov    -0x18c(%rbp),%ecx
movslq -0x178(%rbp),%rax
mov    %ecx,-0x170(%rbp,%rax,4)
movslq -0x178(%rbp),%rax
mov    -0x170(%rbp,%rax,4),%eax
mov    %eax,-0x180(%rbp)
mov    -0x174(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x174(%rbp)
jmp    1183 <skip_scaling_List+0x63>
add    $0x190,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<skip_scaling_List>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %edi,%edi
jle    117f <skip_scaling_List+0x6f>
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %edi,%ebp
mov    $0x8,%ecx
mov    $0x8,%ebx
jmp    114b <skip_scaling_List+0x3b>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %ecx,%ecx
mov    %ebx,%eax
mov    %eax,%ebx
add    $0xffffffff,%ebp
je     117f <skip_scaling_List+0x6f>
test   %ecx,%ecx
je     1140 <skip_scaling_List+0x30>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <read_se@plt>
lea    (%rbx,%rax,1),%ecx
add    $0x100,%ecx
add    %ebx,%eax
add    $0x1ff,%eax
test   %ecx,%ecx
cmovns %ecx,%eax
and    $0xffffff00,%eax
sub    %eax,%ecx
mov    %ecx,%eax
jne    1144 <skip_scaling_List+0x34>
jmp    1140 <skip_scaling_List+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.skip_scaling_List.ZZ_SCAN = [16 x i8] c"\00\01\04\08\05\02\03\06\09\0C\0D\0A\07\0B\0E\0F"
@__const.skip_scaling_List.ZZ_SCAN8 = [64 x i8] c"\00\01\08\10\09\02\03\0A\11\18 \19\12\0B\04\05\0C\13\1A!(0)\22\1B\14\0D\06\07\0E\15\1C#*1892+$\1D\16\0F\17\1E%,3:;4-&\1F'.5<=6/7>?"
define void @skip_scaling_List(i32 %0, i8* %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca [16 x i8]
%10 = alloca [64 x i8]
%11 = alloca [64 x i32]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%17 = bitcast [16 x i8]* %9 to i8*
%18 = bitcast [64 x i8]* %10 to i8*
store i32 8, i32* %15
store i32 8, i32* %16
store i32 0, i32* %12
br label %19
19: ; preds = %68, %4
%20 = load i32, i32* %12
%21 = load i32, i32* %5
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %71
23: ; preds = %19
%24 = load i32, i32* %5
%25 = icmp eq i32 %24, 16
br i1 %25, label %26, label %32
26: ; preds = %23
%27 = load i32, i32* %12
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
br label %38
32: ; preds = %23
%33 = load i32, i32* %12
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
br label %38
38: ; preds = %32, %26
%39 = phi i32 [ %31, %26 ], [ %37, %32 ]
store i32 %39, i32* %13
%40 = load i32, i32* %16
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %52
42: ; preds = %38
%43 = load i8*, i8** %6
%44 = load i32*, i32** %7
%45 = load i32*, i32** %8
%46 = call i32 @read_se(i8* %43, i32* %44, i32* %45)
store i32 %46, i32* %14
%47 = load i32, i32* %15
%48 = load i32, i32* %14
%49 = add nsw i32 %47, %48
%50 = add nsw i32 %49, 256
%51 = srem i32 %50, 256
store i32 %51, i32* %16
br label %52
52: ; preds = %42, %38
%53 = load i32, i32* %16
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %52
%56 = load i32, i32* %15
br label %59
57: ; preds = %52
%58 = load i32, i32* %16
br label %59
59: ; preds = %57, %55
%60 = phi i32 [ %56, %55 ], [ %58, %57 ]
%61 = load i32, i32* %13
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [64 x i32], [64 x i32]* %11, i64 0, i64 %62
store i32 %60, i32* %63
%64 = load i32, i32* %13
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [64 x i32], [64 x i32]* %11, i64 0, i64 %65
%67 = load i32, i32* %66
store i32 %67, i32* %15
br label %68
68: ; preds = %59
%69 = load i32, i32* %12
%70 = add nsw i32 %69, 1
store i32 %70, i32* %12
br label %19
71: ; preds = %19
ret void
}

LLVM IR (-O2):
define void @skip_scaling_List(i32 %0, i8* %1, i32* %2, i32* %3) {
%5 = icmp sgt i32 %0, 0
br i1 %5, label %6, label %23
6: ; preds = %4, %18
%7 = phi i32 [ %19, %18 ], [ 8, %4 ]
%8 = phi i32 [ %20, %18 ], [ 8, %4 ]
%9 = phi i32 [ %21, %18 ], [ 0, %4 ]
%10 = icmp eq i32 %7, 0
br i1 %10, label %17, label %11
11: ; preds = %6
%12 = tail call i32 @read_se(i8* %1, i32* %2, i32* %3)
%13 = add i32 %8, 256
%14 = add i32 %13, %12
%15 = srem i32 %14, 256
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %6, %11
br label %18
18: ; preds = %11, %17
%19 = phi i32 [ 0, %17 ], [ %15, %11 ]
%20 = phi i32 [ %8, %17 ], [ %15, %11 ]
%21 = add nuw nsw i32 %9, 1
%22 = icmp eq i32 %21, %0
br i1 %22, label %23, label %6
23: ; preds = %18, %4
ret void
}