#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ tempdir;

/* Variables and functions */
int EXIT_SUCCESS;
int PATH_MAX;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int /*<<< orphan*/ free(char *);
int get_tempdir(char *, int, int);
char *malloc(int);
int /*<<< orphan*/ memset(char *, char, int);
int read_then_write_file(char *, int *, char *, int);
int register_tempdir_for_cleanup(char *);
int /*<<< orphan*/ stderr;
int test_copy_fd_to_fd(char *, int *, char *);
int main(void) {
  char *bigbuf, tempdir[PATH_MAX];
  int next_id = 0;
  do {
    int __my_ret__ = get_tempdir(tempdir, sizeof(tempdir), 0700);
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 122,
              "get_tempdir(tempdir, sizeof(tempdir), 0700)");
      return __my_ret__;
    }
  } while (0);
  ;
  do {
    int __my_ret__ = register_tempdir_for_cleanup(tempdir);
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 123,
              "register_tempdir_for_cleanup(tempdir)");
      return __my_ret__;
    }
  } while (0);
  ;
  do {
    int __my_ret__ = read_then_write_file(tempdir, &next_id, "", 0);
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 125,
              "read_then_write_file(tempdir, &next_id, \"\", 0)");
      return __my_ret__;
    }
  } while (0);
  ;
  do {
    int __my_ret__ = read_then_write_file(tempdir, &next_id, "abc", 123);
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 126,
              "read_then_write_file(tempdir, &next_id, \"abc\", 123)");
      return __my_ret__;
    }
  } while (0);
  ;
  do {
    int __my_ret__ = read_then_write_file(tempdir, &next_id, "abracadabra", 5);
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 127,
              "read_then_write_file(tempdir, &next_id, \"abracadabra\", 5)");
      return __my_ret__;
    }
  } while (0);
  ;
  do {
    int __my_ret__ = test_copy_fd_to_fd(tempdir, &next_id, "");
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 129,
              "test_copy_fd_to_fd(tempdir, &next_id, \"\")");
      return __my_ret__;
    }
  } while (0);
  ;
  do {
    int __my_ret__ = test_copy_fd_to_fd(tempdir, &next_id, "foo bar");
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 130,
              "test_copy_fd_to_fd(tempdir, &next_id, \"foo bar\")");
      return __my_ret__;
    }
  } while (0);
  ;
  bigbuf = malloc(16384);
  memset(bigbuf, 'm', 16384 - 1);
  bigbuf[16384 - 1] = '\0';
  do {
    if (bigbuf == NULL) {
      fprintf(stderr, "failed on line %d: %s\n", 134, "bigbuf");
      return 1;
    }
  } while (0);
  ;
  do {
    int __my_ret__ = test_copy_fd_to_fd(tempdir, &next_id, bigbuf);
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 135,
              "test_copy_fd_to_fd(tempdir, &next_id, bigbuf)");
      return __my_ret__;
    }
  } while (0);
  ;
  free(bigbuf);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x58(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%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,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rax
mov    %eax,%esi
mov    $0x1c0,%edx
call   1080 <get_tempdir@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     121a <main+0x9a>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
lea    0xe09(%rip),%rsi
mov    $0x7a,%edx
lea    0xe14(%rip),%rcx
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    1568 <main+0x3e8>
jmp    121f <main+0x9f>
jmp    1224 <main+0xa4>
jmp    1229 <main+0xa9>
mov    -0x50(%rbp),%rdi
call   1060 <register_tempdir_for_cleanup@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
je     1272 <main+0xf2>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
lea    0xdb1(%rip),%rsi
mov    $0x7b,%edx
lea    0xde8(%rip),%rcx
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    1568 <main+0x3e8>
jmp    1277 <main+0xf7>
jmp    127c <main+0xfc>
jmp    1281 <main+0x101>
mov    -0x50(%rbp),%rdi
lea    -0x24(%rbp),%rsi
lea    0xd86(%rip),%rdx
xor    %ecx,%ecx
call   1040 <read_then_write_file@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     12d7 <main+0x157>
mov    0x2d2d(%rip),%rax
mov    (%rax),%edi
lea    0xd4c(%rip),%rsi
mov    $0x7d,%edx
lea    0xda9(%rip),%rcx
call   1070 <fprintf@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    1568 <main+0x3e8>
jmp    12dc <main+0x15c>
jmp    12e1 <main+0x161>
jmp    12e6 <main+0x166>
mov    -0x50(%rbp),%rdi
lea    -0x24(%rbp),%rsi
lea    0xda3(%rip),%rdx
mov    $0x7b,%ecx
call   1040 <read_then_write_file@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
je     133f <main+0x1bf>
mov    0x2cc5(%rip),%rax
mov    (%rax),%edi
lea    0xce4(%rip),%rsi
mov    $0x7e,%edx
lea    0xd74(%rip),%rcx
call   1070 <fprintf@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    1568 <main+0x3e8>
jmp    1344 <main+0x1c4>
jmp    1349 <main+0x1c9>
jmp    134e <main+0x1ce>
mov    -0x50(%rbp),%rdi
lea    -0x24(%rbp),%rsi
lea    0xd73(%rip),%rdx
mov    $0x5,%ecx
call   1040 <read_then_write_file@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     13a7 <main+0x227>
mov    0x2c5d(%rip),%rax
mov    (%rax),%edi
lea    0xc7c(%rip),%rsi
mov    $0x7f,%edx
lea    0xd4c(%rip),%rcx
call   1070 <fprintf@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    1568 <main+0x3e8>
jmp    13ac <main+0x22c>
jmp    13b1 <main+0x231>
jmp    13b6 <main+0x236>
mov    -0x50(%rbp),%rdi
lea    -0x24(%rbp),%rsi
lea    0xc51(%rip),%rdx
call   10a0 <test_copy_fd_to_fd@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
je     140a <main+0x28a>
mov    0x2bfa(%rip),%rax
mov    (%rax),%edi
lea    0xc19(%rip),%rsi
mov    $0x81,%edx
lea    0xd23(%rip),%rcx
call   1070 <fprintf@plt>
mov    -0x40(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    1568 <main+0x3e8>
jmp    140f <main+0x28f>
jmp    1414 <main+0x294>
jmp    1419 <main+0x299>
mov    -0x50(%rbp),%rdi
lea    -0x24(%rbp),%rsi
lea    0xd18(%rip),%rdx
call   10a0 <test_copy_fd_to_fd@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
je     146d <main+0x2ed>
mov    0x2b97(%rip),%rax
mov    (%rax),%edi
lea    0xbb6(%rip),%rsi
mov    $0x82,%edx
lea    0xcf2(%rip),%rcx
call   1070 <fprintf@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    1568 <main+0x3e8>
jmp    1472 <main+0x2f2>
jmp    1477 <main+0x2f7>
mov    $0x4000,%edi
call   1090 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x6d,%esi
mov    $0x3fff,%edx
call   1050 <memset@plt>
mov    -0x10(%rbp),%rax
movb   $0x0,0x3fff(%rax)
cmpq   $0x0,-0x10(%rbp)
jne    14e2 <main+0x362>
mov    0x2b23(%rip),%rax
mov    (%rax),%edi
lea    0xb42(%rip),%rsi
mov    $0x86,%edx
lea    0xcaf(%rip),%rcx
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    1568 <main+0x3e8>
jmp    14e7 <main+0x367>
jmp    14ec <main+0x36c>
jmp    14f1 <main+0x371>
mov    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    -0x24(%rbp),%rsi
call   10a0 <test_copy_fd_to_fd@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
je     1542 <main+0x3c2>
mov    0x2ac2(%rip),%rax
mov    (%rax),%edi
lea    0xae1(%rip),%rsi
mov    $0x87,%edx
lea    0xc55(%rip),%rcx
call   1070 <fprintf@plt>
mov    -0x48(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    1568 <main+0x3e8>
jmp    1547 <main+0x3c7>
jmp    154c <main+0x3cc>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    0x2a74(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x18(%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   %rbx
push   %rax
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rbx
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
movl   $0x0,-0x1c(%rbp)
mov    %rbx,%rdi
mov    $0x1c0,%edx
call   1080 <get_tempdir@plt>
test   %eax,%eax
je     11e8 <main+0x68>
mov    %eax,%r14d
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
lea    0xe2e(%rip),%rsi
lea    0xe3e(%rip),%rcx
mov    $0x7a,%edx
call   1070 <fprintf@plt>
jmp    13d8 <main+0x258>
mov    %rbx,%rdi
call   1060 <register_tempdir_for_cleanup@plt>
test   %eax,%eax
je     121d <main+0x9d>
mov    %eax,%r14d
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
lea    0xdf9(%rip),%rsi
lea    0xe35(%rip),%rcx
mov    $0x7b,%edx
call   1070 <fprintf@plt>
jmp    13d8 <main+0x258>
lea    0xdf2(%rip),%rdx
lea    -0x1c(%rbp),%rsi
mov    %rbx,%rdi
xor    %ecx,%ecx
call   1040 <read_then_write_file@plt>
test   %eax,%eax
je     125f <main+0xdf>
mov    %eax,%r14d
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
lea    0xdb7(%rip),%rsi
lea    0xe19(%rip),%rcx
mov    $0x7d,%edx
call   1070 <fprintf@plt>
jmp    13d8 <main+0x258>
lea    0xe32(%rip),%rdx
lea    -0x1c(%rbp),%rsi
mov    %rbx,%rdi
mov    $0x7b,%ecx
call   1040 <read_then_write_file@plt>
test   %eax,%eax
je     12a4 <main+0x124>
mov    %eax,%r14d
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
lea    0xd72(%rip),%rsi
lea    0xe07(%rip),%rcx
mov    $0x7e,%edx
call   1070 <fprintf@plt>
jmp    13d8 <main+0x258>
lea    0xe25(%rip),%rdx
lea    -0x1c(%rbp),%rsi
mov    %rbx,%rdi
mov    $0x5,%ecx
call   1040 <read_then_write_file@plt>
test   %eax,%eax
je     12e9 <main+0x169>
mov    %eax,%r14d
mov    0x2d0e(%rip),%rax
mov    (%rax),%edi
lea    0xd2d(%rip),%rsi
lea    0xe02(%rip),%rcx
mov    $0x7f,%edx
call   1070 <fprintf@plt>
jmp    13d8 <main+0x258>
lea    0xd26(%rip),%rdx
lea    -0x1c(%rbp),%rsi
mov    %rbx,%rdi
call   10a0 <test_copy_fd_to_fd@plt>
test   %eax,%eax
je     1329 <main+0x1a9>
mov    %eax,%r14d
mov    0x2cce(%rip),%rax
mov    (%rax),%edi
lea    0xced(%rip),%rsi
lea    0xdfc(%rip),%rcx
mov    $0x81,%edx
call   1070 <fprintf@plt>
jmp    13d8 <main+0x258>
lea    0xe10(%rip),%rdx
lea    -0x1c(%rbp),%rsi
mov    %rbx,%rdi
call   10a0 <test_copy_fd_to_fd@plt>
test   %eax,%eax
je     1366 <main+0x1e6>
mov    %eax,%r14d
mov    0x2c8e(%rip),%rax
mov    (%rax),%edi
lea    0xcad(%rip),%rsi
lea    0xdee(%rip),%rcx
mov    $0x82,%edx
call   1070 <fprintf@plt>
jmp    13d8 <main+0x258>
mov    $0x4000,%edi
call   1090 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x6d,%esi
mov    $0x3fff,%edx
call   1050 <memset@plt>
movb   $0x0,0x3fff(%r15)
lea    -0x1c(%rbp),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
call   10a0 <test_copy_fd_to_fd@plt>
test   %eax,%eax
je     13c6 <main+0x246>
mov    %eax,%r14d
mov    0x2c2e(%rip),%rax
mov    (%rax),%edi
lea    0xc4d(%rip),%rsi
lea    0xdbf(%rip),%rcx
mov    $0x87,%edx
call   1070 <fprintf@plt>
jmp    13d8 <main+0x258>
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x2bfb(%rip),%rax
mov    (%rax),%r14d
mov    %r14d,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@stderr = global i32 0
@.str = [23 x i8] c"failed on line %d: %s\0A\00"
@.str.1 = [44 x i8] c"get_tempdir(tempdir, sizeof(tempdir), 0700)\00"
@.str.2 = [38 x i8] c"register_tempdir_for_cleanup(tempdir)\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [47 x i8] c"read_then_write_file(tempdir, &next_id, \22\22, 0)\00"
@.str.5 = [4 x i8] c"abc\00"
@.str.6 = [52 x i8] c"read_then_write_file(tempdir, &next_id, \22abc\22, 123)\00"
@.str.7 = [12 x i8] c"abracadabra\00"
@.str.8 = [58 x i8] c"read_then_write_file(tempdir, &next_id, \22abracadabra\22, 5)\00"
@.str.9 = [42 x i8] c"test_copy_fd_to_fd(tempdir, &next_id, \22\22)\00"
@.str.10 = [8 x i8] c"foo bar\00"
@.str.11 = [49 x i8] c"test_copy_fd_to_fd(tempdir, &next_id, \22foo bar\22)\00"
@.str.12 = [7 x i8] c"bigbuf\00"
@.str.13 = [46 x i8] c"test_copy_fd_to_fd(tempdir, &next_id, bigbuf)\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %1
%15 = load i32, i32* @PATH_MAX
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %3
%18 = alloca i8, i64 %16
store i64 %16, i64* %4
store i32 0, i32* %5
br label %19
19: ; preds = %0
%20 = trunc i64 %16 to i32
%21 = call i32 @get_tempdir(i8* %18, i32 %20, i32 448)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %19
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 122, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
%27 = load i32, i32* %6
store i32 %27, i32* %1
store i32 1, i32* %7
br label %126
28: ; preds = %19
br label %29
29: ; preds = %28
br label %30
30: ; preds = %29
br label %31
31: ; preds = %30
%32 = call i32 @register_tempdir_for_cleanup(i8* %18)
store i32 %32, i32* %8
%33 = load i32, i32* %8
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %31
%36 = load i32, i32* @stderr
%37 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 123, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%38 = load i32, i32* %8
store i32 %38, i32* %1
store i32 1, i32* %7
br label %126
39: ; preds = %31
br label %40
40: ; preds = %39
br label %41
41: ; preds = %40
br label %42
42: ; preds = %41
%43 = call i32 @read_then_write_file(i8* %18, i32* %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i32 0)
store i32 %43, i32* %9
%44 = load i32, i32* %9
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %42
%47 = load i32, i32* @stderr
%48 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 125, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0))
%49 = load i32, i32* %9
store i32 %49, i32* %1
store i32 1, i32* %7
br label %126
50: ; preds = %42
br label %51
51: ; preds = %50
br label %52
52: ; preds = %51
br label %53
53: ; preds = %52
%54 = call i32 @read_then_write_file(i8* %18, i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 123)
store i32 %54, i32* %10
%55 = load i32, i32* %10
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %61
57: ; preds = %53
%58 = load i32, i32* @stderr
%59 = call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 126, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.6, i64 0, i64 0))
%60 = load i32, i32* %10
store i32 %60, i32* %1
store i32 1, i32* %7
br label %126
61: ; preds = %53
br label %62
62: ; preds = %61
br label %63
63: ; preds = %62
br label %64
64: ; preds = %63
%65 = call i32 @read_then_write_file(i8* %18, i32* %5, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32 5)
store i32 %65, i32* %11
%66 = load i32, i32* %11
%67 = icmp ne i32 %66, 0
br i1 %67, label %68, label %72
68: ; preds = %64
%69 = load i32, i32* @stderr
%70 = call i32 @fprintf(i32 %69, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 127, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.8, i64 0, i64 0))
%71 = load i32, i32* %11
store i32 %71, i32* %1
store i32 1, i32* %7
br label %126
72: ; preds = %64
br label %73
73: ; preds = %72
br label %74
74: ; preds = %73
br label %75
75: ; preds = %74
%76 = call i32 @test_copy_fd_to_fd(i8* %18, i32* %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
store i32 %76, i32* %12
%77 = load i32, i32* %12
%78 = icmp ne i32 %77, 0
br i1 %78, label %79, label %83
79: ; preds = %75
%80 = load i32, i32* @stderr
%81 = call i32 @fprintf(i32 %80, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 129, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.9, i64 0, i64 0))
%82 = load i32, i32* %12
store i32 %82, i32* %1
store i32 1, i32* %7
br label %126
83: ; preds = %75
br label %84
84: ; preds = %83
br label %85
85: ; preds = %84
br label %86
86: ; preds = %85
%87 = call i32 @test_copy_fd_to_fd(i8* %18, i32* %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0))
store i32 %87, i32* %13
%88 = load i32, i32* %13
%89 = icmp ne i32 %88, 0
br i1 %89, label %90, label %94
90: ; preds = %86
%91 = load i32, i32* @stderr
%92 = call i32 @fprintf(i32 %91, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 130, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.11, i64 0, i64 0))
%93 = load i32, i32* %13
store i32 %93, i32* %1
store i32 1, i32* %7
br label %126
94: ; preds = %86
br label %95
95: ; preds = %94
br label %96
96: ; preds = %95
%97 = call i8* @malloc(i32 16384)
store i8* %97, i8** %2
%98 = load i8*, i8** %2
%99 = call i32 @memset(i8* %98, i8 signext 109, i32 16383)
%100 = load i8*, i8** %2
%101 = getelementptr inbounds i8, i8* %100, i64 16383
store i8 0, i8* %101
br label %102
102: ; preds = %96
%103 = load i8*, i8** %2
%104 = icmp eq i8* %103, null
br i1 %104, label %105, label %108
105: ; preds = %102
%106 = load i32, i32* @stderr
%107 = call i32 @fprintf(i32 %106, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 134, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0))
store i32 1, i32* %1
store i32 1, i32* %7
br label %126
108: ; preds = %102
br label %109
109: ; preds = %108
br label %110
110: ; preds = %109
br label %111
111: ; preds = %110
%112 = load i8*, i8** %2
%113 = call i32 @test_copy_fd_to_fd(i8* %18, i32* %5, i8* %112)
store i32 %113, i32* %14
%114 = load i32, i32* %14
%115 = icmp ne i32 %114, 0
br i1 %115, label %116, label %120
116: ; preds = %111
%117 = load i32, i32* @stderr
%118 = call i32 @fprintf(i32 %117, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 135, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.13, i64 0, i64 0))
%119 = load i32, i32* %14
store i32 %119, i32* %1
store i32 1, i32* %7
br label %126
120: ; preds = %111
br label %121
121: ; preds = %120
br label %122
122: ; preds = %121
%123 = load i8*, i8** %2
%124 = call i32 @free(i8* %123)
%125 = load i32, i32* @EXIT_SUCCESS
store i32 %125, i32* %1
store i32 1, i32* %7
br label %126
126: ; preds = %122, %116, %105, %90, %79, %68, %57, %46, %35, %24
%127 = load i8*, i8** %3
%128 = load i32, i32* %1
ret i32 %128
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@stderr = global i32 0
@.str = [23 x i8] c"failed on line %d: %s\0A\00"
@.str.1 = [44 x i8] c"get_tempdir(tempdir, sizeof(tempdir), 0700)\00"
@.str.2 = [38 x i8] c"register_tempdir_for_cleanup(tempdir)\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [47 x i8] c"read_then_write_file(tempdir, &next_id, \22\22, 0)\00"
@.str.5 = [4 x i8] c"abc\00"
@.str.6 = [52 x i8] c"read_then_write_file(tempdir, &next_id, \22abc\22, 123)\00"
@.str.7 = [12 x i8] c"abracadabra\00"
@.str.8 = [58 x i8] c"read_then_write_file(tempdir, &next_id, \22abracadabra\22, 5)\00"
@.str.9 = [42 x i8] c"test_copy_fd_to_fd(tempdir, &next_id, \22\22)\00"
@.str.10 = [8 x i8] c"foo bar\00"
@.str.11 = [49 x i8] c"test_copy_fd_to_fd(tempdir, &next_id, \22foo bar\22)\00"
@.str.13 = [46 x i8] c"test_copy_fd_to_fd(tempdir, &next_id, bigbuf)\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = load i32, i32* @PATH_MAX
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%6 = call i32 @get_tempdir(i8* %4, i32 %2, i32 448)
%7 = icmp eq i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 122, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
br label %59
11: ; preds = %0
%12 = call i32 @register_tempdir_for_cleanup(i8* %4)
%13 = icmp eq i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 123, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
br label %59
17: ; preds = %11
%18 = call i32 @read_then_write_file(i8* %4, i32* %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i32 0)
%19 = icmp eq i32 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 125, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0))
br label %59
23: ; preds = %17
%24 = call i32 @read_then_write_file(i8* %4, i32* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 123)
%25 = icmp eq i32 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 126, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.6, i64 0, i64 0))
br label %59
29: ; preds = %23
%30 = call i32 @read_then_write_file(i8* %4, i32* %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32 5)
%31 = icmp eq i32 %30, 0
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, i64 0, i64 0), i32 127, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.8, i64 0, i64 0))
br label %59
35: ; preds = %29
%36 = call i32 @test_copy_fd_to_fd(i8* %4, i32* %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%37 = icmp eq i32 %36, 0
br i1 %37, label %41, label %38
38: ; preds = %35
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 129, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.9, i64 0, i64 0))
br label %59
41: ; preds = %35
%42 = call i32 @test_copy_fd_to_fd(i8* %4, i32* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0))
%43 = icmp eq i32 %42, 0
br i1 %43, label %47, label %44
44: ; preds = %41
%45 = load i32, i32* @stderr
%46 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 130, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.11, i64 0, i64 0))
br label %59
47: ; preds = %41
%48 = call dereferenceable_or_null(16384) i8* @malloc(i32 16384)
%49 = call i32 @memset(i8* %48, i8 signext 109, i32 16383)
%50 = getelementptr inbounds i8, i8* %48, i64 16383
store i8 0, i8* %50
%51 = call i32 @test_copy_fd_to_fd(i8* %4, i32* %1, i8* %48)
%52 = icmp eq i32 %51, 0
br i1 %52, label %56, label %53
53: ; preds = %47
%54 = load i32, i32* @stderr
%55 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 135, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.13, i64 0, i64 0))
br label %59
56: ; preds = %47
%57 = call i32 @free(i8* %48)
%58 = load i32, i32* @EXIT_SUCCESS
br label %59
59: ; preds = %53, %44, %38, %32, %26, %20, %14, %8, %56
%60 = phi i32 [ %58, %56 ], [ %51, %53 ], [ %42, %44 ], [ %36, %38 ], [ %30, %32 ], [ %24, %26 ], [ %18, %20 ], [ %12, %14 ], [ %6, %8 ]
ret i32 %60
}