#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, int);
unsigned long writelongcrc(int /*<<< orphan*/ *, unsigned long, unsigned long);
unsigned long write_png_header(FILE *fp, unsigned long w, unsigned long h) {
  unsigned long crc;
  crc = 0;
  crc = beginchunk(fp, crc, "IHDR", 0x0d);
  crc = writelongcrc(fp, crc, w);
  crc = writelongcrc(fp, crc, h);
  crc = writebytecrc(fp, crc, 8);
  crc = writebytecrc(fp, crc, 3);
  crc = writebytecrc(fp, crc, 0);
  crc = writebytecrc(fp, crc, 0);
  crc = writebytecrc(fp, crc, 0);
  crc = endchunk(fp, crc);
  return crc;
}


x86 assembly (clang, -O0):
<write_png_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    0xe95(%rip),%rdx
mov    $0xd,%ecx
call   1030 <beginchunk@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1060 <writelongcrc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1060 <writelongcrc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1050 <writebytecrc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x3,%edx
call   1050 <writebytecrc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1050 <writebytecrc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1050 <writebytecrc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1050 <writebytecrc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <endchunk@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_png_header>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xeab(%rip),%rdx
xor    %esi,%esi
mov    $0xd,%ecx
call   1030 <beginchunk@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %r15,%rdx
call   1060 <writelongcrc@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %r14,%rdx
call   1060 <writelongcrc@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
mov    $0x8,%edx
call   1050 <writebytecrc@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
mov    $0x3,%edx
call   1050 <writebytecrc@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
xor    %edx,%edx
call   1050 <writebytecrc@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
xor    %edx,%edx
call   1050 <writebytecrc@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
xor    %edx,%edx
call   1050 <writebytecrc@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <endchunk@plt>

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

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