#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 stat {
  int st_mode;
  int st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int ENAMETOOLONG;
int ENOENT;
int ENOTSUP;
int /*<<< orphan*/ F_GETFL;
int O_RDONLY;
int S_IFMT;
int S_IFREG;
scalar_t__ close(int);
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fcntl(int, int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
scalar_t__ fstat(int, struct stat *);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ remove(char *);
scalar_t__ rename(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stdout;
int strlen(char *);
int utils_test(void) {
  FILE *f;
  struct stat st;
  int fd;
  int tmp;
  bool fail;
  char buffer[64];
  f = fopen("/home/test.txt", "w");
  if (f == NULL) {
    perror("failed to create /home/test.txt");
    return -1;
  }
  sprintf(buffer, "This is a write Test\n");
  fprintf(f, buffer);
  fclose(f);
  printf("Test stat()...");
  if (stat("/home/test.txt", &st) < 0) {
    fflush(stdout);
    perror("failed");
    return -1;
  }
  if ((st.st_mode & S_IFMT) != S_IFREG) {
    printf("/home/test.txt is not a regular file (0%o)\n", st.st_mode);
    return -1;
  }
  if (st.st_size != strlen(buffer)) {
    printf("/home/test.txt is not %d bytes (%d)\n", (int)strlen(buffer),
           (int)st.st_size);
    return -1;
  }
  printf("passed\n");
  errno = 0;
  printf("Test open()...ENAMETOOLONG...");
  fd = open("/home/1234567890123456789012345678901234567890", O_RDONLY);
  if (errno == ENAMETOOLONG) {
    printf("passed\n");
    errno = 0;
  } else {
    printf("failed (errno %d != %d)\n", errno, ENAMETOOLONG);
    return -1;
  }
  errno = 0;
  printf("Test open()...ENAMETOOLONG...");
  fd = open("/1234567890123456789012345678901234567890", O_RDONLY);
  if (errno == ENAMETOOLONG) {
    printf("passed\n");
    errno = 0;
  } else {
    printf("failed (errno %d != %d)\n", errno, ENAMETOOLONG);
    return -1;
  }
  errno = 0;
  printf("Test open()...ENOENT...");
  fd = open("/home/nofile", O_RDONLY);
  if (errno == ENOENT) {
    printf("passed\n");
    errno = 0;
  } else {
    printf("failed (errno %d != %d)\n", errno, ENOENT);
    return -1;
  }
  errno = 0;
  printf("Test open()...ENOTSUP...");
  fd = open("/nodir/nofile", O_RDONLY);
  if (errno == ENOTSUP) {
    printf("passed\n");
    errno = 0;
  } else {
    printf("failed (errno %d != %d)\n", errno, ENOTSUP);
    return -1;
  }
  printf("Test open()...");
  fd = open("/home/test.txt", O_RDONLY);
  if (fd < 0) {
    fflush(stdout);
    perror("failed");
    return -1;
  }
  printf("passed\n");
  printf("Test fstat()...");
  if (fstat(fd, &st) < 0) {
    fflush(stdout);
    perror("failed");
    return -1;
  }
  if ((st.st_mode & S_IFMT) != S_IFREG) {
    printf("/home/test.txt is not a regular file (0%o)\n", st.st_mode);
    return -1;
  }
  if (st.st_size != 21) {
    printf("/home/test.txt is not 21 bytes (%d)\n", (int)st.st_size);
    return -1;
  }
  printf("passed\n");
  fail = false;
  printf("test fcntl()...F_GETFL...");
  tmp = fcntl(fd, F_GETFL);
  if (tmp != O_RDONLY) {
    printf("F_GETFL access is not O_RDONLY (0x%X)\n", tmp);
    fail = true;
  }
  if (!fail) {
    printf("passed\n");
  }
  if (close(fd) < 0) {
    printf("Failed to close /home/test.txt (%d)\n", errno);
    return -1;
  }
  if (fail) {
    return -1;
  }
  printf("Test rename()...");
  if (rename("/home/test.txt", "/home/test0.txt") < 0) {
    if (errno == ENOTSUP) {
      printf("Not Supported...");
    } else {
      fflush(stdout);
      perror("failed");
      return -1;
    }
  }
  printf("passed\n");
  if (errno != ENOTSUP) {
    printf("Test rename() ENOENT...");
    if (rename("/home/test.txt", "/home/test0.txt") == 0) {
      printf("rename /home/test.txt should have failed\n");
      return -1;
    } else {
      if (errno != ENOENT) {
        printf("rename /home/test.txt did not give ENOENT (%d)\n", errno);
        return -1;
      }
    }
    printf("passed\n");
  }
  printf("Test remove() ENOENT...");
  if (remove("/home/test5.txt") == 0) {
    printf("remove /home/test5.txt should have failed\n");
    return -1;
  } else {
    if (errno != ENOENT) {
      printf("remove /home/test5.txt should produced ENOENT (%d)\n", errno);
      return -1;
    }
  }
  printf("passed\n");
  printf("Test remove()...");
  if (remove("/home/test.txt") < 0) {
    fflush(stdout);
    perror("failed");
    return -1;
  }
  printf("passed\n");
  return 0;
}


x86 assembly (clang, -O0):
<utils_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
lea    0xe11(%rip),%rdi
lea    0xdf7(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1235 <utils_test+0x45>
lea    0xdde(%rip),%rdi
call   10e0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1985 <utils_test+0x795>
lea    -0x70(%rbp),%rdi
lea    0xde2(%rip),%rsi
call   1100 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1090 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xda3(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   10a0 <stat@plt>
cmp    $0x0,%rax
jge    12a9 <utils_test+0xb9>
mov    0x2d26(%rip),%rax
mov    (%rax),%edi
call   10b0 <fflush@plt>
lea    0xdaf(%rip),%rdi
call   10e0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1985 <utils_test+0x795>
mov    -0x18(%rbp),%eax
mov    0x2d15(%rip),%rcx
and    (%rcx),%eax
mov    0x2d24(%rip),%rcx
cmp    (%rcx),%eax
je     12e1 <utils_test+0xf1>
mov    -0x18(%rbp),%esi
lea    0xd80(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1985 <utils_test+0x795>
mov    -0x14(%rbp),%eax
mov    %eax,-0x74(%rbp)
lea    -0x70(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x74(%rbp),%eax
cmp    %ecx,%eax
je     1325 <utils_test+0x135>
lea    -0x70(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%esi
mov    -0x14(%rbp),%edx
lea    0xd68(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1985 <utils_test+0x795>
lea    0xd73(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2c86(%rip),%rax
movl   $0x0,(%rax)
lea    0xd60(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2c93(%rip),%rax
mov    (%rax),%esi
lea    0xd67(%rip),%rdi
call   10c0 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2c53(%rip),%rax
mov    (%rax),%eax
mov    0x2c32(%rip),%rcx
cmp    (%rcx),%eax
jne    139e <utils_test+0x1ae>
lea    0xd1a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2c2d(%rip),%rax
movl   $0x0,(%rax)
jmp    13ca <utils_test+0x1da>
mov    0x2c1b(%rip),%rax
mov    (%rax),%esi
mov    0x2bfa(%rip),%rax
mov    (%rax),%edx
lea    0xd3d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1985 <utils_test+0x795>
mov    0x2bef(%rip),%rax
movl   $0x0,(%rax)
lea    0xcc9(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2bfc(%rip),%rax
mov    (%rax),%esi
lea    0xcd5(%rip),%rdi
call   10c0 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2bbc(%rip),%rax
mov    (%rax),%eax
mov    0x2b9b(%rip),%rcx
cmp    (%rcx),%eax
jne    1435 <utils_test+0x245>
lea    0xc83(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2b96(%rip),%rax
movl   $0x0,(%rax)
jmp    1461 <utils_test+0x271>
mov    0x2b84(%rip),%rax
mov    (%rax),%esi
mov    0x2b63(%rip),%rax
mov    (%rax),%edx
lea    0xca6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1985 <utils_test+0x795>
mov    0x2b58(%rip),%rax
movl   $0x0,(%rax)
lea    0xc98(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2b65(%rip),%rax
mov    (%rax),%esi
lea    0xc99(%rip),%rdi
call   10c0 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2b25(%rip),%rax
mov    (%rax),%eax
mov    0x2af4(%rip),%rcx
cmp    (%rcx),%eax
jne    14cc <utils_test+0x2dc>
lea    0xbec(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2aff(%rip),%rax
movl   $0x0,(%rax)
jmp    14f8 <utils_test+0x308>
mov    0x2aed(%rip),%rax
mov    (%rax),%esi
mov    0x2abc(%rip),%rax
mov    (%rax),%edx
lea    0xc0f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1985 <utils_test+0x795>
mov    0x2ac1(%rip),%rax
movl   $0x0,(%rax)
lea    0xc26(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2ace(%rip),%rax
mov    (%rax),%esi
lea    0xc28(%rip),%rdi
call   10c0 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2a8e(%rip),%rax
mov    (%rax),%eax
mov    0x2a9d(%rip),%rcx
cmp    (%rcx),%eax
jne    1563 <utils_test+0x373>
lea    0xb55(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2a68(%rip),%rax
movl   $0x0,(%rax)
jmp    158f <utils_test+0x39f>
mov    0x2a56(%rip),%rax
mov    (%rax),%esi
mov    0x2a65(%rip),%rax
mov    (%rax),%edx
lea    0xb78(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1985 <utils_test+0x795>
lea    0xbc3(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2a44(%rip),%rax
mov    (%rax),%esi
lea    0xa66(%rip),%rdi
call   10c0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    15e5 <utils_test+0x3f5>
mov    0x29ea(%rip),%rax
mov    (%rax),%edi
call   10b0 <fflush@plt>
lea    0xa73(%rip),%rdi
call   10e0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1985 <utils_test+0x795>
lea    0xab3(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xb6e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x1c(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1110 <fstat@plt>
cmp    $0x0,%rax
jge    163d <utils_test+0x44d>
mov    0x2992(%rip),%rax
mov    (%rax),%edi
call   10b0 <fflush@plt>
lea    0xa1b(%rip),%rdi
call   10e0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1985 <utils_test+0x795>
mov    -0x18(%rbp),%eax
mov    0x2981(%rip),%rcx
and    (%rcx),%eax
mov    0x2990(%rip),%rcx
cmp    (%rcx),%eax
je     1675 <utils_test+0x485>
mov    -0x18(%rbp),%esi
lea    0x9ec(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1985 <utils_test+0x795>
cmpl   $0x15,-0x14(%rbp)
je     169c <utils_test+0x4ac>
mov    -0x14(%rbp),%esi
lea    0xaef(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1985 <utils_test+0x795>
lea    0x9fc(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x24(%rbp)
lea    0xae5(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x1c(%rbp),%edi
mov    0x28ef(%rip),%rax
mov    (%rax),%esi
call   1040 <fcntl@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    0x290b(%rip),%rcx
cmp    (%rcx),%eax
je     16fd <utils_test+0x50d>
mov    -0x20(%rbp),%esi
lea    0xac8(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    1715 <utils_test+0x525>
lea    0x991(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
cmp    $0x0,%rax
jge    174a <utils_test+0x55a>
mov    0x2892(%rip),%rax
mov    (%rax),%esi
lea    0xaa7(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1985 <utils_test+0x795>
cmpl   $0x0,-0x24(%rbp)
je     1760 <utils_test+0x570>
movl   $0xffffffff,-0x4(%rbp)
jmp    1985 <utils_test+0x795>
lea    0xa9c(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0x89e(%rip),%rdi
lea    0xa98(%rip),%rsi
call   10f0 <rename@plt>
cmp    $0x0,%rax
jge    17e1 <utils_test+0x5f1>
mov    0x282e(%rip),%rax
mov    (%rax),%eax
mov    0x283d(%rip),%rcx
cmp    (%rcx),%eax
jne    17b6 <utils_test+0x5c6>
lea    0xa7a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    17dc <utils_test+0x5ec>
mov    0x27f3(%rip),%rax
mov    (%rax),%edi
call   10b0 <fflush@plt>
lea    0x87c(%rip),%rdi
call   10e0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1985 <utils_test+0x795>
jmp    17e1 <utils_test+0x5f1>
lea    0x8b7(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x27ca(%rip),%rax
mov    (%rax),%eax
mov    0x27d9(%rip),%rcx
cmp    (%rcx),%eax
je     189a <utils_test+0x6aa>
lea    0xa27(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0x7f7(%rip),%rdi
lea    0x9f1(%rip),%rsi
call   10f0 <rename@plt>
cmp    $0x0,%rax
jne    184c <utils_test+0x65c>
lea    0xa14(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1985 <utils_test+0x795>
mov    0x276d(%rip),%rax
mov    (%rax),%eax
mov    0x273c(%rip),%rcx
cmp    (%rcx),%eax
je     1887 <utils_test+0x697>
mov    0x2755(%rip),%rax
mov    (%rax),%esi
lea    0xa03(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1985 <utils_test+0x795>
jmp    188c <utils_test+0x69c>
lea    0x80c(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xa06(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xa10(%rip),%rdi
call   1030 <remove@plt>
cmp    $0x0,%rax
jne    18d8 <utils_test+0x6e8>
lea    0xa0a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1985 <utils_test+0x795>
mov    0x26e1(%rip),%rax
mov    (%rax),%eax
mov    0x26b0(%rip),%rcx
cmp    (%rcx),%eax
je     1913 <utils_test+0x723>
mov    0x26c9(%rip),%rax
mov    (%rax),%esi
lea    0x9fa(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1985 <utils_test+0x795>
jmp    1918 <utils_test+0x728>
lea    0x780(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xa01(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0x6d8(%rip),%rdi
call   1030 <remove@plt>
cmp    $0x0,%rax
jge    1970 <utils_test+0x780>
mov    0x265f(%rip),%rax
mov    (%rax),%edi
call   10b0 <fflush@plt>
lea    0x6e8(%rip),%rdi
call   10e0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1985 <utils_test+0x795>
lea    0x728(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utils_test>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
lea    0xe0e(%rip),%rdi
lea    0xdf4(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     15e1 <utils_test+0x3f1>
mov    %rax,%rbx
movups 0xdfe(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movabs $0xa747365542065,%rax
mov    %rax,0x1e(%rsp)
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   10a0 <fprintf@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
lea    0xde4(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xdb1(%rip),%rdi
lea    0x8(%rsp),%rsi
call   10b0 <stat@plt>
test   %rax,%rax
js     15ea <utils_test+0x3fa>
mov    0x8(%rsp),%esi
mov    0x2d48(%rip),%r15
mov    (%r15),%eax
and    %esi,%eax
mov    0x2d54(%rip),%rbp
cmp    0x0(%rbp),%eax
jne    15a8 <utils_test+0x3b8>
mov    0xc(%rsp),%ebx
lea    0x10(%rsp),%rdi
call   1070 <strlen@plt>
cmp    %eax,%ebx
jne    15b8 <utils_test+0x3c8>
lea    0x1053(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d02(%rip),%r14
movl   $0x0,(%r14)
lea    0xdcc(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x2d0e(%rip),%r13
mov    0x0(%r13),%esi
lea    0xdd1(%rip),%rdi
call   10d0 <open@plt>
mov    (%r14),%esi
mov    0x2cb4(%rip),%rbx
mov    (%rbx),%edx
cmp    %edx,%esi
jne    15d1 <utils_test+0x3e1>
lea    0x1000(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,(%r14)
lea    0xd80(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x0(%r13),%esi
lea    0xd91(%rip),%rdi
call   10d0 <open@plt>
mov    (%r14),%esi
mov    (%rbx),%edx
cmp    %edx,%esi
jne    15d1 <utils_test+0x3e1>
lea    0xfc2(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,(%r14)
lea    0xda8(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x0(%r13),%esi
lea    0xdae(%rip),%rdi
call   10d0 <open@plt>
mov    (%r14),%esi
mov    0x2c21(%rip),%rbx
mov    (%rbx),%edx
cmp    %edx,%esi
jne    15d1 <utils_test+0x3e1>
lea    0xf7d(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,(%r14)
lea    0xd88(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x0(%r13),%esi
lea    0xd8f(%rip),%rdi
call   10d0 <open@plt>
mov    (%r14),%esi
mov    0x2c1c(%rip),%rax
mov    (%rax),%edx
cmp    %edx,%esi
jne    15d1 <utils_test+0x3e1>
lea    0xf38(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,(%r14)
lea    0xd6a(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x0(%r13),%esi
lea    0xc21(%rip),%rdi
call   10d0 <open@plt>
test   %eax,%eax
js     15ea <utils_test+0x3fa>
mov    %eax,%r12d
lea    0xefc(%rip),%rdi
call   1040 <puts@plt>
lea    0xd44(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0x8(%rsp),%rsi
mov    %r12d,%edi
call   1110 <fstat@plt>
test   %rax,%rax
js     15ea <utils_test+0x3fa>
mov    0x8(%rsp),%esi
mov    (%r15),%eax
and    %esi,%eax
cmp    0x0(%rbp),%eax
jne    15a8 <utils_test+0x3b8>
mov    0xc(%rsp),%esi
cmp    $0x15,%esi
jne    161a <utils_test+0x42a>
lea    0xead(%rip),%rdi
call   1040 <puts@plt>
lea    0xd2a(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x2b46(%rip),%rax
mov    (%rax),%esi
mov    %r12d,%edi
call   1050 <fcntl@plt>
cmp    0x0(%r13),%eax
jne    1623 <utils_test+0x433>
lea    0xe78(%rip),%rdi
call   1040 <puts@plt>
mov    %r12d,%edi
call   1090 <close@plt>
test   %rax,%rax
js     1645 <utils_test+0x455>
lea    0xd4a(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xb5b(%rip),%rdi
lea    0xd46(%rip),%rsi
call   1100 <rename@plt>
test   %rax,%rax
mov    0x2b0a(%rip),%rbp
jns    14ea <utils_test+0x2fa>
mov    (%r14),%eax
cmp    0x0(%rbp),%eax
jne    15ea <utils_test+0x3fa>
lea    0xd32(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xe14(%rip),%rdi
call   1040 <puts@plt>
mov    (%r14),%eax
cmp    0x0(%rbp),%eax
je     153f <utils_test+0x34f>
lea    0xd21(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xb00(%rip),%rdi
lea    0xceb(%rip),%rsi
call   1100 <rename@plt>
test   %rax,%rax
je     1669 <utils_test+0x479>
mov    (%r14),%esi
cmp    (%rbx),%esi
jne    1677 <utils_test+0x487>
lea    0xdcb(%rip),%rdi
call   1040 <puts@plt>
lea    0xd28(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xd32(%rip),%rdi
call   1030 <remove@plt>
test   %rax,%rax
je     1654 <utils_test+0x464>
mov    (%r14),%esi
cmp    (%rbx),%esi
jne    165d <utils_test+0x46d>
lea    0xd91(%rip),%rdi
call   1040 <puts@plt>
lea    0xd4a(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xa83(%rip),%rdi
call   1030 <remove@plt>
test   %rax,%rax
js     15ea <utils_test+0x3fa>
lea    0xd64(%rip),%rdi
call   1040 <puts@plt>
jmp    1609 <utils_test+0x419>
lea    0xa98(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    1604 <utils_test+0x414>
lea    0x10(%rsp),%rdi
call   1070 <strlen@plt>
mov    0xc(%rsp),%edx
lea    0xaa6(%rip),%rdi
mov    %eax,%esi
jmp    15d8 <utils_test+0x3e8>
lea    0xb0d(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    1604 <utils_test+0x414>
lea    0xa1a(%rip),%rdi
jmp    15ff <utils_test+0x40f>
mov    0x29bf(%rip),%rax
mov    (%rax),%edi
call   10c0 <fflush@plt>
lea    0xcff(%rip),%rdi
call   10f0 <perror@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb48(%rip),%rdi
jmp    15af <utils_test+0x3bf>
lea    0xb7e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r12d,%edi
call   1090 <close@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
jns    1609 <utils_test+0x419>
mov    (%r14),%esi
lea    0xb80(%rip),%rdi
jmp    15af <utils_test+0x3bf>
lea    0xc80(%rip),%rdi
jmp    1670 <utils_test+0x480>
lea    0xc32(%rip),%rdi
jmp    15af <utils_test+0x3bf>
lea    0xc9c(%rip),%rdi
call   1040 <puts@plt>
jmp    1604 <utils_test+0x414>
lea    0xbc0(%rip),%rdi
jmp    15af <utils_test+0x3bf>

LLVM IR (-O0):
%struct.stat = type { i32, i32 }
@.str = [15 x i8] c"/home/test.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [32 x i8] c"failed to create /home/test.txt\00"
@.str.3 = [22 x i8] c"This is a write Test\0A\00"
@.str.4 = [15 x i8] c"Test stat()...\00"
@stdout = global i32 0
@.str.5 = [7 x i8] c"failed\00"
@S_IFMT = global i32 0
@S_IFREG = global i32 0
@.str.6 = [44 x i8] c"/home/test.txt is not a regular file (0%o)\0A\00"
@.str.7 = [37 x i8] c"/home/test.txt is not %d bytes (%d)\0A\00"
@.str.8 = [8 x i8] c"passed\0A\00"
@errno = global i32 0
@.str.9 = [30 x i8] c"Test open()...ENAMETOOLONG...\00"
@.str.10 = [47 x i8] c"/home/1234567890123456789012345678901234567890\00"
@O_RDONLY = global i32 0
@ENAMETOOLONG = global i32 0
@.str.11 = [25 x i8] c"failed (errno %d != %d)\0A\00"
@.str.12 = [42 x i8] c"/1234567890123456789012345678901234567890\00"
@.str.13 = [24 x i8] c"Test open()...ENOENT...\00"
@.str.14 = [13 x i8] c"/home/nofile\00"
@ENOENT = global i32 0
@.str.15 = [25 x i8] c"Test open()...ENOTSUP...\00"
@.str.16 = [14 x i8] c"/nodir/nofile\00"
@ENOTSUP = global i32 0
@.str.17 = [15 x i8] c"Test open()...\00"
@.str.18 = [16 x i8] c"Test fstat()...\00"
@.str.19 = [37 x i8] c"/home/test.txt is not 21 bytes (%d)\0A\00"
@.str.20 = [26 x i8] c"test fcntl()...F_GETFL...\00"
@F_GETFL = global i32 0
@.str.21 = [39 x i8] c"F_GETFL access is not O_RDONLY (0x%X)\0A\00"
@.str.22 = [37 x i8] c"Failed to close /home/test.txt (%d)\0A\00"
@.str.23 = [17 x i8] c"Test rename()...\00"
@.str.24 = [16 x i8] c"/home/test0.txt\00"
@.str.25 = [17 x i8] c"Not Supported...\00"
@.str.26 = [24 x i8] c"Test rename() ENOENT...\00"
@.str.27 = [42 x i8] c"rename /home/test.txt should have failed\0A\00"
@.str.28 = [48 x i8] c"rename /home/test.txt did not give ENOENT (%d)\0A\00"
@.str.29 = [24 x i8] c"Test remove() ENOENT...\00"
@.str.30 = [16 x i8] c"/home/test5.txt\00"
@.str.31 = [43 x i8] c"remove /home/test5.txt should have failed\0A\00"
@.str.32 = [52 x i8] c"remove /home/test5.txt should produced ENOENT (%d)\0A\00"
@.str.33 = [17 x i8] c"Test remove()...\00"
define i32 @utils_test() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca %struct.stat
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [64 x i8]
%8 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %2
%9 = load i32*, i32** %2
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %232
13: ; preds = %0
%14 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%15 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%16 = load i32*, i32** %2
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%18 = call i32 @fprintf(i32* %16, i8* %17)
%19 = load i32*, i32** %2
%20 = call i32 @fclose(i32* %19)
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%22 = call i64 @stat(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), %struct.stat* %3)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %13
%25 = load i32, i32* @stdout
%26 = call i32 @fflush(i32 %25)
%27 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %1
br label %232
28: ; preds = %13
%29 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%30 = load i32, i32* %29
%31 = load i32, i32* @S_IFMT
%32 = and i32 %30, %31
%33 = load i32, i32* @S_IFREG
%34 = icmp ne i32 %32, %33
br i1 %34, label %35, label %39
35: ; preds = %28
%36 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%37 = load i32, i32* %36
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0), i32 %37)
store i32 -1, i32* %1
br label %232
39: ; preds = %28
%40 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 1
%41 = load i32, i32* %40
%42 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%43 = call i32 @strlen(i8* %42)
%44 = icmp ne i32 %41, %43
br i1 %44, label %45, label %51
45: ; preds = %39
%46 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%47 = call i32 @strlen(i8* %46)
%48 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 1
%49 = load i32, i32* %48
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), i32 %47, i32 %49)
store i32 -1, i32* %1
br label %232
51: ; preds = %39
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* @errno
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0))
%54 = load i32, i32* @O_RDONLY
%55 = call i32 @open(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.10, i64 0, i64 0), i32 %54)
store i32 %55, i32* %4
%56 = load i32, i32* @errno
%57 = load i32, i32* @ENAMETOOLONG
%58 = icmp eq i32 %56, %57
br i1 %58, label %59, label %61
59: ; preds = %51
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* @errno
br label %65
61: ; preds = %51
%62 = load i32, i32* @errno
%63 = load i32, i32* @ENAMETOOLONG
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.11, i64 0, i64 0), i32 %62, i32 %63)
store i32 -1, i32* %1
br label %232
65: ; preds = %59
store i32 0, i32* @errno
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0))
%67 = load i32, i32* @O_RDONLY
%68 = call i32 @open(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.12, i64 0, i64 0), i32 %67)
store i32 %68, i32* %4
%69 = load i32, i32* @errno
%70 = load i32, i32* @ENAMETOOLONG
%71 = icmp eq i32 %69, %70
br i1 %71, label %72, label %74
72: ; preds = %65
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* @errno
br label %78
74: ; preds = %65
%75 = load i32, i32* @errno
%76 = load i32, i32* @ENAMETOOLONG
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.11, i64 0, i64 0), i32 %75, i32 %76)
store i32 -1, i32* %1
br label %232
78: ; preds = %72
store i32 0, i32* @errno
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.13, i64 0, i64 0))
%80 = load i32, i32* @O_RDONLY
%81 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.14, i64 0, i64 0), i32 %80)
store i32 %81, i32* %4
%82 = load i32, i32* @errno
%83 = load i32, i32* @ENOENT
%84 = icmp eq i32 %82, %83
br i1 %84, label %85, label %87
85: ; preds = %78
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* @errno
br label %91
87: ; preds = %78
%88 = load i32, i32* @errno
%89 = load i32, i32* @ENOENT
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.11, i64 0, i64 0), i32 %88, i32 %89)
store i32 -1, i32* %1
br label %232
91: ; preds = %85
store i32 0, i32* @errno
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.15, i64 0, i64 0))
%93 = load i32, i32* @O_RDONLY
%94 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.16, i64 0, i64 0), i32 %93)
store i32 %94, i32* %4
%95 = load i32, i32* @errno
%96 = load i32, i32* @ENOTSUP
%97 = icmp eq i32 %95, %96
br i1 %97, label %98, label %100
98: ; preds = %91
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* @errno
br label %104
100: ; preds = %91
%101 = load i32, i32* @errno
%102 = load i32, i32* @ENOTSUP
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.11, i64 0, i64 0), i32 %101, i32 %102)
store i32 -1, i32* %1
br label %232
104: ; preds = %98
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.17, i64 0, i64 0))
%106 = load i32, i32* @O_RDONLY
%107 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %106)
store i32 %107, i32* %4
%108 = load i32, i32* %4
%109 = icmp slt i32 %108, 0
br i1 %109, label %110, label %114
110: ; preds = %104
%111 = load i32, i32* @stdout
%112 = call i32 @fflush(i32 %111)
%113 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %1
br label %232
114: ; preds = %104
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
%116 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.18, i64 0, i64 0))
%117 = load i32, i32* %4
%118 = call i64 @fstat(i32 %117, %struct.stat* %3)
%119 = icmp slt i64 %118, 0
br i1 %119, label %120, label %124
120: ; preds = %114
%121 = load i32, i32* @stdout
%122 = call i32 @fflush(i32 %121)
%123 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %1
br label %232
124: ; preds = %114
%125 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%126 = load i32, i32* %125
%127 = load i32, i32* @S_IFMT
%128 = and i32 %126, %127
%129 = load i32, i32* @S_IFREG
%130 = icmp ne i32 %128, %129
br i1 %130, label %131, label %135
131: ; preds = %124
%132 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%133 = load i32, i32* %132
%134 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0), i32 %133)
store i32 -1, i32* %1
br label %232
135: ; preds = %124
%136 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 1
%137 = load i32, i32* %136
%138 = icmp ne i32 %137, 21
br i1 %138, label %139, label %143
139: ; preds = %135
%140 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 1
%141 = load i32, i32* %140
%142 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.19, i64 0, i64 0), i32 %141)
store i32 -1, i32* %1
br label %232
143: ; preds = %135
%144 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* %6
%145 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.20, i64 0, i64 0))
%146 = load i32, i32* %4
%147 = load i32, i32* @F_GETFL
%148 = call i32 @fcntl(i32 %146, i32 %147)
store i32 %148, i32* %5
%149 = load i32, i32* %5
%150 = load i32, i32* @O_RDONLY
%151 = icmp ne i32 %149, %150
br i1 %151, label %152, label %155
152: ; preds = %143
%153 = load i32, i32* %5
%154 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.21, i64 0, i64 0), i32 %153)
store i32 1, i32* %6
br label %155
155: ; preds = %152, %143
%156 = load i32, i32* %6
%157 = icmp ne i32 %156, 0
br i1 %157, label %160, label %158
158: ; preds = %155
%159 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
br label %160
160: ; preds = %158, %155
%161 = load i32, i32* %4
%162 = call i64 @close(i32 %161)
%163 = icmp slt i64 %162, 0
br i1 %163, label %164, label %167
164: ; preds = %160
%165 = load i32, i32* @errno
%166 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.22, i64 0, i64 0), i32 %165)
store i32 -1, i32* %1
br label %232
167: ; preds = %160
%168 = load i32, i32* %6
%169 = icmp ne i32 %168, 0
br i1 %169, label %170, label %171
170: ; preds = %167
store i32 -1, i32* %1
br label %232
171: ; preds = %167
%172 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.23, i64 0, i64 0))
%173 = call i64 @rename(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.24, i64 0, i64 0))
%174 = icmp slt i64 %173, 0
br i1 %174, label %175, label %186
175: ; preds = %171
%176 = load i32, i32* @errno
%177 = load i32, i32* @ENOTSUP
%178 = icmp eq i32 %176, %177
br i1 %178, label %179, label %181
179: ; preds = %175
%180 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.25, i64 0, i64 0))
br label %185
181: ; preds = %175
%182 = load i32, i32* @stdout
%183 = call i32 @fflush(i32 %182)
%184 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %1
br label %232
185: ; preds = %179
br label %186
186: ; preds = %185, %171
%187 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
%188 = load i32, i32* @errno
%189 = load i32, i32* @ENOTSUP
%190 = icmp ne i32 %188, %189
br i1 %190, label %191, label %207
191: ; preds = %186
%192 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.26, i64 0, i64 0))
%193 = call i64 @rename(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.24, i64 0, i64 0))
%194 = icmp eq i64 %193, 0
br i1 %194, label %195, label %197
195: ; preds = %191
%196 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.27, i64 0, i64 0))
store i32 -1, i32* %1
br label %232
197: ; preds = %191
%198 = load i32, i32* @errno
%199 = load i32, i32* @ENOENT
%200 = icmp ne i32 %198, %199
br i1 %200, label %201, label %204
201: ; preds = %197
%202 = load i32, i32* @errno
%203 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.28, i64 0, i64 0), i32 %202)
store i32 -1, i32* %1
br label %232
204: ; preds = %197
br label %205
205: ; preds = %204
%206 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
br label %207
207: ; preds = %205, %186
%208 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.29, i64 0, i64 0))
%209 = call i64 @remove(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.30, i64 0, i64 0))
%210 = icmp eq i64 %209, 0
br i1 %210, label %211, label %213
211: ; preds = %207
%212 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.31, i64 0, i64 0))
store i32 -1, i32* %1
br label %232
213: ; preds = %207
%214 = load i32, i32* @errno
%215 = load i32, i32* @ENOENT
%216 = icmp ne i32 %214, %215
br i1 %216, label %217, label %220
217: ; preds = %213
%218 = load i32, i32* @errno
%219 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.32, i64 0, i64 0), i32 %218)
store i32 -1, i32* %1
br label %232
220: ; preds = %213
br label %221
221: ; preds = %220
%222 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
%223 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.33, i64 0, i64 0))
%224 = call i64 @remove(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%225 = icmp slt i64 %224, 0
br i1 %225, label %226, label %230
226: ; preds = %221
%227 = load i32, i32* @stdout
%228 = call i32 @fflush(i32 %227)
%229 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %1
br label %232
230: ; preds = %221
%231 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* %1
br label %232
232: ; preds = %230, %226, %217, %211, %201, %195, %181, %170, %164, %139, %131, %120, %110, %100, %87, %74, %61, %45, %35, %24, %11
%233 = load i32, i32* %1
ret i32 %233
}

