#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 BUFSIZ;
int fread(char *, int, int, int /*<<< orphan*/ *);
int fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int cat(char *regs, FILE *in, FILE *out) {
  char buf[BUFSIZ];
  int nread;
  while ((nread = fread(buf, 1, BUFSIZ, in)) > 0) {
    if (fwrite(buf, 1, nread, out) != nread) {
      perror("fwrite");
      return (-1);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<cat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    0x2e95(%rip),%rax
mov    (%rax),%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)
mov    -0x40(%rbp),%rdi
mov    0x2e65(%rip),%rax
mov    (%rax),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jle    11d9 <cat+0xa9>
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fwrite@plt>
cmp    -0x34(%rbp),%eax
je     11d4 <cat+0xa4>
lea    0xe44(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x38(%rbp)
jmp    11e7 <cat+0xb7>
jmp    1170 <cat+0x40>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
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    %rdx,%r14
mov    %rsi,%r15
mov    0x2e95(%rip),%r12
mov    (%r12),%edx
mov    %rsp,%r13
mov    %rdx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    %r13,%rdi
mov    $0x1,%esi
mov    %r15,%rcx
call   1030 <fread@plt>
mov    %eax,%ebx
xor    %eax,%eax
test   %ebx,%ebx
jle    11b2 <cat+0x82>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    $0x1,%esi
mov    %ebx,%edx
mov    %r14,%rcx
call   1050 <fwrite@plt>
cmp    %ebx,%eax
jne    11c1 <cat+0x91>
mov    (%r12),%edx
mov    %r13,%rdi
mov    $0x1,%esi
mov    %r15,%rcx
call   1030 <fread@plt>
mov    %eax,%ebx
test   %eax,%eax
jg     1180 <cat+0x50>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe38(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%eax
jmp    11b2 <cat+0x82>

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [7 x i8] c"fwrite\00"
define i32 @cat(i8* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%12 = load i32, i32* @BUFSIZ
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %8
%15 = alloca i8, i64 %13
store i64 %13, i64* %9
br label %16
16: ; preds = %29, %3
%17 = load i32, i32* @BUFSIZ
%18 = load i32*, i32** %6
%19 = call i32 @fread(i8* %15, i32 1, i32 %17, i32* %18)
store i32 %19, i32* %10
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %30
21: ; preds = %16
%22 = load i32, i32* %10
%23 = load i32*, i32** %7
%24 = call i32 @fwrite(i8* %15, i32 1, i32 %22, i32* %23)
%25 = load i32, i32* %10
%26 = icmp ne i32 %24, %25
br i1 %26, label %27, label %29
27: ; preds = %21
%28 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
store i32 1, i32* %11
br label %31
29: ; preds = %21
br label %16
30: ; preds = %16
store i32 0, i32* %4
store i32 1, i32* %11
br label %31
31: ; preds = %30, %27
%32 = load i8*, i8** %8
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [7 x i8] c"fwrite\00"
define i32 @cat(i8* nocapture readnone %0, i32* nocapture %1, i32* nocapture %2) {
%4 = load i32, i32* @BUFSIZ
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = call i32 @fread(i8* %6, i32 1, i32 %4, i32* %1)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %19
9: ; preds = %3, %13
%10 = phi i32 [ %15, %13 ], [ %7, %3 ]
%11 = call i32 @fwrite(i8* %6, i32 1, i32 %10, i32* %2)
%12 = icmp eq i32 %11, %10
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = load i32, i32* @BUFSIZ
%15 = call i32 @fread(i8* %6, i32 1, i32 %14, i32* %1)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %9, label %19
17: ; preds = %9
%18 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %13, %3, %17
%20 = phi i32 [ -1, %17 ], [ 0, %3 ], [ 0, %13 ]
ret i32 %20
}