#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*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int rmin(int, int);
void copy_input_output(char *buffer, int buf_len, FILE *inputf, FILE *outputf,
                       int copy_len) {
  int copies, i, read_chars, toberead;
  copies = (copy_len / (buf_len - 1)) + 1;
  for (i = 0; i < copies; i++) {
    toberead = rmin(copy_len, buf_len - 1);
    read_chars = fread(buffer, sizeof(char), toberead + 1, inputf);
    buffer[read_chars] = '\0';
    fprintf(outputf, "%s", buffer);
    copy_len -= toberead;
  }
}


x86 assembly (clang, -O0):
<copy_input_output>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    11d5 <copy_input_output+0xa5>
mov    -0x24(%rbp),%edi
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
call   1050 <rmin@plt>
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x34(%rbp),%edx
add    $0x1,%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe49(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x34(%rbp),%ecx
mov    -0x24(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1164 <copy_input_output+0x34>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_input_output>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,(%rsp)
mov    %rdx,%r15
mov    %esi,%r12d
add    $0xffffffff,%r12d
mov    %r8d,%eax
cltd
idiv   %r12d
test   %eax,%eax
js     119d <copy_input_output+0x6d>
mov    %r8d,%ebx
mov    %rdi,%r13
mov    %eax,%ebp
add    $0x1,%ebp
nop
mov    %ebx,%edi
mov    %r12d,%esi
call   1050 <rmin@plt>
mov    %eax,%r14d
lea    0x1(%r14),%edx
mov    %r13,%rdi
mov    $0x1,%esi
mov    %r15,%rcx
call   1030 <fread@plt>
cltq
movb   $0x0,0x0(%r13,%rax,1)
mov    %r13,%rdi
mov    (%rsp),%rsi
call   1040 <fputs@plt>
sub    %r14d,%ebx
add    $0xffffffff,%ebp
jne    1160 <copy_input_output+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
define void @copy_input_output(i8* %0, i32 %1, i32* %2, i32* %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store i32 %4, i32* %10
%15 = load i32, i32* %10
%16 = load i32, i32* %7
%17 = sub nsw i32 %16, 1
%18 = sdiv i32 %15, %17
%19 = add nsw i32 %18, 1
store i32 %19, i32* %11
store i32 0, i32* %12
br label %20
20: ; preds = %44, %5
%21 = load i32, i32* %12
%22 = load i32, i32* %11
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %47
24: ; preds = %20
%25 = load i32, i32* %10
%26 = load i32, i32* %7
%27 = sub nsw i32 %26, 1
%28 = call i32 @rmin(i32 %25, i32 %27)
store i32 %28, i32* %14
%29 = load i8*, i8** %6
%30 = load i32, i32* %14
%31 = add nsw i32 %30, 1
%32 = load i32*, i32** %8
%33 = call i32 @fread(i8* %29, i32 1, i32 %31, i32* %32)
store i32 %33, i32* %13
%34 = load i8*, i8** %6
%35 = load i32, i32* %13
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8 0, i8* %37
%38 = load i32*, i32** %9
%39 = load i8*, i8** %6
%40 = call i32 @fprintf(i32* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %39)
%41 = load i32, i32* %14
%42 = load i32, i32* %10
%43 = sub nsw i32 %42, %41
store i32 %43, i32* %10
br label %44
44: ; preds = %24
%45 = load i32, i32* %12
%46 = add nsw i32 %45, 1
store i32 %46, i32* %12
br label %20
47: ; preds = %20
ret void
}

LLVM IR (-O2):
define void @copy_input_output(i8* nocapture %0, i32 %1, i32* nocapture %2, i32* nocapture %3, i32 %4) {
%6 = add nsw i32 %1, -1
%7 = sdiv i32 %4, %6
%8 = icmp slt i32 %7, 0
br i1 %8, label %21, label %9
9: ; preds = %5, %9
%10 = phi i32 [ %18, %9 ], [ %4, %5 ]
%11 = phi i32 [ %19, %9 ], [ 0, %5 ]
%12 = tail call i32 @rmin(i32 %10, i32 %6)
%13 = add nsw i32 %12, 1
%14 = tail call i32 @fread(i8* %0, i32 1, i32 %13, i32* %2)
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %0, i64 %15
store i8 0, i8* %16
%17 = tail call i32 @fputs(i8* %0, i32* %3)
%18 = sub nsw i32 %10, %12
%19 = add nuw i32 %11, 1
%20 = icmp eq i32 %11, %7
br i1 %20, label %21, label %9
21: ; preds = %9, %5
ret void
}