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

/* Variables and functions */
int BUFSIZ;
int O_CREAT;
int O_TRUNC;
int O_WRONLY;
int _cp_error(char const *, int);
int /*<<< orphan*/ close(int);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
size_t fwrite(char *, int, size_t, int /*<<< orphan*/ *);
int open(char const *, int, int /*<<< orphan*/);
int _cp_single_regular(char const *src, char const *dst, mode_t mode) {
  int ret = 0;
  FILE *fsrc;
  int fd;
  FILE *fdst;
  char buf[BUFSIZ];
  size_t size;
  if ((fsrc = fopen(src, "r")) == NULL)
    return _cp_error(src, 1);
  if ((fd = open(dst, O_WRONLY | O_CREAT | O_TRUNC, mode)) < 0 ||
      (fdst = fdopen(fd, "w")) == NULL) {
    ret = _cp_error(dst, 1);
    if (fd >= 0)
      close(fd);
    fclose(fsrc);
    return ret;
  }
  while ((size = fread(buf, sizeof(char), sizeof(buf), fsrc)) > 0)
    if (fwrite(buf, sizeof(char), size, fdst) != size)
      break;
  if (!feof(fsrc))
    ret |= _cp_error((size == 0) ? src : dst, 1);
  if (fclose(fsrc) != 0)
    ret |= _cp_error(src, 1);
  if (fclose(fdst) != 0)
    return _cp_error(dst, 1);
  return ret;
}