LLVM IR (-O2):
%struct.stat = type { i32, i32 }
@.str = [15 x i8] c"/home/test.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [32 x i8] c"failed to create /home/test.txt\00"
@.str.3 = [22 x i8] c"This is a write Test\0A\00"
@.str.4 = [15 x i8] c"Test stat()...\00"
@stdout = global i32 0
@.str.5 = [7 x i8] c"failed\00"
@S_IFMT = global i32 0
@S_IFREG = global i32 0
@.str.6 = [44 x i8] c"/home/test.txt is not a regular file (0%o)\0A\00"
@.str.7 = [37 x i8] c"/home/test.txt is not %d bytes (%d)\0A\00"
@errno = global i32 0
@.str.9 = [30 x i8] c"Test open()...ENAMETOOLONG...\00"
@.str.10 = [47 x i8] c"/home/1234567890123456789012345678901234567890\00"
@O_RDONLY = global i32 0
@ENAMETOOLONG = global i32 0
@.str.11 = [25 x i8] c"failed (errno %d != %d)\0A\00"
@.str.12 = [42 x i8] c"/1234567890123456789012345678901234567890\00"
@.str.13 = [24 x i8] c"Test open()...ENOENT...\00"
@.str.14 = [13 x i8] c"/home/nofile\00"
@ENOENT = global i32 0
@.str.15 = [25 x i8] c"Test open()...ENOTSUP...\00"
@.str.16 = [14 x i8] c"/nodir/nofile\00"
@ENOTSUP = global i32 0
@.str.17 = [15 x i8] c"Test open()...\00"
@.str.18 = [16 x i8] c"Test fstat()...\00"
@.str.19 = [37 x i8] c"/home/test.txt is not 21 bytes (%d)\0A\00"
@.str.20 = [26 x i8] c"test fcntl()...F_GETFL...\00"
@F_GETFL = global i32 0
@.str.21 = [39 x i8] c"F_GETFL access is not O_RDONLY (0x%X)\0A\00"
@.str.22 = [37 x i8] c"Failed to close /home/test.txt (%d)\0A\00"
@.str.23 = [17 x i8] c"Test rename()...\00"
@.str.24 = [16 x i8] c"/home/test0.txt\00"
@.str.25 = [17 x i8] c"Not Supported...\00"
@.str.26 = [24 x i8] c"Test rename() ENOENT...\00"
@.str.28 = [48 x i8] c"rename /home/test.txt did not give ENOENT (%d)\0A\00"
@.str.29 = [24 x i8] c"Test remove() ENOENT...\00"
@.str.30 = [16 x i8] c"/home/test5.txt\00"
@.str.32 = [52 x i8] c"remove /home/test5.txt should produced ENOENT (%d)\0A\00"
@.str.33 = [17 x i8] c"Test remove()...\00"
@str.44 = [42 x i8] c"remove /home/test5.txt should have failed\00"
@str.45 = [7 x i8] c"passed\00"
@str.46 = [41 x i8] c"rename /home/test.txt should have failed\00"
define i32 @utils_test() {
%1 = alloca %struct.stat
%2 = alloca [64 x i8]
%3 = bitcast %struct.stat* %1 to i8*
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %183
9: ; preds = %0
%10 = call i32 @fprintf(i32* %5, i8* %4)
%11 = tail call i32 @fclose(i32* %5)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%13 = call i64 @stat(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %9
%16 = load i32, i32* @stdout
%17 = call i32 @fflush(i32 %16)
%18 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %183
19: ; preds = %9
%20 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%21 = load i32, i32* %20
%22 = load i32, i32* @S_IFMT
%23 = and i32 %22, %21
%24 = load i32, i32* @S_IFREG
%25 = icmp eq i32 %23, %24
br i1 %25, label %28, label %26
26: ; preds = %19
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0), i32 %21)
br label %183
28: ; preds = %19
%29 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 1
%30 = load i32, i32* %29
%31 = call i32 @strlen(i8* %4)
%32 = icmp eq i32 %30, %31
br i1 %32, label %37, label %33
33: ; preds = %28
%34 = call i32 @strlen(i8* %4)
%35 = load i32, i32* %29
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), i32 %34, i32 %35)
br label %183
37: ; preds = %28
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.45, i64 0, i64 0))
store i32 0, i32* @errno
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0))
%40 = load i32, i32* @O_RDONLY
%41 = call i32 @open(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.10, i64 0, i64 0), i32 %40)
%42 = load i32, i32* @errno
%43 = load i32, i32* @ENAMETOOLONG
%44 = icmp eq i32 %42, %43
br i1 %44, label %45, label %53
45: ; preds = %37
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.45, i64 0, i64 0))
store i32 0, i32* @errno
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0))
%48 = load i32, i32* @O_RDONLY
%49 = call i32 @open(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.12, i64 0, i64 0), i32 %48)
%50 = load i32, i32* @errno
%51 = load i32, i32* @ENAMETOOLONG
%52 = icmp eq i32 %50, %51
br i1 %52, label %55, label %63
53: ; preds = %37
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.11, i64 0, i64 0), i32 %42, i32 %43)
br label %183
55: ; preds = %45
%56 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.45, i64 0, i64 0))
store i32 0, i32* @errno
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.13, i64 0, i64 0))
%58 = load i32, i32* @O_RDONLY
%59 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.14, i64 0, i64 0), i32 %58)
%60 = load i32, i32* @errno
%61 = load i32, i32* @ENOENT
%62 = icmp eq i32 %60, %61
br i1 %62, label %65, label %73
63: ; preds = %45
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.11, i64 0, i64 0), i32 %50, i32 %51)
br label %183
65: ; preds = %55
%66 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.45, i64 0, i64 0))
store i32 0, i32* @errno
%67 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.15, i64 0, i64 0))
%68 = load i32, i32* @O_RDONLY
%69 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.16, i64 0, i64 0), i32 %68)
%70 = load i32, i32* @errno
%71 = load i32, i32* @ENOTSUP
%72 = icmp eq i32 %70, %71
br i1 %72, label %75, label %81
73: ; preds = %55
%74 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.11, i64 0, i64 0), i32 %60, i32 %61)
br label %183
75: ; preds = %65
%76 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.45, i64 0, i64 0))
store i32 0, i32* @errno
%77 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.17, i64 0, i64 0))
%78 = load i32, i32* @O_RDONLY
%79 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %78)
%80 = icmp slt i32 %79, 0
br i1 %80, label %83, label %87
81: ; preds = %65
%82 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.11, i64 0, i64 0), i32 %70, i32 %71)
br label %183
83: ; preds = %75
%84 = load i32, i32* @stdout
%85 = call i32 @fflush(i32 %84)
%86 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %183
87: ; preds = %75
%88 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.45, i64 0, i64 0))
%89 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.18, i64 0, i64 0))
%90 = call i64 @fstat(i32 %79, %struct.stat* %1)
%91 = icmp slt i64 %90, 0
br i1 %91, label %92, label %96
92: ; preds = %87
%93 = load i32, i32* @stdout
%94 = call i32 @fflush(i32 %93)
%95 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %183
96: ; preds = %87
%97 = load i32, i32* %20
%98 = load i32, i32* @S_IFMT
%99 = and i32 %98, %97
%100 = load i32, i32* @S_IFREG
%101 = icmp eq i32 %99, %100
br i1 %101, label %104, label %102
102: ; preds = %96
%103 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0), i32 %97)
br label %183
104: ; preds = %96
%105 = load i32, i32* %29
%106 = icmp eq i32 %105, 21
br i1 %106, label %109, label %107
107: ; preds = %104
%108 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.19, i64 0, i64 0), i32 %105)
br label %183
109: ; preds = %104
%110 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.45, i64 0, i64 0))
%111 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.20, i64 0, i64 0))
%112 = load i32, i32* @F_GETFL
%113 = call i32 @fcntl(i32 %79, i32 %112)
%114 = load i32, i32* @O_RDONLY
%115 = icmp eq i32 %113, %114
br i1 %115, label %116, label %120
116: ; preds = %109
%117 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.45, i64 0, i64 0))
%118 = call i64 @close(i32 %79)
%119 = icmp slt i64 %118, 0
br i1 %119, label %124, label %127
120: ; preds = %109
%121 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.21, i64 0, i64 0), i32 %113)
%122 = call i64 @close(i32 %79)
%123 = icmp slt i64 %122, 0
br i1 %123, label %124, label %183
124: ; preds = %120, %116
%125 = load i32, i32* @errno
%126 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.22, i64 0, i64 0), i32 %125)
br label %183
127: ; preds = %116
%128 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.23, i64 0, i64 0))
%129 = call i64 @rename(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.24, i64 0, i64 0))
%130 = icmp slt i64 %129, 0
br i1 %130, label %131, label %141
131: ; preds = %127
%132 = load i32, i32* @errno
%133 = load i32, i32* @ENOTSUP
%134 = icmp eq i32 %132, %133
br i1 %134, label %135, label %137
135: ; preds = %131
%136 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.25, i64 0, i64 0))
br label %141
137: ; preds = %131
%138 = load i32, i32* @stdout
%139 = call i32 @fflush(i32 %138)
%140 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %183
141: ; preds = %135, %127
%142 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.45, i64 0, i64 0))
%143 = load i32, i32* @errno
%144 = load i32, i32* @ENOTSUP
%145 = icmp eq i32 %143, %144
br i1 %145, label %160, label %146
146: ; preds = %141
%147 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.26, i64 0, i64 0))
%148 = call i64 @rename(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.24, i64 0, i64 0))
%149 = icmp eq i64 %148, 0
br i1 %149, label %150, label %152
150: ; preds = %146
%151 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.46, i64 0, i64 0))
br label %183
152: ; preds = %146
%153 = load i32, i32* @errno
%154 = load i32, i32* @ENOENT
%155 = icmp eq i32 %153, %154
br i1 %155, label %158, label %156
156: ; preds = %152
%157 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.28, i64 0, i64 0), i32 %153)
br label %183
158: ; preds = %152
%159 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.45, i64 0, i64 0))
br label %160
160: ; preds = %158, %141
%161 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.29, i64 0, i64 0))
%162 = call i64 @remove(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.30, i64 0, i64 0))
%163 = icmp eq i64 %162, 0
br i1 %163, label %164, label %166
164: ; preds = %160
%165 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.44, i64 0, i64 0))
br label %183
166: ; preds = %160
%167 = load i32, i32* @errno
%168 = load i32, i32* @ENOENT
%169 = icmp eq i32 %167, %168
br i1 %169, label %172, label %170
170: ; preds = %166
%171 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.32, i64 0, i64 0), i32 %167)
br label %183
172: ; preds = %166
%173 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.45, i64 0, i64 0))
%174 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.33, i64 0, i64 0))
%175 = call i64 @remove(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%176 = icmp slt i64 %175, 0
br i1 %176, label %177, label %181
177: ; preds = %172
%178 = load i32, i32* @stdout
%179 = call i32 @fflush(i32 %178)
%180 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %183
181: ; preds = %172
%182 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.45, i64 0, i64 0))
br label %183
183: ; preds = %120, %181, %177, %170, %164, %156, %150, %137, %124, %107, %102, %92, %83, %81, %73, %63, %53, %33, %26, %15, %7
%184 = phi i32 [ -1, %7 ], [ -1, %15 ], [ -1, %26 ], [ -1, %33 ], [ -1, %83 ], [ -1, %92 ], [ -1, %102 ], [ -1, %107 ], [ -1, %124 ], [ -1, %150 ], [ -1, %156 ], [ -1, %164 ], [ -1, %170 ], [ -1, %177 ], [ 0, %181 ], [ -1, %137 ], [ -1, %81 ], [ -1, %73 ], [ -1, %63 ], [ -1, %53 ], [ -1, %120 ]
ret i32 %184
}