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

/* Variables and functions */
char const *MAP_FAILED;
int /*<<< orphan*/ MAP_PRIVATE;
int /*<<< orphan*/ MAP_SHARED;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_RDWR;
int PATH_MAX;
int PROT_READ;
int PROT_WRITE;
char *basename(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int fstat(int, struct stat *);
int ftruncate(int, int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
void *mmap(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int /*<<< orphan*/ munmap(char *, int);
int open(char *, int, ...);
int /*<<< orphan*/ perror(char *);
int snprintf(char *, int, char *, char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  char const *src;
  char path[PATH_MAX + 1], *dst;
  int n, fd;
  size_t i, d = argc - 1;
  struct stat src_st, dst_st;
  off_t size;
  if (argc < 3) {
    fprintf(stderr, "%s [SOURCE] [DIRECTORY]\n", argv[0]);
    return 0;
  }
  for (i = 1; i < d; ++i) {
    n = snprintf(path, PATH_MAX, "%s/%s", argv[d], basename(argv[i]));
    if (n >= PATH_MAX) {
      fprintf(stderr, "Name too long: '%s/%s'\n", argv[d], basename(argv[i]));
      return 1;
    }
    fd = open(argv[i], O_RDONLY);
    if (fd < 0) {
      fprintf(stderr, "Failed to copy '%s' to '%s'\n", argv[i], path);
      perror("Could not open source");
      return 1;
    }
    n = fstat(fd, &src_st);
    if (n) {
      fprintf(stderr, "Failed to copy '%s' to '%s'\n", argv[i], path);
      perror("failed to stat source file.");
      return 1;
    }
    src = mmap(NULL, src_st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
    if (src == MAP_FAILED) {
      fprintf(stderr, "Failed to copy '%s' to '%s'\n", argv[i], path);
      perror("Could not map source");
    }
    close(fd);
    fd = open(path, O_RDWR | O_CREAT, src_st.st_mode);
    if (n < 0) {
      fprintf(stderr, "Failed to copy '%s' to '%s'\n", argv[i], path);
      perror("Could not open destination");
      return 1;
    }
    n = fstat(fd, &dst_st);
    if (n) {
      fprintf(stderr, "Failed to copy '%s' to '%s'\n", argv[i], path);
      perror("failed to stat destination file.");
      return 1;
    }
    size = (((src_st.st_size) + (dst_st.st_blksize) - 1) &
            ~(dst_st.st_blksize - 1));
    n = ftruncate(fd, size);
    if (n < 0) {
      fprintf(stderr, "Failed to copy '%s' to '%s'\n", argv[i], path);
      perror("Could not truncate destination");
      return 1;
    }
    dst = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
    if (dst == MAP_FAILED) {
      fprintf(stderr, "Failed to copy '%s' to '%s'\n", argv[i], path);
      perror("Could not map destination");
      return 1;
    }
    close(fd);
    memcpy(dst, src, src_st.st_size);
    munmap((void *)src, src_st.st_size);
    munmap(dst, src_st.st_size);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e10(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x78(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
cltq
mov    %rax,-0x48(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    123f <main+0x8f>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xddb(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x70(%rbp)
jmp    167c <main+0x4cc>
movq   $0x1,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x48(%rbp),%rax
jae    1675 <main+0x4c5>
mov    0x2d84(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x84(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x80(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x40(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1080 <basename@plt>
mov    -0x78(%rbp),%rdi
mov    -0x84(%rbp),%esi
mov    -0x80(%rbp),%rcx
mov    %rax,%r8
lea    0xd7c(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    0x2d31(%rip),%rcx
cmp    (%rcx),%eax
jl     131b <main+0x16b>
mov    0x2cf2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x94(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x90(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x40(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1080 <basename@plt>
mov    -0x94(%rbp),%edi
mov    -0x90(%rbp),%rdx
mov    %rax,%rcx
lea    0xd1e(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x70(%rbp)
jmp    167c <main+0x4cc>
mov    -0x10(%rbp),%rax
mov    -0x40(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2c92(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10b0 <open@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jge    138a <main+0x1da>
mov    -0x78(%rbp),%rcx
mov    0x2c61(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    -0x40(%rbp),%rdx
mov    (%rax,%rdx,8),%rdx
lea    0xcd3(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
lea    0xce2(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x70(%rbp)
jmp    167c <main+0x4cc>
mov    -0x38(%rbp),%edi
lea    -0x58(%rbp),%rsi
call   10d0 <fstat@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     13e9 <main+0x239>
mov    -0x78(%rbp),%rcx
mov    0x2c02(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    -0x40(%rbp),%rdx
mov    (%rax,%rdx,8),%rdx
lea    0xc74(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
lea    0xc99(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x70(%rbp)
jmp    167c <main+0x4cc>
mov    -0x58(%rbp),%esi
mov    0x2bfd(%rip),%rax
mov    (%rax),%edx
mov    0x2ba4(%rip),%rax
mov    (%rax),%ecx
mov    -0x38(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2b7b(%rip),%rcx
cmp    (%rcx),%rax
jne    1459 <main+0x2a9>
mov    -0x78(%rbp),%rcx
mov    0x2b7f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    -0x40(%rbp),%rdx
mov    (%rax,%rdx,8),%rdx
lea    0xbf1(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
lea    0xc32(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x38(%rbp),%edi
call   1060 <close@plt>
mov    -0x78(%rbp),%rdi
mov    0x2b5c(%rip),%rax
mov    (%rax),%esi
mov    0x2b83(%rip),%rax
or     (%rax),%esi
mov    -0x50(%rbp),%edx
mov    $0x0,%al
call   10b0 <open@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    14d4 <main+0x324>
mov    -0x78(%rbp),%rcx
mov    0x2b17(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    -0x40(%rbp),%rdx
mov    (%rax,%rdx,8),%rdx
lea    0xb89(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
lea    0xbdf(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x70(%rbp)
jmp    167c <main+0x4cc>
mov    -0x38(%rbp),%edi
lea    -0x68(%rbp),%rsi
call   10d0 <fstat@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     1533 <main+0x383>
mov    -0x78(%rbp),%rcx
mov    0x2ab8(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    -0x40(%rbp),%rdx
mov    (%rax,%rdx,8),%rdx
lea    0xb2a(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
lea    0xb9b(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x70(%rbp)
jmp    167c <main+0x4cc>
mov    -0x58(%rbp),%eax
add    -0x64(%rbp),%eax
sub    $0x1,%eax
mov    -0x64(%rbp),%ecx
sub    $0x1,%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    %eax,-0x6c(%rbp)
mov    -0x38(%rbp),%edi
mov    -0x6c(%rbp),%esi
call   1050 <ftruncate@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    15a8 <main+0x3f8>
mov    -0x78(%rbp),%rcx
mov    0x2a43(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    -0x40(%rbp),%rdx
mov    (%rax,%rdx,8),%rdx
lea    0xab5(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
lea    0xb47(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x70(%rbp)
jmp    167c <main+0x4cc>
mov    -0x6c(%rbp),%esi
mov    0x2a3e(%rip),%rax
mov    (%rax),%edx
mov    0x29ed(%rip),%rax
or     (%rax),%edx
mov    0x2a14(%rip),%rax
mov    (%rax),%ecx
mov    -0x38(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    0x29b3(%rip),%rcx
cmp    (%rcx),%rax
jne    1634 <main+0x484>
mov    -0x78(%rbp),%rcx
mov    0x29b7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    -0x40(%rbp),%rdx
mov    (%rax,%rdx,8),%rdx
lea    0xa29(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
lea    0xada(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x70(%rbp)
jmp    167c <main+0x4cc>
mov    -0x38(%rbp),%edi
call   1060 <close@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x58(%rbp),%edx
call   1090 <memcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x58(%rbp),%esi
call   10a0 <munmap@plt>
mov    -0x30(%rbp),%rdi
mov    -0x58(%rbp),%esi
call   10a0 <munmap@plt>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    1247 <main+0x97>
movl   $0x0,-0x70(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%r13
mov    0x2e15(%rip),%rax
mov    (%rax),%ebx
lea    0x1(%rbx),%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
cmp    $0x3,%edi
jge    1208 <main+0x58>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
mov    0x0(%r13),%rdx
lea    0xe06(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1456 <main+0x2a6>
add    $0xffffffff,%edi
movslq %edi,%r15
mov    0x0(%r13,%r15,8),%rax
mov    %rax,-0x38(%rbp)
lea    0x8(%r13),%r14
mov    0x8(%r13),%rdi
call   1080 <basename@plt>
lea    0xdee(%rip),%rdx
mov    %r12,%rdi
mov    %ebx,%esi
mov    -0x38(%rbp),%rcx
mov    %rax,%r8
call   1040 <snprintf@plt>
mov    0x2d9d(%rip),%rcx
cmp    (%rcx),%eax
mov    %r15,-0x40(%rbp)
jge    141d <main+0x26d>
lea    -0x2(%r15),%rax
mov    %rax,-0x38(%rbp)
mov    %r12,-0x30(%rbp)
mov    %r13,-0x48(%rbp)
nop
mov    (%r14),%rdi
mov    0x2d56(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   10b0 <open@plt>
test   %eax,%eax
js     1467 <main+0x2b7>
mov    %eax,%ebx
mov    %eax,%edi
lea    -0x58(%rbp),%rsi
call   10d0 <fstat@plt>
test   %eax,%eax
jne    1490 <main+0x2e0>
mov    -0x58(%rbp),%r15d
mov    0x2d55(%rip),%rax
mov    (%rax),%edx
mov    0x2cfc(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %r15d,%esi
mov    %ebx,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%r13
mov    0x2cd8(%rip),%rax
cmp    (%rax),%r13
je     13ef <main+0x23f>
mov    %ebx,%edi
call   1060 <close@plt>
mov    0x2d21(%rip),%rax
mov    (%rax),%esi
mov    0x2ce8(%rip),%rax
or     (%rax),%esi
mov    -0x50(%rbp),%edx
mov    %r12,%rdi
xor    %eax,%eax
call   10b0 <open@plt>
mov    %eax,%r12d
mov    %eax,%edi
lea    -0x68(%rbp),%rsi
call   10d0 <fstat@plt>
test   %eax,%eax
jne    14b6 <main+0x306>
mov    -0x64(%rbp),%ebx
lea    (%r15,%rbx,1),%eax
add    $0xffffffff,%eax
neg    %ebx
and    %eax,%ebx
mov    %r12d,%edi
mov    %ebx,%esi
call   1050 <ftruncate@plt>
test   %eax,%eax
js     14dd <main+0x32d>
mov    0x2c7c(%rip),%rax
mov    (%rax),%edx
mov    0x2cbb(%rip),%rax
or     (%rax),%edx
mov    0x2c9a(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %ebx,%esi
mov    %r12d,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbx
mov    0x2c3f(%rip),%rax
cmp    (%rax),%rbx
je     1504 <main+0x354>
mov    %r12d,%edi
call   1060 <close@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r15d,%edx
call   1090 <memcpy@plt>
mov    %r13,%rdi
mov    %r15d,%esi
call   10a0 <munmap@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
call   10a0 <munmap@plt>
mov    -0x38(%rbp),%rax
sub    $0x1,%rax
jb     1454 <main+0x2a4>
mov    %rax,-0x38(%rbp)
mov    0x2c39(%rip),%rax
mov    (%rax),%ebx
mov    -0x48(%rbp),%r13
mov    -0x40(%rbp),%rax
mov    0x0(%r13,%rax,8),%r15
mov    0x8(%r14),%rdi
add    $0x8,%r14
call   1080 <basename@plt>
mov    -0x30(%rbp),%r12
mov    %r12,%rdi
mov    %ebx,%esi
lea    0xc46(%rip),%rdx
mov    %r15,%rcx
mov    %rax,%r8
call   1040 <snprintf@plt>
mov    0x2bfb(%rip),%rcx
cmp    (%rcx),%eax
jl     1260 <main+0xb0>
jmp    141d <main+0x26d>
mov    0x2bba(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xc35(%rip),%rsi
mov    %r12,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xc73(%rip),%rdi
call   10c0 <perror@plt>
jmp    12c9 <main+0x119>
mov    0x2b8c(%rip),%rax
mov    (%rax),%ebx
mov    -0x40(%rbp),%rax
mov    0x0(%r13,%rax,8),%r15
mov    (%r14),%rdi
call   1080 <basename@plt>
lea    0xbe1(%rip),%rsi
mov    %ebx,%edi
mov    %r15,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%ebx
jmp    1456 <main+0x2a6>
xor    %ebx,%ebx
mov    %ebx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b42(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xbbd(%rip),%rsi
mov    %r12,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xbc9(%rip),%rdi
jmp    1529 <main+0x379>
mov    0x2b19(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xb94(%rip),%rsi
mov    %r12,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xbb6(%rip),%rdi
jmp    1529 <main+0x379>
mov    0x2af3(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xb6e(%rip),%rsi
mov    -0x30(%rbp),%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xbc0(%rip),%rdi
jmp    1529 <main+0x379>
mov    0x2acc(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xb47(%rip),%rsi
mov    -0x30(%rbp),%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xbba(%rip),%rdi
jmp    1529 <main+0x379>
mov    0x2aa5(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xb20(%rip),%rsi
mov    -0x30(%rbp),%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xbb2(%rip),%rdi
call   10c0 <perror@plt>
jmp    144d <main+0x29d>

LLVM IR (-O0):
%struct.stat = type { i32, i32, i32 }
@PATH_MAX = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"%s [SOURCE] [DIRECTORY]\0A\00"
@.str.1 = [6 x i8] c"%s/%s\00"
@.str.2 = [24 x i8] c"Name too long: '%s/%s'\0A\00"
@O_RDONLY = global i32 0
@.str.3 = [29 x i8] c"Failed to copy '%s' to '%s'\0A\00"
@.str.4 = [22 x i8] c"Could not open source\00"
@.str.5 = [28 x i8] c"failed to stat source file.\00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
@.str.6 = [21 x i8] c"Could not map source\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.7 = [27 x i8] c"Could not open destination\00"
@.str.8 = [33 x i8] c"failed to stat destination file.\00"
@.str.9 = [31 x i8] c"Could not truncate destination\00"
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@.str.10 = [26 x i8] c"Could not map destination\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 i64
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i64
%13 = alloca i64
%14 = alloca %struct.stat
%15 = alloca %struct.stat
%16 = alloca i32
%17 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%18 = load i32, i32* @PATH_MAX
%19 = add nsw i32 %18, 1
%20 = zext i32 %19 to i64
%21 = call i8* @llvm.stacksave()
store i8* %21, i8** %7
%22 = alloca i8, i64 %20
store i64 %20, i64* %8
%23 = load i32, i32* %4
%24 = sub nsw i32 %23, 1
%25 = sext i32 %24 to i64
store i64 %25, i64* %13
%26 = load i32, i32* %4
%27 = icmp slt i32 %26, 3
br i1 %27, label %28, label %34
28: ; preds = %2
%29 = load i32, i32* @stderr
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 0
%32 = load i8*, i8** %31
%33 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %32)
store i32 0, i32* %3
store i32 1, i32* %17
br label %210
34: ; preds = %2
store i64 1, i64* %12
br label %35
35: ; preds = %206, %34
%36 = load i64, i64* %12
%37 = load i64, i64* %13
%38 = icmp ult i64 %36, %37
br i1 %38, label %39, label %209
39: ; preds = %35
%40 = load i32, i32* @PATH_MAX
%41 = load i8**, i8*** %5
%42 = load i64, i64* %13
%43 = getelementptr inbounds i8*, i8** %41, i64 %42
%44 = load i8*, i8** %43
%45 = load i8**, i8*** %5
%46 = load i64, i64* %12
%47 = getelementptr inbounds i8*, i8** %45, i64 %46
%48 = load i8*, i8** %47
%49 = call i8* @basename(i8* %48)
%50 = call i32 @snprintf(i8* %22, i32 %40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %44, i8* %49)
store i32 %50, i32* %10
%51 = load i32, i32* %10
%52 = load i32, i32* @PATH_MAX
%53 = icmp sge i32 %51, %52
br i1 %53, label %54, label %66
54: ; preds = %39
%55 = load i32, i32* @stderr
%56 = load i8**, i8*** %5
%57 = load i64, i64* %13
%58 = getelementptr inbounds i8*, i8** %56, i64 %57
%59 = load i8*, i8** %58
%60 = load i8**, i8*** %5
%61 = load i64, i64* %12
%62 = getelementptr inbounds i8*, i8** %60, i64 %61
%63 = load i8*, i8** %62
%64 = call i8* @basename(i8* %63)
%65 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %59, i8* %64)
store i32 1, i32* %3
store i32 1, i32* %17
br label %210
66: ; preds = %39
%67 = load i8**, i8*** %5
%68 = load i64, i64* %12
%69 = getelementptr inbounds i8*, i8** %67, i64 %68
%70 = load i8*, i8** %69
%71 = load i32, i32* @O_RDONLY
%72 = call i32 (i8*, i32, ...) @open(i8* %70, i32 %71)
store i32 %72, i32* %11
%73 = load i32, i32* %11
%74 = icmp slt i32 %73, 0
br i1 %74, label %75, label %83
75: ; preds = %66
%76 = load i32, i32* @stderr
%77 = load i8**, i8*** %5
%78 = load i64, i64* %12
%79 = getelementptr inbounds i8*, i8** %77, i64 %78
%80 = load i8*, i8** %79
%81 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %80, i8* %22)
%82 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %17
br label %210
83: ; preds = %66
%84 = load i32, i32* %11
%85 = call i32 @fstat(i32 %84, %struct.stat* %14)
store i32 %85, i32* %10
%86 = load i32, i32* %10
%87 = icmp ne i32 %86, 0
br i1 %87, label %88, label %96
88: ; preds = %83
%89 = load i32, i32* @stderr
%90 = load i8**, i8*** %5
%91 = load i64, i64* %12
%92 = getelementptr inbounds i8*, i8** %90, i64 %91
%93 = load i8*, i8** %92
%94 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %89, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %93, i8* %22)
%95 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %17
br label %210
96: ; preds = %83
%97 = getelementptr inbounds %struct.stat, %struct.stat* %14, i32 0, i32 0
%98 = load i32, i32* %97
%99 = load i32, i32* @PROT_READ
%100 = load i32, i32* @MAP_PRIVATE
%101 = load i32, i32* %11
%102 = call i8* @mmap(i32* null, i32 %98, i32 %99, i32 %100, i32 %101, i32 0)
store i8* %102, i8** %6
%103 = load i8*, i8** %6
%104 = load i8*, i8** @MAP_FAILED
%105 = icmp eq i8* %103, %104
br i1 %105, label %106, label %114
106: ; preds = %96
%107 = load i32, i32* @stderr
%108 = load i8**, i8*** %5
%109 = load i64, i64* %12
%110 = getelementptr inbounds i8*, i8** %108, i64 %109
%111 = load i8*, i8** %110
%112 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %107, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %111, i8* %22)
%113 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
br label %114
114: ; preds = %106, %96
%115 = load i32, i32* %11
%116 = call i32 @close(i32 %115)
%117 = load i32, i32* @O_RDWR
%118 = load i32, i32* @O_CREAT
%119 = or i32 %117, %118
%120 = getelementptr inbounds %struct.stat, %struct.stat* %14, i32 0, i32 2
%121 = load i32, i32* %120
%122 = call i32 (i8*, i32, ...) @open(i8* %22, i32 %119, i32 %121)
store i32 %122, i32* %11
%123 = load i32, i32* %10
%124 = icmp slt i32 %123, 0
br i1 %124, label %125, label %133
125: ; preds = %114
%126 = load i32, i32* @stderr
%127 = load i8**, i8*** %5
%128 = load i64, i64* %12
%129 = getelementptr inbounds i8*, i8** %127, i64 %128
%130 = load i8*, i8** %129
%131 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %126, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %130, i8* %22)
%132 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %17
br label %210
133: ; preds = %114
%134 = load i32, i32* %11
%135 = call i32 @fstat(i32 %134, %struct.stat* %15)
store i32 %135, i32* %10
%136 = load i32, i32* %10
%137 = icmp ne i32 %136, 0
br i1 %137, label %138, label %146
138: ; preds = %133
%139 = load i32, i32* @stderr
%140 = load i8**, i8*** %5
%141 = load i64, i64* %12
%142 = getelementptr inbounds i8*, i8** %140, i64 %141
%143 = load i8*, i8** %142
%144 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %139, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %143, i8* %22)
%145 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %17
br label %210
146: ; preds = %133
%147 = getelementptr inbounds %struct.stat, %struct.stat* %14, i32 0, i32 0
%148 = load i32, i32* %147
%149 = getelementptr inbounds %struct.stat, %struct.stat* %15, i32 0, i32 1
%150 = load i32, i32* %149
%151 = add nsw i32 %148, %150
%152 = sub nsw i32 %151, 1
%153 = getelementptr inbounds %struct.stat, %struct.stat* %15, i32 0, i32 1
%154 = load i32, i32* %153
%155 = sub nsw i32 %154, 1
%156 = xor i32 %155, -1
%157 = and i32 %152, %156
store i32 %157, i32* %16
%158 = load i32, i32* %11
%159 = load i32, i32* %16
%160 = call i32 @ftruncate(i32 %158, i32 %159)
store i32 %160, i32* %10
%161 = load i32, i32* %10
%162 = icmp slt i32 %161, 0
br i1 %162, label %163, label %171
163: ; preds = %146
%164 = load i32, i32* @stderr
%165 = load i8**, i8*** %5
%166 = load i64, i64* %12
%167 = getelementptr inbounds i8*, i8** %165, i64 %166
%168 = load i8*, i8** %167
%169 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %164, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %168, i8* %22)
%170 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %17
br label %210
171: ; preds = %146
%172 = load i32, i32* %16
%173 = load i32, i32* @PROT_READ
%174 = load i32, i32* @PROT_WRITE
%175 = or i32 %173, %174
%176 = load i32, i32* @MAP_SHARED
%177 = load i32, i32* %11
%178 = call i8* @mmap(i32* null, i32 %172, i32 %175, i32 %176, i32 %177, i32 0)
store i8* %178, i8** %9
%179 = load i8*, i8** %9
%180 = load i8*, i8** @MAP_FAILED
%181 = icmp eq i8* %179, %180
br i1 %181, label %182, label %190
182: ; preds = %171
%183 = load i32, i32* @stderr
%184 = load i8**, i8*** %5
%185 = load i64, i64* %12
%186 = getelementptr inbounds i8*, i8** %184, i64 %185
%187 = load i8*, i8** %186
%188 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %183, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %187, i8* %22)
%189 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %17
br label %210
190: ; preds = %171
%191 = load i32, i32* %11
%192 = call i32 @close(i32 %191)
%193 = load i8*, i8** %9
%194 = load i8*, i8** %6
%195 = getelementptr inbounds %struct.stat, %struct.stat* %14, i32 0, i32 0
%196 = load i32, i32* %195
%197 = call i32 @memcpy(i8* %193, i8* %194, i32 %196)
%198 = load i8*, i8** %6
%199 = getelementptr inbounds %struct.stat, %struct.stat* %14, i32 0, i32 0
%200 = load i32, i32* %199
%201 = call i32 @munmap(i8* %198, i32 %200)
%202 = load i8*, i8** %9
%203 = getelementptr inbounds %struct.stat, %struct.stat* %14, i32 0, i32 0
%204 = load i32, i32* %203
%205 = call i32 @munmap(i8* %202, i32 %204)
br label %206
206: ; preds = %190
%207 = load i64, i64* %12
%208 = add i64 %207, 1
store i64 %208, i64* %12
br label %35
209: ; preds = %35
store i32 0, i32* %17
br label %210
210: ; preds = %209, %182, %163, %138, %125, %88, %75, %54, %28
%211 = load i8*, i8** %7
%212 = load i32, i32* %17
switch i32 %212, label %215 [
i32 0, label %213
i32 1, label %213
]
213: ; preds = %210, %210
%214 = load i32, i32* %3
ret i32 %214
215: ; preds = %210
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i32, i32, i32 }
@PATH_MAX = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"%s [SOURCE] [DIRECTORY]\0A\00"
@.str.1 = [6 x i8] c"%s/%s\00"
@.str.2 = [24 x i8] c"Name too long: '%s/%s'\0A\00"
@O_RDONLY = global i32 0
@.str.3 = [29 x i8] c"Failed to copy '%s' to '%s'\0A\00"
@.str.4 = [22 x i8] c"Could not open source\00"
@.str.5 = [28 x i8] c"failed to stat source file.\00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
@.str.6 = [21 x i8] c"Could not map source\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.8 = [33 x i8] c"failed to stat destination file.\00"
@.str.9 = [31 x i8] c"Could not truncate destination\00"
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@.str.10 = [26 x i8] c"Could not map destination\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = alloca %struct.stat
%5 = load i32, i32* @PATH_MAX
%6 = add nsw i32 %5, 1
%7 = zext i32 %6 to i64
%8 = alloca i8, i64 %7
%9 = add nsw i32 %0, -1
%10 = sext i32 %9 to i64
%11 = bitcast %struct.stat* %3 to i8*
%12 = bitcast %struct.stat* %4 to i8*
%13 = icmp slt i32 %0, 3
br i1 %13, label %26, label %14
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 %10
%16 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%17 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 2
%18 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 1
%19 = load i8*, i8** %15
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = call i8* @basename(i8* %21)
%23 = call i32 @snprintf(i8* %8, i32 %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %19, i8* %22)
%24 = load i32, i32* @PATH_MAX
%25 = icmp slt i32 %23, %24
br i1 %25, label %37, label %30
26: ; preds = %2
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %1
%29 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %28)
br label %125
30: ; preds = %116, %14
%31 = phi i8** [ %20, %14 ], [ %119, %116 ]
%32 = load i32, i32* @stderr
%33 = load i8*, i8** %15
%34 = load i8*, i8** %31
%35 = call i8* @basename(i8* %34)
%36 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %33, i8* %35)
br label %125
37: ; preds = %14, %116
%38 = phi i8** [ %119, %116 ], [ %20, %14 ]
%39 = phi i64 [ %114, %116 ], [ 1, %14 ]
%40 = load i8*, i8** %38
%41 = load i32, i32* @O_RDONLY
%42 = call i32 (i8*, i32, ...) @open(i8* %40, i32 %41)
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %49
44: ; preds = %37
%45 = load i32, i32* @stderr
%46 = load i8*, i8** %38
%47 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %46, i8* %8)
%48 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
br label %125
49: ; preds = %37
%50 = call i32 @fstat(i32 %42, %struct.stat* %3)
%51 = icmp eq i32 %50, 0
br i1 %51, label %57, label %52
52: ; preds = %49
%53 = load i32, i32* @stderr
%54 = load i8*, i8** %38
%55 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %54, i8* %8)
%56 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %125
57: ; preds = %49
%58 = load i32, i32* %16
%59 = load i32, i32* @PROT_READ
%60 = load i32, i32* @MAP_PRIVATE
%61 = call i8* @mmap(i32* null, i32 %58, i32 %59, i32 %60, i32 %42, i32 0)
%62 = load i8*, i8** @MAP_FAILED
%63 = icmp eq i8* %61, %62
br i1 %63, label %64, label %69
64: ; preds = %57
%65 = load i32, i32* @stderr
%66 = load i8*, i8** %38
%67 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %66, i8* %8)
%68 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
br label %69
69: ; preds = %64, %57
%70 = call i32 @close(i32 %42)
%71 = load i32, i32* @O_RDWR
%72 = load i32, i32* @O_CREAT
%73 = or i32 %72, %71
%74 = load i32, i32* %17
%75 = call i32 (i8*, i32, ...) @open(i8* %8, i32 %73, i32 %74)
%76 = call i32 @fstat(i32 %75, %struct.stat* %4)
%77 = icmp eq i32 %76, 0
br i1 %77, label %83, label %78
78: ; preds = %69
%79 = load i32, i32* @stderr
%80 = load i8*, i8** %38
%81 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %80, i8* %8)
%82 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0))
br label %125
83: ; preds = %69
%84 = load i32, i32* %18
%85 = add i32 %58, -1
%86 = add i32 %85, %84
%87 = sub i32 0, %84
%88 = and i32 %86, %87
%89 = call i32 @ftruncate(i32 %75, i32 %88)
%90 = icmp slt i32 %89, 0
br i1 %90, label %91, label %96
91: ; preds = %83
%92 = load i32, i32* @stderr
%93 = load i8*, i8** %38
%94 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %92, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %93, i8* %8)
%95 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0))
br label %125
96: ; preds = %83
%97 = load i32, i32* @PROT_READ
%98 = load i32, i32* @PROT_WRITE
%99 = or i32 %98, %97
%100 = load i32, i32* @MAP_SHARED
%101 = call i8* @mmap(i32* null, i32 %88, i32 %99, i32 %100, i32 %75, i32 0)
%102 = load i8*, i8** @MAP_FAILED
%103 = icmp eq i8* %101, %102
br i1 %103, label %104, label %109
104: ; preds = %96
%105 = load i32, i32* @stderr
%106 = load i8*, i8** %38
%107 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %105, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %106, i8* %8)
%108 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0))
br label %125
109: ; preds = %96
%110 = call i32 @close(i32 %75)
%111 = call i32 @memcpy(i8* %101, i8* %61, i32 %58)
%112 = call i32 @munmap(i8* %61, i32 %58)
%113 = call i32 @munmap(i8* %101, i32 %58)
%114 = add nuw i64 %39, 1
%115 = icmp eq i64 %114, %10
br i1 %115, label %125, label %116
116: ; preds = %109
%117 = load i32, i32* @PATH_MAX
%118 = load i8*, i8** %15
%119 = getelementptr inbounds i8*, i8** %1, i64 %114
%120 = load i8*, i8** %119
%121 = call i8* @basename(i8* %120)
%122 = call i32 @snprintf(i8* %8, i32 %117, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %118, i8* %121)
%123 = load i32, i32* @PATH_MAX
%124 = icmp slt i32 %122, %123
br i1 %124, label %37, label %30
125: ; preds = %109, %104, %91, %78, %52, %44, %30, %26
%126 = phi i32 [ 0, %26 ], [ 1, %30 ], [ 1, %44 ], [ 1, %52 ], [ 1, %78 ], [ 1, %91 ], [ 1, %104 ], [ 0, %109 ]
ret i32 %126
}