#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 qadd_table(int inter) {
  const int max_q_add = 5592405;
  printf("%s\n", inter ? "inter" : "intra");
  for (int qp = 0; qp < 52; qp++) {
    int qp_div_6 = qp / 6;
    int old = 1398101 >> (7 - qp_div_6 + (inter ? 1 : 0));
    int div = inter ? 6 : 3;
    int q_add = (2 << (15 + (qp_div_6))) / div;
    int new_q_add = max_q_add >> (8 - qp_div_6 + (inter ? 1 : 0));
    printf("qp = %2d\t div6 = %d\tq_add = %7d\t new = %7d old = %7d\n", qp,
           qp_div_6, q_add, new_q_add, old);
  }
}


x86 assembly (clang, -O0):
<qadd_table>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x555555,-0x8(%rbp)
mov    -0x4(%rbp),%ecx
lea    0xede(%rip),%rsi
lea    0xed1(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x34,-0xc(%rbp)
jge    1206 <qadd_table+0xf6>
mov    -0xc(%rbp),%eax
mov    $0x6,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    $0x7,%ecx
sub    -0x10(%rbp),%ecx
mov    -0x4(%rbp),%esi
xor    %eax,%eax
mov    $0x1,%edx
cmp    $0x0,%esi
cmovne %edx,%eax
add    %eax,%ecx
mov    $0x155555,%eax
sar    %cl,%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edx
mov    $0x3,%eax
mov    $0x6,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%ecx
add    $0xf,%ecx
mov    $0x2,%eax
shl    %cl,%eax
cltd
idivl  -0x18(%rbp)
mov    %eax,-0x1c(%rbp)
mov    $0x8,%ecx
sub    -0x10(%rbp),%ecx
mov    -0x4(%rbp),%esi
xor    %eax,%eax
mov    $0x1,%edx
cmp    $0x0,%esi
cmovne %edx,%eax
add    %eax,%ecx
mov    $0x555555,%eax
sar    %cl,%eax
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
mov    -0x14(%rbp),%r9d
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114f <qadd_table+0x3f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qadd_table>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %ebx,%ebx
xor    %r15d,%r15d
test   %edi,%edi
setne  %bl
sete   %r15b
lea    0xec6(%rip),%rax
lea    0xeb9(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
mov    $0x8,%r12d
sub    %r15d,%r12d
lea    (%rbx,%rbx,2),%r13d
add    $0x3,%r13d
xor    $0x9,%r15d
lea    0xea0(%rip),%r14
xor    %ebp,%ebp
xchg   %ax,%ax
movzbl %bpl,%eax
imul   $0xab,%eax,%ebx
shr    $0xa,%ebx
mov    %r12d,%ecx
sub    %ebx,%ecx
mov    $0x155555,%r9d
shr    %cl,%r9d
mov    $0x10000,%eax
mov    %ebx,%ecx
shl    %cl,%eax
xor    %edx,%edx
div    %r13d
mov    %r15d,%ecx
sub    %ebx,%ecx
mov    $0x555555,%r8d
shr    %cl,%r8d
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebp
cmp    $0x34,%ebp
jne    1170 <qadd_table+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [6 x i8] c"inter\00"
@.str.2 = [6 x i8] c"intra\00"
@.str.3 = [54 x i8] c"qp = %2d\09 div6 = %d\09q_add = %7d\09 new = %7d old = %7d\0A\00"
define void @qadd_table(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %2
store i32 5592405, i32* %3
%10 = load i32, i32* %2
%11 = icmp ne i32 %10, 0
%12 = zext i1 %11 to i64
%13 = select i1 %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %13)
store i32 0, i32* %4
br label %15
15: ; preds = %52, %1
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 52
br i1 %17, label %18, label %55
18: ; preds = %15
%19 = load i32, i32* %4
%20 = sdiv i32 %19, 6
store i32 %20, i32* %5
%21 = load i32, i32* %5
%22 = sub nsw i32 7, %21
%23 = load i32, i32* %2
%24 = icmp ne i32 %23, 0
%25 = zext i1 %24 to i64
%26 = select i1 %24, i32 1, i32 0
%27 = add nsw i32 %22, %26
%28 = ashr i32 1398101, %27
store i32 %28, i32* %6
%29 = load i32, i32* %2
%30 = icmp ne i32 %29, 0
%31 = zext i1 %30 to i64
%32 = select i1 %30, i32 6, i32 3
store i32 %32, i32* %7
%33 = load i32, i32* %5
%34 = add nsw i32 15, %33
%35 = shl i32 2, %34
%36 = load i32, i32* %7
%37 = sdiv i32 %35, %36
store i32 %37, i32* %8
%38 = load i32, i32* %5
%39 = sub nsw i32 8, %38
%40 = load i32, i32* %2
%41 = icmp ne i32 %40, 0
%42 = zext i1 %41 to i64
%43 = select i1 %41, i32 1, i32 0
%44 = add nsw i32 %39, %43
%45 = ashr i32 5592405, %44
store i32 %45, i32* %9
%46 = load i32, i32* %4
%47 = load i32, i32* %5
%48 = load i32, i32* %8
%49 = load i32, i32* %9
%50 = load i32, i32* %6
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0), i32 %46, i32 %47, i32 %48, i32 %49, i32 %50)
br label %52
52: ; preds = %18
%53 = load i32, i32* %4
%54 = add nsw i32 %53, 1
store i32 %54, i32* %4
br label %15
55: ; preds = %15
ret void
}

LLVM IR (-O2):
@.str.1 = [6 x i8] c"inter\00"
@.str.2 = [6 x i8] c"intra\00"
@.str.3 = [54 x i8] c"qp = %2d\09 div6 = %d\09q_add = %7d\09 new = %7d old = %7d\0A\00"
define void @qadd_table(i32 %0) {
%2 = icmp eq i32 %0, 0
%3 = select i1 %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0)
%4 = tail call i32 @puts(i8* dereferenceable(1) %3)
%5 = select i1 %2, i32 7, i32 8
%6 = select i1 %2, i32 3, i32 6
%7 = select i1 %2, i32 8, i32 9
br label %9
8: ; preds = %9
ret void
9: ; preds = %1, %9
%10 = phi i32 [ 0, %1 ], [ %21, %9 ]
%11 = trunc i32 %10 to i8
%12 = udiv i8 %11, 6
%13 = zext i8 %12 to i32
%14 = sub nsw i32 %5, %13
%15 = lshr i32 1398101, %14
%16 = shl nuw nsw i32 65536, %13
%17 = udiv i32 %16, %6
%18 = sub nsw i32 %7, %13
%19 = lshr i32 5592405, %18
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0), i32 %10, i32 %13, i32 %17, i32 %19, i32 %15)
%21 = add nuw nsw i32 %10, 1
%22 = icmp eq i32 %21, 52
br i1 %22, label %8, label %9
}