#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;
int /*<<< orphan*/ eprintf(char *, char const *);
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
size_t 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)) > 0) {
    if (fwrite(buf, 1, n, fp2) != n)
      eprintf("%s: write error:", s2);
    if (feof(fp1))
      break;
  }
  if (ferror(fp1))
    eprintf("%s: read error:", s1);
}


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    0x2e71(%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
jbe    120b <concat+0xbb>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1070 <fwrite@plt>
cmp    -0x38(%rbp),%rax
je     11ee <concat+0x9e>
mov    -0x20(%rbp),%rsi
lea    0xe17(%rip),%rdi
call   1060 <eprintf@plt>
mov    -0x8(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%rax
je     1206 <concat+0xb6>
jmp    120b <concat+0xbb>
jmp    1198 <concat+0x48>
mov    -0x8(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     122e <concat+0xde>
mov    -0x10(%rbp),%rsi
lea    0xde8(%rip),%rdi
call   1060 <eprintf@plt>
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   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,-0x38(%rbp)
mov    %rdx,%r12
mov    %rsi,-0x30(%rbp)
mov    %rdi,%rbx
mov    0x2e6a(%rip),%rax
mov    (%rax),%r13d
mov    %rsp,%r14
mov    %r13,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
jmp    119d <concat+0x4d>
nop
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %rax,%rax
jne    11e2 <concat+0x92>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %r13d,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
test   %rax,%rax
je     11e2 <concat+0x92>
mov    %rax,%r15
mov    %r14,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
mov    %r12,%rcx
call   1070 <fwrite@plt>
cmp    %r15,%rax
je     1190 <concat+0x40>
lea    0xe29(%rip),%rdi
mov    -0x38(%rbp),%rsi
call   1060 <eprintf@plt>
jmp    1190 <concat+0x40>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     120d <concat+0xbd>
lea    0xe1b(%rip),%rdi
mov    -0x30(%rbp),%rsi
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <eprintf@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [17 x i8] c"%s: write error:\00"
@.str.1 = [16 x i8] c"%s: read error:\00"
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 = %35, %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 ugt i64 %19, 0
br i1 %20, label %21, label %36
21: ; preds = %16
%22 = load i64, i64* %11
%23 = load i32*, i32** %7
%24 = call i64 @fwrite(i8* %15, i32 1, i64 %22, i32* %23)
%25 = load i64, i64* %11
%26 = icmp ne i64 %24, %25
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = load i8*, i8** %8
%29 = call i32 @eprintf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %27, %21
%31 = load i32*, i32** %5
%32 = call i64 @feof(i32* %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %30
br label %36
35: ; preds = %30
br label %16
36: ; preds = %34, %16
%37 = load i32*, i32** %5
%38 = call i64 @ferror(i32* %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = load i8*, i8** %6
%42 = call i32 @eprintf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %41)
br label %43
43: ; preds = %40, %36
%44 = load i8*, i8** %9
ret void
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [17 x i8] c"%s: write error:\00"
@.str.1 = [16 x i8] c"%s: read error:\00"
define void @concat(i32* nocapture %0, i8* %1, i32* nocapture %2, i8* %3) {
%5 = load i32, i32* @BUFSIZ
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
br label %8
8: ; preds = %16, %4
%9 = call i64 @fread(i8* %7, i32 1, i32 %5, i32* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %19, label %11
11: ; preds = %8
%12 = call i64 @fwrite(i8* %7, i32 1, i64 %9, i32* %2)
%13 = icmp eq i64 %12, %9
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = tail call i32 @eprintf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %16
16: ; preds = %14, %11
%17 = tail call i64 @feof(i32* %0)
%18 = icmp eq i64 %17, 0
br i1 %18, label %8, label %19
19: ; preds = %16, %8
%20 = tail call i64 @ferror(i32* %0)
%21 = icmp eq i64 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = tail call i32 @eprintf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %24
24: ; preds = %22, %19
ret void
}