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

/* Forward declarations */

/* Type definitions */
struct fast_log_buf {
  int dummy;
};
typedef int /*<<< orphan*/ fname;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ EINTR;
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int PATH_MAX;
int close(int);
int /*<<< orphan*/ create_some_logs(struct fast_log_buf *, int);
scalar_t__ errno;
struct fast_log_buf *fast_log_create(char *);
int /*<<< orphan*/ fast_log_destroy(struct fast_log_buf *);
int fast_log_dump(struct fast_log_buf *, struct fast_log_buf *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int open(char *, int, int);
scalar_t__ simple_io_read_whole_file_zt(char *, char *, int);
int /*<<< orphan*/ stderr;
int strcmp(char *, char const *);
int zsnprintf(char *, int, char *, char const *);
int dump_small_buf(const char *tdir) {
  char fname[PATH_MAX];
  char buf[512] = {0};
  const char expected[] = "*** FASTLOG small\nfoo=0x1, bar=0x2, "
                          "bar=0x3\nfoo=0x10, bar=0x20, bar=0x30\nblah blah\n";
  struct fast_log_buf *scratch, *small;
  int res, fd;
  do {
    int __my_ret__ = zsnprintf(fname, sizeof(fname), "%s/small", tdir);
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 145,
              "zsnprintf(fname, sizeof(fname), \"%s/small\", tdir)");
      return __my_ret__;
    }
  } while (0);
  ;
  fd = open(fname, O_CREAT | O_TRUNC | O_RDWR, 0644);
  do {
    if (fd < 0) {
      fprintf(stderr, "failed on line %d: %s\n", 147, "fd");
      return 1;
    }
  } while (0);
  ;
  scratch = fast_log_create("scratch");
  do {
    if (scratch == NULL) {
      fprintf(stderr, "failed on line %d: %s\n", 149, "scratch");
      return 1;
    }
  } while (0);
  ;
  small = fast_log_create("small");
  do {
    if (small == NULL) {
      fprintf(stderr, "failed on line %d: %s\n", 151, "small");
      return 1;
    }
  } while (0);
  ;
  create_some_logs(small, 1);
  do {
    int __my_ret__ = fast_log_dump(small, scratch, fd);
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 153,
              "fast_log_dump(small, scratch, fd)");
      return __my_ret__;
    }
  } while (0);
  ;
  do {
    res = close(fd);
  } while ((res == -1) && (errno == EINTR));
  ;
  fast_log_destroy(small);
  fast_log_destroy(scratch);
  do {
    if (simple_io_read_whole_file_zt(fname, buf, sizeof(buf)) <= 0) {
      fprintf(stderr, "failed on line %d: %s\n", 158,
              "simple_io_read_whole_file_zt(fname, buf, sizeof(buf))");
      return 1;
    }
  } while (0);
  ;
  do {
    int __my_ret__ = strcmp(buf, expected);
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 159, "strcmp(buf, expected)");
      return __my_ret__;
    }
  } while (0);
  ;
  return 0;
}


