#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 st_blksize;
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int creat(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fatal(int /*<<< orphan*/, char *, char const *,
                         int /*<<< orphan*/);
int open(char const *, int /*<<< orphan*/);
int read(int, char *, int const);
scalar_t__ stat(char const *, struct stat *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int write(int, char *, int);
extern int fcp(const char *src, const char *dst) {
  struct stat statbuf;
  if (stat(src, &statbuf))
    fatal(0, "in fcp(): stat(\"%s\") failed: %s", src, strerror(errno));
  const int size = statbuf.st_blksize;
  char buf[size];
  int ifd = open(src, O_RDONLY);
  if (ifd < 0)
    fatal(0, "in fcp(): open(\"%s\") failed: %s", src, strerror(errno));
  int ofd = creat(dst, statbuf.st_mode);
  if (ofd < 0)
    fatal(0, "in fcp(): creat(\"%s\") failed: %s", dst, strerror(errno));
  int n;
  while ((n = read(ifd, buf, size)) > 0)
    if (write(ofd, buf, n) != n)
      fatal(0, "in fcp(): write(\"%s\") failed: %s", dst, strerror(errno));
  if (n < 0)
    fatal(0, "in fcp(): read(\"%s\") failed: %s", src, strerror(errno));
  close(ifd);
  close(ofd);
  return 1;
}


x86 assembly (clang, -O0):
<fcp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0x0,%rax
je     11d1 <fcp+0x51>
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x48(%rbp),%rdx
mov    %eax,%ecx
xor    %edi,%edi
lea    0xe34(%rip),%rsi
call   10a0 <fatal@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2de0(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    1246 <fcp+0xc6>
mov    -0x8(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x58(%rbp),%rdx
mov    %eax,%ecx
xor    %edi,%edi
lea    0xddf(%rip),%rsi
call   10a0 <fatal@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1080 <creat@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jge    1289 <fcp+0x109>
mov    -0x10(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x60(%rbp),%rdx
mov    %eax,%ecx
xor    %edi,%edi
lea    0xdbc(%rip),%rsi
call   10a0 <fatal@plt>
jmp    128e <fcp+0x10e>
mov    -0x50(%rbp),%rsi
mov    -0x34(%rbp),%edi
mov    -0x1c(%rbp),%edx
call   1050 <read@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0x0,%eax
jle    12f0 <fcp+0x170>
mov    -0x50(%rbp),%rsi
mov    -0x38(%rbp),%edi
mov    -0x3c(%rbp),%edx
call   1030 <write@plt>
cmp    -0x3c(%rbp),%eax
je     12eb <fcp+0x16b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    0x2d08(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x68(%rbp),%rdx
mov    %eax,%ecx
xor    %edi,%edi
lea    0xd7b(%rip),%rsi
call   10a0 <fatal@plt>
jmp    128e <fcp+0x10e>
cmpl   $0x0,-0x3c(%rbp)
jge    1324 <fcp+0x1a4>
mov    -0x8(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    0x2ccf(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x70(%rbp),%rdx
mov    %eax,%ecx
xor    %edi,%edi
lea    0xd63(%rip),%rsi
call   10a0 <fatal@plt>
mov    -0x34(%rbp),%edi
call   1040 <close@plt>
mov    -0x38(%rbp),%edi
call   1040 <close@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    $0x1,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fcp>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,-0x30(%rbp)
mov    %rdi,%r14
lea    -0x38(%rbp),%rsi
call   1060 <stat@plt>
test   %rax,%rax
je     11c7 <fcp+0x47>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe45(%rip),%rsi
xor    %edi,%edi
mov    %r14,%rdx
mov    %eax,%ecx
call   10a0 <fatal@plt>
mov    %rsp,-0x48(%rbp)
mov    -0x38(%rbp),%r13d
mov    %rsp,%rbx
lea    0xf(%r13),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1070 <open@plt>
mov    %eax,%r12d
test   %eax,%eax
jns    1219 <fcp+0x99>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe13(%rip),%rsi
xor    %edi,%edi
mov    %r14,%rdx
mov    %eax,%ecx
call   10a0 <fatal@plt>
mov    %r14,-0x40(%rbp)
mov    -0x34(%rbp),%esi
mov    -0x30(%rbp),%rdi
call   1080 <creat@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    1252 <fcp+0xd2>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdfb(%rip),%rsi
xor    %edi,%edi
mov    -0x30(%rbp),%rdx
mov    %eax,%ecx
call   10a0 <fatal@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %r13d,%edx
call   1050 <read@plt>
mov    %eax,%r15d
test   %eax,%eax
jle    1293 <fcp+0x113>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1030 <write@plt>
cmp    %r15d,%eax
je     1252 <fcp+0xd2>
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
xor    %edi,%edi
lea    0xdd0(%rip),%rsi
jmp    1247 <fcp+0xc7>
test   %r15d,%r15d
jns    12ba <fcp+0x13a>
mov    0x2d39(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdd5(%rip),%rsi
xor    %edi,%edi
mov    -0x40(%rbp),%rdx
mov    %eax,%ecx
call   10a0 <fatal@plt>
mov    %r12d,%edi
call   1040 <close@plt>
mov    %r14d,%edi
call   1040 <close@plt>
mov    -0x48(%rbp),%rsp
mov    $0x1,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32, i32 }
@.str = [32 x i8] c"in fcp(): stat(\22%s\22) failed: %s\00"
@errno = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [32 x i8] c"in fcp(): open(\22%s\22) failed: %s\00"
@.str.2 = [33 x i8] c"in fcp(): creat(\22%s\22) failed: %s\00"
@.str.3 = [33 x i8] c"in fcp(): write(\22%s\22) failed: %s\00"
@.str.4 = [32 x i8] c"in fcp(): read(\22%s\22) failed: %s\00"
define i32 @fcp(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.stat
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%12 = load i8*, i8** %3
%13 = call i64 @stat(i8* %12, %struct.stat* %5)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i8*, i8** %3
%17 = load i32, i32* @errno
%18 = call i32 @strerror(i32 %17)
%19 = call i32 @fatal(i32 0, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %16, i32 %18)
br label %20
20: ; preds = %15, %2
%21 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%22 = load i32, i32* %21
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = zext i32 %23 to i64
%25 = call i8* @llvm.stacksave()
store i8* %25, i8** %7
%26 = alloca i8, i64 %24
store i64 %24, i64* %8
%27 = load i8*, i8** %3
%28 = load i32, i32* @O_RDONLY
%29 = call i32 @open(i8* %27, i32 %28)
store i32 %29, i32* %9
%30 = load i32, i32* %9
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %20
%33 = load i8*, i8** %3
%34 = load i32, i32* @errno
%35 = call i32 @strerror(i32 %34)
%36 = call i32 @fatal(i32 0, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %33, i32 %35)
br label %37
37: ; preds = %32, %20
%38 = load i8*, i8** %4
%39 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 1
%40 = load i32, i32* %39
%41 = call i32 @creat(i8* %38, i32 %40)
store i32 %41, i32* %10
%42 = load i32, i32* %10
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %49
44: ; preds = %37
%45 = load i8*, i8** %4
%46 = load i32, i32* @errno
%47 = call i32 @strerror(i32 %46)
%48 = call i32 @fatal(i32 0, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %45, i32 %47)
br label %49
49: ; preds = %44, %37
br label %50
50: ; preds = %66, %49
%51 = load i32, i32* %9
%52 = load i32, i32* %6
%53 = call i32 @read(i32 %51, i8* %26, i32 %52)
store i32 %53, i32* %11
%54 = icmp sgt i32 %53, 0
br i1 %54, label %55, label %67
55: ; preds = %50
%56 = load i32, i32* %10
%57 = load i32, i32* %11
%58 = call i32 @write(i32 %56, i8* %26, i32 %57)
%59 = load i32, i32* %11
%60 = icmp ne i32 %58, %59
br i1 %60, label %61, label %66
61: ; preds = %55
%62 = load i8*, i8** %4
%63 = load i32, i32* @errno
%64 = call i32 @strerror(i32 %63)
%65 = call i32 @fatal(i32 0, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %62, i32 %64)
br label %66
66: ; preds = %61, %55
br label %50
67: ; preds = %50
%68 = load i32, i32* %11
%69 = icmp slt i32 %68, 0
br i1 %69, label %70, label %75
70: ; preds = %67
%71 = load i8*, i8** %3
%72 = load i32, i32* @errno
%73 = call i32 @strerror(i32 %72)
%74 = call i32 @fatal(i32 0, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %71, i32 %73)
br label %75
75: ; preds = %70, %67
%76 = load i32, i32* %9
%77 = call i32 @close(i32 %76)
%78 = load i32, i32* %10
%79 = call i32 @close(i32 %78)
%80 = load i8*, i8** %7
ret i32 1
}

LLVM IR (-O2):
%struct.stat = type { i32, i32 }
@.str = [32 x i8] c"in fcp(): stat(\22%s\22) failed: %s\00"
@errno = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [32 x i8] c"in fcp(): open(\22%s\22) failed: %s\00"
@.str.2 = [33 x i8] c"in fcp(): creat(\22%s\22) failed: %s\00"
@.str.3 = [33 x i8] c"in fcp(): write(\22%s\22) failed: %s\00"
@.str.4 = [32 x i8] c"in fcp(): read(\22%s\22) failed: %s\00"
define i32 @fcp(i8* %0, i8* %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = call i64 @stat(i8* %0, %struct.stat* %3)
%6 = icmp eq i64 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = load i32, i32* @errno
%9 = call i32 @strerror(i32 %8)
%10 = call i32 @fatal(i32 0, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %9)
br label %11
11: ; preds = %7, %2
%12 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%13 = load i32, i32* %12
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
%16 = alloca i8, i64 %14
%17 = load i32, i32* @O_RDONLY
%18 = call i32 @open(i8* %0, i32 %17)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %11
%21 = load i32, i32* @errno
%22 = call i32 @strerror(i32 %21)
%23 = call i32 @fatal(i32 0, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %22)
br label %24
24: ; preds = %20, %11
%25 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%26 = load i32, i32* %25
%27 = call i32 @creat(i8* %1, i32 %26)
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %24
%30 = load i32, i32* @errno
%31 = call i32 @strerror(i32 %30)
%32 = call i32 @fatal(i32 0, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %1, i32 %31)
br label %33
33: ; preds = %29, %24
%34 = call i32 @read(i32 %18, i8* %16, i32 %13)
%35 = icmp sgt i32 %34, 0
br i1 %35, label %36, label %47
36: ; preds = %33, %44
%37 = phi i32 [ %45, %44 ], [ %34, %33 ]
%38 = call i32 @write(i32 %27, i8* %16, i32 %37)
%39 = icmp eq i32 %38, %37
br i1 %39, label %44, label %40
40: ; preds = %36
%41 = load i32, i32* @errno
%42 = call i32 @strerror(i32 %41)
%43 = call i32 @fatal(i32 0, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %1, i32 %42)
br label %44
44: ; preds = %40, %36
%45 = call i32 @read(i32 %18, i8* %16, i32 %13)
%46 = icmp sgt i32 %45, 0
br i1 %46, label %36, label %47
47: ; preds = %44, %33
%48 = phi i32 [ %34, %33 ], [ %45, %44 ]
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %54
50: ; preds = %47
%51 = load i32, i32* @errno
%52 = call i32 @strerror(i32 %51)
%53 = call i32 @fatal(i32 0, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %0, i32 %52)
br label %54
54: ; preds = %50, %47
%55 = call i32 @close(i32 %18)
%56 = call i32 @close(i32 %27)
ret i32 1
}