#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*/ fname;
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int PATH_MAX;
int errno;
int fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int memcmp(char *, char *, scalar_t__);
scalar_t__ simple_io_read_whole_file_zt(char *, char *, int);
int /*<<< orphan*/ stderr;
size_t strlen(char *);
int zfprintf(int /*<<< orphan*/ *, char *, int);
int zsnprintf(char *, int, char *, char const *);
int test_zfprintf(const char *tdir) {
  int ret, i;
  FILE *fp;
  char fname[PATH_MAX], buf[512];
  char expected[] = "abracadabra i=123";
  size_t expected_len;
  ssize_t res;
  do {
    int __my_ret__ = zsnprintf(fname, sizeof(fname), "%s/zfprintf", tdir);
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 136,
              "zsnprintf(fname, sizeof(fname), \"%s/zfprintf\", tdir)");
      return __my_ret__;
    }
  } while (0);
  ;
  fp = fopen(fname, "w");
  if (!fp) {
    ret = -errno;
    fprintf(stderr,
            "test_zfprintf: error opening %s for "
            "write: error %d\n",
            fname, ret);
    return ret;
  }
  i = 123;
  do {
    int __my_ret__ = zfprintf(fp, "abracadabra i=%d", i);
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 145,
              "zfprintf(fp, \"abracadabra i=%d\", i)");
      return __my_ret__;
    }
  } while (0);
  ;
  do {
    int __my_ret__ = fclose(fp);
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 146, "fclose(fp)");
      return __my_ret__;
    }
  } while (0);
  ;
  expected_len = strlen(expected);
  res = simple_io_read_whole_file_zt(fname, buf, sizeof(buf) - 1);
  do {
    if ((res) != ((ssize_t)expected_len)) {
      fprintf(stderr, "failed on line %d: %s\n", 149, "res");
      return 1;
    }
  } while (0);
  ;
  do {
    int __my_ret__ = memcmp(expected, buf, res);
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 150,
              "memcmp(expected, buf, res)");
      return __my_ret__;
    }
  } while (0);
  ;
  fp = fopen(fname, "r");
  if (!fp) {
    ret = -errno;
    fprintf(stderr,
            "test_zfprintf: error opening %s for "
            "read: error %d\n",
            fname, ret);
    return ret;
  }
  do {
    int __my_ret__ = zfprintf(fp, "abracadabra i=%d\n", i);
    if (__my_ret__ == 0) {
      fprintf(stderr, "failed on line %d: %s\n", 160,
              "zfprintf(fp, \"abracadabra i=%d\\n\", i)");
      return -1;
    }
  } while (0);
  ;
  do {
    int __my_ret__ = fclose(fp);
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 161, "fclose(fp)");
      return __my_ret__;
    }
  } while (0);
  ;
  return 0;
}