x86 assembly (clang, -O0):
<dump_small_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2c0,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e0a(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x2b8(%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,-0x2b0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1070 <memset@plt>
lea    -0x280(%rbp),%rdi
lea    0xdda(%rip),%rsi
mov    $0x54,%edx
call   10c0 <memcpy@plt>
mov    -0x2b0(%rbp),%rdi
mov    -0x2b8(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rcx
lea    0xe09(%rip),%rdx
call   10d0 <zsnprintf@plt>
mov    %eax,-0x29c(%rbp)
cmpl   $0x0,-0x29c(%rbp)
je     129c <dump_small_buf+0xdc>
mov    0x2d56(%rip),%rax
mov    (%rax),%edi
lea    0xdea(%rip),%rsi
mov    $0x91,%edx
lea    0xdf5(%rip),%rcx
call   10a0 <fprintf@plt>
mov    -0x29c(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2a0(%rbp)
jmp    15ba <dump_small_buf+0x3fa>
jmp    12a1 <dump_small_buf+0xe1>
jmp    12a6 <dump_small_buf+0xe6>
mov    -0x2b0(%rbp),%rdi
mov    0x2d44(%rip),%rax
mov    (%rax),%esi
mov    0x2d33(%rip),%rax
or     (%rax),%esi
mov    0x2d0a(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   10e0 <open@plt>
mov    %eax,-0x298(%rbp)
cmpl   $0x0,-0x298(%rbp)
jge    131c <dump_small_buf+0x15c>
mov    0x2cd4(%rip),%rax
mov    (%rax),%edi
lea    0xd68(%rip),%rsi
mov    $0x93,%edx
lea    0xda5(%rip),%rcx
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x2a0(%rbp)
jmp    15ba <dump_small_buf+0x3fa>
jmp    1321 <dump_small_buf+0x161>
jmp    1326 <dump_small_buf+0x166>
lea    0xd7c(%rip),%rdi
call   1040 <fast_log_create@plt>
mov    %rax,-0x288(%rbp)
cmpq   $0x0,-0x288(%rbp)
jne    137e <dump_small_buf+0x1be>
mov    0x2c72(%rip),%rax
mov    (%rax),%edi
lea    0xd06(%rip),%rsi
mov    $0x95,%edx
lea    0xd46(%rip),%rcx
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x2a0(%rbp)
jmp    15ba <dump_small_buf+0x3fa>
jmp    1383 <dump_small_buf+0x1c3>
jmp    1388 <dump_small_buf+0x1c8>
lea    0xcc8(%rip),%rdi
call   1040 <fast_log_create@plt>
mov    %rax,-0x290(%rbp)
cmpq   $0x0,-0x290(%rbp)
jne    13e0 <dump_small_buf+0x220>
mov    0x2c10(%rip),%rax
mov    (%rax),%edi
lea    0xca4(%rip),%rsi
mov    $0x97,%edx
lea    0xc92(%rip),%rcx
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x2a0(%rbp)
jmp    15ba <dump_small_buf+0x3fa>
jmp    13e5 <dump_small_buf+0x225>
jmp    13ea <dump_small_buf+0x22a>
mov    -0x290(%rbp),%rdi
mov    $0x1,%esi
call   1050 <create_some_logs@plt>
mov    -0x290(%rbp),%rdi
mov    -0x288(%rbp),%rsi
mov    -0x298(%rbp),%edx
call   10b0 <fast_log_dump@plt>
mov    %eax,-0x2a4(%rbp)
cmpl   $0x0,-0x2a4(%rbp)
je     1460 <dump_small_buf+0x2a0>
mov    0x2b92(%rip),%rax
mov    (%rax),%edi
lea    0xc26(%rip),%rsi
mov    $0x99,%edx
lea    0xc6e(%rip),%rcx
call   10a0 <fprintf@plt>
mov    -0x2a4(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2a0(%rbp)
jmp    15ba <dump_small_buf+0x3fa>
jmp    1465 <dump_small_buf+0x2a5>
jmp    146a <dump_small_buf+0x2aa>
jmp    146f <dump_small_buf+0x2af>
mov    -0x298(%rbp),%edi
call   1080 <close@plt>
mov    %eax,-0x294(%rbp)
xor    %eax,%eax
cmpl   $0xffffffff,-0x294(%rbp)
mov    %al,-0x2b9(%rbp)
jne    14b2 <dump_small_buf+0x2f2>
mov    0x2b1c(%rip),%rax
mov    (%rax),%rax
mov    0x2b0a(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x2b9(%rbp)
mov    -0x2b9(%rbp),%al
test   $0x1,%al
jne    146f <dump_small_buf+0x2af>
mov    -0x290(%rbp),%rdi
call   1030 <fast_log_destroy@plt>
mov    -0x288(%rbp),%rdi
call   1030 <fast_log_destroy@plt>
mov    -0x2b0(%rbp),%rdi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
call   1060 <simple_io_read_whole_file_zt@plt>
cmp    $0x0,%rax
jg     1531 <dump_small_buf+0x371>
mov    0x2abf(%rip),%rax
mov    (%rax),%edi
lea    0xb53(%rip),%rsi
mov    $0x9e,%edx
lea    0xbbd(%rip),%rcx
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x2a0(%rbp)
jmp    15ba <dump_small_buf+0x3fa>
jmp    1536 <dump_small_buf+0x376>
jmp    153b <dump_small_buf+0x37b>
jmp    1540 <dump_small_buf+0x380>
lea    -0x220(%rbp),%rdi
lea    -0x280(%rbp),%rsi
call   1090 <strcmp@plt>
mov    %eax,-0x2a8(%rbp)
cmpl   $0x0,-0x2a8(%rbp)
je     159f <dump_small_buf+0x3df>
mov    0x2a53(%rip),%rax
mov    (%rax),%edi
lea    0xae7(%rip),%rsi
mov    $0x9f,%edx
lea    0xb87(%rip),%rcx
call   10a0 <fprintf@plt>
mov    -0x2a8(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2a0(%rbp)
jmp    15ba <dump_small_buf+0x3fa>
jmp    15a4 <dump_small_buf+0x3e4>
jmp    15a9 <dump_small_buf+0x3e9>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x2a0(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_small_buf>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %rdi,%r14
mov    0x2e12(%rip),%rax
mov    (%rax),%ebx
mov    %rsp,%r12
mov    %rbx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    -0x230(%rbp),%rdi
mov    $0x200,%edx
xor    %esi,%esi
call   1070 <memset@plt>
lea    0xe56(%rip),%rdx
mov    %r12,%rdi
mov    %ebx,%esi
mov    %r14,%rcx
call   10c0 <zsnprintf@plt>
test   %eax,%eax
je     1238 <dump_small_buf+0x88>
mov    %eax,%r14d
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
lea    0xe3b(%rip),%rsi
lea    0xe4b(%rip),%rcx
mov    $0x91,%edx
call   10a0 <fprintf@plt>
jmp    1341 <dump_small_buf+0x191>
mov    0x2db9(%rip),%rax
mov    0x2daa(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d7f(%rip),%rax
or     (%rax),%esi
mov    %r12,%rdi
mov    $0x1a4,%edx
call   10d0 <open@plt>
test   %eax,%eax
js     12de <dump_small_buf+0x12e>
mov    %eax,%r15d
lea    0xe3b(%rip),%rdi
call   1040 <fast_log_create@plt>
test   %rax,%rax
je     12fc <dump_small_buf+0x14c>
mov    %rax,%rbx
lea    0xdd1(%rip),%rdi
call   1040 <fast_log_create@plt>
test   %rax,%rax
je     131a <dump_small_buf+0x16a>
mov    %rax,%r13
mov    %rax,%rdi
mov    $0x1,%esi
call   1050 <create_some_logs@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   10b0 <fast_log_dump@plt>
test   %eax,%eax
je     1353 <dump_small_buf+0x1a3>
mov    %eax,%r14d
mov    0x2cfc(%rip),%rax
mov    (%rax),%edi
lea    0xd90(%rip),%rsi
lea    0xddd(%rip),%rcx
mov    $0x99,%edx
jmp    122e <dump_small_buf+0x7e>
mov    0x2cdb(%rip),%rax
mov    (%rax),%edi
lea    0xd6f(%rip),%rsi
lea    0xdb1(%rip),%rcx
mov    $0x93,%edx
jmp    1336 <dump_small_buf+0x186>
mov    0x2cbd(%rip),%rax
mov    (%rax),%edi
lea    0xd51(%rip),%rsi
lea    0xd96(%rip),%rcx
mov    $0x95,%edx
jmp    1336 <dump_small_buf+0x186>
mov    0x2c9f(%rip),%rax
mov    (%rax),%edi
lea    0xd33(%rip),%rsi
lea    0xd26(%rip),%rcx
mov    $0x97,%edx
call   10a0 <fprintf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,-0x30(%rbp)
mov    0x2c5a(%rip),%r14
mov    0x2c4b(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15d,%edi
call   1080 <close@plt>
cmp    $0xffffffff,%eax
jne    1385 <dump_small_buf+0x1d5>
mov    (%rbx),%rax
cmp    %rax,(%r14)
je     1370 <dump_small_buf+0x1c0>
mov    %r13,%rdi
call   1030 <fast_log_destroy@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fast_log_destroy@plt>
lea    -0x230(%rbp),%rsi
mov    %r12,%rdi
mov    $0x200,%edx
call   1060 <simple_io_read_whole_file_zt@plt>
test   %rax,%rax
jle    13ea <dump_small_buf+0x23a>
lea    0xc4a(%rip),%rsi
lea    -0x230(%rbp),%rdi
call   1090 <strcmp@plt>
test   %eax,%eax
je     140b <dump_small_buf+0x25b>
mov    %eax,%r14d
mov    0x2bf0(%rip),%rax
mov    (%rax),%edi
lea    0xc84(%rip),%rsi
lea    0xd29(%rip),%rcx
mov    $0x9f,%edx
jmp    122e <dump_small_buf+0x7e>
mov    0x2bcf(%rip),%rax
mov    (%rax),%edi
lea    0xc63(%rip),%rsi
lea    0xcd2(%rip),%rcx
mov    $0x9e,%edx
jmp    1336 <dump_small_buf+0x186>
xor    %r14d,%r14d
jmp    1341 <dump_small_buf+0x191>

LLVM IR (-O0):
%struct.fast_log_buf = type { i32 }
@PATH_MAX = global i32 0
@__const.dump_small_buf.expected = [84 x i8] c"*** FASTLOG small\0Afoo=0x1, bar=0x2, bar=0x3\0Afoo=0x10, bar=0x20, bar=0x30\0Ablah blah\0A\00"
@.str = [9 x i8] c"%s/small\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"failed on line %d: %s\0A\00"
@.str.2 = [50 x i8] c"zsnprintf(fname, sizeof(fname), \22%s/small\22, tdir)\00"
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_RDWR = global i32 0
@.str.3 = [3 x i8] c"fd\00"
@.str.4 = [8 x i8] c"scratch\00"
@.str.5 = [6 x i8] c"small\00"
@.str.6 = [34 x i8] c"fast_log_dump(small, scratch, fd)\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.7 = [54 x i8] c"simple_io_read_whole_file_zt(fname, buf, sizeof(buf))\00"
@.str.8 = [22 x i8] c"strcmp(buf, expected)\00"
define i32 @dump_small_buf(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca [512 x i8]
%7 = alloca [84 x i8]
%8 = alloca %struct.fast_log_buf*
%9 = alloca %struct.fast_log_buf*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i8* %0, i8** %3
%16 = load i32, i32* @PATH_MAX
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %4
%19 = alloca i8, i64 %17
store i64 %17, i64* %5
%20 = bitcast [512 x i8]* %6 to i8*
%21 = bitcast [84 x i8]* %7 to i8*
br label %22
22: ; preds = %1
%23 = trunc i64 %17 to i32
%24 = load i8*, i8** %3
%25 = call i32 @zsnprintf(i8* %19, i32 %23, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %24)
store i32 %25, i32* %12
%26 = load i32, i32* %12
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %22
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 145, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
%31 = load i32, i32* %12
store i32 %31, i32* %2
store i32 1, i32* %13
br label %126
32: ; preds = %22
br label %33
33: ; preds = %32
br label %34
34: ; preds = %33
%35 = load i32, i32* @O_CREAT
%36 = load i32, i32* @O_TRUNC
%37 = or i32 %35, %36
%38 = load i32, i32* @O_RDWR
%39 = or i32 %37, %38
%40 = call i32 @open(i8* %19, i32 %39, i32 420)
store i32 %40, i32* %11
br label %41
41: ; preds = %34
%42 = load i32, i32* %11
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %41
%45 = load i32, i32* @stderr
%46 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 147, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %2
store i32 1, i32* %13
br label %126
47: ; preds = %41
br label %48
48: ; preds = %47
br label %49
49: ; preds = %48
%50 = call %struct.fast_log_buf* @fast_log_create(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
store %struct.fast_log_buf* %50, %struct.fast_log_buf** %8
br label %51
51: ; preds = %49
%52 = load %struct.fast_log_buf*, %struct.fast_log_buf** %8
%53 = icmp eq %struct.fast_log_buf* %52, null
br i1 %53, label %54, label %57
54: ; preds = %51
%55 = load i32, i32* @stderr
%56 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 149, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %2
store i32 1, i32* %13
br label %126
57: ; preds = %51
br label %58
58: ; preds = %57
br label %59
59: ; preds = %58
%60 = call %struct.fast_log_buf* @fast_log_create(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
store %struct.fast_log_buf* %60, %struct.fast_log_buf** %9
br label %61
61: ; preds = %59
%62 = load %struct.fast_log_buf*, %struct.fast_log_buf** %9
%63 = icmp eq %struct.fast_log_buf* %62, null
br i1 %63, label %64, label %67
64: ; preds = %61
%65 = load i32, i32* @stderr
%66 = call i32 @fprintf(i32 %65, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 151, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %2
store i32 1, i32* %13
br label %126
67: ; preds = %61
br label %68
68: ; preds = %67
br label %69
69: ; preds = %68
%70 = load %struct.fast_log_buf*, %struct.fast_log_buf** %9
%71 = call i32 @create_some_logs(%struct.fast_log_buf* %70, i32 1)
br label %72
72: ; preds = %69
%73 = load %struct.fast_log_buf*, %struct.fast_log_buf** %9
%74 = load %struct.fast_log_buf*, %struct.fast_log_buf** %8
%75 = load i32, i32* %11
%76 = call i32 @fast_log_dump(%struct.fast_log_buf* %73, %struct.fast_log_buf* %74, i32 %75)
store i32 %76, i32* %14
%77 = load i32, i32* %14
%78 = icmp ne i32 %77, 0
br i1 %78, label %79, label %83
79: ; preds = %72
%80 = load i32, i32* @stderr
%81 = call i32 @fprintf(i32 %80, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 153, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0))
%82 = load i32, i32* %14
store i32 %82, i32* %2
store i32 1, i32* %13
br label %126
83: ; preds = %72
br label %84
84: ; preds = %83
br label %85
85: ; preds = %84
br label %86
86: ; preds = %96, %85
%87 = load i32, i32* %11
%88 = call i32 @close(i32 %87)
store i32 %88, i32* %10
br label %89
89: ; preds = %86
%90 = load i32, i32* %10
%91 = icmp eq i32 %90, -1
br i1 %91, label %92, label %96
92: ; preds = %89
%93 = load i64, i64* @errno
%94 = load i64, i64* @EINTR
%95 = icmp eq i64 %93, %94
br label %96
96: ; preds = %92, %89
%97 = phi i1 [ false, %89 ], [ %95, %92 ]
br i1 %97, label %86, label %98
98: ; preds = %96
%99 = load %struct.fast_log_buf*, %struct.fast_log_buf** %9
%100 = call i32 @fast_log_destroy(%struct.fast_log_buf* %99)
%101 = load %struct.fast_log_buf*, %struct.fast_log_buf** %8
%102 = call i32 @fast_log_destroy(%struct.fast_log_buf* %101)
br label %103
103: ; preds = %98
%104 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%105 = call i64 @simple_io_read_whole_file_zt(i8* %19, i8* %104, i32 512)
%106 = icmp sle i64 %105, 0
br i1 %106, label %107, label %110
107: ; preds = %103
%108 = load i32, i32* @stderr
%109 = call i32 @fprintf(i32 %108, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 158, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %2
store i32 1, i32* %13
br label %126
110: ; preds = %103
br label %111
111: ; preds = %110
br label %112
112: ; preds = %111
br label %113
113: ; preds = %112
%114 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%115 = getelementptr inbounds [84 x i8], [84 x i8]* %7, i64 0, i64 0
%116 = call i32 @strcmp(i8* %114, i8* %115)
store i32 %116, i32* %15
%117 = load i32, i32* %15
%118 = icmp ne i32 %117, 0
br i1 %118, label %119, label %123
119: ; preds = %113
%120 = load i32, i32* @stderr
%121 = call i32 @fprintf(i32 %120, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 159, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0))
%122 = load i32, i32* %15
store i32 %122, i32* %2
store i32 1, i32* %13
br label %126
123: ; preds = %113
br label %124
124: ; preds = %123
br label %125
125: ; preds = %124
store i32 0, i32* %2
store i32 1, i32* %13
br label %126
126: ; preds = %125, %119, %107, %79, %64, %54, %44, %28
%127 = load i8*, i8** %4
%128 = load i32, i32* %2
ret i32 %128
}

LLVM IR (-O2):
%struct.fast_log_buf = type { i32 }
@PATH_MAX = global i32 0
@__const.dump_small_buf.expected = [84 x i8] c"*** FASTLOG small\0Afoo=0x1, bar=0x2, bar=0x3\0Afoo=0x10, bar=0x20, bar=0x30\0Ablah blah\0A\00"
@.str = [9 x i8] c"%s/small\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"failed on line %d: %s\0A\00"
@.str.2 = [50 x i8] c"zsnprintf(fname, sizeof(fname), \22%s/small\22, tdir)\00"
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_RDWR = global i32 0
@.str.3 = [3 x i8] c"fd\00"
@.str.4 = [8 x i8] c"scratch\00"
@.str.5 = [6 x i8] c"small\00"
@.str.6 = [34 x i8] c"fast_log_dump(small, scratch, fd)\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.7 = [54 x i8] c"simple_io_read_whole_file_zt(fname, buf, sizeof(buf))\00"
@.str.8 = [22 x i8] c"strcmp(buf, expected)\00"
define i32 @dump_small_buf(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 ([9 x i8], [9 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 @fprintf(i32 %10, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 145, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
br label %63
12: ; preds = %1
%13 = load i32, i32* @O_CREAT
%14 = load i32, i32* @O_TRUNC
%15 = or i32 %14, %13
%16 = load i32, i32* @O_RDWR
%17 = or i32 %15, %16
%18 = call i32 @open(i8* %5, i32 %17, i32 420)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %12
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 147, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %63
23: ; preds = %12
%24 = call %struct.fast_log_buf* @fast_log_create(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%25 = icmp eq %struct.fast_log_buf* %24, null
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 149, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %63
29: ; preds = %23
%30 = call %struct.fast_log_buf* @fast_log_create(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%31 = icmp eq %struct.fast_log_buf* %30, null
br i1 %31, label %32, label %35
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 151, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %63
35: ; preds = %29
%36 = call i32 @create_some_logs(%struct.fast_log_buf* %30, i32 1)
%37 = call i32 @fast_log_dump(%struct.fast_log_buf* %30, %struct.fast_log_buf* %24, i32 %18)
%38 = icmp eq i32 %37, 0
br i1 %38, label %42, label %39
39: ; preds = %35
%40 = load i32, i32* @stderr
%41 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 153, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0))
br label %63
42: ; preds = %35, %42
%43 = call i32 @close(i32 %18)
%44 = icmp eq i32 %43, -1
%45 = load i64, i64* @errno
%46 = load i64, i64* @EINTR
%47 = icmp eq i64 %45, %46
%48 = select i1 %44, i1 %47, i1 false
br i1 %48, label %42, label %49
49: ; preds = %42
%50 = call i32 @fast_log_destroy(%struct.fast_log_buf* %30)
%51 = call i32 @fast_log_destroy(%struct.fast_log_buf* %24)
%52 = call i64 @simple_io_read_whole_file_zt(i8* %5, i8* %6, i32 512)
%53 = icmp slt i64 %52, 1
br i1 %53, label %54, label %57
54: ; preds = %49
%55 = load i32, i32* @stderr
%56 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 158, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.7, i64 0, i64 0))
br label %63
57: ; preds = %49
%58 = call i32 @strcmp(i8* %6, i8* dereferenceable(84) getelementptr inbounds ([84 x i8], [84 x i8]* @__const.dump_small_buf.expected, i64 0, i64 0))
%59 = icmp eq i32 %58, 0
br i1 %59, label %63, label %60
60: ; preds = %57
%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 159, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0))
br label %63
63: ; preds = %60, %57, %39, %9, %54, %32, %26, %20
%64 = phi i32 [ 1, %20 ], [ 1, %26 ], [ 1, %32 ], [ 1, %54 ], [ %7, %9 ], [ %37, %39 ], [ 0, %57 ], [ %58, %60 ]
ret i32 %64
}