x86 assembly (clang, -O0):
<_cp_single_regular>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    0x2e1f(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x68(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe1b(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1215 <_cp_single_regular+0x85>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1070 <_cp_error@plt>
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x54(%rbp)
jmp    13a2 <_cp_single_regular+0x212>
mov    -0x18(%rbp),%rdi
mov    0x2da0(%rip),%rax
mov    (%rax),%esi
mov    0x2dcf(%rip),%rax
or     (%rax),%esi
mov    0x2dbe(%rip),%rax
or     (%rax),%esi
mov    -0x1c(%rbp),%edx
call   1090 <open@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jl     1265 <_cp_single_regular+0xd5>
mov    -0x2c(%rbp),%edi
lea    0xdb0(%rip),%rsi
call   1080 <fdopen@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    12a3 <_cp_single_regular+0x113>
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1070 <_cp_error@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jl     1288 <_cp_single_regular+0xf8>
mov    -0x2c(%rbp),%edi
call   1050 <close@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x54(%rbp)
jmp    13a2 <_cp_single_regular+0x212>
jmp    12a8 <_cp_single_regular+0x118>
mov    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%rax
mov    %eax,%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,-0x50(%rbp)
cmp    $0x0,%rax
jbe    12f8 <_cp_single_regular+0x168>
mov    -0x60(%rbp),%rdi
mov    -0x50(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    $0x1,%esi
call   10b0 <fwrite@plt>
cmp    -0x50(%rbp),%rax
je     12f3 <_cp_single_regular+0x163>
jmp    12f8 <_cp_single_regular+0x168>
jmp    12a8 <_cp_single_regular+0x118>
mov    -0x28(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
jne    133e <_cp_single_regular+0x1ae>
cmpq   $0x0,-0x50(%rbp)
jne    1322 <_cp_single_regular+0x192>
mov    -0x10(%rbp),%rax
mov    %rax,-0x70(%rbp)
jmp    132a <_cp_single_regular+0x19a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rdi
mov    $0x1,%esi
call   1070 <_cp_error@plt>
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     1365 <_cp_single_regular+0x1d5>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1070 <_cp_error@plt>
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     1395 <_cp_single_regular+0x205>
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1070 <_cp_error@plt>
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x54(%rbp)
jmp    13a2 <_cp_single_regular+0x212>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x54(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_cp_single_regular>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,-0x30(%rbp)
mov    %rsi,%r15
mov    %rdi,%r12
mov    0x2e1f(%rip),%rax
mov    (%rax),%ebx
mov    %rsp,%r14
lea    0xf(%rbx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
lea    0xe35(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12cd <_cp_single_regular+0x13d>
mov    %rax,%r13
mov    %r12,-0x38(%rbp)
mov    0x2dd9(%rip),%rax
mov    0x2e0a(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2df7(%rip),%rax
or     (%rax),%esi
mov    %r15,%rdi
mov    -0x30(%rbp),%edx
call   1090 <open@plt>
mov    %r15,%rdi
test   %eax,%eax
js     12e8 <_cp_single_regular+0x158>
mov    %eax,%r15d
mov    %rdi,-0x30(%rbp)
lea    0xde3(%rip),%rsi
mov    %eax,%edi
call   1080 <fdopen@plt>
test   %rax,%rax
je     12f6 <_cp_single_regular+0x166>
mov    %rax,%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    $0x1,%esi
mov    %ebx,%edx
mov    %r13,%rcx
call   1030 <fread@plt>
mov    %rax,%r15
test   %rax,%rax
je     1272 <_cp_single_regular+0xe2>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %r12,%rcx
call   10b0 <fwrite@plt>
cmp    %r15,%rax
je     1240 <_cp_single_regular+0xb0>
mov    %r13,%rdi
call   1060 <feof@plt>
xor    %ebx,%ebx
test   %eax,%eax
mov    -0x38(%rbp),%r14
jne    129b <_cp_single_regular+0x10b>
test   %r15,%r15
mov    -0x30(%rbp),%rdi
cmove  %r14,%rdi
mov    $0x1,%esi
call   1070 <_cp_error@plt>
mov    %eax,%ebx
mov    %r13,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
je     12b7 <_cp_single_regular+0x127>
mov    %r14,%rdi
mov    $0x1,%esi
call   1070 <_cp_error@plt>
or     %eax,%ebx
mov    -0x30(%rbp),%r14
mov    %r12,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
je     1316 <_cp_single_regular+0x186>
mov    %r14,%rdi
jmp    12d0 <_cp_single_regular+0x140>
mov    %r12,%rdi
mov    $0x1,%esi
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <_cp_error@plt>
mov    $0x1,%esi
call   1070 <_cp_error@plt>
mov    %eax,%ebx
jmp    130e <_cp_single_regular+0x17e>
mov    -0x30(%rbp),%rdi
mov    $0x1,%esi
call   1070 <_cp_error@plt>
mov    %eax,%ebx
mov    %r15d,%edi
call   1050 <close@plt>
mov    %r13,%rdi
call   1040 <fclose@plt>
mov    %ebx,%eax
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 = [2 x i8] c"r\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [2 x i8] c"w\00"
define i32 @_cp_single_regular(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i64
%15 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 0, i32* %8
%16 = load i32, i32* @BUFSIZ
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %12
%19 = alloca i8, i64 %17
store i64 %17, i64* %13
%20 = load i8*, i8** %5
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %21, i32** %9
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %26
23: ; preds = %3
%24 = load i8*, i8** %5
%25 = call i32 @_cp_error(i8* %24, i32 1)
store i32 %25, i32* %4
store i32 1, i32* %15
br label %100
26: ; preds = %3
%27 = load i8*, i8** %6
%28 = load i32, i32* @O_WRONLY
%29 = load i32, i32* @O_CREAT
%30 = or i32 %28, %29
%31 = load i32, i32* @O_TRUNC
%32 = or i32 %30, %31
%33 = load i32, i32* %7
%34 = call i32 @open(i8* %27, i32 %32, i32 %33)
store i32 %34, i32* %10
%35 = icmp slt i32 %34, 0
br i1 %35, label %40, label %36
36: ; preds = %26
%37 = load i32, i32* %10
%38 = call i32* @fdopen(i32 %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %38, i32** %11
%39 = icmp eq i32* %38, null
br i1 %39, label %40, label %52
40: ; preds = %36, %26
%41 = load i8*, i8** %6
%42 = call i32 @_cp_error(i8* %41, i32 1)
store i32 %42, i32* %8
%43 = load i32, i32* %10
%44 = icmp sge i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %40
%46 = load i32, i32* %10
%47 = call i32 @close(i32 %46)
br label %48
48: ; preds = %45, %40
%49 = load i32*, i32** %9
%50 = call i64 @fclose(i32* %49)
%51 = load i32, i32* %8
store i32 %51, i32* %4
store i32 1, i32* %15
br label %100
52: ; preds = %36
br label %53
53: ; preds = %65, %52
%54 = trunc i64 %17 to i32
%55 = load i32*, i32** %9
%56 = call i64 @fread(i8* %19, i32 1, i32 %54, i32* %55)
store i64 %56, i64* %14
%57 = icmp ugt i64 %56, 0
br i1 %57, label %58, label %66
58: ; preds = %53
%59 = load i64, i64* %14
%60 = load i32*, i32** %11
%61 = call i64 @fwrite(i8* %19, i32 1, i64 %59, i32* %60)
%62 = load i64, i64* %14
%63 = icmp ne i64 %61, %62
br i1 %63, label %64, label %65
64: ; preds = %58
br label %66
65: ; preds = %58
br label %53
66: ; preds = %64, %53
%67 = load i32*, i32** %9
%68 = call i32 @feof(i32* %67)
%69 = icmp ne i32 %68, 0
br i1 %69, label %82, label %70
70: ; preds = %66
%71 = load i64, i64* %14
%72 = icmp eq i64 %71, 0
br i1 %72, label %73, label %75
73: ; preds = %70
%74 = load i8*, i8** %5
br label %77
75: ; preds = %70
%76 = load i8*, i8** %6
br label %77
77: ; preds = %75, %73
%78 = phi i8* [ %74, %73 ], [ %76, %75 ]
%79 = call i32 @_cp_error(i8* %78, i32 1)
%80 = load i32, i32* %8
%81 = or i32 %80, %79
store i32 %81, i32* %8
br label %82
82: ; preds = %77, %66
%83 = load i32*, i32** %9
%84 = call i64 @fclose(i32* %83)
%85 = icmp ne i64 %84, 0
br i1 %85, label %86, label %91
86: ; preds = %82
%87 = load i8*, i8** %5
%88 = call i32 @_cp_error(i8* %87, i32 1)
%89 = load i32, i32* %8
%90 = or i32 %89, %88
store i32 %90, i32* %8
br label %91
91: ; preds = %86, %82
%92 = load i32*, i32** %11
%93 = call i64 @fclose(i32* %92)
%94 = icmp ne i64 %93, 0
br i1 %94, label %95, label %98
95: ; preds = %91
%96 = load i8*, i8** %6
%97 = call i32 @_cp_error(i8* %96, i32 1)
store i32 %97, i32* %4
store i32 1, i32* %15
br label %100
98: ; preds = %91
%99 = load i32, i32* %8
store i32 %99, i32* %4
store i32 1, i32* %15
br label %100
100: ; preds = %98, %95, %48, %23
%101 = load i8*, i8** %12
%102 = load i32, i32* %4
ret i32 %102
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [2 x i8] c"r\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [2 x i8] c"w\00"
define i32 @_cp_single_regular(i8* %0, i8* %1, i32 %2) {
%4 = load i32, i32* @BUFSIZ
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = tail call i32 @_cp_error(i8* %0, i32 1)
br label %55
11: ; preds = %3
%12 = load i32, i32* @O_WRONLY
%13 = load i32, i32* @O_CREAT
%14 = or i32 %13, %12
%15 = load i32, i32* @O_TRUNC
%16 = or i32 %14, %15
%17 = tail call i32 @open(i8* %1, i32 %16, i32 %2)
%18 = icmp slt i32 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %11
%20 = tail call i32* @fdopen(i32 %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %24, label %30
22: ; preds = %11
%23 = tail call i32 @_cp_error(i8* %1, i32 1)
br label %27
24: ; preds = %19
%25 = tail call i32 @_cp_error(i8* %1, i32 1)
%26 = tail call i32 @close(i32 %17)
br label %27
27: ; preds = %22, %24
%28 = phi i32 [ %25, %24 ], [ %23, %22 ]
%29 = tail call i64 @fclose(i32* %7)
br label %55
30: ; preds = %19, %33
%31 = call i64 @fread(i8* %6, i32 1, i32 %4, i32* %7)
%32 = icmp eq i64 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %30
%34 = call i64 @fwrite(i8* %6, i32 1, i64 %31, i32* %20)
%35 = icmp eq i64 %34, %31
br i1 %35, label %30, label %36
36: ; preds = %33, %30
%37 = tail call i32 @feof(i32* %7)
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = select i1 %32, i8* %0, i8* %1
%41 = tail call i32 @_cp_error(i8* %40, i32 1)
br label %42
42: ; preds = %39, %36
%43 = phi i32 [ 0, %36 ], [ %41, %39 ]
%44 = tail call i64 @fclose(i32* %7)
%45 = icmp eq i64 %44, 0
br i1 %45, label %49, label %46
46: ; preds = %42
%47 = tail call i32 @_cp_error(i8* %0, i32 1)
%48 = or i32 %47, %43
br label %49
49: ; preds = %46, %42
%50 = phi i32 [ %48, %46 ], [ %43, %42 ]
%51 = tail call i64 @fclose(i32* %20)
%52 = icmp eq i64 %51, 0
br i1 %52, label %55, label %53
53: ; preds = %49
%54 = tail call i32 @_cp_error(i8* %1, i32 1)
br label %55
55: ; preds = %49, %53, %27, %9
%56 = phi i32 [ %10, %9 ], [ %28, %27 ], [ %54, %53 ], [ %50, %49 ]
ret i32 %56
}