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

/* Variables and functions */
int /*<<< orphan*/ direct_copy(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                               unsigned int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
size_t fread(unsigned int *, int, int, int /*<<< orphan*/ *);
unsigned int ntohl(unsigned int);
int /*<<< orphan*/ stderr;
void unchunk_copy(FILE *in, FILE *out) {
  unsigned int chunk_size;
  do {
    size_t items_read = fread(&chunk_size, sizeof(chunk_size), 1, in);
    if (items_read < 1) {
      fprintf(stderr, "Error while reading chunk size.");
      break;
    }
    chunk_size = ntohl(chunk_size);
    direct_copy(in, out, chunk_size);
  } while (chunk_size > 0);
}


x86 assembly (clang, -O0):
<unchunk_copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rcx
lea    -0x14(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x1,-0x20(%rbp)
jae    1190 <unchunk_copy+0x50>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
lea    0xe7a(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11b5 <unchunk_copy+0x75>
mov    -0x14(%rbp),%edi
call   1060 <ntohl@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <direct_copy@plt>
cmpl   $0x0,-0x14(%rbp)
ja     1150 <unchunk_copy+0x10>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unchunk_copy>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x4(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
test   %rax,%rax
je     11a5 <unchunk_copy+0x65>
mov    0x4(%rsp),%edi
call   1060 <ntohl@plt>
mov    %eax,%ebp
mov    %eax,0x4(%rsp)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <direct_copy@plt>
test   %ebp,%ebp
jne    1160 <unchunk_copy+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fprintf@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c"Error while reading chunk size.\00"
define void @unchunk_copy(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i64
store i32* %0, i32** %3
store i32* %1, i32** %4
br label %7
7: ; preds = %22, %2
%8 = load i32*, i32** %3
%9 = call i64 @fread(i32* %5, i32 4, i32 1, i32* %8)
store i64 %9, i64* %6
%10 = load i64, i64* %6
%11 = icmp ult i64 %10, 1
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %25
15: ; preds = %7
%16 = load i32, i32* %5
%17 = call i32 @ntohl(i32 %16)
store i32 %17, i32* %5
%18 = load i32*, i32** %3
%19 = load i32*, i32** %4
%20 = load i32, i32* %5
%21 = call i32 @direct_copy(i32* %18, i32* %19, i32 %20)
br label %22
22: ; preds = %15
%23 = load i32, i32* %5
%24 = icmp ugt i32 %23, 0
br i1 %24, label %7, label %25
25: ; preds = %22, %12
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"Error while reading chunk size.\00"
define void @unchunk_copy(i32* %0, i32* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
br label %5
5: ; preds = %11, %2
%6 = call i64 @fread(i32* %3, i32 4, i32 1, i32* %0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %16
11: ; preds = %5
%12 = load i32, i32* %3
%13 = tail call i32 @ntohl(i32 %12)
store i32 %13, i32* %3
%14 = tail call i32 @direct_copy(i32* %0, i32* %1, i32 %13)
%15 = icmp eq i32 %13, 0
br i1 %15, label %16, label %5
16: ; preds = %11, %8
ret void
}