#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 */
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fread(char *, int, unsigned int, int /*<<< orphan*/ *);
scalar_t__ fwrite(char *, int, unsigned int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int cat(FILE *in, FILE *out, unsigned size, unsigned buff_size) {
  unsigned bytes_left = size;
  char buf[buff_size];
  int ret = 0;
  while (bytes_left) {
    fread(buf, sizeof(char), buff_size, in);
    if (!feof(in)) {
      bytes_left -= fwrite(buf, sizeof(char), buff_size, out);
    } else
      bytes_left = 0;
  }
  ret = ferror(in) | ferror(out);
  if (ret)
    fprintf(stderr, "ERROR: Occured during file concatenation\n");
  return ret;
}


x86 assembly (clang, -O0):
<cat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11fc <cat+0xac>
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%edx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x8(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
jne    11f0 <cat+0xa0>
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1070 <fwrite@plt>
mov    %rax,%rcx
mov    -0x1c(%rbp),%eax
sub    %rcx,%rax
mov    %eax,-0x1c(%rbp)
jmp    11f7 <cat+0xa7>
movl   $0x0,-0x1c(%rbp)
jmp    1199 <cat+0x49>
mov    -0x8(%rbp),%rdi
call   1030 <ferror@plt>
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
or     %ecx,%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     123a <cat+0xea>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
lea    0xdcb(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x34(%rbp),%eax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cat>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
mov    %ecx,%eax
mov    %rsp,%r13
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
test   %edx,%edx
je     11b6 <cat+0x66>
mov    %ecx,%r15d
mov    %edx,%ebx
mov    %r13,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
mov    %r12,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    11b6 <cat+0x66>
mov    %r13,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %r14,%rcx
call   1070 <fwrite@plt>
sub    %eax,%ebx
jne    1180 <cat+0x30>
mov    %r12,%rdi
call   1030 <ferror@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1030 <ferror@plt>
mov    %eax,%ebx
or     %r15d,%ebx
je     11e5 <cat+0x95>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
call   1050 <fprintf@plt>
mov    %ebx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [42 x i8] c"ERROR: Occured during file concatenation\0A\00"
define i32 @cat(i32* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%13 = load i32, i32* %7
store i32 %13, i32* %9
%14 = load i32, i32* %8
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %10
%17 = alloca i8, i64 %15
store i64 %15, i64* %11
store i32 0, i32* %12
br label %18
18: ; preds = %37, %4
%19 = load i32, i32* %9
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %38
21: ; preds = %18
%22 = load i32, i32* %8
%23 = load i32*, i32** %5
%24 = call i32 @fread(i8* %17, i32 1, i32 %22, i32* %23)
%25 = load i32*, i32** %5
%26 = call i32 @feof(i32* %25)
%27 = icmp ne i32 %26, 0
br i1 %27, label %36, label %28
28: ; preds = %21
%29 = load i32, i32* %8
%30 = load i32*, i32** %6
%31 = call i64 @fwrite(i8* %17, i32 1, i32 %29, i32* %30)
%32 = load i32, i32* %9
%33 = zext i32 %32 to i64
%34 = sub nsw i64 %33, %31
%35 = trunc i64 %34 to i32
store i32 %35, i32* %9
br label %37
36: ; preds = %21
store i32 0, i32* %9
br label %37
37: ; preds = %36, %28
br label %18
38: ; preds = %18
%39 = load i32*, i32** %5
%40 = call i32 @ferror(i32* %39)
%41 = load i32*, i32** %6
%42 = call i32 @ferror(i32* %41)
%43 = or i32 %40, %42
store i32 %43, i32* %12
%44 = load i32, i32* %12
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %38
%47 = load i32, i32* @stderr
%48 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
br label %49
49: ; preds = %46, %38
%50 = load i32, i32* %12
%51 = load i8*, i8** %10
ret i32 %50
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [42 x i8] c"ERROR: Occured during file concatenation\0A\00"
define i32 @cat(i32* nocapture %0, i32* nocapture %1, i32 %2, i32 %3) {
%5 = zext i32 %3 to i64
%6 = alloca i8, i64 %5
%7 = icmp eq i32 %2, 0
br i1 %7, label %18, label %8
8: ; preds = %4, %13
%9 = phi i32 [ %16, %13 ], [ %2, %4 ]
%10 = call i32 @fread(i8* %6, i32 1, i32 %3, i32* %0)
%11 = tail call i32 @feof(i32* %0)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %8
%14 = call i64 @fwrite(i8* %6, i32 1, i32 %3, i32* %1)
%15 = trunc i64 %14 to i32
%16 = sub i32 %9, %15
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %8
18: ; preds = %8, %13, %4
%19 = tail call i32 @ferror(i32* %0)
%20 = tail call i32 @ferror(i32* %1)
%21 = or i32 %20, %19
%22 = icmp eq i32 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %18
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %23, %18
ret i32 %21
}