x86 assembly (clang, -O0):
<test_zfprintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x290,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x290(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x288(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    0xe34(%rip),%rax
mov    %rax,-0x250(%rbp)
mov    0xe2e(%rip),%rax
mov    %rax,-0x248(%rbp)
mov    0xe28(%rip),%ax
mov    %ax,-0x240(%rbp)
mov    -0x288(%rbp),%rdi
mov    -0x290(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rcx
lea    0xe08(%rip),%rdx
call   1080 <zsnprintf@plt>
mov    %eax,-0x264(%rbp)
cmpl   $0x0,-0x264(%rbp)
je     125d <test_zfprintf+0xdd>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
lea    0xdec(%rip),%rsi
mov    $0x88,%edx
lea    0xdf7(%rip),%rcx
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x264(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x268(%rbp)
jmp    15f0 <test_zfprintf+0x470>
jmp    1262 <test_zfprintf+0xe2>
jmp    1267 <test_zfprintf+0xe7>
mov    -0x288(%rbp),%rdi
lea    0xdf5(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12cd <test_zfprintf+0x14d>
mov    -0x288(%rbp),%rdx
xor    %eax,%eax
mov    0x2d37(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x14(%rbp)
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%ecx
lea    0xdbb(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x268(%rbp)
jmp    15f0 <test_zfprintf+0x470>
movl   $0x7b,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xdbf(%rip),%rsi
call   10a0 <zfprintf@plt>
mov    %eax,-0x26c(%rbp)
cmpl   $0x0,-0x26c(%rbp)
je     1335 <test_zfprintf+0x1b5>
mov    0x2cd7(%rip),%rax
mov    (%rax),%edi
lea    0xd14(%rip),%rsi
mov    $0x91,%edx
lea    0xd9c(%rip),%rcx
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x26c(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x268(%rbp)
jmp    15f0 <test_zfprintf+0x470>
jmp    133a <test_zfprintf+0x1ba>
jmp    133f <test_zfprintf+0x1bf>
jmp    1344 <test_zfprintf+0x1c4>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    %eax,-0x270(%rbp)
cmpl   $0x0,-0x270(%rbp)
je     139b <test_zfprintf+0x21b>
mov    0x2c71(%rip),%rax
mov    (%rax),%edi
lea    0xcae(%rip),%rsi
mov    $0x92,%edx
lea    0xd5a(%rip),%rcx
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x270(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x268(%rbp)
jmp    15f0 <test_zfprintf+0x470>
jmp    13a0 <test_zfprintf+0x220>
jmp    13a5 <test_zfprintf+0x225>
lea    -0x250(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x288(%rbp),%rdi
mov    %rax,-0x258(%rbp)
lea    -0x230(%rbp),%rsi
mov    $0x1ff,%edx
call   1050 <simple_io_read_whole_file_zt@plt>
mov    %rax,-0x260(%rbp)
mov    -0x260(%rbp),%rax
cmp    -0x258(%rbp),%rax
je     1424 <test_zfprintf+0x2a4>
mov    0x2be6(%rip),%rax
mov    (%rax),%edi
lea    0xc23(%rip),%rsi
mov    $0x95,%edx
lea    0xcda(%rip),%rcx
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x268(%rbp)
jmp    15f0 <test_zfprintf+0x470>
jmp    1429 <test_zfprintf+0x2a9>
jmp    142e <test_zfprintf+0x2ae>
jmp    1433 <test_zfprintf+0x2b3>
lea    -0x250(%rbp),%rdi
lea    -0x230(%rbp),%rsi
mov    -0x260(%rbp),%rdx
call   1060 <memcmp@plt>
mov    %eax,-0x274(%rbp)
cmpl   $0x0,-0x274(%rbp)
je     149b <test_zfprintf+0x31b>
mov    0x2b71(%rip),%rax
mov    (%rax),%edi
lea    0xbae(%rip),%rsi
mov    $0x96,%edx
lea    0xc69(%rip),%rcx
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x274(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x268(%rbp)
jmp    15f0 <test_zfprintf+0x470>
jmp    14a0 <test_zfprintf+0x320>
jmp    14a5 <test_zfprintf+0x325>
mov    -0x288(%rbp),%rdi
lea    0xc4d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    150b <test_zfprintf+0x38b>
mov    -0x288(%rbp),%rdx
xor    %eax,%eax
mov    0x2af9(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x14(%rbp)
mov    0x2af5(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%ecx
lea    0xc13(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x268(%rbp)
jmp    15f0 <test_zfprintf+0x470>
jmp    1510 <test_zfprintf+0x390>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xc18(%rip),%rsi
call   10a0 <zfprintf@plt>
mov    %eax,-0x278(%rbp)
cmpl   $0x0,-0x278(%rbp)
jne    156f <test_zfprintf+0x3ef>
mov    0x2a9b(%rip),%rax
mov    (%rax),%edi
lea    0xad8(%rip),%rsi
mov    $0xa0,%edx
lea    0xbf6(%rip),%rcx
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x268(%rbp)
jmp    15f0 <test_zfprintf+0x470>
jmp    1574 <test_zfprintf+0x3f4>
jmp    1579 <test_zfprintf+0x3f9>
jmp    157e <test_zfprintf+0x3fe>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    %eax,-0x27c(%rbp)
cmpl   $0x0,-0x27c(%rbp)
je     15d5 <test_zfprintf+0x455>
mov    0x2a37(%rip),%rax
mov    (%rax),%edi
lea    0xa74(%rip),%rsi
mov    $0xa1,%edx
lea    0xb20(%rip),%rcx
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x27c(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x268(%rbp)
jmp    15f0 <test_zfprintf+0x470>
jmp    15da <test_zfprintf+0x45a>
jmp    15df <test_zfprintf+0x45f>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x268(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_zfprintf>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %rdi,%rcx
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rbx
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe6b(%rip),%rdx
mov    %rbx,%rdi
call   1070 <zsnprintf@plt>
test   %eax,%eax
je     11e7 <test_zfprintf+0x77>
mov    %eax,%r14d
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
lea    0xe58(%rip),%rsi
lea    0xe68(%rip),%rcx
mov    $0x88,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r14d,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe7c(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1237 <test_zfprintf+0xc7>
mov    %rax,%r15
lea    0xe9c(%rip),%rsi
mov    %rax,%rdi
mov    $0x7b,%edx
call   1090 <zfprintf@plt>
test   %eax,%eax
je     1266 <test_zfprintf+0xf6>
mov    %eax,%r14d
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
lea    0xdf5(%rip),%rsi
lea    0xe82(%rip),%rcx
mov    $0x91,%edx
jmp    11d2 <test_zfprintf+0x62>
mov    0x2d92(%rip),%rax
xor    %r14d,%r14d
sub    (%rax),%r14d
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
lea    0xe18(%rip),%rsi
mov    %rbx,%rdx
mov    %r14d,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    11d9 <test_zfprintf+0x69>
mov    %r15,%rdi
call   1030 <fclose@plt>
test   %eax,%eax
je     1296 <test_zfprintf+0x126>
mov    %eax,%r14d
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
lea    0xd99(%rip),%rsi
lea    0xe4a(%rip),%rcx
mov    $0x92,%edx
jmp    11d2 <test_zfprintf+0x62>
lea    -0x220(%rbp),%rsi
mov    %rbx,%rdi
mov    $0x1ff,%edx
call   1040 <simple_io_read_whole_file_zt@plt>
cmp    $0x11,%rax
jne    12f0 <test_zfprintf+0x180>
lea    0xd49(%rip),%rdi
lea    -0x220(%rbp),%rsi
mov    $0x11,%edx
call   1050 <memcmp@plt>
test   %eax,%eax
je     131e <test_zfprintf+0x1ae>
mov    %eax,%r14d
mov    0x2d02(%rip),%rax
mov    (%rax),%edi
lea    0xd3f(%rip),%rsi
lea    0xdff(%rip),%rcx
mov    $0x96,%edx
jmp    11d2 <test_zfprintf+0x62>
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
lea    0xd1e(%rip),%rsi
lea    0xdda(%rip),%rcx
mov    $0x95,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%r14d
jmp    11d9 <test_zfprintf+0x69>
lea    0xddb(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     137d <test_zfprintf+0x20d>
mov    %rax,%r14
lea    0xdfa(%rip),%rsi
mov    %rax,%rdi
mov    $0x7b,%edx
call   1090 <zfprintf@plt>
test   %eax,%eax
je     139f <test_zfprintf+0x22f>
mov    %r14,%rdi
call   1030 <fclose@plt>
test   %eax,%eax
je     13cd <test_zfprintf+0x25d>
mov    %eax,%r14d
mov    0x2c75(%rip),%rax
mov    (%rax),%edi
lea    0xcb2(%rip),%rsi
lea    0xd63(%rip),%rcx
mov    $0xa1,%edx
jmp    11d2 <test_zfprintf+0x62>
mov    0x2c4c(%rip),%rax
xor    %r14d,%r14d
sub    (%rax),%r14d
mov    0x2c47(%rip),%rax
mov    (%rax),%edi
lea    0xd68(%rip),%rsi
jmp    1254 <test_zfprintf+0xe4>
mov    0x2c32(%rip),%rax
mov    (%rax),%edi
lea    0xc6f(%rip),%rsi
lea    0xd92(%rip),%rcx
mov    $0xa0,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%r14d
jmp    11d9 <test_zfprintf+0x69>
xor    %r14d,%r14d
jmp    11d9 <test_zfprintf+0x69>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@__const.test_zfprintf.expected = [18 x i8] c"abracadabra i=123\00"
@.str = [12 x i8] c"%s/zfprintf\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"failed on line %d: %s\0A\00"
@.str.2 = [53 x i8] c"zsnprintf(fname, sizeof(fname), \22%s/zfprintf\22, tdir)\00"
@.str.3 = [2 x i8] c"w\00"
@errno = global i32 0
@.str.4 = [53 x i8] c"test_zfprintf: error opening %s for write: error %d\0A\00"
@.str.5 = [17 x i8] c"abracadabra i=%d\00"
@.str.6 = [36 x i8] c"zfprintf(fp, \22abracadabra i=%d\22, i)\00"
@.str.7 = [11 x i8] c"fclose(fp)\00"
@.str.8 = [4 x i8] c"res\00"
@.str.9 = [27 x i8] c"memcmp(expected, buf, res)\00"
@.str.10 = [2 x i8] c"r\00"
@.str.11 = [52 x i8] c"test_zfprintf: error opening %s for read: error %d\0A\00"
@.str.12 = [18 x i8] c"abracadabra i=%d\0A\00"
@.str.13 = [38 x i8] c"zfprintf(fp, \22abracadabra i=%d\\n\22, i)\00"
define i32 @test_zfprintf(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca [512 x i8]
%10 = alloca [18 x i8]
%11 = alloca i64
%12 = alloca i64
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
store i8* %0, i8** %3
%20 = load i32, i32* @PATH_MAX
%21 = zext i32 %20 to i64
%22 = call i8* @llvm.stacksave()
store i8* %22, i8** %7
%23 = alloca i8, i64 %21
store i64 %21, i64* %8
%24 = bitcast [18 x i8]* %10 to i8*
br label %25
25: ; preds = %1
%26 = trunc i64 %21 to i32
%27 = load i8*, i8** %3
%28 = call i32 @zsnprintf(i8* %23, i32 %26, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %27)
store i32 %28, i32* %13
%29 = load i32, i32* %13
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %25
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 136, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
%34 = load i32, i32* %13
store i32 %34, i32* %2
store i32 1, i32* %14
br label %137
35: ; preds = %25
br label %36
36: ; preds = %35
br label %37
37: ; preds = %36
%38 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %38, i32** %6
%39 = load i32*, i32** %6
%40 = icmp ne i32* %39, null
br i1 %40, label %48, label %41
41: ; preds = %37
%42 = load i32, i32* @errno
%43 = sub nsw i32 0, %42
store i32 %43, i32* %4
%44 = load i32, i32* @stderr
%45 = load i32, i32* %4
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i8* %23, i32 %45)
%47 = load i32, i32* %4
store i32 %47, i32* %2
store i32 1, i32* %14
br label %137
48: ; preds = %37
store i32 123, i32* %5
br label %49
49: ; preds = %48
%50 = load i32*, i32** %6
%51 = load i32, i32* %5
%52 = call i32 @zfprintf(i32* %50, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 %51)
store i32 %52, i32* %15
%53 = load i32, i32* %15
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %59
55: ; preds = %49
%56 = load i32, i32* @stderr
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 145, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
%58 = load i32, i32* %15
store i32 %58, i32* %2
store i32 1, i32* %14
br label %137
59: ; preds = %49
br label %60
60: ; preds = %59
br label %61
61: ; preds = %60
br label %62
62: ; preds = %61
%63 = load i32*, i32** %6
%64 = call i32 @fclose(i32* %63)
store i32 %64, i32* %16
%65 = load i32, i32* %16
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %71
67: ; preds = %62
%68 = load i32, i32* @stderr
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 146, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%70 = load i32, i32* %16
store i32 %70, i32* %2
store i32 1, i32* %14
br label %137
71: ; preds = %62
br label %72
72: ; preds = %71
br label %73
73: ; preds = %72
%74 = getelementptr inbounds [18 x i8], [18 x i8]* %10, i64 0, i64 0
%75 = call i64 @strlen(i8* %74)
store i64 %75, i64* %11
%76 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%77 = call i64 @simple_io_read_whole_file_zt(i8* %23, i8* %76, i32 511)
store i64 %77, i64* %12
br label %78
78: ; preds = %73
%79 = load i64, i64* %12
%80 = load i64, i64* %11
%81 = icmp ne i64 %79, %80
br i1 %81, label %82, label %85
82: ; preds = %78
%83 = load i32, i32* @stderr
%84 = call i32 (i32, i8*, ...) @fprintf(i32 %83, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 149, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %2
store i32 1, i32* %14
br label %137
85: ; preds = %78
br label %86
86: ; preds = %85
br label %87
87: ; preds = %86
br label %88
88: ; preds = %87
%89 = getelementptr inbounds [18 x i8], [18 x i8]* %10, i64 0, i64 0
%90 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%91 = load i64, i64* %12
%92 = call i32 @memcmp(i8* %89, i8* %90, i64 %91)
store i32 %92, i32* %17
%93 = load i32, i32* %17
%94 = icmp ne i32 %93, 0
br i1 %94, label %95, label %99
95: ; preds = %88
%96 = load i32, i32* @stderr
%97 = call i32 (i32, i8*, ...) @fprintf(i32 %96, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 150, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
%98 = load i32, i32* %17
store i32 %98, i32* %2
store i32 1, i32* %14
br label %137
99: ; preds = %88
br label %100
100: ; preds = %99
br label %101
101: ; preds = %100
%102 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
store i32* %102, i32** %6
%103 = load i32*, i32** %6
%104 = icmp ne i32* %103, null
br i1 %104, label %112, label %105
105: ; preds = %101
%106 = load i32, i32* @errno
%107 = sub nsw i32 0, %106
store i32 %107, i32* %4
%108 = load i32, i32* @stderr
%109 = load i32, i32* %4
%110 = call i32 (i32, i8*, ...) @fprintf(i32 %108, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.11, i64 0, i64 0), i8* %23, i32 %109)
%111 = load i32, i32* %4
store i32 %111, i32* %2
store i32 1, i32* %14
br label %137
112: ; preds = %101
br label %113
113: ; preds = %112
%114 = load i32*, i32** %6
%115 = load i32, i32* %5
%116 = call i32 @zfprintf(i32* %114, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0), i32 %115)
store i32 %116, i32* %18
%117 = load i32, i32* %18
%118 = icmp eq i32 %117, 0
br i1 %118, label %119, label %122
119: ; preds = %113
%120 = load i32, i32* @stderr
%121 = call i32 (i32, i8*, ...) @fprintf(i32 %120, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 160, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.13, i64 0, i64 0))
store i32 -1, i32* %2
store i32 1, i32* %14
br label %137
122: ; preds = %113
br label %123
123: ; preds = %122
br label %124
124: ; preds = %123
br label %125
125: ; preds = %124
%126 = load i32*, i32** %6
%127 = call i32 @fclose(i32* %126)
store i32 %127, i32* %19
%128 = load i32, i32* %19
%129 = icmp ne i32 %128, 0
br i1 %129, label %130, label %134
130: ; preds = %125
%131 = load i32, i32* @stderr
%132 = call i32 (i32, i8*, ...) @fprintf(i32 %131, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 161, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%133 = load i32, i32* %19
store i32 %133, i32* %2
store i32 1, i32* %14
br label %137
134: ; preds = %125
br label %135
135: ; preds = %134
br label %136
136: ; preds = %135
store i32 0, i32* %2
store i32 1, i32* %14
br label %137
137: ; preds = %136, %130, %119, %105, %95, %82, %67, %55, %41, %31
%138 = load i8*, i8** %7
%139 = load i32, i32* %2
ret i32 %139
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@__const.test_zfprintf.expected = [18 x i8] c"abracadabra i=123\00"
@.str = [12 x i8] c"%s/zfprintf\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"failed on line %d: %s\0A\00"
@.str.2 = [53 x i8] c"zsnprintf(fname, sizeof(fname), \22%s/zfprintf\22, tdir)\00"
@.str.3 = [2 x i8] c"w\00"
@errno = global i32 0
@.str.4 = [53 x i8] c"test_zfprintf: error opening %s for write: error %d\0A\00"
@.str.5 = [17 x i8] c"abracadabra i=%d\00"
@.str.6 = [36 x i8] c"zfprintf(fp, \22abracadabra i=%d\22, i)\00"
@.str.7 = [11 x i8] c"fclose(fp)\00"
@.str.8 = [4 x i8] c"res\00"
@.str.9 = [27 x i8] c"memcmp(expected, buf, res)\00"
@.str.10 = [2 x i8] c"r\00"
@.str.11 = [52 x i8] c"test_zfprintf: error opening %s for read: error %d\0A\00"
@.str.12 = [18 x i8] c"abracadabra i=%d\0A\00"
@.str.13 = [38 x i8] c"zfprintf(fp, \22abracadabra i=%d\\n\22, i)\00"
define i32 @test_zfprintf(i8* %0) {
%2 = alloca [512 x i8]
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%7 = call i32 @zsnprintf(i8* %5, i32 %3, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = icmp eq i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 136, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
br label %64
12: ; preds = %1
%13 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = load i32, i32* @errno
%17 = sub nsw i32 0, %16
%18 = load i32, i32* @stderr
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i8* %5, i32 %17)
br label %64
20: ; preds = %12
%21 = call i32 @zfprintf(i32* %13, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 123)
%22 = icmp eq i32 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 145, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
br label %64
26: ; preds = %20
%27 = call i32 @fclose(i32* %13)
%28 = icmp eq i32 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 146, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
br label %64
32: ; preds = %26
%33 = call i64 @simple_io_read_whole_file_zt(i8* %5, i8* %6, i32 511)
%34 = icmp eq i64 %33, 17
br i1 %34, label %38, label %35
35: ; preds = %32
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 149, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
br label %64
38: ; preds = %32
%39 = call i32 @memcmp(i8* dereferenceable(17) getelementptr inbounds ([18 x i8], [18 x i8]* @__const.test_zfprintf.expected, i64 0, i64 0), i8* dereferenceable(17) %6, i64 17)
%40 = icmp eq i32 %39, 0
br i1 %40, label %44, label %41
41: ; preds = %38
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 150, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
br label %64
44: ; preds = %38
%45 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%46 = icmp eq i32* %45, null
br i1 %46, label %47, label %52
47: ; preds = %44
%48 = load i32, i32* @errno
%49 = sub nsw i32 0, %48
%50 = load i32, i32* @stderr
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.11, i64 0, i64 0), i8* %5, i32 %49)
br label %64
52: ; preds = %44
%53 = call i32 @zfprintf(i32* %45, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0), i32 123)
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %52
%56 = load i32, i32* @stderr
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 160, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.13, i64 0, i64 0))
br label %64
58: ; preds = %52
%59 = call i32 @fclose(i32* %45)
%60 = icmp eq i32 %59, 0
br i1 %60, label %64, label %61
61: ; preds = %58
%62 = load i32, i32* @stderr
%63 = call i32 (i32, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 161, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
br label %64
64: ; preds = %61, %58, %55, %41, %29, %23, %9, %47, %35, %15
%65 = phi i32 [ 1, %35 ], [ %49, %47 ], [ %39, %41 ], [ %27, %29 ], [ %21, %23 ], [ %17, %15 ], [ %7, %9 ], [ -1, %55 ], [ 0, %58 ], [ %59, %61 ]
ret i32 %65
}