#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*/ free(char *);
int /*<<< orphan*/ kpgetdim(char *, long, long *, long *);
scalar_t__ kprender(char *, long, long, long, long, long, int /*<<< orphan*/,
                    int /*<<< orphan*/);
int /*<<< orphan*/ kzclose();
long kzfilelength();
int /*<<< orphan*/ kzopen(char const *);
int /*<<< orphan*/ kzread(char *, long);
scalar_t__ malloc(long);
void kpzload(const char *filnam, long *pic, long *bpl, long *xsiz, long *ysiz) {
  char *buf;
  long leng;
  (*pic) = 0;
  if (!kzopen(filnam))
    return;
  leng = kzfilelength();
  buf = (char *)malloc(leng);
  if (!buf)
    return;
  kzread(buf, leng);
  kzclose();
  kpgetdim(buf, leng, xsiz, ysiz);
  (*bpl) = ((*xsiz) << 2);
  (*pic) = (long)malloc((*ysiz) * (*bpl));
  if (!(*pic)) {
    free(buf);
    return;
  }
  if (kprender(buf, leng, *pic, *bpl, *xsiz, *ysiz, 0, 0) < 0) {
    free(buf);
    free((void *)*pic);
    (*pic) = 0;
    return;
  }
  free(buf);
}


x86 assembly (clang, -O0):
<kpzload>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1040 <kzopen@plt>
cmp    $0x0,%eax
jne    11be <kpzload+0x3e>
jmp    12cd <kpzload+0x14d>
mov    $0x0,%al
call   1090 <kzfilelength@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11e6 <kpzload+0x66>
jmp    12cd <kpzload+0x14d>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1060 <kzread@plt>
mov    $0x0,%al
call   1050 <kzclose@plt>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1070 <kpgetdim@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
shl    $0x2,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rax
imul   (%rax),%rdi
call   1080 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    125b <kpzload+0xdb>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    12cd <kpzload+0x14d>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
mov    -0x20(%rbp),%rax
mov    (%rax),%r8
mov    -0x28(%rbp),%rax
mov    (%rax),%r9
xor    %eax,%eax
movl   $0x0,(%rsp)
movl   $0x0,0x8(%rsp)
call   10a0 <kprender@plt>
cmp    $0x0,%rax
jge    12c4 <kpzload+0x144>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
jmp    12cd <kpzload+0x14d>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kpzload>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r13
mov    %rdx,%r12
mov    %rsi,%r15
movq   $0x0,(%rsi)
call   1040 <kzopen@plt>
test   %eax,%eax
je     1249 <kpzload+0xc9>
xor    %eax,%eax
call   1090 <kzfilelength@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1080 <malloc@plt>
test   %rax,%rax
je     1249 <kpzload+0xc9>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
call   1060 <kzread@plt>
xor    %eax,%eax
call   1050 <kzclose@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r13,%rdx
mov    %r14,%rcx
call   1070 <kpgetdim@plt>
mov    0x0(%r13),%rdi
shl    $0x2,%rdi
mov    %rdi,(%r12)
imul   (%r14),%rdi
call   1080 <malloc@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     1258 <kpzload+0xd8>
mov    (%r12),%rcx
mov    0x0(%r13),%r8
mov    (%r14),%r9
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %rax,%rdx
push   $0x0
push   $0x0
call   10a0 <kprender@plt>
add    $0x10,%rsp
mov    %rax,%rbp
mov    %rbx,%rdi
call   1030 <free@plt>
test   %rbp,%rbp
jns    1249 <kpzload+0xc9>
mov    (%r15),%rdi
call   1030 <free@plt>
movq   $0x0,(%r15)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @kpzload(i8* %0, i64* %1, i64* %2, i64* %3, i64* %4) {
%6 = alloca i8*
%7 = alloca i64*
%8 = alloca i64*
%9 = alloca i64*
%10 = alloca i64*
%11 = alloca i8*
%12 = alloca i64
store i8* %0, i8** %6
store i64* %1, i64** %7
store i64* %2, i64** %8
store i64* %3, i64** %9
store i64* %4, i64** %10
%13 = load i64*, i64** %7
store i64 0, i64* %13
%14 = load i8*, i8** %6
%15 = call i32 @kzopen(i8* %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %5
br label %77
18: ; preds = %5
%19 = call i64 (...) @kzfilelength()
store i64 %19, i64* %12
%20 = load i64, i64* %12
%21 = call i64 @malloc(i64 %20)
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %11
%23 = load i8*, i8** %11
%24 = icmp ne i8* %23, null
br i1 %24, label %26, label %25
25: ; preds = %18
br label %77
26: ; preds = %18
%27 = load i8*, i8** %11
%28 = load i64, i64* %12
%29 = call i32 @kzread(i8* %27, i64 %28)
%30 = call i32 (...) @kzclose()
%31 = load i8*, i8** %11
%32 = load i64, i64* %12
%33 = load i64*, i64** %9
%34 = load i64*, i64** %10
%35 = call i32 @kpgetdim(i8* %31, i64 %32, i64* %33, i64* %34)
%36 = load i64*, i64** %9
%37 = load i64, i64* %36
%38 = shl i64 %37, 2
%39 = load i64*, i64** %8
store i64 %38, i64* %39
%40 = load i64*, i64** %10
%41 = load i64, i64* %40
%42 = load i64*, i64** %8
%43 = load i64, i64* %42
%44 = mul nsw i64 %41, %43
%45 = call i64 @malloc(i64 %44)
%46 = load i64*, i64** %7
store i64 %45, i64* %46
%47 = load i64*, i64** %7
%48 = load i64, i64* %47
%49 = icmp ne i64 %48, 0
br i1 %49, label %53, label %50
50: ; preds = %26
%51 = load i8*, i8** %11
%52 = call i32 @free(i8* %51)
br label %77
53: ; preds = %26
%54 = load i8*, i8** %11
%55 = load i64, i64* %12
%56 = load i64*, i64** %7
%57 = load i64, i64* %56
%58 = load i64*, i64** %8
%59 = load i64, i64* %58
%60 = load i64*, i64** %9
%61 = load i64, i64* %60
%62 = load i64*, i64** %10
%63 = load i64, i64* %62
%64 = call i64 @kprender(i8* %54, i64 %55, i64 %57, i64 %59, i64 %61, i64 %63, i32 0, i32 0)
%65 = icmp slt i64 %64, 0
br i1 %65, label %66, label %74
66: ; preds = %53
%67 = load i8*, i8** %11
%68 = call i32 @free(i8* %67)
%69 = load i64*, i64** %7
%70 = load i64, i64* %69
%71 = inttoptr i64 %70 to i8*
%72 = call i32 @free(i8* %71)
%73 = load i64*, i64** %7
store i64 0, i64* %73
br label %77
74: ; preds = %53
%75 = load i8*, i8** %11
%76 = call i32 @free(i8* %75)
br label %77
77: ; preds = %74, %66, %50, %25, %17
ret void
}

LLVM IR (-O2):
define void @kpzload(i8* %0, i64* nocapture %1, i64* nocapture %2, i64* %3, i64* %4) {
store i64 0, i64* %1
%6 = tail call i32 @kzopen(i8* %0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %36, label %8
8: ; preds = %5
%9 = tail call i64 (...) @kzfilelength()
%10 = tail call i64 @malloc(i64 %9)
%11 = inttoptr i64 %10 to i8*
%12 = icmp eq i64 %10, 0
br i1 %12, label %36, label %13
13: ; preds = %8
%14 = tail call i32 @kzread(i8* %11, i64 %9)
%15 = tail call i32 (...) @kzclose()
%16 = tail call i32 @kpgetdim(i8* %11, i64 %9, i64* %3, i64* %4)
%17 = load i64, i64* %3
%18 = shl i64 %17, 2
store i64 %18, i64* %2
%19 = load i64, i64* %4
%20 = mul nsw i64 %19, %18
%21 = tail call i64 @malloc(i64 %20)
store i64 %21, i64* %1
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %13
%24 = tail call i32 @free(i8* %11)
br label %36
25: ; preds = %13
%26 = load i64, i64* %2
%27 = load i64, i64* %3
%28 = load i64, i64* %4
%29 = tail call i64 @kprender(i8* %11, i64 %9, i64 %21, i64 %26, i64 %27, i64 %28, i32 0, i32 0)
%30 = icmp slt i64 %29, 0
%31 = tail call i32 @free(i8* %11)
br i1 %30, label %32, label %36
32: ; preds = %25
%33 = load i64, i64* %1
%34 = inttoptr i64 %33 to i8*
%35 = tail call i32 @free(i8* %34)
store i64 0, i64* %1
br label %36
36: ; preds = %25, %8, %5, %32, %23
ret void
}