#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 scalar_t__ ssize_t;
typedef int /*<<< orphan*/ src_file;
typedef int /*<<< orphan*/ dst_file;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EIO;
int PATH_MAX;
char *calloc(int, size_t);
int copy_fd_to_fd(int /*<<< orphan*/, int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ *freopen(char *, char *, int /*<<< orphan*/ *);
size_t fwrite(char const *, int, size_t, int /*<<< orphan*/ *);
scalar_t__ memcmp(char const *, char *, size_t);
scalar_t__ simple_io_read_whole_file_zt(char *, char *, size_t);
int /*<<< orphan*/ stderr;
size_t strlen(char const *);
int zsnprintf(char *, int, char *, char const *, int);
int test_copy_fd_to_fd(const char *tempdir, int *next_id, const char *buf) {
  size_t buf_len = strlen(buf);
  ssize_t res;
  char *nbuf, src_file[PATH_MAX], dst_file[PATH_MAX];
  FILE *ifp, *ofp;
  int ret;
  do {
    int __my_ret__ = zsnprintf(src_file, sizeof(src_file), "%s/src_file.%d",
                               tempdir, *next_id);
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 76,
              "zsnprintf(src_file, sizeof(src_file), \"%s/src_file.%d\", "
              "tempdir, *next_id)");
      return __my_ret__;
    }
  } while (0);
  ;
  do {
    int __my_ret__ = zsnprintf(dst_file, sizeof(dst_file), "%s/dst_file.%d",
                               tempdir, *next_id);
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 78,
              "zsnprintf(dst_file, sizeof(dst_file), \"%s/dst_file.%d\", "
              "tempdir, *next_id)");
      return __my_ret__;
    }
  } while (0);
  ;
  *next_id = *next_id + 1;
  ifp = fopen(src_file, "w");
  if (!ifp) {
    ret = errno;
    return ret;
  }
  do {
    if (fwrite(buf, 1, buf_len, ifp) != buf_len) {
      fprintf(stderr, "failed on line %d: %s\n", 86,
              "fwrite(buf, 1, buf_len, ifp)");
      return 1;
    }
  } while (0);
  ;
  ifp = freopen(src_file, "r", ifp);
  if (!ifp) {
    ret = errno;
    return ret;
  }
  ofp = fopen(dst_file, "w");
  if (!ofp) {
    ret = errno;
    fclose(ifp);
    return ret;
  }
  ret = copy_fd_to_fd(fileno(ifp), fileno(ofp));
  do {
    int __my_ret__ = ret;
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 99, "ret");
      return __my_ret__;
    }
  } while (0);
  ;
  fclose(ofp);
  fclose(ifp);
  nbuf = calloc(1, buf_len + 1);
  do {
    if (nbuf == NULL) {
      fprintf(stderr, "failed on line %d: %s\n", 104, "nbuf");
      return 1;
    }
  } while (0);
  ;
  res = simple_io_read_whole_file_zt(dst_file, nbuf, buf_len + 1);
  if (res < 0) {
    free(nbuf);
    return res;
  }
  if ((res > 0) && (memcmp(buf, nbuf, buf_len - 1))) {
    free(nbuf);
    return -EIO;
  }
  free(nbuf);
  return 0;
}


