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

/* Variables and functions */
int BUFSIZ;
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, size_t, int /*<<< orphan*/ *);
void concat(FILE *fp1, const char *s1, FILE *fp2, const char *s2) {
  char buf[BUFSIZ];
  size_t n;
  while ((n = fread(buf, 1, sizeof(buf), fp1))) {
    fwrite(buf, 1, n, fp2);
    if (feof(fp1) || ferror(fp1) || ferror(fp2))
      break;
  }
}


x86 assembly (clang, -O0):
<concat>:
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    0x2e81(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x48(%rbp)
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    -0x48(%rbp),%rax
mov    %eax,%edx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     1207 <concat+0xc7>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fwrite@plt>
mov    -0x8(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%rax
jne    11fd <concat+0xbd>
mov    -0x8(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
jne    11fd <concat+0xbd>
mov    -0x18(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1202 <concat+0xc2>
jmp    1207 <concat+0xc7>
jmp    1188 <concat+0x48>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<concat>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rdi,%rbx
mov    0x2e88(%rip),%rax
mov    (%rax),%r15d
mov    %rsp,%r12
mov    %r15,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
nop
mov    %r12,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
test   %rax,%rax
je     11c2 <concat+0x82>
mov    %r12,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
mov    %r14,%rcx
call   1060 <fwrite@plt>
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %rax,%rax
jne    11c2 <concat+0x82>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    11c2 <concat+0x82>
mov    %r14,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     1170 <concat+0x30>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
define void @concat(i32* %0, i8* %1, i32* %2, i8* %3) {
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
store i8* %3, i8** %8
%12 = load i32, i32* @BUFSIZ
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %9
%15 = alloca i8, i64 %13
store i64 %13, i64* %10
br label %16
16: ; preds = %37, %4
%17 = trunc i64 %13 to i32
%18 = load i32*, i32** %5
%19 = call i64 @fread(i8* %15, i32 1, i32 %17, i32* %18)
store i64 %19, i64* %11
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %38
21: ; preds = %16
%22 = load i64, i64* %11
%23 = load i32*, i32** %7
%24 = call i32 @fwrite(i8* %15, i32 1, i64 %22, i32* %23)
%25 = load i32*, i32** %5
%26 = call i64 @feof(i32* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %36, label %28
28: ; preds = %21
%29 = load i32*, i32** %5
%30 = call i64 @ferror(i32* %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %36, label %32
32: ; preds = %28
%33 = load i32*, i32** %7
%34 = call i64 @ferror(i32* %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %32, %28, %21
br label %38
37: ; preds = %32
br label %16
38: ; preds = %36, %16
%39 = load i8*, i8** %9
ret void
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
define void @concat(i32* nocapture %0, i8* nocapture readnone %1, i32* nocapture %2, i8* nocapture readnone %3) {
%5 = load i32, i32* @BUFSIZ
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
br label %8
8: ; preds = %18, %4
%9 = call i64 @fread(i8* %7, i32 1, i32 %5, i32* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %21, label %11
11: ; preds = %8
%12 = call i32 @fwrite(i8* %7, i32 1, i64 %9, i32* %2)
%13 = tail call i64 @feof(i32* %0)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %11
%16 = tail call i64 @ferror(i32* %0)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = tail call i64 @ferror(i32* %2)
%20 = icmp eq i64 %19, 0
br i1 %20, label %8, label %21
21: ; preds = %11, %15, %18, %8
ret void
}