#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 {
  scalar_t__ st_dev;
  scalar_t__ st_ino;
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ F_OK;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ R_OK;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
scalar_t__ S_ISREG(int /*<<< orphan*/);
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ basename(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err_exit(char *, char *, ...);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char *file_path_combine(char *, int /*<<< orphan*/);
int open(char *, int, ...);
int read(int, char *, int);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ usage();
int write(int, char *, int);
int main(int argc, char **argv) {
  if (argc != 3) {
    usage();
    exit(EXIT_FAILURE);
  }
  char *source, *target, *dest;
  struct stat stat_buf, stat_buf1;
  source = argv[1];
  target = argv[2];
  if (stat(source, &stat_buf) < 0) {
    err_exit("tcp: cannot stat '%s': %s\n", source, strerror(errno));
  }
  if (!S_ISREG(stat_buf.st_mode)) {
    err_exit("tcp: '%s' doesn't point to a regular file'\n", source);
  }
  if (access(source, R_OK) < 0) {
    err_exit("tcp: '%s': no read permission\n", source);
  }
  if (access(target, F_OK) == 0) {
    if (stat(target, &stat_buf1) < 0) {
      err_exit("tcp: cannot stat '%s': %s\n", target, strerror(errno));
    }
    if (S_ISREG(stat_buf1.st_mode)) {
      dest = target;
    } else if (S_ISDIR(stat_buf1.st_mode)) {
      dest = file_path_combine(target, basename(source));
    } else {
      err_exit("tcp: '%s' isn't a regular file or a directory'\n", target);
    }
  } else {
    dest = target;
  }
  if (access(dest, F_OK) == 0) {
    if (stat(dest, &stat_buf1) < 0) {
      err_exit("tcp: cannot stat '%s': %s\n", dest, strerror(errno));
    }
    if (stat_buf.st_dev == stat_buf1.st_dev &&
        stat_buf.st_ino == stat_buf1.st_ino) {
      exit(EXIT_SUCCESS);
    }
  }
  int src_fd, dest_fd, n;
  char buf[4096];
  if ((src_fd = open(source, O_RDONLY)) == -1) {
    err_exit("tcp: cannot open '%s': %s\n", source, strerror(errno));
  }
  if ((dest_fd = open(dest, O_WRONLY | O_CREAT | O_TRUNC, stat_buf.st_mode)) ==
      -1) {
    err_exit("tcp: cannot open '%s': %s\n", dest, strerror(errno));
  }
  while ((n = read(src_fd, buf, 4096)) > 0) {
    if (write(dest_fd, buf, n) != n) {
      err_exit("tcp: write error at '%s': %s\n", dest, strerror(errno));
    }
  }
  close(src_fd);
  close(dest_fd);
  if (n < 0) {
    err_exit("tcp: read error at '%s': %s\n", source, strerror(errno));
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10b0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1218 <main+0x38>
mov    $0x0,%al
call   10c0 <usage@plt>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1080 <stat@plt>
cmp    $0x0,%rax
jge    1277 <main+0x97>
mov    -0x18(%rbp),%rax
mov    %rax,-0x1078(%rbp)
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x1078(%rbp),%rsi
mov    %eax,%edx
lea    0xd90(%rip),%rdi
mov    $0x0,%al
call   10a0 <err_exit@plt>
mov    -0x30(%rbp),%edi
call   1090 <S_ISREG@plt>
cmp    $0x0,%rax
jne    129b <main+0xbb>
mov    -0x18(%rbp),%rsi
lea    0xd87(%rip),%rdi
mov    $0x0,%al
call   10a0 <err_exit@plt>
mov    -0x18(%rbp),%rdi
mov    0x2d12(%rip),%rax
mov    (%rax),%esi
call   10e0 <access@plt>
cmp    $0x0,%rax
jge    12c9 <main+0xe9>
mov    -0x18(%rbp),%rsi
lea    0xd85(%rip),%rdi
mov    $0x0,%al
call   10a0 <err_exit@plt>
mov    -0x20(%rbp),%rdi
mov    0x2cc4(%rip),%rax
mov    (%rax),%esi
call   10e0 <access@plt>
cmp    $0x0,%rax
jne    13a4 <main+0x1c4>
mov    -0x20(%rbp),%rdi
lea    -0x58(%rbp),%rsi
call   1080 <stat@plt>
cmp    $0x0,%rax
jge    132c <main+0x14c>
mov    -0x20(%rbp),%rax
mov    %rax,-0x1080(%rbp)
mov    0x2cba(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x1080(%rbp),%rsi
mov    %eax,%edx
lea    0xcdb(%rip),%rdi
mov    $0x0,%al
call   10a0 <err_exit@plt>
mov    -0x48(%rbp),%edi
call   1090 <S_ISREG@plt>
cmp    $0x0,%rax
je     134b <main+0x16b>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    139f <main+0x1bf>
mov    -0x48(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1388 <main+0x1a8>
mov    -0x20(%rbp),%rax
mov    %rax,-0x1088(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <basename@plt>
mov    -0x1088(%rbp),%rdi
mov    %eax,%esi
call   10b0 <file_path_combine@plt>
mov    %rax,-0x28(%rbp)
jmp    139a <main+0x1ba>
mov    -0x20(%rbp),%rsi
lea    0xcd3(%rip),%rdi
mov    $0x0,%al
call   10a0 <err_exit@plt>
jmp    139f <main+0x1bf>
jmp    13ac <main+0x1cc>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2be1(%rip),%rax
mov    (%rax),%esi
call   10e0 <access@plt>
cmp    $0x0,%rax
jne    143e <main+0x25e>
mov    -0x28(%rbp),%rdi
lea    -0x58(%rbp),%rsi
call   1080 <stat@plt>
cmp    $0x0,%rax
jge    140f <main+0x22f>
mov    -0x28(%rbp),%rax
mov    %rax,-0x1090(%rbp)
mov    0x2bd7(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x1090(%rbp),%rsi
mov    %eax,%edx
lea    0xbf8(%rip),%rdi
mov    $0x0,%al
call   10a0 <err_exit@plt>
mov    -0x40(%rbp),%rax
cmp    -0x58(%rbp),%rax
jne    1439 <main+0x259>
mov    -0x38(%rbp),%rax
cmp    -0x50(%rbp),%rax
jne    1439 <main+0x259>
mov    0x2b7e(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
jmp    143e <main+0x25e>
mov    -0x18(%rbp),%rdi
mov    0x2b8f(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10d0 <open@plt>
mov    %eax,-0x5c(%rbp)
cmp    $0xffffffff,%eax
jne    148e <main+0x2ae>
mov    -0x18(%rbp),%rax
mov    %rax,-0x1098(%rbp)
mov    0x2b58(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x1098(%rbp),%rsi
mov    %eax,%edx
lea    0xc0f(%rip),%rdi
mov    $0x0,%al
call   10a0 <err_exit@plt>
mov    -0x28(%rbp),%rdi
mov    0x2b07(%rip),%rax
mov    (%rax),%esi
mov    0x2b56(%rip),%rax
or     (%rax),%esi
mov    0x2b45(%rip),%rax
or     (%rax),%esi
mov    -0x30(%rbp),%edx
mov    $0x0,%al
call   10d0 <open@plt>
mov    %eax,-0x60(%rbp)
cmp    $0xffffffff,%eax
jne    14f3 <main+0x313>
mov    -0x28(%rbp),%rax
mov    %rax,-0x10a0(%rbp)
mov    0x2af3(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x10a0(%rbp),%rsi
mov    %eax,%edx
lea    0xbaa(%rip),%rdi
mov    $0x0,%al
call   10a0 <err_exit@plt>
jmp    14f8 <main+0x318>
mov    -0x5c(%rbp),%edi
lea    -0x1070(%rbp),%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
mov    %eax,-0x64(%rbp)
cmp    $0x0,%eax
jle    1568 <main+0x388>
mov    -0x60(%rbp),%edi
lea    -0x1070(%rbp),%rsi
mov    -0x64(%rbp),%edx
call   1030 <write@plt>
cmp    -0x64(%rbp),%eax
je     1563 <main+0x383>
mov    -0x28(%rbp),%rax
mov    %rax,-0x10a8(%rbp)
mov    0x2a83(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x10a8(%rbp),%rsi
mov    %eax,%edx
lea    0xb55(%rip),%rdi
mov    $0x0,%al
call   10a0 <err_exit@plt>
jmp    14f8 <main+0x318>
mov    -0x5c(%rbp),%edi
call   1050 <close@plt>
mov    -0x60(%rbp),%edi
call   1050 <close@plt>
cmpl   $0x0,-0x64(%rbp)
jge    15b2 <main+0x3d2>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10b0(%rbp)
mov    0x2a34(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x10b0(%rbp),%rsi
mov    %eax,%edx
lea    0xb24(%rip),%rdi
mov    $0x0,%al
call   10a0 <err_exit@plt>
mov    0x29f7(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1048,%rsp
cmp    $0x3,%edi
jne    12f7 <main+0x117>
mov    0x8(%rsi),%r13
mov    0x10(%rsi),%r15
lea    0x28(%rsp),%rsi
mov    %r13,%rdi
call   1080 <stat@plt>
test   %rax,%rax
jns    1235 <main+0x55>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xdd7(%rip),%rdi
mov    %r13,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10a0 <err_exit@plt>
mov    0x38(%rsp),%edi
call   1090 <S_ISREG@plt>
test   %rax,%rax
jne    1254 <main+0x74>
lea    0xdd1(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   10a0 <err_exit@plt>
mov    0x2d5d(%rip),%rax
mov    (%rax),%esi
mov    %r13,%rdi
call   10e0 <access@plt>
test   %rax,%rax
jns    127b <main+0x9b>
lea    0xdd6(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   10a0 <err_exit@plt>
mov    0x2d16(%rip),%rbx
mov    (%rbx),%esi
mov    %r15,%rdi
call   10e0 <access@plt>
test   %rax,%rax
jne    1321 <main+0x141>
lea    0x10(%rsp),%rsi
mov    %r15,%rdi
call   1080 <stat@plt>
test   %rax,%rax
jns    12c8 <main+0xe8>
mov    0x2d1a(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xd44(%rip),%rdi
mov    %r15,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10a0 <err_exit@plt>
mov    0x20(%rsp),%edi
call   1090 <S_ISREG@plt>
test   %rax,%rax
jne    1321 <main+0x141>
mov    0x20(%rsp),%edi
call   1040 <S_ISDIR@plt>
test   %rax,%rax
jne    130c <main+0x12c>
lea    0xd7b(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   10a0 <err_exit@plt>
jmp    1321 <main+0x141>
xor    %eax,%eax
call   10c0 <usage@plt>
mov    0x2cbb(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    %r13,%rdi
call   1070 <basename@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   10b0 <file_path_combine@plt>
mov    %rax,%r15
mov    (%rbx),%esi
mov    %r15,%rdi
call   10e0 <access@plt>
test   %rax,%rax
jne    137f <main+0x19f>
lea    0x10(%rsp),%rsi
mov    %r15,%rdi
call   1080 <stat@plt>
test   %rax,%rax
jns    1363 <main+0x183>
mov    0x2c7f(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xca9(%rip),%rdi
mov    %r15,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10a0 <err_exit@plt>
mov    0x28(%rsp),%rax
cmp    0x10(%rsp),%rax
jne    137f <main+0x19f>
mov    0x30(%rsp),%rax
cmp    0x18(%rsp),%rax
je     14bf <main+0x2df>
mov    0x2c52(%rip),%rax
mov    (%rax),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   10d0 <open@plt>
mov    %eax,%r12d
cmp    $0xffffffff,%eax
jne    13bb <main+0x1db>
mov    0x2c27(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xce7(%rip),%rdi
mov    %r13,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10a0 <err_exit@plt>
mov    0x2bde(%rip),%rax
mov    0x2c2f(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2c1c(%rip),%rax
or     (%rax),%esi
mov    0x38(%rsp),%edx
mov    %r15,%rdi
xor    %eax,%eax
call   10d0 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    140c <main+0x22c>
mov    0x2bd6(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xc96(%rip),%rdi
mov    %r15,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10a0 <err_exit@plt>
lea    0x40(%rsp),%rsi
mov    %r12d,%edi
mov    $0x1000,%edx
call   1060 <read@plt>
mov    %eax,%r14d
test   %eax,%eax
mov    %r13,0x8(%rsp)
jle    1488 <main+0x2a8>
lea    0x40(%rsp),%rbp
lea    0xc7b(%rip),%r13
jmp    1457 <main+0x277>
nopl   0x0(%rax,%rax,1)
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
mov    %eax,%r14d
test   %eax,%eax
jle    1488 <main+0x2a8>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r14d,%edx
call   1030 <write@plt>
cmp    %r14d,%eax
je     1440 <main+0x260>
mov    0x2b58(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10a0 <err_exit@plt>
jmp    1440 <main+0x260>
mov    %r12d,%edi
call   1050 <close@plt>
mov    %ebx,%edi
call   1050 <close@plt>
test   %r14d,%r14d
jns    14bf <main+0x2df>
mov    0x2b25(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xc1e(%rip),%rdi
mov    0x8(%rsp),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10a0 <err_exit@plt>
mov    0x2aea(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i64, i64, i32 }
@EXIT_FAILURE = global i32 0
@.str = [27 x i8] c"tcp: cannot stat '%s': %s\0A\00"
@errno = global i32 0
@.str.1 = [44 x i8] c"tcp: '%s' doesn't point to a regular file'\0A\00"
@R_OK = global i32 0
@.str.2 = [31 x i8] c"tcp: '%s': no read permission\0A\00"
@F_OK = global i32 0
@.str.3 = [48 x i8] c"tcp: '%s' isn't a regular file or a directory'\0A\00"
@EXIT_SUCCESS = global i32 0
@O_RDONLY = global i32 0
@.str.4 = [27 x i8] c"tcp: cannot open '%s': %s\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.5 = [30 x i8] c"tcp: write error at '%s': %s\0A\00"
@.str.6 = [29 x i8] c"tcp: read error at '%s': %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca %struct.stat
%10 = alloca %struct.stat
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca [4096 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 3
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = call i32 (...) @usage()
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
store i8* %24, i8** %6
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
store i8* %27, i8** %7
%28 = load i8*, i8** %6
%29 = call i64 @stat(i8* %28, %struct.stat* %9)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %21
%32 = load i8*, i8** %6
%33 = load i32, i32* @errno
%34 = call i32 @strerror(i32 %33)
%35 = call i32 (i8*, i8*, ...) @err_exit(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %32, i32 %34)
br label %36
36: ; preds = %31, %21
%37 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 2
%38 = load i32, i32* %37
%39 = call i64 @S_ISREG(i32 %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %44, label %41
41: ; preds = %36
%42 = load i8*, i8** %6
%43 = call i32 (i8*, i8*, ...) @err_exit(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %42)
br label %44
44: ; preds = %41, %36
%45 = load i8*, i8** %6
%46 = load i32, i32* @R_OK
%47 = call i64 @access(i8* %45, i32 %46)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %44
%50 = load i8*, i8** %6
%51 = call i32 (i8*, i8*, ...) @err_exit(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %50)
br label %52
52: ; preds = %49, %44
%53 = load i8*, i8** %7
%54 = load i32, i32* @F_OK
%55 = call i64 @access(i8* %53, i32 %54)
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %88
57: ; preds = %52
%58 = load i8*, i8** %7
%59 = call i64 @stat(i8* %58, %struct.stat* %10)
%60 = icmp slt i64 %59, 0
br i1 %60, label %61, label %66
61: ; preds = %57
%62 = load i8*, i8** %7
%63 = load i32, i32* @errno
%64 = call i32 @strerror(i32 %63)
%65 = call i32 (i8*, i8*, ...) @err_exit(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %62, i32 %64)
br label %66
66: ; preds = %61, %57
%67 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 2
%68 = load i32, i32* %67
%69 = call i64 @S_ISREG(i32 %68)
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %66
%72 = load i8*, i8** %7
store i8* %72, i8** %8
br label %87
73: ; preds = %66
%74 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 2
%75 = load i32, i32* %74
%76 = call i64 @S_ISDIR(i32 %75)
%77 = icmp ne i64 %76, 0
br i1 %77, label %78, label %83
78: ; preds = %73
%79 = load i8*, i8** %7
%80 = load i8*, i8** %6
%81 = call i32 @basename(i8* %80)
%82 = call i8* @file_path_combine(i8* %79, i32 %81)
store i8* %82, i8** %8
br label %86
83: ; preds = %73
%84 = load i8*, i8** %7
%85 = call i32 (i8*, i8*, ...) @err_exit(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0), i8* %84)
br label %86
86: ; preds = %83, %78
br label %87
87: ; preds = %86, %71
br label %90
88: ; preds = %52
%89 = load i8*, i8** %7
store i8* %89, i8** %8
br label %90
90: ; preds = %88, %87
%91 = load i8*, i8** %8
%92 = load i32, i32* @F_OK
%93 = call i64 @access(i8* %91, i32 %92)
%94 = icmp eq i64 %93, 0
br i1 %94, label %95, label %120
95: ; preds = %90
%96 = load i8*, i8** %8
%97 = call i64 @stat(i8* %96, %struct.stat* %10)
%98 = icmp slt i64 %97, 0
br i1 %98, label %99, label %104
99: ; preds = %95
%100 = load i8*, i8** %8
%101 = load i32, i32* @errno
%102 = call i32 @strerror(i32 %101)
%103 = call i32 (i8*, i8*, ...) @err_exit(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %100, i32 %102)
br label %104
104: ; preds = %99, %95
%105 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%106 = load i64, i64* %105
%107 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%108 = load i64, i64* %107
%109 = icmp eq i64 %106, %108
br i1 %109, label %110, label %119
110: ; preds = %104
%111 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 1
%112 = load i64, i64* %111
%113 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 1
%114 = load i64, i64* %113
%115 = icmp eq i64 %112, %114
br i1 %115, label %116, label %119
116: ; preds = %110
%117 = load i32, i32* @EXIT_SUCCESS
%118 = call i32 @exit(i32 %117)
unreachable
119: ; preds = %110, %104
br label %120
120: ; preds = %119, %90
%121 = load i8*, i8** %6
%122 = load i32, i32* @O_RDONLY
%123 = call i32 (i8*, i32, ...) @open(i8* %121, i32 %122)
store i32 %123, i32* %11
%124 = icmp eq i32 %123, -1
br i1 %124, label %125, label %130
125: ; preds = %120
%126 = load i8*, i8** %6
%127 = load i32, i32* @errno
%128 = call i32 @strerror(i32 %127)
%129 = call i32 (i8*, i8*, ...) @err_exit(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %126, i32 %128)
br label %130
130: ; preds = %125, %120
%131 = load i8*, i8** %8
%132 = load i32, i32* @O_WRONLY
%133 = load i32, i32* @O_CREAT
%134 = or i32 %132, %133
%135 = load i32, i32* @O_TRUNC
%136 = or i32 %134, %135
%137 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 2
%138 = load i32, i32* %137
%139 = call i32 (i8*, i32, ...) @open(i8* %131, i32 %136, i32 %138)
store i32 %139, i32* %12
%140 = icmp eq i32 %139, -1
br i1 %140, label %141, label %146
141: ; preds = %130
%142 = load i8*, i8** %8
%143 = load i32, i32* @errno
%144 = call i32 @strerror(i32 %143)
%145 = call i32 (i8*, i8*, ...) @err_exit(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %142, i32 %144)
br label %146
146: ; preds = %141, %130
br label %147
147: ; preds = %164, %146
%148 = load i32, i32* %11
%149 = getelementptr inbounds [4096 x i8], [4096 x i8]* %14, i64 0, i64 0
%150 = call i32 @read(i32 %148, i8* %149, i32 4096)
store i32 %150, i32* %13
%151 = icmp sgt i32 %150, 0
br i1 %151, label %152, label %165
152: ; preds = %147
%153 = load i32, i32* %12
%154 = getelementptr inbounds [4096 x i8], [4096 x i8]* %14, i64 0, i64 0
%155 = load i32, i32* %13
%156 = call i32 @write(i32 %153, i8* %154, i32 %155)
%157 = load i32, i32* %13
%158 = icmp ne i32 %156, %157
br i1 %158, label %159, label %164
159: ; preds = %152
%160 = load i8*, i8** %8
%161 = load i32, i32* @errno
%162 = call i32 @strerror(i32 %161)
%163 = call i32 (i8*, i8*, ...) @err_exit(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i8* %160, i32 %162)
br label %164
164: ; preds = %159, %152
br label %147
165: ; preds = %147
%166 = load i32, i32* %11
%167 = call i32 @close(i32 %166)
%168 = load i32, i32* %12
%169 = call i32 @close(i32 %168)
%170 = load i32, i32* %13
%171 = icmp slt i32 %170, 0
br i1 %171, label %172, label %177
172: ; preds = %165
%173 = load i8*, i8** %6
%174 = load i32, i32* @errno
%175 = call i32 @strerror(i32 %174)
%176 = call i32 (i8*, i8*, ...) @err_exit(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i8* %173, i32 %175)
br label %177
177: ; preds = %172, %165
%178 = load i32, i32* @EXIT_SUCCESS
%179 = call i32 @exit(i32 %178)
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i64, i64, i32 }
@EXIT_FAILURE = global i32 0
@.str = [27 x i8] c"tcp: cannot stat '%s': %s\0A\00"
@errno = global i32 0
@.str.1 = [44 x i8] c"tcp: '%s' doesn't point to a regular file'\0A\00"
@R_OK = global i32 0
@.str.2 = [31 x i8] c"tcp: '%s': no read permission\0A\00"
@F_OK = global i32 0
@.str.3 = [48 x i8] c"tcp: '%s' isn't a regular file or a directory'\0A\00"
@EXIT_SUCCESS = global i32 0
@O_RDONLY = global i32 0
@.str.4 = [27 x i8] c"tcp: cannot open '%s': %s\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.5 = [30 x i8] c"tcp: write error at '%s': %s\0A\00"
@.str.6 = [29 x i8] c"tcp: read error at '%s': %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = alloca %struct.stat
%5 = alloca [4096 x i8]
%6 = icmp eq i32 %0, 3
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = tail call i32 (...) @usage()
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %2
%12 = bitcast %struct.stat* %3 to i8*
%13 = bitcast %struct.stat* %4 to i8*
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = call i64 @stat(i8* %15, %struct.stat* %3)
%19 = icmp slt i64 %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 (i8*, i8*, ...) @err_exit(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %15, i32 %22)
br label %24
24: ; preds = %20, %11
%25 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 2
%26 = load i32, i32* %25
%27 = call i64 @S_ISREG(i32 %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = call i32 (i8*, i8*, ...) @err_exit(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %31
31: ; preds = %29, %24
%32 = load i32, i32* @R_OK
%33 = call i64 @access(i8* %15, i32 %32)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i32 (i8*, i8*, ...) @err_exit(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %15)
br label %37
37: ; preds = %35, %31
%38 = load i32, i32* @F_OK
%39 = call i64 @access(i8* %17, i32 %38)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %62
41: ; preds = %37
%42 = call i64 @stat(i8* %17, %struct.stat* %4)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %41
%45 = load i32, i32* @errno
%46 = call i32 @strerror(i32 %45)
%47 = call i32 (i8*, i8*, ...) @err_exit(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %17, i32 %46)
br label %48
48: ; preds = %44, %41
%49 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 2
%50 = load i32, i32* %49
%51 = call i64 @S_ISREG(i32 %50)
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %62
53: ; preds = %48
%54 = load i32, i32* %49
%55 = call i64 @S_ISDIR(i32 %54)
%56 = icmp eq i64 %55, 0
br i1 %56, label %60, label %57
57: ; preds = %53
%58 = call i32 @basename(i8* %15)
%59 = call i8* @file_path_combine(i8* %17, i32 %58)
br label %62
60: ; preds = %53
%61 = call i32 (i8*, i8*, ...) @err_exit(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0), i8* %17)
br label %62
62: ; preds = %37, %48, %60, %57
%63 = phi i8* [ %59, %57 ], [ undef, %60 ], [ %17, %48 ], [ %17, %37 ]
%64 = load i32, i32* @F_OK
%65 = call i64 @access(i8* %63, i32 %64)
%66 = icmp eq i64 %65, 0
br i1 %66, label %67, label %89
67: ; preds = %62
%68 = call i64 @stat(i8* %63, %struct.stat* %4)
%69 = icmp slt i64 %68, 0
br i1 %69, label %70, label %74
70: ; preds = %67
%71 = load i32, i32* @errno
%72 = call i32 @strerror(i32 %71)
%73 = call i32 (i8*, i8*, ...) @err_exit(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %63, i32 %72)
br label %74
74: ; preds = %70, %67
%75 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%76 = load i64, i64* %75
%77 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%78 = load i64, i64* %77
%79 = icmp eq i64 %76, %78
br i1 %79, label %80, label %89
80: ; preds = %74
%81 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%82 = load i64, i64* %81
%83 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 1
%84 = load i64, i64* %83
%85 = icmp eq i64 %82, %84
br i1 %85, label %86, label %89
86: ; preds = %80
%87 = load i32, i32* @EXIT_SUCCESS
%88 = call i32 @exit(i32 %87)
unreachable
89: ; preds = %74, %80, %62
%90 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%91 = load i32, i32* @O_RDONLY
%92 = call i32 (i8*, i32, ...) @open(i8* %15, i32 %91)
%93 = icmp eq i32 %92, -1
br i1 %93, label %94, label %98
94: ; preds = %89
%95 = load i32, i32* @errno
%96 = call i32 @strerror(i32 %95)
%97 = call i32 (i8*, i8*, ...) @err_exit(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %15, i32 %96)
br label %98
98: ; preds = %94, %89
%99 = load i32, i32* @O_WRONLY
%100 = load i32, i32* @O_CREAT
%101 = or i32 %100, %99
%102 = load i32, i32* @O_TRUNC
%103 = or i32 %101, %102
%104 = load i32, i32* %25
%105 = call i32 (i8*, i32, ...) @open(i8* %63, i32 %103, i32 %104)
%106 = icmp eq i32 %105, -1
br i1 %106, label %107, label %111
107: ; preds = %98
%108 = load i32, i32* @errno
%109 = call i32 @strerror(i32 %108)
%110 = call i32 (i8*, i8*, ...) @err_exit(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %63, i32 %109)
br label %111
111: ; preds = %107, %98
%112 = call i32 @read(i32 %92, i8* %90, i32 4096)
%113 = icmp sgt i32 %112, 0
br i1 %113, label %114, label %125
114: ; preds = %111, %122
%115 = phi i32 [ %123, %122 ], [ %112, %111 ]
%116 = call i32 @write(i32 %105, i8* %90, i32 %115)
%117 = icmp eq i32 %116, %115
br i1 %117, label %122, label %118
118: ; preds = %114
%119 = load i32, i32* @errno
%120 = call i32 @strerror(i32 %119)
%121 = call i32 (i8*, i8*, ...) @err_exit(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i8* %63, i32 %120)
br label %122
122: ; preds = %118, %114
%123 = call i32 @read(i32 %92, i8* %90, i32 4096)
%124 = icmp sgt i32 %123, 0
br i1 %124, label %114, label %125
125: ; preds = %122, %111
%126 = phi i32 [ %112, %111 ], [ %123, %122 ]
%127 = call i32 @close(i32 %92)
%128 = call i32 @close(i32 %105)
%129 = icmp slt i32 %126, 0
br i1 %129, label %130, label %134
130: ; preds = %125
%131 = load i32, i32* @errno
%132 = call i32 @strerror(i32 %131)
%133 = call i32 (i8*, i8*, ...) @err_exit(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i8* %15, i32 %132)
br label %134
134: ; preds = %130, %125
%135 = load i32, i32* @EXIT_SUCCESS
%136 = call i32 @exit(i32 %135)
unreachable
}