#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 test_zfprintf(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", 169,
              "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", 170,
              "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", 172,
              "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", 173,
              "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", 174,
              "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", 176,
              "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", 177,
              "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", 181, "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", 182,
              "test_copy_fd_to_fd(tempdir, &next_id, bigbuf)");
      return __my_ret__;
    }
  } while (0);
  ;
  free(bigbuf);
  do {
    int __my_ret__ = test_zfprintf(tempdir);
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 184, "test_zfprintf(tempdir)");
      return __my_ret__;
    }
  } while (0);
  ;
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x60(%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,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x60(%rbp),%rax
mov    %eax,%esi
mov    $0x1c0,%edx
call   1080 <get_tempdir@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     122a <main+0x9a>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
lea    0xdf9(%rip),%rsi
mov    $0xa9,%edx
lea    0xe04(%rip),%rcx
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    15cb <main+0x43b>
jmp    122f <main+0x9f>
jmp    1234 <main+0xa4>
jmp    1239 <main+0xa9>
mov    -0x58(%rbp),%rdi
call   1060 <register_tempdir_for_cleanup@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
je     1282 <main+0xf2>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
lea    0xda1(%rip),%rsi
mov    $0xaa,%edx
lea    0xdd8(%rip),%rcx
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    15cb <main+0x43b>
jmp    1287 <main+0xf7>
jmp    128c <main+0xfc>
jmp    1291 <main+0x101>
mov    -0x58(%rbp),%rdi
lea    -0x24(%rbp),%rsi
lea    0xd76(%rip),%rdx
xor    %ecx,%ecx
call   1040 <read_then_write_file@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     12e7 <main+0x157>
mov    0x2d1d(%rip),%rax
mov    (%rax),%edi
lea    0xd3c(%rip),%rsi
mov    $0xac,%edx
lea    0xd99(%rip),%rcx
call   1070 <fprintf@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    15cb <main+0x43b>
jmp    12ec <main+0x15c>
jmp    12f1 <main+0x161>
jmp    12f6 <main+0x166>
mov    -0x58(%rbp),%rdi
lea    -0x24(%rbp),%rsi
lea    0xd93(%rip),%rdx
mov    $0x7b,%ecx
call   1040 <read_then_write_file@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
je     134f <main+0x1bf>
mov    0x2cb5(%rip),%rax
mov    (%rax),%edi
lea    0xcd4(%rip),%rsi
mov    $0xad,%edx
lea    0xd64(%rip),%rcx
call   1070 <fprintf@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    15cb <main+0x43b>
jmp    1354 <main+0x1c4>
jmp    1359 <main+0x1c9>
jmp    135e <main+0x1ce>
mov    -0x58(%rbp),%rdi
lea    -0x24(%rbp),%rsi
lea    0xd63(%rip),%rdx
mov    $0x5,%ecx
call   1040 <read_then_write_file@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     13b7 <main+0x227>
mov    0x2c4d(%rip),%rax
mov    (%rax),%edi
lea    0xc6c(%rip),%rsi
mov    $0xae,%edx
lea    0xd3c(%rip),%rcx
call   1070 <fprintf@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    15cb <main+0x43b>
jmp    13bc <main+0x22c>
jmp    13c1 <main+0x231>
jmp    13c6 <main+0x236>
mov    -0x58(%rbp),%rdi
lea    -0x24(%rbp),%rsi
lea    0xc41(%rip),%rdx
call   10a0 <test_copy_fd_to_fd@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
je     141a <main+0x28a>
mov    0x2bea(%rip),%rax
mov    (%rax),%edi
lea    0xc09(%rip),%rsi
mov    $0xb0,%edx
lea    0xd13(%rip),%rcx
call   1070 <fprintf@plt>
mov    -0x40(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    15cb <main+0x43b>
jmp    141f <main+0x28f>
jmp    1424 <main+0x294>
jmp    1429 <main+0x299>
mov    -0x58(%rbp),%rdi
lea    -0x24(%rbp),%rsi
lea    0xd08(%rip),%rdx
call   10a0 <test_copy_fd_to_fd@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
je     147d <main+0x2ed>
mov    0x2b87(%rip),%rax
mov    (%rax),%edi
lea    0xba6(%rip),%rsi
mov    $0xb1,%edx
lea    0xce2(%rip),%rcx
call   1070 <fprintf@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    15cb <main+0x43b>
jmp    1482 <main+0x2f2>
jmp    1487 <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    14f2 <main+0x362>
mov    0x2b13(%rip),%rax
mov    (%rax),%edi
lea    0xb32(%rip),%rsi
mov    $0xb5,%edx
lea    0xc9f(%rip),%rcx
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    15cb <main+0x43b>
jmp    14f7 <main+0x367>
jmp    14fc <main+0x36c>
jmp    1501 <main+0x371>
mov    -0x58(%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     1552 <main+0x3c2>
mov    0x2ab2(%rip),%rax
mov    (%rax),%edi
lea    0xad1(%rip),%rsi
mov    $0xb6,%edx
lea    0xc45(%rip),%rcx
call   1070 <fprintf@plt>
mov    -0x48(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    15cb <main+0x43b>
jmp    1557 <main+0x3c7>
jmp    155c <main+0x3cc>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x58(%rbp),%rdi
call   10b0 <test_zfprintf@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
je     15ae <main+0x41e>
mov    0x2a56(%rip),%rax
mov    (%rax),%edi
lea    0xa75(%rip),%rsi
mov    $0xb8,%edx
lea    0xc17(%rip),%rcx
call   1070 <fprintf@plt>
mov    -0x4c(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    15cb <main+0x43b>
jmp    15b3 <main+0x423>
jmp    15b8 <main+0x428>
mov    0x2a11(%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    0x2e4f(%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     11f8 <main+0x68>
mov    %eax,%r14d
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
lea    0xe1e(%rip),%rsi
lea    0xe2e(%rip),%rcx
mov    $0xa9,%edx
call   1070 <fprintf@plt>
jmp    1420 <main+0x290>
mov    %rbx,%rdi
call   1060 <register_tempdir_for_cleanup@plt>
test   %eax,%eax
je     122d <main+0x9d>
mov    %eax,%r14d
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
lea    0xde9(%rip),%rsi
lea    0xe25(%rip),%rcx
mov    $0xaa,%edx
call   1070 <fprintf@plt>
jmp    1420 <main+0x290>
lea    0xde2(%rip),%rdx
lea    -0x1c(%rbp),%rsi
mov    %rbx,%rdi
xor    %ecx,%ecx
call   1040 <read_then_write_file@plt>
test   %eax,%eax
je     126f <main+0xdf>
mov    %eax,%r14d
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
lea    0xda7(%rip),%rsi
lea    0xe09(%rip),%rcx
mov    $0xac,%edx
call   1070 <fprintf@plt>
jmp    1420 <main+0x290>
lea    0xe22(%rip),%rdx
lea    -0x1c(%rbp),%rsi
mov    %rbx,%rdi
mov    $0x7b,%ecx
call   1040 <read_then_write_file@plt>
test   %eax,%eax
je     12b4 <main+0x124>
mov    %eax,%r14d
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
lea    0xd62(%rip),%rsi
lea    0xdf7(%rip),%rcx
mov    $0xad,%edx
call   1070 <fprintf@plt>
jmp    1420 <main+0x290>
lea    0xe15(%rip),%rdx
lea    -0x1c(%rbp),%rsi
mov    %rbx,%rdi
mov    $0x5,%ecx
call   1040 <read_then_write_file@plt>
test   %eax,%eax
je     12f9 <main+0x169>
mov    %eax,%r14d
mov    0x2cfe(%rip),%rax
mov    (%rax),%edi
lea    0xd1d(%rip),%rsi
lea    0xdf2(%rip),%rcx
mov    $0xae,%edx
call   1070 <fprintf@plt>
jmp    1420 <main+0x290>
lea    0xd16(%rip),%rdx
lea    -0x1c(%rbp),%rsi
mov    %rbx,%rdi
call   10a0 <test_copy_fd_to_fd@plt>
test   %eax,%eax
je     1339 <main+0x1a9>
mov    %eax,%r14d
mov    0x2cbe(%rip),%rax
mov    (%rax),%edi
lea    0xcdd(%rip),%rsi
lea    0xdec(%rip),%rcx
mov    $0xb0,%edx
call   1070 <fprintf@plt>
jmp    1420 <main+0x290>
lea    0xe00(%rip),%rdx
lea    -0x1c(%rbp),%rsi
mov    %rbx,%rdi
call   10a0 <test_copy_fd_to_fd@plt>
test   %eax,%eax
je     1379 <main+0x1e9>
mov    %eax,%r14d
mov    0x2c7e(%rip),%rax
mov    (%rax),%edi
lea    0xc9d(%rip),%rsi
lea    0xdde(%rip),%rcx
mov    $0xb1,%edx
call   1070 <fprintf@plt>
jmp    1420 <main+0x290>
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     13d9 <main+0x249>
mov    %eax,%r14d
mov    0x2c1b(%rip),%rax
mov    (%rax),%edi
lea    0xc3a(%rip),%rsi
lea    0xdac(%rip),%rcx
mov    $0xb6,%edx
call   1070 <fprintf@plt>
jmp    1420 <main+0x290>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   10b0 <test_zfprintf@plt>
mov    %eax,%r14d
test   %eax,%eax
je     1411 <main+0x281>
mov    0x2be1(%rip),%rax
mov    (%rax),%edi
lea    0xc00(%rip),%rsi
lea    0xda0(%rip),%rcx
mov    $0xb8,%edx
call   1070 <fprintf@plt>
test   %r14d,%r14d
jne    1420 <main+0x290>
mov    0x2bb3(%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"
@.str.14 = [23 x i8] c"test_zfprintf(tempdir)\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
%15 = alloca i32
store i32 0, i32* %1
%16 = load i32, i32* @PATH_MAX
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %3
%19 = alloca i8, i64 %17
store i64 %17, i64* %4
store i32 0, i32* %5
br label %20
20: ; preds = %0
%21 = trunc i64 %17 to i32
%22 = call i32 @get_tempdir(i8* %19, i32 %21, i32 448)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %20
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 169, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
%28 = load i32, i32* %6
store i32 %28, i32* %1
store i32 1, i32* %7
br label %138
29: ; preds = %20
br label %30
30: ; preds = %29
br label %31
31: ; preds = %30
br label %32
32: ; preds = %31
%33 = call i32 @register_tempdir_for_cleanup(i8* %19)
store i32 %33, i32* %8
%34 = load i32, i32* %8
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %32
%37 = load i32, i32* @stderr
%38 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 170, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%39 = load i32, i32* %8
store i32 %39, i32* %1
store i32 1, i32* %7
br label %138
40: ; preds = %32
br label %41
41: ; preds = %40
br label %42
42: ; preds = %41
br label %43
43: ; preds = %42
%44 = call i32 @read_then_write_file(i8* %19, i32* %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i32 0)
store i32 %44, i32* %9
%45 = load i32, i32* %9
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %43
%48 = load i32, i32* @stderr
%49 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 172, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0))
%50 = load i32, i32* %9
store i32 %50, i32* %1
store i32 1, i32* %7
br label %138
51: ; preds = %43
br label %52
52: ; preds = %51
br label %53
53: ; preds = %52
br label %54
54: ; preds = %53
%55 = call i32 @read_then_write_file(i8* %19, i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 123)
store i32 %55, i32* %10
%56 = load i32, i32* %10
%57 = icmp ne i32 %56, 0
br i1 %57, label %58, label %62
58: ; preds = %54
%59 = load i32, i32* @stderr
%60 = call i32 @fprintf(i32 %59, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 173, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.6, i64 0, i64 0))
%61 = load i32, i32* %10
store i32 %61, i32* %1
store i32 1, i32* %7
br label %138
62: ; preds = %54
br label %63
63: ; preds = %62
br label %64
64: ; preds = %63
br label %65
65: ; preds = %64
%66 = call i32 @read_then_write_file(i8* %19, i32* %5, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32 5)
store i32 %66, i32* %11
%67 = load i32, i32* %11
%68 = icmp ne i32 %67, 0
br i1 %68, label %69, label %73
69: ; preds = %65
%70 = load i32, i32* @stderr
%71 = call i32 @fprintf(i32 %70, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 174, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.8, i64 0, i64 0))
%72 = load i32, i32* %11
store i32 %72, i32* %1
store i32 1, i32* %7
br label %138
73: ; preds = %65
br label %74
74: ; preds = %73
br label %75
75: ; preds = %74
br label %76
76: ; preds = %75
%77 = call i32 @test_copy_fd_to_fd(i8* %19, i32* %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
store i32 %77, i32* %12
%78 = load i32, i32* %12
%79 = icmp ne i32 %78, 0
br i1 %79, label %80, label %84
80: ; preds = %76
%81 = load i32, i32* @stderr
%82 = call i32 @fprintf(i32 %81, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 176, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.9, i64 0, i64 0))
%83 = load i32, i32* %12
store i32 %83, i32* %1
store i32 1, i32* %7
br label %138
84: ; preds = %76
br label %85
85: ; preds = %84
br label %86
86: ; preds = %85
br label %87
87: ; preds = %86
%88 = call i32 @test_copy_fd_to_fd(i8* %19, i32* %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0))
store i32 %88, i32* %13
%89 = load i32, i32* %13
%90 = icmp ne i32 %89, 0
br i1 %90, label %91, label %95
91: ; preds = %87
%92 = load i32, i32* @stderr
%93 = call i32 @fprintf(i32 %92, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 177, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.11, i64 0, i64 0))
%94 = load i32, i32* %13
store i32 %94, i32* %1
store i32 1, i32* %7
br label %138
95: ; preds = %87
br label %96
96: ; preds = %95
br label %97
97: ; preds = %96
%98 = call i8* @malloc(i32 16384)
store i8* %98, i8** %2
%99 = load i8*, i8** %2
%100 = call i32 @memset(i8* %99, i8 signext 109, i32 16383)
%101 = load i8*, i8** %2
%102 = getelementptr inbounds i8, i8* %101, i64 16383
store i8 0, i8* %102
br label %103
103: ; preds = %97
%104 = load i8*, i8** %2
%105 = icmp eq i8* %104, null
br i1 %105, label %106, label %109
106: ; preds = %103
%107 = load i32, i32* @stderr
%108 = call i32 @fprintf(i32 %107, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 181, 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 %138
109: ; preds = %103
br label %110
110: ; preds = %109
br label %111
111: ; preds = %110
br label %112
112: ; preds = %111
%113 = load i8*, i8** %2
%114 = call i32 @test_copy_fd_to_fd(i8* %19, i32* %5, i8* %113)
store i32 %114, i32* %14
%115 = load i32, i32* %14
%116 = icmp ne i32 %115, 0
br i1 %116, label %117, label %121
117: ; preds = %112
%118 = load i32, i32* @stderr
%119 = call i32 @fprintf(i32 %118, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 182, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.13, i64 0, i64 0))
%120 = load i32, i32* %14
store i32 %120, i32* %1
store i32 1, i32* %7
br label %138
121: ; preds = %112
br label %122
122: ; preds = %121
br label %123
123: ; preds = %122
%124 = load i8*, i8** %2
%125 = call i32 @free(i8* %124)
br label %126
126: ; preds = %123
%127 = call i32 @test_zfprintf(i8* %19)
store i32 %127, i32* %15
%128 = load i32, i32* %15
%129 = icmp ne i32 %128, 0
br i1 %129, label %130, label %134
130: ; preds = %126
%131 = load i32, i32* @stderr
%132 = call i32 @fprintf(i32 %131, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 184, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.14, i64 0, i64 0))
%133 = load i32, i32* %15
store i32 %133, i32* %1
store i32 1, i32* %7
br label %138
134: ; preds = %126
br label %135
135: ; preds = %134
br label %136
136: ; preds = %135
%137 = load i32, i32* @EXIT_SUCCESS
store i32 %137, i32* %1
store i32 1, i32* %7
br label %138
138: ; preds = %136, %130, %117, %106, %91, %80, %69, %58, %47, %36, %25
%139 = load i8*, i8** %3
%140 = load i32, i32* %1
ret i32 %140
}

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"
@.str.14 = [23 x i8] c"test_zfprintf(tempdir)\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 169, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
br label %66
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 170, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
br label %66
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 172, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0))
br label %66
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 173, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.6, i64 0, i64 0))
br label %66
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 174, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.8, i64 0, i64 0))
br label %66
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 176, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.9, i64 0, i64 0))
br label %66
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 177, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.11, i64 0, i64 0))
br label %66
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 182, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.13, i64 0, i64 0))
br label %66
56: ; preds = %47
%57 = call i32 @free(i8* %48)
%58 = call i32 @test_zfprintf(i8* %4)
%59 = icmp eq i32 %58, 0
br i1 %59, label %63, label %60
60: ; preds = %56
%61 = load i32, i32* @stderr
%62 = call i32 @fprintf(i32 %61, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 184, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.14, i64 0, i64 0))
br label %63
63: ; preds = %56, %60
%64 = load i32, i32* @EXIT_SUCCESS
%65 = select i1 %59, i32 %64, i32 %58
br label %66
66: ; preds = %53, %44, %38, %32, %26, %20, %14, %8, %63
%67 = phi i32 [ %51, %53 ], [ %42, %44 ], [ %36, %38 ], [ %30, %32 ], [ %24, %26 ], [ %18, %20 ], [ %12, %14 ], [ %6, %8 ], [ %65, %63 ]
ret i32 %67
}