#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 */
struct coder {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ Ptngc_writebits(struct coder *, int const, int,
                                   unsigned char **);
int /*<<< orphan*/ write_instruction(struct coder *, int, unsigned char **);
int /*<<< orphan*/ write_three_large(struct coder *, int *, int *, int const,
                                     unsigned char *, unsigned char **);
void flush_large(struct coder *coder, int *has_large, int *has_large_ints,
                 const int n, int *large_index, const int large_nbits,
                 unsigned char *compress_buffer, unsigned char **output_ptr) {
  int i;
  if (n < 3) {
    for (i = 0; i < n; i++) {
      write_instruction(coder, 2, output_ptr);
      write_three_large(coder, has_large_ints + i * 3, large_index, large_nbits,
                        compress_buffer, output_ptr);
    }
  } else {
    write_instruction(coder, 6, output_ptr);
    Ptngc_writebits(coder, n - 3, 4, output_ptr);
    for (i = 0; i < n; i++)
      write_three_large(coder, has_large_ints + i * 3, large_index, large_nbits,
                        compress_buffer, output_ptr);
  }
  if (((*has_large) - n) != 0) {
    int j;
    for (i = 0; i < (*has_large) - n; i++)
      for (j = 0; j < 3; j++)
        has_large_ints[i * 3 + j] = has_large_ints[(i + n) * 3 + j];
  }
  *has_large = (*has_large) - n;
}


x86 assembly (clang, -O0):
<flush_large>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
jge    11c2 <flush_large+0x92>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11bd <flush_large+0x8d>
mov    -0x8(%rbp),%rdi
mov    0x18(%rbp),%rdx
mov    $0x2,%esi
call   1040 <write_instruction@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
imul   $0x3,-0x30(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x28(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
mov    0x10(%rbp),%r8
mov    0x18(%rbp),%r9
call   1030 <write_three_large@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1168 <flush_large+0x38>
jmp    123b <flush_large+0x10b>
mov    -0x8(%rbp),%rdi
mov    0x18(%rbp),%rdx
mov    $0x6,%esi
call   1040 <write_instruction@plt>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
sub    $0x3,%esi
mov    0x18(%rbp),%rcx
mov    $0x4,%edx
call   1050 <Ptngc_writebits@plt>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1236 <flush_large+0x106>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
imul   $0x3,-0x30(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x28(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
mov    0x10(%rbp),%r8
mov    0x18(%rbp),%r9
call   1030 <write_three_large@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11f3 <flush_large+0xc3>
jmp    123b <flush_large+0x10b>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
sub    -0x1c(%rbp),%eax
cmp    $0x0,%eax
je     12c6 <flush_large+0x196>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%ecx
sub    -0x1c(%rbp),%ecx
cmp    %ecx,%eax
jge    12c1 <flush_large+0x191>
movl   $0x0,-0x34(%rbp)
cmpl   $0x3,-0x34(%rbp)
jge    12ae <flush_large+0x17e>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%ecx
add    -0x1c(%rbp),%ecx
imul   $0x3,%ecx,%ecx
add    -0x34(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x18(%rbp),%rax
imul   $0x3,-0x30(%rbp),%ecx
add    -0x34(%rbp),%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    126f <flush_large+0x13f>
jmp    12b3 <flush_large+0x183>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1254 <flush_large+0x124>
jmp    12c6 <flush_large+0x196>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
sub    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flush_large>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,%r14d
mov    %r8,%r13
mov    %ecx,%ebx
mov    %rdx,%r15
mov    %rsi,0x10(%rsp)
mov    %rdi,%r12
mov    0x58(%rsp),%rbp
cmp    $0x2,%ecx
mov    %rbx,0x8(%rsp)
jg     11b6 <flush_large+0x86>
test   %ebx,%ebx
mov    %r14d,0x4(%rsp)
jle    1205 <flush_large+0xd5>
mov    0x8(%rsp),%r14d
mov    %r15,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
mov    $0x2,%esi
mov    %rbp,%rdx
call   1040 <write_instruction@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
mov    0x4(%rsp),%ecx
mov    0x50(%rsp),%r8
mov    %rbp,%r9
call   1030 <write_three_large@plt>
add    $0xc,%rbx
add    $0xffffffffffffffff,%r14
jne    1180 <flush_large+0x50>
jmp    1205 <flush_large+0xd5>
mov    %r12,%rdi
mov    $0x6,%esi
mov    %rbp,%rdx
call   1040 <write_instruction@plt>
lea    -0x3(%rbx),%esi
mov    %r12,%rdi
mov    $0x4,%edx
mov    %rbp,%rcx
call   1050 <Ptngc_writebits@plt>
mov    %ebx,%ebp
mov    %r15,%rbx
xchg   %ax,%ax
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
mov    %r14d,%ecx
mov    0x50(%rsp),%r8
mov    0x58(%rsp),%r9
call   1030 <write_three_large@plt>
add    $0xc,%rbx
add    $0xffffffffffffffff,%rbp
jne    11e0 <flush_large+0xb0>
mov    0x10(%rsp),%rbp
mov    0x0(%rbp),%eax
mov    0x8(%rsp),%rdi
mov    %edi,%edx
cmp    %edi,%eax
je     1260 <flush_large+0x130>
mov    %eax,%edx
jle    1260 <flush_large+0x130>
movslq %edi,%rax
add    $0x8,%r15
shl    $0x2,%rax
lea    (%rax,%rax,2),%rax
xor    %ecx,%ecx
nopl   (%rax)
mov    -0x8(%r15,%rax,1),%edx
mov    %edx,-0x8(%r15)
mov    -0x4(%r15,%rax,1),%edx
mov    %edx,-0x4(%r15)
mov    (%r15,%rax,1),%edx
mov    %edx,(%r15)
add    $0x1,%rcx
mov    0x0(%rbp),%edx
mov    %edx,%esi
sub    %edi,%esi
movslq %esi,%rsi
add    $0xc,%r15
cmp    %rsi,%rcx
jl     1230 <flush_large+0x100>
sub    %edi,%edx
mov    %edx,0x0(%rbp)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.coder = type { i32 }
define void @flush_large(%struct.coder* %0, i32* %1, i32* %2, i32 %3, i32* %4, i32 %5, i8* %6, i8** %7) {
%9 = alloca %struct.coder*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i8**
%17 = alloca i32
%18 = alloca i32
store %struct.coder* %0, %struct.coder** %9
store i32* %1, i32** %10
store i32* %2, i32** %11
store i32 %3, i32* %12
store i32* %4, i32** %13
store i32 %5, i32* %14
store i8* %6, i8** %15
store i8** %7, i8*** %16
%19 = load i32, i32* %12
%20 = icmp slt i32 %19, 3
br i1 %20, label %21, label %45
21: ; preds = %8
store i32 0, i32* %17
br label %22
22: ; preds = %41, %21
%23 = load i32, i32* %17
%24 = load i32, i32* %12
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %44
26: ; preds = %22
%27 = load %struct.coder*, %struct.coder** %9
%28 = load i8**, i8*** %16
%29 = call i32 @write_instruction(%struct.coder* %27, i32 2, i8** %28)
%30 = load %struct.coder*, %struct.coder** %9
%31 = load i32*, i32** %11
%32 = load i32, i32* %17
%33 = mul nsw i32 %32, 3
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %31, i64 %34
%36 = load i32*, i32** %13
%37 = load i32, i32* %14
%38 = load i8*, i8** %15
%39 = load i8**, i8*** %16
%40 = call i32 @write_three_large(%struct.coder* %30, i32* %35, i32* %36, i32 %37, i8* %38, i8** %39)
br label %41
41: ; preds = %26
%42 = load i32, i32* %17
%43 = add nsw i32 %42, 1
store i32 %43, i32* %17
br label %22
44: ; preds = %22
br label %74
45: ; preds = %8
%46 = load %struct.coder*, %struct.coder** %9
%47 = load i8**, i8*** %16
%48 = call i32 @write_instruction(%struct.coder* %46, i32 6, i8** %47)
%49 = load %struct.coder*, %struct.coder** %9
%50 = load i32, i32* %12
%51 = sub nsw i32 %50, 3
%52 = load i8**, i8*** %16
%53 = call i32 @Ptngc_writebits(%struct.coder* %49, i32 %51, i32 4, i8** %52)
store i32 0, i32* %17
br label %54
54: ; preds = %70, %45
%55 = load i32, i32* %17
%56 = load i32, i32* %12
%57 = icmp slt i32 %55, %56
br i1 %57, label %58, label %73
58: ; preds = %54
%59 = load %struct.coder*, %struct.coder** %9
%60 = load i32*, i32** %11
%61 = load i32, i32* %17
%62 = mul nsw i32 %61, 3
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i32, i32* %60, i64 %63
%65 = load i32*, i32** %13
%66 = load i32, i32* %14
%67 = load i8*, i8** %15
%68 = load i8**, i8*** %16
%69 = call i32 @write_three_large(%struct.coder* %59, i32* %64, i32* %65, i32 %66, i8* %67, i8** %68)
br label %70
70: ; preds = %58
%71 = load i32, i32* %17
%72 = add nsw i32 %71, 1
store i32 %72, i32* %17
br label %54
73: ; preds = %54
br label %74
74: ; preds = %73, %44
%75 = load i32*, i32** %10
%76 = load i32, i32* %75
%77 = load i32, i32* %12
%78 = sub nsw i32 %76, %77
%79 = icmp ne i32 %78, 0
br i1 %79, label %80, label %118
80: ; preds = %74
store i32 0, i32* %17
br label %81
81: ; preds = %114, %80
%82 = load i32, i32* %17
%83 = load i32*, i32** %10
%84 = load i32, i32* %83
%85 = load i32, i32* %12
%86 = sub nsw i32 %84, %85
%87 = icmp slt i32 %82, %86
br i1 %87, label %88, label %117
88: ; preds = %81
store i32 0, i32* %18
br label %89
89: ; preds = %110, %88
%90 = load i32, i32* %18
%91 = icmp slt i32 %90, 3
br i1 %91, label %92, label %113
92: ; preds = %89
%93 = load i32*, i32** %11
%94 = load i32, i32* %17
%95 = load i32, i32* %12
%96 = add nsw i32 %94, %95
%97 = mul nsw i32 %96, 3
%98 = load i32, i32* %18
%99 = add nsw i32 %97, %98
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds i32, i32* %93, i64 %100
%102 = load i32, i32* %101
%103 = load i32*, i32** %11
%104 = load i32, i32* %17
%105 = mul nsw i32 %104, 3
%106 = load i32, i32* %18
%107 = add nsw i32 %105, %106
%108 = sext i32 %107 to i64
%109 = getelementptr inbounds i32, i32* %103, i64 %108
store i32 %102, i32* %109
br label %110
110: ; preds = %92
%111 = load i32, i32* %18
%112 = add nsw i32 %111, 1
store i32 %112, i32* %18
br label %89
113: ; preds = %89
br label %114
114: ; preds = %113
%115 = load i32, i32* %17
%116 = add nsw i32 %115, 1
store i32 %116, i32* %17
br label %81
117: ; preds = %81
br label %118
118: ; preds = %117, %74
%119 = load i32*, i32** %10
%120 = load i32, i32* %119
%121 = load i32, i32* %12
%122 = sub nsw i32 %120, %121
%123 = load i32*, i32** %10
store i32 %122, i32* %123
ret void
}

LLVM IR (-O2):
%struct.coder = type { i32 }
define void @flush_large(%struct.coder* %0, i32* nocapture %1, i32* %2, i32 %3, i32* %4, i32 %5, i8* %6, i8** %7) {
%9 = icmp slt i32 %3, 3
br i1 %9, label %10, label %23
10: ; preds = %8
%11 = icmp sgt i32 %3, 0
br i1 %11, label %12, label %35
12: ; preds = %10
%13 = zext i32 %3 to i64
br label %14
14: ; preds = %12, %14
%15 = phi i64 [ 0, %12 ], [ %21, %14 ]
%16 = tail call i32 @write_instruction(%struct.coder* %0, i32 2, i8** %7)
%17 = mul i64 %15, 3
%18 = and i64 %17, 4294967295
%19 = getelementptr inbounds i32, i32* %2, i64 %18
%20 = tail call i32 @write_three_large(%struct.coder* %0, i32* %19, i32* %4, i32 %5, i8* %6, i8** %7)
%21 = add nuw nsw i64 %15, 1
%22 = icmp eq i64 %21, %13
br i1 %22, label %35, label %14
23: ; preds = %8
%24 = tail call i32 @write_instruction(%struct.coder* %0, i32 6, i8** %7)
%25 = add nsw i32 %3, -3
%26 = tail call i32 @Ptngc_writebits(%struct.coder* %0, i32 %25, i32 4, i8** %7)
%27 = zext i32 %3 to i64
br label %28
28: ; preds = %23, %28
%29 = phi i64 [ 0, %23 ], [ %33, %28 ]
%30 = mul nuw nsw i64 %29, 3
%31 = getelementptr inbounds i32, i32* %2, i64 %30
%32 = tail call i32 @write_three_large(%struct.coder* %0, i32* %31, i32* %4, i32 %5, i8* %6, i8** %7)
%33 = add nuw nsw i64 %29, 1
%34 = icmp eq i64 %33, %27
br i1 %34, label %35, label %28
35: ; preds = %28, %14, %10
%36 = load i32, i32* %1
%37 = icmp eq i32 %36, %3
br i1 %37, label %65, label %38
38: ; preds = %35
%39 = icmp sgt i32 %36, %3
br i1 %39, label %40, label %65
40: ; preds = %38
%41 = sext i32 %3 to i64
br label %42
42: ; preds = %40, %42
%43 = phi i64 [ 0, %40 ], [ %60, %42 ]
%44 = add nsw i64 %43, %41
%45 = mul nsw i64 %44, 3
%46 = mul nuw nsw i64 %43, 3
%47 = getelementptr inbounds i32, i32* %2, i64 %45
%48 = load i32, i32* %47
%49 = getelementptr inbounds i32, i32* %2, i64 %46
store i32 %48, i32* %49
%50 = add nsw i64 %45, 1
%51 = getelementptr inbounds i32, i32* %2, i64 %50
%52 = load i32, i32* %51
%53 = add nuw nsw i64 %46, 1
%54 = getelementptr inbounds i32, i32* %2, i64 %53
store i32 %52, i32* %54
%55 = add nsw i64 %45, 2
%56 = getelementptr inbounds i32, i32* %2, i64 %55
%57 = load i32, i32* %56
%58 = add nuw nsw i64 %46, 2
%59 = getelementptr inbounds i32, i32* %2, i64 %58
store i32 %57, i32* %59
%60 = add nuw nsw i64 %43, 1
%61 = load i32, i32* %1
%62 = sub nsw i32 %61, %3
%63 = sext i32 %62 to i64
%64 = icmp slt i64 %60, %63
br i1 %64, label %42, label %65
65: ; preds = %42, %38, %35
%66 = phi i32 [ %36, %38 ], [ %3, %35 ], [ %61, %42 ]
%67 = sub nsw i32 %66, %3
store i32 %67, i32* %1
ret void
}