#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
unsigned long beginchunk(int /*<<< orphan*/ *, unsigned long, char *, int);
unsigned long endchunk(int /*<<< orphan*/ *, unsigned long);
unsigned long writebytecrc(int /*<<< orphan*/ *, unsigned long, unsigned int);
unsigned long write_png_palet(FILE *fp, unsigned long crc) {
  unsigned int i;
  crc = beginchunk(fp, crc, "PLTE", 256 * 3);
  for (i = 0; i < 256; i++) {
    crc = writebytecrc(fp, crc, (i & 0xc0));
    crc = writebytecrc(fp, crc, (i & 0x38) << 2);
    crc = writebytecrc(fp, crc, (i & 0x07) << 5);
  }
  crc = endchunk(fp, crc);
  return crc;
}


x86 assembly (clang, -O0):
<write_png_palet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xeb1(%rip),%rdx
mov    $0x300,%ecx
call   1030 <beginchunk@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x100,-0x14(%rbp)
jae    11cd <write_png_palet+0x9d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
and    $0xc0,%edx
call   1050 <writebytecrc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
and    $0x38,%edx
shl    $0x2,%edx
call   1050 <writebytecrc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
and    $0x7,%edx
shl    $0x5,%edx
call   1050 <writebytecrc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1164 <write_png_palet+0x34>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <endchunk@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_png_palet>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xebf(%rip),%rdx
mov    $0x300,%ecx
call   1030 <beginchunk@plt>
xor    %r15d,%r15d
xor    %ebx,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%edx
and    $0xc0,%edx
mov    %r14,%rdi
mov    %rax,%rsi
call   1050 <writebytecrc@plt>
mov    %ebx,%edx
and    $0xe0,%edx
mov    %r14,%rdi
mov    %rax,%rsi
call   1050 <writebytecrc@plt>
mov    %r15d,%edx
and    $0xe0,%edx
mov    %r14,%rdi
mov    %rax,%rsi
call   1050 <writebytecrc@plt>
add    $0x1,%ebp
add    $0x4,%ebx
add    $0x20,%r15d
cmp    $0x100,%ebp
jne    1160 <write_png_palet+0x30>
mov    %r14,%rdi
mov    %rax,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <endchunk@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"PLTE\00"
define i64 @write_png_palet(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i32
store i32* %0, i32** %3
store i64 %1, i64* %4
%6 = load i32*, i32** %3
%7 = load i64, i64* %4
%8 = call i64 @beginchunk(i32* %6, i64 %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 768)
store i64 %8, i64* %4
store i32 0, i32* %5
br label %9
9: ; preds = %30, %2
%10 = load i32, i32* %5
%11 = icmp ult i32 %10, 256
br i1 %11, label %12, label %33
12: ; preds = %9
%13 = load i32*, i32** %3
%14 = load i64, i64* %4
%15 = load i32, i32* %5
%16 = and i32 %15, 192
%17 = call i64 @writebytecrc(i32* %13, i64 %14, i32 %16)
store i64 %17, i64* %4
%18 = load i32*, i32** %3
%19 = load i64, i64* %4
%20 = load i32, i32* %5
%21 = and i32 %20, 56
%22 = shl i32 %21, 2
%23 = call i64 @writebytecrc(i32* %18, i64 %19, i32 %22)
store i64 %23, i64* %4
%24 = load i32*, i32** %3
%25 = load i64, i64* %4
%26 = load i32, i32* %5
%27 = and i32 %26, 7
%28 = shl i32 %27, 5
%29 = call i64 @writebytecrc(i32* %24, i64 %25, i32 %28)
store i64 %29, i64* %4
br label %30
30: ; preds = %12
%31 = load i32, i32* %5
%32 = add i32 %31, 1
store i32 %32, i32* %5
br label %9
33: ; preds = %9
%34 = load i32*, i32** %3
%35 = load i64, i64* %4
%36 = call i64 @endchunk(i32* %34, i64 %35)
store i64 %36, i64* %4
%37 = load i64, i64* %4
ret i64 %37
}

LLVM IR (-O2):
@.str = [5 x i8] c"PLTE\00"
define i64 @write_png_palet(i32* %0, i64 %1) {
%3 = tail call i64 @beginchunk(i32* %0, i64 %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 768)
br label %4
4: ; preds = %2, %4
%5 = phi i32 [ 0, %2 ], [ %15, %4 ]
%6 = phi i64 [ %3, %2 ], [ %14, %4 ]
%7 = and i32 %5, 192
%8 = tail call i64 @writebytecrc(i32* %0, i64 %6, i32 %7)
%9 = shl nuw nsw i32 %5, 2
%10 = and i32 %9, 224
%11 = tail call i64 @writebytecrc(i32* %0, i64 %8, i32 %10)
%12 = shl nuw nsw i32 %5, 5
%13 = and i32 %12, 224
%14 = tail call i64 @writebytecrc(i32* %0, i64 %11, i32 %13)
%15 = add nuw nsw i32 %5, 1
%16 = icmp eq i32 %15, 256
br i1 %16, label %17, label %4
17: ; preds = %4
%18 = tail call i64 @endchunk(i32* %0, i64 %14)
ret i64 %18
}