#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*/ deflate_put_bits(int, int /*<<< orphan*/);
int /*<<< orphan*/ deflate_put_length(unsigned int);
int /*<<< orphan*/ deflate_put_literal(unsigned int);
unsigned long deflate_put_pixel(int flush, unsigned char lit, unsigned long x,
                                unsigned long w, unsigned long adler_crc) {
  int i;
  unsigned long s1;
  unsigned long s2;
  static unsigned int color;
  static unsigned int length;
  s1 = adler_crc & 0xffff;
  s2 = (adler_crc >> 16) & 0xffff;
  s1 += lit;
  s2 += s1;
  s1 %= 65521L;
  s2 %= 65521L;
  adler_crc = (s2 << 16) | s1;
  if (flush) {
    deflate_put_literal(lit);
    color = 256;
    length = 0;
    return 1;
  }
  if (lit != color || length > 256 || x == (w - 1)) {
    if (length > 2) {
      deflate_put_length(length);
      deflate_put_bits(5, 0);
    } else {
      for (i = 0; i < length; i++)
        deflate_put_literal(color);
    }
    color = lit;
    deflate_put_literal(color);
    length = 0;
  } else {
    length++;
  }
  return adler_crc;
}


x86 assembly (clang, -O0):
<deflate_put_pixel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %sil,%al
mov    %edi,-0xc(%rbp)
mov    %al,-0xd(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x28(%rbp),%rax
and    $0xffff,%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
shr    $0x10,%rax
and    $0xffff,%rax
mov    %rax,-0x40(%rbp)
movzbl -0xd(%rbp),%eax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
add    -0x40(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rax
mov    $0xfff1,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x38(%rbp)
mov    -0x40(%rbp),%rax
mov    $0xfff1,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x40(%rbp)
mov    -0x40(%rbp),%rax
shl    $0x10,%rax
or     -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11ed <deflate_put_pixel+0xbd>
movzbl -0xd(%rbp),%edi
call   1030 <deflate_put_literal@plt>
movl   $0x100,0x2e66(%rip)
movl   $0x0,0x2e60(%rip)
movq   $0x1,-0x8(%rbp)
jmp    12ba <deflate_put_pixel+0x18a>
movzbl -0xd(%rbp),%eax
cmp    0x2e45(%rip),%eax
jne    1222 <deflate_put_pixel+0xf2>
cmpl   $0x100,0x2e39(%rip)
ja     1222 <deflate_put_pixel+0xf2>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jne    12a3 <deflate_put_pixel+0x173>
cmpl   $0x2,0x2e17(%rip)
jbe    124b <deflate_put_pixel+0x11b>
mov    0x2e0b(%rip),%edi
call   1050 <deflate_put_length@plt>
mov    $0x5,%edi
xor    %esi,%esi
call   1040 <deflate_put_bits@plt>
jmp    127f <deflate_put_pixel+0x14f>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    0x2de5(%rip),%eax
jae    127a <deflate_put_pixel+0x14a>
mov    0x2dd5(%rip),%edi
call   1030 <deflate_put_literal@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1252 <deflate_put_pixel+0x122>
jmp    127f <deflate_put_pixel+0x14f>
movzbl -0xd(%rbp),%eax
mov    %eax,0x2db3(%rip)
mov    0x2dad(%rip),%edi
call   1030 <deflate_put_literal@plt>
movl   $0x0,0x2da2(%rip)
jmp    12b2 <deflate_put_pixel+0x182>
mov    0x2d97(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2d8e(%rip)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<deflate_put_pixel>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
test   %edi,%edi
je     1157 <deflate_put_pixel+0x27>
mov    %r14d,%edi
call   1030 <deflate_put_literal@plt>
movl   $0x100,0x2eef(%rip)
mov    $0x1,%ebx
jmp    1225 <deflate_put_pixel+0xf5>
mov    %r8,%rbx
movzwl %bx,%eax
shr    $0x10,%ebx
mov    %r14d,%esi
add    %rax,%rsi
add    %rsi,%rbx
mov    $0x80078071,%eax
mov    %rsi,%rdi
imul   %rax,%rdi
shr    $0x2f,%rdi
imul   $0xfff1,%edi,%edi
sub    %edi,%esi
mov    %rbx,%rdi
imul   %rax,%rdi
shr    $0x2f,%rdi
imul   $0xfff1,%edi,%eax
sub    %eax,%ebx
shl    $0x10,%ebx
or     %esi,%ebx
mov    0x2e9d(%rip),%eax
mov    0x2e9b(%rip),%edi
add    $0xffffffffffffffff,%rcx
cmp    %rdx,%rcx
je     11c0 <deflate_put_pixel+0x90>
cmp    %r14d,%eax
jne    11c0 <deflate_put_pixel+0x90>
cmp    $0x101,%edi
jae    11c0 <deflate_put_pixel+0x90>
add    $0x1,%edi
jmp    1227 <deflate_put_pixel+0xf7>
cmp    $0x2,%edi
jbe    11d8 <deflate_put_pixel+0xa8>
call   1050 <deflate_put_length@plt>
mov    $0x5,%edi
xor    %esi,%esi
call   1040 <deflate_put_bits@plt>
jmp    1216 <deflate_put_pixel+0xe6>
test   %edi,%edi
je     1216 <deflate_put_pixel+0xe6>
mov    %eax,%edi
call   1030 <deflate_put_literal@plt>
cmpl   $0x2,0x2e56(%rip)
jb     1216 <deflate_put_pixel+0xe6>
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x2e36(%rip),%edi
call   1030 <deflate_put_literal@plt>
add    $0x1,%ebp
cmp    0x2e2c(%rip),%ebp
jb     1200 <deflate_put_pixel+0xd0>
mov    %r14d,0x2e1f(%rip)
mov    %r14d,%edi
call   1030 <deflate_put_literal@plt>
xor    %edi,%edi
mov    %ebx,%eax
mov    %edi,0x2e11(%rip)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@deflate_put_pixel.color = internal global i32 0
@deflate_put_pixel.length = internal global i32 0
define i64 @deflate_put_pixel(i32 %0, i8 zeroext %1, i64 %2, i64 %3, i64 %4) {
%6 = alloca i64
%7 = alloca i32
%8 = alloca i8
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i32
%13 = alloca i64
%14 = alloca i64
store i32 %0, i32* %7
store i8 %1, i8* %8
store i64 %2, i64* %9
store i64 %3, i64* %10
store i64 %4, i64* %11
%15 = load i64, i64* %11
%16 = and i64 %15, 65535
store i64 %16, i64* %13
%17 = load i64, i64* %11
%18 = lshr i64 %17, 16
%19 = and i64 %18, 65535
store i64 %19, i64* %14
%20 = load i8, i8* %8
%21 = zext i8 %20 to i64
%22 = load i64, i64* %13
%23 = add i64 %22, %21
store i64 %23, i64* %13
%24 = load i64, i64* %13
%25 = load i64, i64* %14
%26 = add i64 %25, %24
store i64 %26, i64* %14
%27 = load i64, i64* %13
%28 = urem i64 %27, 65521
store i64 %28, i64* %13
%29 = load i64, i64* %14
%30 = urem i64 %29, 65521
store i64 %30, i64* %14
%31 = load i64, i64* %14
%32 = shl i64 %31, 16
%33 = load i64, i64* %13
%34 = or i64 %32, %33
store i64 %34, i64* %11
%35 = load i32, i32* %7
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %5
%38 = load i8, i8* %8
%39 = zext i8 %38 to i32
%40 = call i32 @deflate_put_literal(i32 %39)
store i32 256, i32* @deflate_put_pixel.color
store i32 0, i32* @deflate_put_pixel.length
store i64 1, i64* %6
br label %83
41: ; preds = %5
%42 = load i8, i8* %8
%43 = zext i8 %42 to i32
%44 = load i32, i32* @deflate_put_pixel.color
%45 = icmp ne i32 %43, %44
br i1 %45, label %54, label %46
46: ; preds = %41
%47 = load i32, i32* @deflate_put_pixel.length
%48 = icmp ugt i32 %47, 256
br i1 %48, label %54, label %49
49: ; preds = %46
%50 = load i64, i64* %9
%51 = load i64, i64* %10
%52 = sub i64 %51, 1
%53 = icmp eq i64 %50, %52
br i1 %53, label %54, label %78
54: ; preds = %49, %46, %41
%55 = load i32, i32* @deflate_put_pixel.length
%56 = icmp ugt i32 %55, 2
br i1 %56, label %57, label %61
57: ; preds = %54
%58 = load i32, i32* @deflate_put_pixel.length
%59 = call i32 @deflate_put_length(i32 %58)
%60 = call i32 @deflate_put_bits(i32 5, i32 0)
br label %73
61: ; preds = %54
store i32 0, i32* %12
br label %62
62: ; preds = %69, %61
%63 = load i32, i32* %12
%64 = load i32, i32* @deflate_put_pixel.length
%65 = icmp ult i32 %63, %64
br i1 %65, label %66, label %72
66: ; preds = %62
%67 = load i32, i32* @deflate_put_pixel.color
%68 = call i32 @deflate_put_literal(i32 %67)
br label %69
69: ; preds = %66
%70 = load i32, i32* %12
%71 = add nsw i32 %70, 1
store i32 %71, i32* %12
br label %62
72: ; preds = %62
br label %73
73: ; preds = %72, %57
%74 = load i8, i8* %8
%75 = zext i8 %74 to i32
store i32 %75, i32* @deflate_put_pixel.color
%76 = load i32, i32* @deflate_put_pixel.color
%77 = call i32 @deflate_put_literal(i32 %76)
store i32 0, i32* @deflate_put_pixel.length
br label %81
78: ; preds = %49
%79 = load i32, i32* @deflate_put_pixel.length
%80 = add i32 %79, 1
store i32 %80, i32* @deflate_put_pixel.length
br label %81
81: ; preds = %78, %73
%82 = load i64, i64* %11
store i64 %82, i64* %6
br label %83
83: ; preds = %81, %37
%84 = load i64, i64* %6
ret i64 %84
}

LLVM IR (-O2):
@deflate_put_pixel.color = internal unnamed_addr global i32 0
@deflate_put_pixel.length = internal unnamed_addr global i32 0
define i64 @deflate_put_pixel(i32 %0, i8 zeroext %1, i64 %2, i64 %3, i64 %4) {
%6 = and i64 %4, 65535
%7 = lshr i64 %4, 16
%8 = and i64 %7, 65535
%9 = zext i8 %1 to i64
%10 = add nuw nsw i64 %6, %9
%11 = add nuw nsw i64 %8, %10
%12 = trunc i64 %10 to i32
%13 = urem i32 %12, 65521
%14 = trunc i64 %11 to i32
%15 = urem i32 %14, 65521
%16 = shl nuw i32 %15, 16
%17 = or i32 %16, %13
%18 = icmp eq i32 %0, 0
%19 = zext i8 %1 to i32
br i1 %18, label %22, label %20
20: ; preds = %5
%21 = tail call i32 @deflate_put_literal(i32 %19)
store i32 256, i32* @deflate_put_pixel.color
br label %53
22: ; preds = %5
%23 = load i32, i32* @deflate_put_pixel.color
%24 = icmp ne i32 %23, %19
%25 = load i32, i32* @deflate_put_pixel.length
%26 = icmp ugt i32 %25, 256
%27 = select i1 %24, i1 true, i1 %26
%28 = add i64 %3, -1
%29 = icmp eq i64 %28, %2
%30 = or i1 %29, %27
br i1 %30, label %31, label %51
31: ; preds = %22
%32 = icmp ugt i32 %25, 2
br i1 %32, label %39, label %33
33: ; preds = %31
%34 = icmp eq i32 %25, 0
br i1 %34, label %49, label %35
35: ; preds = %33
%36 = tail call i32 @deflate_put_literal(i32 %23)
%37 = load i32, i32* @deflate_put_pixel.length
%38 = icmp ugt i32 %37, 1
br i1 %38, label %42, label %49
39: ; preds = %31
%40 = tail call i32 @deflate_put_length(i32 %25)
%41 = tail call i32 @deflate_put_bits(i32 5, i32 0)
br label %49
42: ; preds = %35, %42
%43 = phi i32 [ %46, %42 ], [ 1, %35 ]
%44 = load i32, i32* @deflate_put_pixel.color
%45 = tail call i32 @deflate_put_literal(i32 %44)
%46 = add nuw nsw i32 %43, 1
%47 = load i32, i32* @deflate_put_pixel.length
%48 = icmp ult i32 %46, %47
br i1 %48, label %42, label %49
49: ; preds = %42, %35, %33, %39
store i32 %19, i32* @deflate_put_pixel.color
%50 = tail call i32 @deflate_put_literal(i32 %19)
br label %53
51: ; preds = %22
%52 = add nuw nsw i32 %25, 1
br label %53
53: ; preds = %49, %51, %20
%54 = phi i32 [ 0, %20 ], [ %52, %51 ], [ 0, %49 ]
%55 = phi i32 [ 1, %20 ], [ %17, %51 ], [ %17, %49 ]
%56 = zext i32 %55 to i64
store i32 %54, i32* @deflate_put_pixel.length
ret i64 %56
}