x86 assembly (clang, -O0):
<test_copy_fd_to_fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    0x2df5(%rip),%rax
mov    (%rax),%ecx
mov    %rcx,-0x98(%rbp)
mov    %rsp,%rdx
mov    %rdx,-0x40(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x90(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x48(%rbp)
mov    (%rax),%eax
mov    %rax,-0x88(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x80(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x50(%rbp)
mov    -0x90(%rbp),%rdi
mov    -0x98(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    (%rax),%r8d
lea    0xd8f(%rip),%rdx
call   10d0 <zsnprintf@plt>
mov    %eax,-0x68(%rbp)
cmpl   $0x0,-0x68(%rbp)
je     12b6 <test_copy_fd_to_fd+0xe6>
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
lea    0xd7c(%rip),%rsi
mov    $0x4c,%edx
lea    0xd87(%rip),%rcx
call   10b0 <fprintf@plt>
mov    -0x68(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x6c(%rbp)
jmp    15f9 <test_copy_fd_to_fd+0x429>
jmp    12bb <test_copy_fd_to_fd+0xeb>
jmp    12c0 <test_copy_fd_to_fd+0xf0>
jmp    12c5 <test_copy_fd_to_fd+0xf5>
mov    -0x80(%rbp),%rdi
mov    -0x88(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    (%rax),%r8d
lea    0xd8d(%rip),%rdx
call   10d0 <zsnprintf@plt>
mov    %eax,-0x70(%rbp)
cmpl   $0x0,-0x70(%rbp)
je     1329 <test_copy_fd_to_fd+0x159>
mov    0x2cd3(%rip),%rax
mov    (%rax),%edi
lea    0xd09(%rip),%rsi
mov    $0x4e,%edx
lea    0xd6e(%rip),%rcx
call   10b0 <fprintf@plt>
mov    -0x70(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x6c(%rbp)
jmp    15f9 <test_copy_fd_to_fd+0x429>
jmp    132e <test_copy_fd_to_fd+0x15e>
jmp    1333 <test_copy_fd_to_fd+0x163>
mov    -0x90(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
lea    0xd7b(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    1382 <test_copy_fd_to_fd+0x1b2>
mov    0x2c5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x6c(%rbp)
jmp    15f9 <test_copy_fd_to_fd+0x429>
jmp    1387 <test_copy_fd_to_fd+0x1b7>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x58(%rbp),%rcx
mov    $0x1,%esi
call   10f0 <fwrite@plt>
cmp    -0x28(%rbp),%rax
je     13db <test_copy_fd_to_fd+0x20b>
mov    0x2c22(%rip),%rax
mov    (%rax),%edi
lea    0xc58(%rip),%rsi
mov    $0x56,%edx
lea    0xd0a(%rip),%rcx
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x6c(%rbp)
jmp    15f9 <test_copy_fd_to_fd+0x429>
jmp    13e0 <test_copy_fd_to_fd+0x210>
jmp    13e5 <test_copy_fd_to_fd+0x215>
mov    -0x90(%rbp),%rdi
mov    -0x58(%rbp),%rdx
lea    0xcf3(%rip),%rsi
call   1080 <freopen@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    1429 <test_copy_fd_to_fd+0x259>
mov    0x2bb6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x6c(%rbp)
jmp    15f9 <test_copy_fd_to_fd+0x429>
mov    -0x80(%rbp),%rdi
lea    0xc97(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
jne    146f <test_copy_fd_to_fd+0x29f>
mov    0x2b79(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    -0x58(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x64(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x6c(%rbp)
jmp    15f9 <test_copy_fd_to_fd+0x429>
mov    -0x58(%rbp),%rdi
call   10c0 <fileno@plt>
mov    %eax,-0x9c(%rbp)
mov    -0x60(%rbp),%rdi
call   10c0 <fileno@plt>
mov    -0x9c(%rbp),%edi
mov    %eax,%esi
call   1040 <copy_fd_to_fd@plt>
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%eax
mov    %eax,-0x74(%rbp)
cmpl   $0x0,-0x74(%rbp)
je     14da <test_copy_fd_to_fd+0x30a>
mov    0x2b22(%rip),%rax
mov    (%rax),%edi
lea    0xb58(%rip),%rsi
mov    $0x63,%edx
lea    0xc29(%rip),%rcx
call   10b0 <fprintf@plt>
mov    -0x74(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x6c(%rbp)
jmp    15f9 <test_copy_fd_to_fd+0x429>
jmp    14df <test_copy_fd_to_fd+0x30f>
jmp    14e4 <test_copy_fd_to_fd+0x314>
mov    -0x60(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x58(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rsi
add    $0x1,%rsi
mov    $0x1,%edi
call   10a0 <calloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    154b <test_copy_fd_to_fd+0x37b>
mov    0x2ab2(%rip),%rax
mov    (%rax),%edi
lea    0xae8(%rip),%rsi
mov    $0x68,%edx
lea    0xbbd(%rip),%rcx
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x6c(%rbp)
jmp    15f9 <test_copy_fd_to_fd+0x429>
jmp    1550 <test_copy_fd_to_fd+0x380>
jmp    1555 <test_copy_fd_to_fd+0x385>
mov    -0x80(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x28(%rbp),%rdx
add    $0x1,%rdx
call   1070 <simple_io_read_whole_file_zt@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jge    1595 <test_copy_fd_to_fd+0x3c5>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x6c(%rbp)
jmp    15f9 <test_copy_fd_to_fd+0x429>
cmpq   $0x0,-0x30(%rbp)
jle    15e2 <test_copy_fd_to_fd+0x412>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x28(%rbp),%rdx
sub    $0x1,%rdx
call   1090 <memcmp@plt>
cmp    $0x0,%rax
je     15e2 <test_copy_fd_to_fd+0x412>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
mov    0x2a07(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x6c(%rbp)
jmp    15f9 <test_copy_fd_to_fd+0x429>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x6c(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_copy_fd_to_fd>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
mov    %rdi,%r13
mov    %rdx,-0x38(%rbp)
mov    %rdx,%rdi
call   1060 <strlen@plt>
mov    %rax,-0x48(%rbp)
mov    0x2df2(%rip),%rax
mov    (%rax),%r12d
mov    %rsp,%r15
mov    %r12,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    %rsp,%r14
sub    %rax,%r14
mov    %r14,%rsp
mov    %rbx,-0x40(%rbp)
mov    (%rbx),%r8d
lea    0xdd4(%rip),%rdx
mov    %r15,%rdi
mov    %r12d,%esi
mov    %r13,-0x30(%rbp)
mov    %r13,%rcx
call   10d0 <zsnprintf@plt>
test   %eax,%eax
je     126b <test_copy_fd_to_fd+0x9b>
mov    %rax,%rbx
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
lea    0xdba(%rip),%rsi
lea    0xdca(%rip),%rcx
mov    $0x4c,%edx
call   10b0 <fprintf@plt>
mov    %rbx,%r12
jmp    12b4 <test_copy_fd_to_fd+0xe4>
mov    -0x38(%rbp),%r13
mov    -0x40(%rbp),%rax
mov    (%rax),%r8d
lea    0xdf4(%rip),%rdx
mov    %r14,%rdi
mov    %r12d,%esi
mov    -0x30(%rbp),%rcx
call   10d0 <zsnprintf@plt>
test   %eax,%eax
je     12c6 <test_copy_fd_to_fd+0xf6>
mov    %eax,%r12d
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
lea    0xd6c(%rip),%rsi
lea    0xdd6(%rip),%rcx
mov    $0x4e,%edx
call   10b0 <fprintf@plt>
mov    %r12d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,-0x30(%rbp)
mov    -0x40(%rbp),%rax
addl   $0x1,(%rax)
lea    0xdf3(%rip),%rsi
mov    %r15,%rdi
call   10e0 <fopen@plt>
test   %rax,%rax
je     1389 <test_copy_fd_to_fd+0x1b9>
mov    %rax,%r14
mov    $0x1,%r12d
mov    %r13,%rdi
mov    $0x1,%esi
mov    -0x48(%rbp),%r13
mov    %r13,%rdx
mov    %rax,%rcx
call   10f0 <fwrite@plt>
cmp    %r13,%rax
jne    1398 <test_copy_fd_to_fd+0x1c8>
lea    0xdd1(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
call   1080 <freopen@plt>
test   %rax,%rax
je     1389 <test_copy_fd_to_fd+0x1b9>
mov    %rax,%rbx
lea    0xd98(%rip),%rsi
mov    -0x30(%rbp),%rdi
call   10e0 <fopen@plt>
test   %rax,%rax
je     13b9 <test_copy_fd_to_fd+0x1e9>
mov    %rax,%r14
mov    %rbx,%rdi
call   10c0 <fileno@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   10c0 <fileno@plt>
mov    %r15d,%edi
mov    %eax,%esi
call   1040 <copy_fd_to_fd@plt>
test   %eax,%eax
je     13d0 <test_copy_fd_to_fd+0x200>
mov    %eax,%r12d
mov    0x2c61(%rip),%rax
mov    (%rax),%edi
lea    0xc97(%rip),%rsi
lea    0xd6d(%rip),%rcx
mov    $0x63,%edx
jmp    12af <test_copy_fd_to_fd+0xdf>
mov    0x2c38(%rip),%rax
mov    (%rax),%r12d
jmp    12b4 <test_copy_fd_to_fd+0xe4>
mov    0x2c31(%rip),%rax
mov    (%rax),%edi
lea    0xc67(%rip),%rsi
lea    0xd1e(%rip),%rcx
mov    $0x56,%edx
jmp    12af <test_copy_fd_to_fd+0xdf>
mov    0x2c08(%rip),%rax
mov    (%rax),%r12d
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    12b4 <test_copy_fd_to_fd+0xe4>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0x1(%r13),%rbx
mov    $0x1,%r12d
mov    $0x1,%edi
mov    %rbx,%rsi
call   10a0 <calloc@plt>
test   %rax,%rax
je     1447 <test_copy_fd_to_fd+0x277>
mov    %rax,%r14
mov    -0x30(%rbp),%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1070 <simple_io_read_whole_file_zt@plt>
test   %rax,%rax
js     1468 <test_copy_fd_to_fd+0x298>
je     1478 <test_copy_fd_to_fd+0x2a8>
add    $0xffffffffffffffff,%r13
mov    -0x38(%rbp),%rdi
mov    %r14,%rsi
mov    %r13,%rdx
call   1090 <memcmp@plt>
test   %rax,%rax
je     1478 <test_copy_fd_to_fd+0x2a8>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x2b9c(%rip),%rax
xor    %r12d,%r12d
sub    (%rax),%r12d
jmp    12b4 <test_copy_fd_to_fd+0xe4>
mov    0x2b82(%rip),%rax
mov    (%rax),%edi
lea    0xbb8(%rip),%rsi
lea    0xc92(%rip),%rcx
mov    $0x68,%edx
jmp    12af <test_copy_fd_to_fd+0xdf>
mov    %rax,%r12
mov    %r14,%rdi
call   1030 <free@plt>
jmp    12b4 <test_copy_fd_to_fd+0xe4>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %r12d,%r12d
jmp    12b4 <test_copy_fd_to_fd+0xe4>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [15 x i8] c"%s/src_file.%d\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"failed on line %d: %s\0A\00"
@.str.2 = [75 x i8] c"zsnprintf(src_file, sizeof(src_file), \22%s/src_file.%d\22, tempdir, *next_id)\00"
@.str.3 = [15 x i8] c"%s/dst_file.%d\00"
@.str.4 = [75 x i8] c"zsnprintf(dst_file, sizeof(dst_file), \22%s/dst_file.%d\22, tempdir, *next_id)\00"
@.str.5 = [2 x i8] c"w\00"
@errno = global i32 0
@.str.6 = [29 x i8] c"fwrite(buf, 1, buf_len, ifp)\00"
@.str.7 = [2 x i8] c"r\00"
@.str.8 = [4 x i8] c"ret\00"
@.str.9 = [5 x i8] c"nbuf\00"
@EIO = global i32 0
define i32 @test_copy_fd_to_fd(i8* %0, i32* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i64
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i8* %2, i8** %7
%21 = load i8*, i8** %7
%22 = call i64 @strlen(i8* %21)
store i64 %22, i64* %8
%23 = load i32, i32* @PATH_MAX
%24 = zext i32 %23 to i64
%25 = call i8* @llvm.stacksave()
store i8* %25, i8** %11
%26 = alloca i8, i64 %24
store i64 %24, i64* %12
%27 = load i32, i32* @PATH_MAX
%28 = zext i32 %27 to i64
%29 = alloca i8, i64 %28
store i64 %28, i64* %13
br label %30
30: ; preds = %3
%31 = trunc i64 %24 to i32
%32 = load i8*, i8** %5
%33 = load i32*, i32** %6
%34 = load i32, i32* %33
%35 = call i32 @zsnprintf(i8* %26, i32 %31, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %32, i32 %34)
store i32 %35, i32* %17
%36 = load i32, i32* %17
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %30
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 76, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.2, i64 0, i64 0))
%41 = load i32, i32* %17
store i32 %41, i32* %4
store i32 1, i32* %18
br label %162
42: ; preds = %30
br label %43
43: ; preds = %42
br label %44
44: ; preds = %43
br label %45
45: ; preds = %44
%46 = trunc i64 %28 to i32
%47 = load i8*, i8** %5
%48 = load i32*, i32** %6
%49 = load i32, i32* %48
%50 = call i32 @zsnprintf(i8* %29, i32 %46, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %47, i32 %49)
store i32 %50, i32* %19
%51 = load i32, i32* %19
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %57
53: ; preds = %45
%54 = load i32, i32* @stderr
%55 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 78, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.4, i64 0, i64 0))
%56 = load i32, i32* %19
store i32 %56, i32* %4
store i32 1, i32* %18
br label %162
57: ; preds = %45
br label %58
58: ; preds = %57
br label %59
59: ; preds = %58
%60 = load i32*, i32** %6
%61 = load i32, i32* %60
%62 = add nsw i32 %61, 1
%63 = load i32*, i32** %6
store i32 %62, i32* %63
%64 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %64, i32** %14
%65 = load i32*, i32** %14
%66 = icmp ne i32* %65, null
br i1 %66, label %70, label %67
67: ; preds = %59
%68 = load i32, i32* @errno
store i32 %68, i32* %16
%69 = load i32, i32* %16
store i32 %69, i32* %4
store i32 1, i32* %18
br label %162
70: ; preds = %59
br label %71
71: ; preds = %70
%72 = load i8*, i8** %7
%73 = load i64, i64* %8
%74 = load i32*, i32** %14
%75 = call i64 @fwrite(i8* %72, i32 1, i64 %73, i32* %74)
%76 = load i64, i64* %8
%77 = icmp ne i64 %75, %76
br i1 %77, label %78, label %81
78: ; preds = %71
%79 = load i32, i32* @stderr
%80 = call i32 @fprintf(i32 %79, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 86, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %4
store i32 1, i32* %18
br label %162
81: ; preds = %71
br label %82
82: ; preds = %81
br label %83
83: ; preds = %82
%84 = load i32*, i32** %14
%85 = call i32* @freopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), i32* %84)
store i32* %85, i32** %14
%86 = load i32*, i32** %14
%87 = icmp ne i32* %86, null
br i1 %87, label %91, label %88
88: ; preds = %83
%89 = load i32, i32* @errno
store i32 %89, i32* %16
%90 = load i32, i32* %16
store i32 %90, i32* %4
store i32 1, i32* %18
br label %162
91: ; preds = %83
%92 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %92, i32** %15
%93 = load i32*, i32** %15
%94 = icmp ne i32* %93, null
br i1 %94, label %100, label %95
95: ; preds = %91
%96 = load i32, i32* @errno
store i32 %96, i32* %16
%97 = load i32*, i32** %14
%98 = call i32 @fclose(i32* %97)
%99 = load i32, i32* %16
store i32 %99, i32* %4
store i32 1, i32* %18
br label %162
100: ; preds = %91
%101 = load i32*, i32** %14
%102 = call i32 @fileno(i32* %101)
%103 = load i32*, i32** %15
%104 = call i32 @fileno(i32* %103)
%105 = call i32 @copy_fd_to_fd(i32 %102, i32 %104)
store i32 %105, i32* %16
br label %106
106: ; preds = %100
%107 = load i32, i32* %16
store i32 %107, i32* %20
%108 = load i32, i32* %20
%109 = icmp ne i32 %108, 0
br i1 %109, label %110, label %114
110: ; preds = %106
%111 = load i32, i32* @stderr
%112 = call i32 @fprintf(i32 %111, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 99, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%113 = load i32, i32* %20
store i32 %113, i32* %4
store i32 1, i32* %18
br label %162
114: ; preds = %106
br label %115
115: ; preds = %114
br label %116
116: ; preds = %115
%117 = load i32*, i32** %15
%118 = call i32 @fclose(i32* %117)
%119 = load i32*, i32** %14
%120 = call i32 @fclose(i32* %119)
%121 = load i64, i64* %8
%122 = add i64 %121, 1
%123 = call i8* @calloc(i32 1, i64 %122)
store i8* %123, i8** %10
br label %124
124: ; preds = %116
%125 = load i8*, i8** %10
%126 = icmp eq i8* %125, null
br i1 %126, label %127, label %130
127: ; preds = %124
%128 = load i32, i32* @stderr
%129 = call i32 @fprintf(i32 %128, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 104, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
store i32 1, i32* %4
store i32 1, i32* %18
br label %162
130: ; preds = %124
br label %131
131: ; preds = %130
br label %132
132: ; preds = %131
%133 = load i8*, i8** %10
%134 = load i64, i64* %8
%135 = add i64 %134, 1
%136 = call i64 @simple_io_read_whole_file_zt(i8* %29, i8* %133, i64 %135)
store i64 %136, i64* %9
%137 = load i64, i64* %9
%138 = icmp slt i64 %137, 0
br i1 %138, label %139, label %144
139: ; preds = %132
%140 = load i8*, i8** %10
%141 = call i32 @free(i8* %140)
%142 = load i64, i64* %9
%143 = trunc i64 %142 to i32
store i32 %143, i32* %4
store i32 1, i32* %18
br label %162
144: ; preds = %132
%145 = load i64, i64* %9
%146 = icmp sgt i64 %145, 0
br i1 %146, label %147, label %159
147: ; preds = %144
%148 = load i8*, i8** %7
%149 = load i8*, i8** %10
%150 = load i64, i64* %8
%151 = sub i64 %150, 1
%152 = call i64 @memcmp(i8* %148, i8* %149, i64 %151)
%153 = icmp ne i64 %152, 0
br i1 %153, label %154, label %159
154: ; preds = %147
%155 = load i8*, i8** %10
%156 = call i32 @free(i8* %155)
%157 = load i32, i32* @EIO
%158 = sub nsw i32 0, %157
store i32 %158, i32* %4
store i32 1, i32* %18
br label %162
159: ; preds = %147, %144
%160 = load i8*, i8** %10
%161 = call i32 @free(i8* %160)
store i32 0, i32* %4
store i32 1, i32* %18
br label %162
162: ; preds = %159, %154, %139, %127, %110, %95, %88, %78, %67, %53, %38
%163 = load i8*, i8** %11
%164 = load i32, i32* %4
ret i32 %164
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [15 x i8] c"%s/src_file.%d\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"failed on line %d: %s\0A\00"
@.str.2 = [75 x i8] c"zsnprintf(src_file, sizeof(src_file), \22%s/src_file.%d\22, tempdir, *next_id)\00"
@.str.3 = [15 x i8] c"%s/dst_file.%d\00"
@.str.4 = [75 x i8] c"zsnprintf(dst_file, sizeof(dst_file), \22%s/dst_file.%d\22, tempdir, *next_id)\00"
@.str.5 = [2 x i8] c"w\00"
@errno = global i32 0
@.str.6 = [29 x i8] c"fwrite(buf, 1, buf_len, ifp)\00"
@.str.7 = [2 x i8] c"r\00"
@.str.8 = [4 x i8] c"ret\00"
@.str.9 = [5 x i8] c"nbuf\00"
@EIO = global i32 0
define i32 @test_copy_fd_to_fd(i8* %0, i32* nocapture %1, i8* %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%5 = load i32, i32* @PATH_MAX
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = alloca i8, i64 %6
%9 = load i32, i32* %1
%10 = call i32 @zsnprintf(i8* %7, i32 %5, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %3
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 76, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.2, i64 0, i64 0))
br label %81
15: ; preds = %3
%16 = load i32, i32* %1
%17 = call i32 @zsnprintf(i8* %8, i32 %5, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %0, i32 %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 78, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.4, i64 0, i64 0))
br label %81
22: ; preds = %15
%23 = load i32, i32* %1
%24 = add nsw i32 %23, 1
store i32 %24, i32* %1
%25 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = load i32, i32* @errno
br label %81
29: ; preds = %22
%30 = call i64 @fwrite(i8* %2, i32 1, i64 %4, i32* %25)
%31 = icmp eq i64 %30, %4
br i1 %31, label %35, label %32
32: ; preds = %29
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 86, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
br label %81
35: ; preds = %29
%36 = call i32* @freopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), i32* %25)
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = load i32, i32* @errno
br label %81
40: ; preds = %35
%41 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%42 = icmp eq i32* %41, null
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = load i32, i32* @errno
%45 = call i32 @fclose(i32* %36)
br label %81
46: ; preds = %40
%47 = call i32 @fileno(i32* %36)
%48 = call i32 @fileno(i32* %41)
%49 = call i32 @copy_fd_to_fd(i32 %47, i32 %48)
%50 = icmp eq i32 %49, 0
br i1 %50, label %54, label %51
51: ; preds = %46
%52 = load i32, i32* @stderr
%53 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 99, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
br label %81
54: ; preds = %46
%55 = call i32 @fclose(i32* %41)
%56 = call i32 @fclose(i32* %36)
%57 = add i64 %4, 1
%58 = call i8* @calloc(i32 1, i64 %57)
%59 = icmp eq i8* %58, null
br i1 %59, label %60, label %63
60: ; preds = %54
%61 = load i32, i32* @stderr
%62 = call i32 @fprintf(i32 %61, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 104, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
br label %81
63: ; preds = %54
%64 = call i64 @simple_io_read_whole_file_zt(i8* %8, i8* %58, i64 %57)
%65 = icmp slt i64 %64, 0
br i1 %65, label %66, label %69
66: ; preds = %63
%67 = call i32 @free(i8* %58)
%68 = trunc i64 %64 to i32
br label %81
69: ; preds = %63
%70 = icmp eq i64 %64, 0
br i1 %70, label %79, label %71
71: ; preds = %69
%72 = add i64 %4, -1
%73 = call i64 @memcmp(i8* %2, i8* %58, i64 %72)
%74 = icmp eq i64 %73, 0
br i1 %74, label %79, label %75
75: ; preds = %71
%76 = call i32 @free(i8* %58)
%77 = load i32, i32* @EIO
%78 = sub nsw i32 0, %77
br label %81
79: ; preds = %71, %69
%80 = call i32 @free(i8* %58)
br label %81
81: ; preds = %51, %19, %12, %79, %75, %66, %60, %43, %38, %32, %27
%82 = phi i32 [ 1, %32 ], [ 1, %60 ], [ %68, %66 ], [ %78, %75 ], [ 0, %79 ], [ %49, %51 ], [ %44, %43 ], [ %39, %38 ], [ %28, %27 ], [ %17, %19 ], [ %10, %12 ]
ret i32 %82
}