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

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ cannot(char *, char const *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fread(char **, int, int, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int fwrite(char *, int, int, int /*<<< orphan*/ *);
long copy(const char *name, FILE *out, const char *outname) {
  FILE *f;
  long size, offs;
  int first = 1;
  f = fopen(name, "rb");
  if (f == NULL)
    cannot("open", name);
  if (fseek(f, 0, SEEK_END) != 0)
    cannot("seek", name);
  size = ftell(f);
  if (fseek(f, 0, SEEK_SET) != 0)
    cannot("seek", name);
  for (;;) {
    char b[BUFSIZ];
    int n = fread(&b, 1, sizeof(b), f);
    if (n == 0) {
      if (ferror(f))
        cannot("read", name);
      else
        break;
    }
    offs = 0;
    if (first) {
      if (b[0] == '#' && b[1] == '!' && b[2] == '/') {
        offs += 3;
        while (b[offs] != '\n')
          ++offs;
        ++offs;
        size -= offs;
      }
      first = 0;
    }
    if (fwrite(&b[offs], n - offs, 1, out) != 1)
      cannot("write", outname);
  }
  fclose(f);
  return size;
}


x86 assembly (clang, -O0):
<copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe5a(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ca <copy+0x4a>
mov    -0x8(%rbp),%rsi
lea    0xe3e(%rip),%rdi
call   1060 <cannot@plt>
mov    -0x20(%rbp),%rdi
mov    0x2e13(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
cmp    $0x0,%rax
je     11f8 <copy+0x78>
mov    -0x8(%rbp),%rsi
lea    0xe15(%rip),%rdi
call   1060 <cannot@plt>
mov    -0x20(%rbp),%rdi
call   1070 <ftell@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2dc0(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
cmp    $0x0,%rax
je     1233 <copy+0xb3>
mov    -0x8(%rbp),%rsi
lea    0xdda(%rip),%rdi
call   1060 <cannot@plt>
jmp    1238 <copy+0xb8>
mov    0x2d99(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x58(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x48(%rbp)
mov    %eax,%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jne    12ba <copy+0x13a>
mov    -0x20(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     12a9 <copy+0x129>
mov    -0x8(%rbp),%rsi
lea    0xd6e(%rip),%rdi
call   1060 <cannot@plt>
jmp    12b5 <copy+0x135>
movl   $0x2,-0x50(%rbp)
jmp    1392 <copy+0x212>
jmp    12ba <copy+0x13a>
movq   $0x0,-0x30(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     1352 <copy+0x1d2>
mov    -0x58(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    134b <copy+0x1cb>
mov    -0x58(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x21,%eax
jne    134b <copy+0x1cb>
mov    -0x58(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x2f,%eax
jne    134b <copy+0x1cb>
mov    -0x30(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x30(%rbp)
mov    -0x58(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     1330 <copy+0x1b0>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    130a <copy+0x18a>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x58(%rbp),%rdi
add    -0x30(%rbp),%rdi
movslq -0x4c(%rbp),%rax
sub    -0x30(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
call   10a0 <fwrite@plt>
cmp    $0x1,%eax
je     138b <copy+0x20b>
mov    -0x18(%rbp),%rsi
lea    0xc8c(%rip),%rdi
call   1060 <cannot@plt>
movl   $0x0,-0x50(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
mov    -0x50(%rbp),%eax
test   %eax,%eax
je     13ae <copy+0x22e>
jmp    13a9 <copy+0x229>
jmp    13b3 <copy+0x233>
jmp    1238 <copy+0xb8>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,-0x40(%rbp)
mov    %rsi,-0x48(%rbp)
lea    0xe60(%rip),%rsi
mov    %rdi,-0x30(%rbp)
call   1090 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11c1 <copy+0x41>
lea    0xe4b(%rip),%rdi
mov    -0x30(%rbp),%rsi
call   1060 <cannot@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
test   %rax,%rax
je     11e9 <copy+0x69>
lea    0xe28(%rip),%rdi
mov    -0x30(%rbp),%rsi
call   1060 <cannot@plt>
mov    %rbx,%rdi
call   1070 <ftell@plt>
mov    %rax,-0x38(%rbp)
mov    0x2dd4(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
test   %rax,%rax
je     121d <copy+0x9d>
lea    0xdf4(%rip),%rdi
mov    -0x30(%rbp),%rsi
call   1060 <cannot@plt>
xor    %r12d,%r12d
jmp    1236 <copy+0xb6>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rsp
mov    $0x1,%r12b
mov    %rsp,%r14
mov    0x2d98(%rip),%rax
mov    (%rax),%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    %rbx,%rcx
call   1040 <fread@plt>
mov    %eax,%r15d
test   %eax,%eax
je     1280 <copy+0x100>
test   $0x1,%r12b
je     12a7 <copy+0x127>
jmp    12f0 <copy+0x170>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     132a <copy+0x1aa>
lea    0xd75(%rip),%rdi
mov    -0x30(%rbp),%rsi
call   1060 <cannot@plt>
test   $0x1,%r12b
jne    12f0 <copy+0x170>
cmpb   $0x23,0x0(%r13)
jne    12f0 <copy+0x170>
cmpb   $0x21,0x1(%r13)
jne    12f0 <copy+0x170>
cmpb   $0x2f,0x2(%r13)
jne    12f0 <copy+0x170>
mov    $0x3,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmpb   $0xa,0x0(%r13,%rax,1)
lea    0x1(%rax),%rax
jne    12d0 <copy+0x150>
sub    %rax,-0x38(%rbp)
jmp    12f2 <copy+0x172>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
add    %rax,%r13
sub    %eax,%r15d
mov    %r13,%rdi
mov    %r15d,%esi
mov    $0x1,%edx
mov    -0x48(%rbp),%rcx
call   10a0 <fwrite@plt>
cmp    $0x1,%eax
je     1230 <copy+0xb0>
lea    0xcf6(%rip),%rdi
mov    -0x40(%rbp),%rsi
call   1060 <cannot@plt>
jmp    1230 <copy+0xb0>
mov    %r14,%rsp
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    -0x38(%rbp),%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [5 x i8] c"open\00"
@SEEK_END = global i32 0
@.str.2 = [5 x i8] c"seek\00"
@SEEK_SET = global i32 0
@BUFSIZ = global i32 0
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [6 x i8] c"write\00"
define i64 @copy(i8* %0, i32* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i8* %2, i8** %6
store i32 1, i32* %10
%15 = load i8*, i8** %4
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %7
%17 = load i32*, i32** %7
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %3
%20 = load i8*, i8** %4
%21 = call i32 @cannot(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %19, %3
%23 = load i32*, i32** %7
%24 = load i32, i32* @SEEK_END
%25 = call i64 @fseek(i32* %23, i32 0, i32 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = load i8*, i8** %4
%29 = call i32 @cannot(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %27, %22
%31 = load i32*, i32** %7
%32 = call i64 @ftell(i32* %31)
store i64 %32, i64* %8
%33 = load i32*, i32** %7
%34 = load i32, i32* @SEEK_SET
%35 = call i64 @fseek(i32* %33, i32 0, i32 %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %30
%38 = load i8*, i8** %4
%39 = call i32 @cannot(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %38)
br label %40
40: ; preds = %37, %30
br label %41
41: ; preds = %116, %40
%42 = load i32, i32* @BUFSIZ
%43 = zext i32 %42 to i64
%44 = call i8* @llvm.stacksave()
store i8* %44, i8** %11
%45 = alloca i8, i64 %43
store i64 %43, i64* %12
%46 = bitcast i8* %45 to i8**
%47 = trunc i64 %43 to i32
%48 = load i32*, i32** %7
%49 = call i32 @fread(i8** %46, i32 1, i32 %47, i32* %48)
store i32 %49, i32* %13
%50 = load i32, i32* %13
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %61
52: ; preds = %41
%53 = load i32*, i32** %7
%54 = call i64 @ferror(i32* %53)
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %52
%57 = load i8*, i8** %4
%58 = call i32 @cannot(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %57)
br label %60
59: ; preds = %52
store i32 2, i32* %14
br label %113
60: ; preds = %56
br label %61
61: ; preds = %60, %41
store i64 0, i64* %9
%62 = load i32, i32* %10
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %98
64: ; preds = %61
%65 = getelementptr inbounds i8, i8* %45, i64 0
%66 = load i8, i8* %65
%67 = sext i8 %66 to i32
%68 = icmp eq i32 %67, 35
br i1 %68, label %69, label %97
69: ; preds = %64
%70 = getelementptr inbounds i8, i8* %45, i64 1
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
%73 = icmp eq i32 %72, 33
br i1 %73, label %74, label %97
74: ; preds = %69
%75 = getelementptr inbounds i8, i8* %45, i64 2
%76 = load i8, i8* %75
%77 = sext i8 %76 to i32
%78 = icmp eq i32 %77, 47
br i1 %78, label %79, label %97
79: ; preds = %74
%80 = load i64, i64* %9
%81 = add nsw i64 %80, 3
store i64 %81, i64* %9
br label %82
82: ; preds = %88, %79
%83 = load i64, i64* %9
%84 = getelementptr inbounds i8, i8* %45, i64 %83
%85 = load i8, i8* %84
%86 = sext i8 %85 to i32
%87 = icmp ne i32 %86, 10
br i1 %87, label %88, label %91
88: ; preds = %82
%89 = load i64, i64* %9
%90 = add nsw i64 %89, 1
store i64 %90, i64* %9
br label %82
91: ; preds = %82
%92 = load i64, i64* %9
%93 = add nsw i64 %92, 1
store i64 %93, i64* %9
%94 = load i64, i64* %9
%95 = load i64, i64* %8
%96 = sub nsw i64 %95, %94
store i64 %96, i64* %8
br label %97
97: ; preds = %91, %74, %69, %64
store i32 0, i32* %10
br label %98
98: ; preds = %97, %61
%99 = load i64, i64* %9
%100 = getelementptr inbounds i8, i8* %45, i64 %99
%101 = load i32, i32* %13
%102 = sext i32 %101 to i64
%103 = load i64, i64* %9
%104 = sub nsw i64 %102, %103
%105 = trunc i64 %104 to i32
%106 = load i32*, i32** %5
%107 = call i32 @fwrite(i8* %100, i32 %105, i32 1, i32* %106)
%108 = icmp ne i32 %107, 1
br i1 %108, label %109, label %112
109: ; preds = %98
%110 = load i8*, i8** %6
%111 = call i32 @cannot(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %110)
br label %112
112: ; preds = %109, %98
store i32 0, i32* %14
br label %113
113: ; preds = %112, %59
%114 = load i8*, i8** %11
%115 = load i32, i32* %14
switch i32 %115, label %121 [
i32 0, label %116
i32 2, label %117
]
116: ; preds = %113
br label %41
117: ; preds = %113
%118 = load i32*, i32** %7
%119 = call i32 @fclose(i32* %118)
%120 = load i64, i64* %8
ret i64 %120
121: ; preds = %113
unreachable
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [5 x i8] c"open\00"
@SEEK_END = global i32 0
@.str.2 = [5 x i8] c"seek\00"
@SEEK_SET = global i32 0
@BUFSIZ = global i32 0
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [6 x i8] c"write\00"
define i64 @copy(i8* %0, i32* nocapture %1, i8* %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @cannot(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %8
8: ; preds = %6, %3
%9 = load i32, i32* @SEEK_END
%10 = tail call i64 @fseek(i32* %4, i32 0, i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %8
%13 = tail call i32 @cannot(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %14
14: ; preds = %12, %8
%15 = tail call i64 @ftell(i32* %4)
%16 = load i32, i32* @SEEK_SET
%17 = tail call i64 @fseek(i32* %4, i32 0, i32 %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %14
%20 = tail call i32 @cannot(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %21
21: ; preds = %19, %14
br label %22
22: ; preds = %21, %67
%23 = phi i1 [ true, %67 ], [ false, %21 ]
%24 = phi i64 [ %59, %67 ], [ %15, %21 ]
%25 = load i32, i32* @BUFSIZ
%26 = zext i32 %25 to i64
%27 = tail call i8* @llvm.stacksave()
%28 = alloca i8, i64 %26
%29 = bitcast i8* %28 to i8**
%30 = call i32 @fread(i8** %29, i32 1, i32 %25, i32* %4)
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %22
%33 = tail call i64 @ferror(i32* %4)
%34 = icmp eq i64 %33, 0
br i1 %34, label %68, label %35
35: ; preds = %32
%36 = tail call i32 @cannot(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %37
37: ; preds = %35, %22
br i1 %23, label %57, label %38
38: ; preds = %37
%39 = load i8, i8* %28
%40 = icmp eq i8 %39, 35
br i1 %40, label %41, label %57
41: ; preds = %38
%42 = getelementptr inbounds i8, i8* %28, i64 1
%43 = load i8, i8* %42
%44 = icmp eq i8 %43, 33
br i1 %44, label %45, label %57
45: ; preds = %41
%46 = getelementptr inbounds i8, i8* %28, i64 2
%47 = load i8, i8* %46
%48 = icmp eq i8 %47, 47
br i1 %48, label %49, label %57
49: ; preds = %45, %49
%50 = phi i64 [ %54, %49 ], [ 3, %45 ]
%51 = getelementptr inbounds i8, i8* %28, i64 %50
%52 = load i8, i8* %51
%53 = icmp eq i8 %52, 10
%54 = add nuw nsw i64 %50, 1
br i1 %53, label %55, label %49
55: ; preds = %49
%56 = sub nsw i64 %24, %54
br label %57
57: ; preds = %38, %41, %45, %55, %37
%58 = phi i64 [ 0, %37 ], [ %54, %55 ], [ 0, %45 ], [ 0, %41 ], [ 0, %38 ]
%59 = phi i64 [ %24, %37 ], [ %56, %55 ], [ %24, %45 ], [ %24, %41 ], [ %24, %38 ]
%60 = getelementptr inbounds i8, i8* %28, i64 %58
%61 = trunc i64 %58 to i32
%62 = sub i32 %30, %61
%63 = call i32 @fwrite(i8* %60, i32 %62, i32 1, i32* %1)
%64 = icmp eq i32 %63, 1
br i1 %64, label %67, label %65
65: ; preds = %57
%66 = tail call i32 @cannot(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %2)
br label %67
67: ; preds = %57, %65
tail call void @llvm.stackrestore(i8* %27)
br label %22
68: ; preds = %32
tail call void @llvm.stackrestore(i8* %27)
%69 = tail call i32 @fclose(i32* %4)
ret i64 %24
}