#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);
int /*<<< orphan*/ fwrite(unsigned char *, int, unsigned long,
                          int /*<<< orphan*/ *);
unsigned long update_crc(unsigned char *, unsigned long, unsigned long);
unsigned long writelongcrc(int /*<<< orphan*/ *, unsigned long, unsigned long);
unsigned long writewordcrc(int /*<<< orphan*/ *, unsigned long, int);
unsigned long write_png_data(FILE *fp, unsigned long crc,
                             unsigned long adler_crc, unsigned char *data,
                             unsigned long len) {
  crc = beginchunk(fp, crc, "IDAT", 2 + len + 4);
  crc = writewordcrc(fp, crc, ((0x0800 + 30) / 31) * 31);
  fwrite(data, 1, len, fp);
  crc = update_crc(data, len, crc);
  crc = writelongcrc(fp, crc, adler_crc);
  crc = endchunk(fp, crc);
  return crc;
}


x86 assembly (clang, -O0):
<write_png_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rax
add    $0x2,%rax
add    $0x4,%rax
mov    %eax,%ecx
lea    0xe67(%rip),%rdx
call   1030 <beginchunk@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x81d,%edx
call   1040 <writewordcrc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1070 <fwrite@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1060 <update_crc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1080 <writelongcrc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <endchunk@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_png_data>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,%r14
mov    %rdi,%rbx
lea    0x6(%r8),%ecx
lea    0xe80(%rip),%rdx
call   1030 <beginchunk@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
mov    $0x81d,%edx
call   1040 <writewordcrc@plt>
mov    %rax,%r13
mov    %r12,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1060 <update_crc@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %r14,%rdx
call   1080 <writelongcrc@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1050 <endchunk@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"IDAT\00"
define i64 @write_png_data(i32* %0, i64 %1, i64 %2, i8* %3, i64 %4) {
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i64
store i32* %0, i32** %6
store i64 %1, i64* %7
store i64 %2, i64* %8
store i8* %3, i8** %9
store i64 %4, i64* %10
%11 = load i32*, i32** %6
%12 = load i64, i64* %7
%13 = load i64, i64* %10
%14 = add i64 2, %13
%15 = add i64 %14, 4
%16 = trunc i64 %15 to i32
%17 = call i64 @beginchunk(i32* %11, i64 %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %16)
store i64 %17, i64* %7
%18 = load i32*, i32** %6
%19 = load i64, i64* %7
%20 = call i64 @writewordcrc(i32* %18, i64 %19, i32 2077)
store i64 %20, i64* %7
%21 = load i8*, i8** %9
%22 = load i64, i64* %10
%23 = load i32*, i32** %6
%24 = call i32 @fwrite(i8* %21, i32 1, i64 %22, i32* %23)
%25 = load i8*, i8** %9
%26 = load i64, i64* %10
%27 = load i64, i64* %7
%28 = call i64 @update_crc(i8* %25, i64 %26, i64 %27)
store i64 %28, i64* %7
%29 = load i32*, i32** %6
%30 = load i64, i64* %7
%31 = load i64, i64* %8
%32 = call i64 @writelongcrc(i32* %29, i64 %30, i64 %31)
store i64 %32, i64* %7
%33 = load i32*, i32** %6
%34 = load i64, i64* %7
%35 = call i64 @endchunk(i32* %33, i64 %34)
store i64 %35, i64* %7
%36 = load i64, i64* %7
ret i64 %36
}

LLVM IR (-O2):
@.str = [5 x i8] c"IDAT\00"
define i64 @write_png_data(i32* %0, i64 %1, i64 %2, i8* %3, i64 %4) {
%6 = trunc i64 %4 to i32
%7 = add i32 %6, 6
%8 = tail call i64 @beginchunk(i32* %0, i64 %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = tail call i64 @writewordcrc(i32* %0, i64 %8, i32 2077)
%10 = tail call i32 @fwrite(i8* %3, i32 1, i64 %4, i32* %0)
%11 = tail call i64 @update_crc(i8* %3, i64 %4, i64 %9)
%12 = tail call i64 @writelongcrc(i32* %0, i64 %11, i64 %2)
%13 = tail call i64 @endchunk(i32* %0, i64 %12)
ret i64 %13
}