#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};
typedef int ssize_t;

/* Variables and functions */
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ewe(char *, ...);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int, ...);
int read(int, char *, int);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ write(int, char *, int);
void mass_copy_file(char **output, char *input, int n) {
  char buf[8192];
  int i;
  struct stat results;
  int in_fd = open(input, O_RDONLY);
  if (in_fd == -1) {
    ewe("File %s can not be opened\n", input);
  }
  stat(input, &results);
  int out_fd[10];
  for (i = 0; i < n; i++) {
    out_fd[i] = open(output[i], O_WRONLY | O_CREAT | O_TRUNC, results.st_mode);
    if (out_fd[i] == -1) {
      ewe("File %s can not be opened\n", output);
    }
  }
  while (1) {
    memset(buf, 0, (8192) * sizeof(char));
    ssize_t result = read(in_fd, buf, 8192 * sizeof(char));
    if (result == 0) {
      break;
    }
    for (i = 0; i < n; i++) {
      write(out_fd[i], buf, result * sizeof(char));
    }
  }
  close(in_fd);
  for (i = 0; i < n; i++) {
    close(out_fd[i]);
  }
}


x86 assembly (clang, -O0):
<mass_copy_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2070,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,-0x202c(%rbp)
cmpl   $0xffffffff,-0x202c(%rbp)
jne    11bf <mass_copy_file+0x4f>
mov    -0x10(%rbp),%rsi
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1040 <ewe@plt>
mov    -0x10(%rbp),%rdi
lea    -0x2028(%rbp),%rsi
call   1080 <stat@plt>
movl   $0x0,-0x2024(%rbp)
mov    -0x2024(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    126f <mass_copy_file+0xff>
mov    -0x8(%rbp),%rax
movslq -0x2024(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2dc2(%rip),%rax
mov    (%rax),%esi
mov    0x2df1(%rip),%rax
or     (%rax),%esi
mov    0x2de0(%rip),%rax
or     (%rax),%esi
mov    -0x2028(%rbp),%edx
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,%ecx
movslq -0x2024(%rbp),%rax
mov    %ecx,-0x2060(%rbp,%rax,4)
movslq -0x2024(%rbp),%rax
cmpl   $0xffffffff,-0x2060(%rbp,%rax,4)
ff
jne    1256 <mass_copy_file+0xe6>
mov    -0x8(%rbp),%rsi
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1040 <ewe@plt>
jmp    125b <mass_copy_file+0xeb>
mov    -0x2024(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2024(%rbp)
jmp    11d9 <mass_copy_file+0x69>
jmp    1274 <mass_copy_file+0x104>
lea    -0x2020(%rbp),%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1050 <memset@plt>
mov    -0x202c(%rbp),%edi
lea    -0x2020(%rbp),%rsi
mov    $0x2000,%edx
call   1070 <read@plt>
mov    %eax,-0x2064(%rbp)
cmpl   $0x0,-0x2064(%rbp)
jne    12b6 <mass_copy_file+0x146>
jmp    130f <mass_copy_file+0x19f>
movl   $0x0,-0x2024(%rbp)
mov    -0x2024(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    130a <mass_copy_file+0x19a>
movslq -0x2024(%rbp),%rax
mov    -0x2060(%rbp,%rax,4),%edi
lea    -0x2020(%rbp),%rsi
movslq -0x2064(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x2024(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2024(%rbp)
jmp    12c0 <mass_copy_file+0x150>
jmp    1274 <mass_copy_file+0x104>
mov    -0x202c(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x2024(%rbp)
mov    -0x2024(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    135a <mass_copy_file+0x1ea>
movslq -0x2024(%rbp),%rax
mov    -0x2060(%rbp,%rax,4),%edi
call   1060 <close@plt>
mov    -0x2024(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2024(%rbp)
jmp    1324 <mass_copy_file+0x1b4>
add    $0x2070,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mass_copy_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2048,%rsp
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1090 <open@plt>
mov    %eax,0x8(%rsp)
cmp    $0xffffffff,%eax
jne    11b6 <mass_copy_file+0x46>
lea    0xe54(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <ewe@plt>
mov    %rsp,%rsi
mov    %r14,%rdi
call   1080 <stat@plt>
mov    %ebp,%r13d
mov    %ebp,0xc(%rsp)
test   %ebp,%ebp
jle    1232 <mass_copy_file+0xc2>
mov    (%rsp),%ebp
mov    0x2e22(%rip),%r14
mov    0x2e13(%rip),%r15
xor    %r12d,%r12d
jmp    11f9 <mass_copy_file+0x89>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%r12
cmp    %r12,%r13
je     1232 <mass_copy_file+0xc2>
mov    (%rbx,%r12,8),%rdi
mov    (%r14),%esi
mov    0x2db9(%rip),%rax
or     (%rax),%esi
or     (%r15),%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1090 <open@plt>
mov    %eax,0x10(%rsp,%r12,4)
cmp    $0xffffffff,%eax
jne    11f0 <mass_copy_file+0x80>
lea    0xdda(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <ewe@plt>
jmp    11f0 <mass_copy_file+0x80>
lea    0x40(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1050 <memset@plt>
mov    0x8(%rsp),%r12d
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x2000,%edx
call   1070 <read@plt>
test   %eax,%eax
mov    0xc(%rsp),%r15d
je     12b9 <mass_copy_file+0x149>
mov    %eax,%ebp
lea    0x40(%rsp),%r14
jmp    1295 <mass_copy_file+0x125>
nopl   (%rax)
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1050 <memset@plt>
mov    %r12d,%edi
mov    %r14,%rsi
mov    $0x2000,%edx
call   1070 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
je     12b9 <mass_copy_file+0x149>
test   %r15d,%r15d
jle    1270 <mass_copy_file+0x100>
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    0x10(%rsp,%rbx,4),%edi
mov    %r14,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    12a0 <mass_copy_file+0x130>
jmp    1270 <mass_copy_file+0x100>
mov    %r12d,%edi
call   1060 <close@plt>
test   %r15d,%r15d
jle    12e2 <mass_copy_file+0x172>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    0x10(%rsp,%rbx,4),%edi
call   1060 <close@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    12d0 <mass_copy_file+0x160>
add    $0x2048,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@O_RDONLY = global i32 0
@.str = [27 x i8] c"File %s can not be opened\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
define void @mass_copy_file(i8** %0, i8* %1, i32 %2) {
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [8192 x i8]
%8 = alloca i32
%9 = alloca %struct.stat
%10 = alloca i32
%11 = alloca [10 x i32]
%12 = alloca i32
store i8** %0, i8*** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%13 = load i8*, i8** %5
%14 = load i32, i32* @O_RDONLY
%15 = call i32 (i8*, i32, ...) @open(i8* %13, i32 %14)
store i32 %15, i32* %10
%16 = load i32, i32* %10
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %3
%19 = load i8*, i8** %5
%20 = call i32 (i8*, ...) @ewe(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %18, %3
%22 = load i8*, i8** %5
%23 = call i32 @stat(i8* %22, %struct.stat* %9)
store i32 0, i32* %8
br label %24
24: ; preds = %54, %21
%25 = load i32, i32* %8
%26 = load i32, i32* %6
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %57
28: ; preds = %24
%29 = load i8**, i8*** %4
%30 = load i32, i32* %8
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
%33 = load i8*, i8** %32
%34 = load i32, i32* @O_WRONLY
%35 = load i32, i32* @O_CREAT
%36 = or i32 %34, %35
%37 = load i32, i32* @O_TRUNC
%38 = or i32 %36, %37
%39 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%40 = load i32, i32* %39
%41 = call i32 (i8*, i32, ...) @open(i8* %33, i32 %38, i32 %40)
%42 = load i32, i32* %8
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [10 x i32], [10 x i32]* %11, i64 0, i64 %43
store i32 %41, i32* %44
%45 = load i32, i32* %8
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [10 x i32], [10 x i32]* %11, i64 0, i64 %46
%48 = load i32, i32* %47
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %53
50: ; preds = %28
%51 = load i8**, i8*** %4
%52 = call i32 (i8*, ...) @ewe(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8** %51)
br label %53
53: ; preds = %50, %28
br label %54
54: ; preds = %53
%55 = load i32, i32* %8
%56 = add nsw i32 %55, 1
store i32 %56, i32* %8
br label %24
57: ; preds = %24
br label %58
58: ; preds = %57, %86
%59 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%60 = call i32 @memset(i8* %59, i32 0, i32 8192)
%61 = load i32, i32* %10
%62 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%63 = call i32 @read(i32 %61, i8* %62, i32 8192)
store i32 %63, i32* %12
%64 = load i32, i32* %12
%65 = icmp eq i32 %64, 0
br i1 %65, label %66, label %67
66: ; preds = %58
br label %87
67: ; preds = %58
store i32 0, i32* %8
br label %68
68: ; preds = %83, %67
%69 = load i32, i32* %8
%70 = load i32, i32* %6
%71 = icmp slt i32 %69, %70
br i1 %71, label %72, label %86
72: ; preds = %68
%73 = load i32, i32* %8
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds [10 x i32], [10 x i32]* %11, i64 0, i64 %74
%76 = load i32, i32* %75
%77 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%78 = load i32, i32* %12
%79 = sext i32 %78 to i64
%80 = mul i64 %79, 1
%81 = trunc i64 %80 to i32
%82 = call i32 @write(i32 %76, i8* %77, i32 %81)
br label %83
83: ; preds = %72
%84 = load i32, i32* %8
%85 = add nsw i32 %84, 1
store i32 %85, i32* %8
br label %68
86: ; preds = %68
br label %58
87: ; preds = %66
%88 = load i32, i32* %10
%89 = call i32 @close(i32 %88)
store i32 0, i32* %8
br label %90
90: ; preds = %100, %87
%91 = load i32, i32* %8
%92 = load i32, i32* %6
%93 = icmp slt i32 %91, %92
br i1 %93, label %94, label %103
94: ; preds = %90
%95 = load i32, i32* %8
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds [10 x i32], [10 x i32]* %11, i64 0, i64 %96
%98 = load i32, i32* %97
%99 = call i32 @close(i32 %98)
br label %100
100: ; preds = %94
%101 = load i32, i32* %8
%102 = add nsw i32 %101, 1
store i32 %102, i32* %8
br label %90
103: ; preds = %90
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@O_RDONLY = global i32 0
@.str = [27 x i8] c"File %s can not be opened\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
define void @mass_copy_file(i8** %0, i8* %1, i32 %2) {
%4 = alloca [8192 x i8]
%5 = alloca %struct.stat
%6 = alloca [10 x i32]
%7 = getelementptr inbounds [8192 x i8], [8192 x i8]* %4, i64 0, i64 0
%8 = bitcast %struct.stat* %5 to i8*
%9 = load i32, i32* @O_RDONLY
%10 = tail call i32 (i8*, i32, ...) @open(i8* %1, i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = tail call i32 (i8*, ...) @ewe(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %14
14: ; preds = %12, %3
%15 = call i32 @stat(i8* %1, %struct.stat* %5)
%16 = bitcast [10 x i32]* %6 to i8*
%17 = icmp sgt i32 %2, 0
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 0
%20 = load i32, i32* %19
%21 = zext i32 %2 to i64
br label %28
22: ; preds = %42, %14
%23 = call i32 @memset(i8* %7, i32 0, i32 8192)
%24 = call i32 @read(i32 %10, i8* %7, i32 8192)
%25 = icmp eq i32 %24, 0
br i1 %25, label %58, label %26
26: ; preds = %22
%27 = zext i32 %2 to i64
br label %49
28: ; preds = %18, %42
%29 = phi i64 [ 0, %18 ], [ %43, %42 ]
%30 = getelementptr inbounds i8*, i8** %0, i64 %29
%31 = load i8*, i8** %30
%32 = load i32, i32* @O_WRONLY
%33 = load i32, i32* @O_CREAT
%34 = or i32 %33, %32
%35 = load i32, i32* @O_TRUNC
%36 = or i32 %34, %35
%37 = tail call i32 (i8*, i32, ...) @open(i8* %31, i32 %36, i32 %20)
%38 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %29
store i32 %37, i32* %38
%39 = icmp eq i32 %37, -1
br i1 %39, label %40, label %42
40: ; preds = %28
%41 = tail call i32 (i8*, ...) @ewe(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8** %0)
br label %42
42: ; preds = %28, %40
%43 = add nuw nsw i64 %29, 1
%44 = icmp eq i64 %43, %21
br i1 %44, label %22, label %28
45: ; preds = %51, %49
%46 = call i32 @memset(i8* %7, i32 0, i32 8192)
%47 = call i32 @read(i32 %10, i8* %7, i32 8192)
%48 = icmp eq i32 %47, 0
br i1 %48, label %58, label %49
49: ; preds = %26, %45
%50 = phi i32 [ %24, %26 ], [ %47, %45 ]
br i1 %17, label %51, label %45
51: ; preds = %49, %51
%52 = phi i64 [ %56, %51 ], [ 0, %49 ]
%53 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %52
%54 = load i32, i32* %53
%55 = call i32 @write(i32 %54, i8* %7, i32 %50)
%56 = add nuw nsw i64 %52, 1
%57 = icmp eq i64 %56, %27
br i1 %57, label %45, label %51
58: ; preds = %45, %22
%59 = call i32 @close(i32 %10)
br i1 %17, label %60, label %69
60: ; preds = %58
%61 = zext i32 %2 to i64
br label %62
62: ; preds = %60, %62
%63 = phi i64 [ 0, %60 ], [ %67, %62 ]
%64 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %63
%65 = load i32, i32* %64
%66 = call i32 @close(i32 %65)
%67 = add nuw nsw i64 %63, 1
%68 = icmp eq i64 %67, %61
br i1 %68, label %69, label %62
69: ; preds = %62, %58
ret void
}