#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 dummy;
};
typedef size_t ssize_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int O_APPEND;
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ mkfifo(char *, int);
int open(char *, int, ...);
size_t read(int, char *, int);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ *strstr(char *, char *);
int /*<<< orphan*/ unlink(char *);
int write(int, char *, int);
int add_reach_runlevel_mark() {
  int fd, found, ret;
  ssize_t len, w;
  char buf[4096];
  struct stat st;
  unlink("/.vzfifo");
  if (mkfifo("/.vzfifo", 0644)) {
    fprintf(stderr,
            "Unable to create "
            "/.vzfifo"
            " %s\n",
            strerror(errno));
    return -1;
  }
  if (!stat("/etc/init/", &st)) {
    fd = open("/etc/init/"
              "vz_init_done.conf",
              O_WRONLY | O_TRUNC | O_CREAT, 0644);
    if (fd == -1) {
      fprintf(stderr,
              "Unable to create "
              "/etc/init/"
              "vz_init_done.conf"
              ": %s\n",
              strerror(errno));
      return -1;
    }
    len = sizeof("# tell vzctl that start was successfull\n"
                 "#\n"
                 "# This task is to tell vzctl that start was successfull\n"
                 "\n"
                 "description	\"tell vzctl that start was successfull\"\n"
                 "\n"
                 "start on stopped rc RUNLEVEL=[2345]\n"
                 "\n"
                 "task\n"
                 "\n"
                 "exec touch "
                 "/.vzfifo"
                 "\n") -
          1;
    w = write(fd,
              "# tell vzctl that start was successfull\n"
              "#\n"
              "# This task is to tell vzctl that start was successfull\n"
              "\n"
              "description	\"tell vzctl that start was successfull\"\n"
              "\n"
              "start on stopped rc RUNLEVEL=[2345]\n"
              "\n"
              "task\n"
              "\n"
              "exec touch "
              "/.vzfifo"
              "\n",
              len);
    close(fd);
    if (len != w) {
      fprintf(stderr,
              "Error writing "
              "/etc/init/"
              "vz_init_done.conf"
              ": %s\n",
              strerror(errno));
      return -1;
    }
    return 0;
  } else if (!stat("/etc/event.d/", &st)) {
    fd = open("/etc/event.d/"
              "vz_init_done",
              O_WRONLY | O_TRUNC | O_CREAT, 0644);
    if (fd == -1) {
      fprintf(stderr,
              "Unable to create "
              "/etc/event.d/"
              "vz_init_done"
              ": %s\n",
              strerror(errno));
      return -1;
    }
    len = sizeof("# This task runs if default runlevel is reached\n"
                 "# Added by OpenVZ vzctl\n"
                 "start on stopped rc2\n"
                 "start on stopped rc3\n"
                 "start on stopped rc4\n"
                 "start on stopped rc5\n"
                 "exec touch "
                 "/.vzfifo"
                 "\n") -
          1;
    w = write(fd,
              "# This task runs if default runlevel is reached\n"
              "# Added by OpenVZ vzctl\n"
              "start on stopped rc2\n"
              "start on stopped rc3\n"
              "start on stopped rc4\n"
              "start on stopped rc5\n"
              "exec touch "
              "/.vzfifo"
              "\n",
              len);
    close(fd);
    if (len != w) {
      fprintf(stderr,
              "Error writing "
              "/etc/event.d/"
              "vz_init_done"
              ": %s\n",
              strerror(errno));
      return -1;
    }
    return 0;
  }
  if ((fd = open("/etc/inittab", O_RDWR | O_APPEND)) == -1) {
    fprintf(stderr,
            "Unable to open "
            "/etc/inittab"
            " %s\n",
            strerror(errno));
    return -1;
  }
  ret = 0;
  found = 0;
  while (1) {
    len = read(fd, buf, sizeof(buf));
    if (len == 0)
      break;
    if (len < 0) {
      fprintf(stderr,
              "Unable to read from "
              "/etc/inittab"
              " %s\n",
              strerror(errno));
      ret = -1;
      break;
    }
    buf[len] = 0;
    if (strstr(buf, "\n"
                    "vz:") != NULL) {
      found = 1;
      break;
    }
  }
  if (!found) {
    if (write(fd,
              "vz:"
              "2345:once:touch "
              "/.vzfifo"
              "\n",
              sizeof("vz:"
                     "2345:once:touch "
                     "/.vzfifo"
                     "\n") -
                  1) == -1) {
      fprintf(stderr,
              "Unable to write to "
              "/etc/inittab"
              " %s\n",
              strerror(errno));
      ret = -1;
    }
  }
  close(fd);
  return ret;
}


x86 assembly (clang, -O0):
<add_reach_runlevel_mark>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1050,%rsp
lea    0xe4e(%rip),%rdi
call   1030 <unlink@plt>
lea    0xe42(%rip),%rdi
mov    $0x1a4,%esi
call   1080 <mkfifo@plt>
cmp    $0x0,%rax
je     1210 <add_reach_runlevel_mark+0x70>
mov    0x2def(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x102c(%rbp)
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x102c(%rbp),%edi
mov    %rax,%rdx
lea    0xe0a(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15db <add_reach_runlevel_mark+0x43b>
lea    0xe10(%rip),%rdi
lea    -0x1028(%rbp),%rsi
call   1090 <stat@plt>
cmp    $0x0,%eax
jne    1328 <add_reach_runlevel_mark+0x188>
mov    0x2d7d(%rip),%rax
mov    (%rax),%esi
mov    0x2db4(%rip),%rax
or     (%rax),%esi
mov    0x2db3(%rip),%rax
or     (%rax),%esi
lea    0xde4(%rip),%rdi
mov    $0x1a4,%edx
mov    $0x0,%al
call   10a0 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    12a5 <add_reach_runlevel_mark+0x105>
mov    0x2d5a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1030(%rbp)
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x1030(%rbp),%edi
mov    %rax,%rdx
lea    0xdba(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15db <add_reach_runlevel_mark+0x43b>
movq   $0xd7,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rax
mov    %eax,%edx
lea    0xdc3(%rip),%rsi
call   1040 <write@plt>
cltq
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     131c <add_reach_runlevel_mark+0x17c>
mov    0x2ce3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1034(%rbp)
mov    0x2ccc(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x1034(%rbp),%edi
mov    %rax,%rdx
lea    0xe4d(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15db <add_reach_runlevel_mark+0x43b>
movl   $0x0,-0x4(%rbp)
jmp    15db <add_reach_runlevel_mark+0x43b>
lea    0xe58(%rip),%rdi
lea    -0x1028(%rbp),%rsi
call   1090 <stat@plt>
cmp    $0x0,%eax
jne    1440 <add_reach_runlevel_mark+0x2a0>
mov    0x2c65(%rip),%rax
mov    (%rax),%esi
mov    0x2c9c(%rip),%rax
or     (%rax),%esi
mov    0x2c9b(%rip),%rax
or     (%rax),%esi
lea    0xe2f(%rip),%rdi
mov    $0x1a4,%edx
mov    $0x0,%al
call   10a0 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    13bd <add_reach_runlevel_mark+0x21d>
mov    0x2c42(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1038(%rbp)
mov    0x2c2b(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x1038(%rbp),%edi
mov    %rax,%rdx
lea    0xe03(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15db <add_reach_runlevel_mark+0x43b>
movq   $0xb0,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rax
mov    %eax,%edx
lea    0xe0a(%rip),%rsi
call   1040 <write@plt>
cltq
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     1434 <add_reach_runlevel_mark+0x294>
mov    0x2bcb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x103c(%rbp)
mov    0x2bb4(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x103c(%rbp),%edi
mov    %rax,%rdx
lea    0xe6d(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15db <add_reach_runlevel_mark+0x43b>
movl   $0x0,-0x4(%rbp)
jmp    15db <add_reach_runlevel_mark+0x43b>
jmp    1445 <add_reach_runlevel_mark+0x2a5>
mov    0x2b8c(%rip),%rax
mov    (%rax),%esi
mov    0x2b53(%rip),%rax
or     (%rax),%esi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   10a0 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    14af <add_reach_runlevel_mark+0x30f>
mov    0x2b50(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1040(%rbp)
mov    0x2b39(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x1040(%rbp),%edi
mov    %rax,%rdx
lea    0xe2c(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15db <add_reach_runlevel_mark+0x43b>
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    14e5 <add_reach_runlevel_mark+0x345>
jmp    1568 <add_reach_runlevel_mark+0x3c8>
cmpq   $0x0,-0x18(%rbp)
jae    152e <add_reach_runlevel_mark+0x38e>
mov    0x2ad1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1044(%rbp)
mov    0x2aba(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x1044(%rbp),%edi
mov    %rax,%rdx
lea    0xdcd(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x10(%rbp)
jmp    1568 <add_reach_runlevel_mark+0x3c8>
mov    -0x18(%rbp),%rax
movb   $0x0,-0x1020(%rbp,%rax,1)
lea    -0x1020(%rbp),%rdi
lea    0xdc7(%rip),%rsi
call   10c0 <strstr@plt>
cmp    $0x0,%rax
je     1563 <add_reach_runlevel_mark+0x3c3>
movl   $0x1,-0xc(%rbp)
jmp    1568 <add_reach_runlevel_mark+0x3c8>
jmp    14bd <add_reach_runlevel_mark+0x31d>
cmpl   $0x0,-0xc(%rbp)
jne    15cd <add_reach_runlevel_mark+0x42d>
mov    -0x8(%rbp),%edi
lea    0xd98(%rip),%rsi
mov    $0x1c,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
jne    15c8 <add_reach_runlevel_mark+0x428>
mov    0x2a32(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1048(%rbp)
mov    0x2a1b(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x1048(%rbp),%edi
mov    %rax,%rdx
lea    0xd75(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x10(%rbp)
jmp    15cd <add_reach_runlevel_mark+0x42d>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_reach_runlevel_mark>:
push   %rbp
push   %r14
push   %rbx
sub    $0x1010,%rsp
lea    0xe4e(%rip),%rbx
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    %rbx,%rdi
mov    $0x1a4,%esi
call   1080 <mkfifo@plt>
test   %rax,%rax
je     1207 <add_reach_runlevel_mark+0x67>
mov    0x2df5(%rip),%rax
mov    (%rax),%ebx
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xe1f(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1070 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x1010,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe19(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1090 <stat@plt>
test   %eax,%eax
je     12a4 <add_reach_runlevel_mark+0x104>
lea    0xf60(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1090 <stat@plt>
test   %eax,%eax
je     132c <add_reach_runlevel_mark+0x18c>
mov    0x2d98(%rip),%rax
mov    0x2d61(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0x106b(%rip),%rdi
xor    %eax,%eax
call   10a0 <open@plt>
cmp    $0xffffffff,%eax
je     13b4 <add_reach_runlevel_mark+0x214>
mov    %eax,%ebp
lea    0x10(%rsp),%rbx
lea    0x107a(%rip),%r14
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
test   %rax,%rax
je     13fa <add_reach_runlevel_mark+0x25a>
movb   $0x0,0x10(%rsp,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   10c0 <strstr@plt>
test   %rax,%rax
je     1270 <add_reach_runlevel_mark+0xd0>
xor    %ebx,%ebx
jmp    1441 <add_reach_runlevel_mark+0x2a1>
mov    0x2d05(%rip),%rax
mov    0x2d3e(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d3b(%rip),%rax
or     (%rax),%esi
lea    0xd6c(%rip),%rdi
xor    %ebx,%ebx
mov    $0x1a4,%edx
xor    %eax,%eax
call   10a0 <open@plt>
cmp    $0xffffffff,%eax
je     13d7 <add_reach_runlevel_mark+0x237>
mov    %eax,%ebp
lea    0xd9a(%rip),%rsi
mov    %eax,%edi
mov    $0xd7,%edx
call   1040 <write@plt>
mov    %eax,%r14d
mov    %ebp,%edi
call   1050 <close@plt>
cmp    $0xd7,%r14d
je     11f9 <add_reach_runlevel_mark+0x59>
mov    0x2cb8(%rip),%rax
mov    (%rax),%ebx
mov    0x2ca7(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xe31(%rip),%rsi
jmp    11ea <add_reach_runlevel_mark+0x4a>
mov    0x2c7d(%rip),%rax
mov    0x2cb6(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2cb3(%rip),%rax
or     (%rax),%esi
lea    0xe47(%rip),%rdi
xor    %ebx,%ebx
mov    $0x1a4,%edx
xor    %eax,%eax
call   10a0 <open@plt>
cmp    $0xffffffff,%eax
je     144d <add_reach_runlevel_mark+0x2ad>
mov    %eax,%ebp
lea    0xe71(%rip),%rsi
mov    %eax,%edi
mov    $0xb0,%edx
call   1040 <write@plt>
mov    %eax,%r14d
mov    %ebp,%edi
call   1050 <close@plt>
cmp    $0xb0,%r14d
je     11f9 <add_reach_runlevel_mark+0x59>
mov    0x2c30(%rip),%rax
mov    (%rax),%ebx
mov    0x2c1f(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xee1(%rip),%rsi
jmp    11ea <add_reach_runlevel_mark+0x4a>
mov    0x2c0d(%rip),%rax
mov    (%rax),%ebx
mov    0x2bfc(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xef8(%rip),%rsi
jmp    11ea <add_reach_runlevel_mark+0x4a>
mov    0x2bea(%rip),%rax
mov    (%rax),%ebx
mov    0x2bd9(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xc59(%rip),%rsi
jmp    11ea <add_reach_runlevel_mark+0x4a>
lea    0xeee(%rip),%rsi
mov    %ebp,%edi
mov    $0x1c,%edx
call   1040 <write@plt>
xor    %ebx,%ebx
cmp    $0xffffffff,%eax
jne    1441 <add_reach_runlevel_mark+0x2a1>
mov    0x2bad(%rip),%rax
mov    (%rax),%ebx
mov    0x2b9c(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xeda(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1070 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebp,%edi
call   1050 <close@plt>
jmp    11f9 <add_reach_runlevel_mark+0x59>
mov    0x2b74(%rip),%rax
mov    (%rax),%ebx
mov    0x2b63(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd44(%rip),%rsi
jmp    11ea <add_reach_runlevel_mark+0x4a>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [9 x i8] c"/.vzfifo\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"Unable to create /.vzfifo %s\0A\00"
@errno = global i32 0
@.str.2 = [11 x i8] c"/etc/init/\00"
@.str.3 = [28 x i8] c"/etc/init/vz_init_done.conf\00"
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@O_CREAT = global i32 0
@.str.4 = [50 x i8] c"Unable to create /etc/init/vz_init_done.conf: %s\0A\00"
@.str.5 = [216 x i8] c"# tell vzctl that start was successfull\0A#\0A# This task is to tell vzctl that start was successfull\0A\0Adescription\09\22tell vzctl that start was successfull\22\0A\0Astart on stopped rc RUNLEVEL=[2345]\0A\0Atask\0A\0Aexec touch /.vzfifo\0A\00"
@.str.6 = [47 x i8] c"Error writing /etc/init/vz_init_done.conf: %s\0A\00"
@.str.7 = [14 x i8] c"/etc/event.d/\00"
@.str.8 = [26 x i8] c"/etc/event.d/vz_init_done\00"
@.str.9 = [48 x i8] c"Unable to create /etc/event.d/vz_init_done: %s\0A\00"
@.str.10 = [177 x i8] c"# This task runs if default runlevel is reached\0A# Added by OpenVZ vzctl\0Astart on stopped rc2\0Astart on stopped rc3\0Astart on stopped rc4\0Astart on stopped rc5\0Aexec touch /.vzfifo\0A\00"
@.str.11 = [45 x i8] c"Error writing /etc/event.d/vz_init_done: %s\0A\00"
@.str.12 = [13 x i8] c"/etc/inittab\00"
@O_RDWR = global i32 0
@O_APPEND = global i32 0
@.str.13 = [32 x i8] c"Unable to open /etc/inittab %s\0A\00"
@.str.14 = [37 x i8] c"Unable to read from /etc/inittab %s\0A\00"
@.str.15 = [5 x i8] c"\0Avz:\00"
@.str.16 = [29 x i8] c"vz:2345:once:touch /.vzfifo\0A\00"
@.str.17 = [36 x i8] c"Unable to write to /etc/inittab %s\0A\00"
define i32 @add_reach_runlevel_mark() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca [4096 x i8]
%8 = alloca %struct.stat
%9 = call i32 @unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%10 = call i64 @mkfifo(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 420)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %0
%13 = load i32, i32* @stderr
%14 = load i32, i32* @errno
%15 = call i8* @strerror(i32 %14)
%16 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %15)
store i32 -1, i32* %1
br label %138
17: ; preds = %0
%18 = call i32 @stat(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), %struct.stat* %8)
%19 = icmp ne i32 %18, 0
br i1 %19, label %51, label %20
20: ; preds = %17
%21 = load i32, i32* @O_WRONLY
%22 = load i32, i32* @O_TRUNC
%23 = or i32 %21, %22
%24 = load i32, i32* @O_CREAT
%25 = or i32 %23, %24
%26 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %25, i32 420)
store i32 %26, i32* %2
%27 = load i32, i32* %2
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %34
29: ; preds = %20
%30 = load i32, i32* @stderr
%31 = load i32, i32* @errno
%32 = call i8* @strerror(i32 %31)
%33 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0), i8* %32)
store i32 -1, i32* %1
br label %138
34: ; preds = %20
store i64 215, i64* %5
%35 = load i32, i32* %2
%36 = load i64, i64* %5
%37 = trunc i64 %36 to i32
%38 = call i32 @write(i32 %35, i8* getelementptr inbounds ([216 x i8], [216 x i8]* @.str.5, i64 0, i64 0), i32 %37)
%39 = sext i32 %38 to i64
store i64 %39, i64* %6
%40 = load i32, i32* %2
%41 = call i32 @close(i32 %40)
%42 = load i64, i64* %5
%43 = load i64, i64* %6
%44 = icmp ne i64 %42, %43
br i1 %44, label %45, label %50
45: ; preds = %34
%46 = load i32, i32* @stderr
%47 = load i32, i32* @errno
%48 = call i8* @strerror(i32 %47)
%49 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.6, i64 0, i64 0), i8* %48)
store i32 -1, i32* %1
br label %138
50: ; preds = %34
store i32 0, i32* %1
br label %138
51: ; preds = %17
%52 = call i32 @stat(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), %struct.stat* %8)
%53 = icmp ne i32 %52, 0
br i1 %53, label %85, label %54
54: ; preds = %51
%55 = load i32, i32* @O_WRONLY
%56 = load i32, i32* @O_TRUNC
%57 = or i32 %55, %56
%58 = load i32, i32* @O_CREAT
%59 = or i32 %57, %58
%60 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i32 %59, i32 420)
store i32 %60, i32* %2
%61 = load i32, i32* %2
%62 = icmp eq i32 %61, -1
br i1 %62, label %63, label %68
63: ; preds = %54
%64 = load i32, i32* @stderr
%65 = load i32, i32* @errno
%66 = call i8* @strerror(i32 %65)
%67 = call i32 @fprintf(i32 %64, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.9, i64 0, i64 0), i8* %66)
store i32 -1, i32* %1
br label %138
68: ; preds = %54
store i64 176, i64* %5
%69 = load i32, i32* %2
%70 = load i64, i64* %5
%71 = trunc i64 %70 to i32
%72 = call i32 @write(i32 %69, i8* getelementptr inbounds ([177 x i8], [177 x i8]* @.str.10, i64 0, i64 0), i32 %71)
%73 = sext i32 %72 to i64
store i64 %73, i64* %6
%74 = load i32, i32* %2
%75 = call i32 @close(i32 %74)
%76 = load i64, i64* %5
%77 = load i64, i64* %6
%78 = icmp ne i64 %76, %77
br i1 %78, label %79, label %84
79: ; preds = %68
%80 = load i32, i32* @stderr
%81 = load i32, i32* @errno
%82 = call i8* @strerror(i32 %81)
%83 = call i32 @fprintf(i32 %80, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.11, i64 0, i64 0), i8* %82)
store i32 -1, i32* %1
br label %138
84: ; preds = %68
store i32 0, i32* %1
br label %138
85: ; preds = %51
br label %86
86: ; preds = %85
%87 = load i32, i32* @O_RDWR
%88 = load i32, i32* @O_APPEND
%89 = or i32 %87, %88
%90 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.12, i64 0, i64 0), i32 %89)
store i32 %90, i32* %2
%91 = icmp eq i32 %90, -1
br i1 %91, label %92, label %97
92: ; preds = %86
%93 = load i32, i32* @stderr
%94 = load i32, i32* @errno
%95 = call i8* @strerror(i32 %94)
%96 = call i32 @fprintf(i32 %93, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.13, i64 0, i64 0), i8* %95)
store i32 -1, i32* %1
br label %138
97: ; preds = %86
store i32 0, i32* %4
store i32 0, i32* %3
br label %98
98: ; preds = %97, %120
%99 = load i32, i32* %2
%100 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%101 = call i64 @read(i32 %99, i8* %100, i32 4096)
store i64 %101, i64* %5
%102 = load i64, i64* %5
%103 = icmp eq i64 %102, 0
br i1 %103, label %104, label %105
104: ; preds = %98
br label %121
105: ; preds = %98
%106 = load i64, i64* %5
%107 = icmp ult i64 %106, 0
br i1 %107, label %108, label %113
108: ; preds = %105
%109 = load i32, i32* @stderr
%110 = load i32, i32* @errno
%111 = call i8* @strerror(i32 %110)
%112 = call i32 @fprintf(i32 %109, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.14, i64 0, i64 0), i8* %111)
store i32 -1, i32* %4
br label %121
113: ; preds = %105
%114 = load i64, i64* %5
%115 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 %114
store i8 0, i8* %115
%116 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%117 = call i32* @strstr(i8* %116, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.15, i64 0, i64 0))
%118 = icmp ne i32* %117, null
br i1 %118, label %119, label %120
119: ; preds = %113
store i32 1, i32* %3
br label %121
120: ; preds = %113
br label %98
121: ; preds = %119, %108, %104
%122 = load i32, i32* %3
%123 = icmp ne i32 %122, 0
br i1 %123, label %134, label %124
124: ; preds = %121
%125 = load i32, i32* %2
%126 = call i32 @write(i32 %125, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.16, i64 0, i64 0), i32 28)
%127 = icmp eq i32 %126, -1
br i1 %127, label %128, label %133
128: ; preds = %124
%129 = load i32, i32* @stderr
%130 = load i32, i32* @errno
%131 = call i8* @strerror(i32 %130)
%132 = call i32 @fprintf(i32 %129, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.17, i64 0, i64 0), i8* %131)
store i32 -1, i32* %4
br label %133
133: ; preds = %128, %124
br label %134
134: ; preds = %133, %121
%135 = load i32, i32* %2
%136 = call i32 @close(i32 %135)
%137 = load i32, i32* %4
store i32 %137, i32* %1
br label %138
138: ; preds = %134, %92, %84, %79, %63, %50, %45, %29, %12
%139 = load i32, i32* %1
ret i32 %139
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [9 x i8] c"/.vzfifo\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"Unable to create /.vzfifo %s\0A\00"
@errno = global i32 0
@.str.2 = [11 x i8] c"/etc/init/\00"
@.str.3 = [28 x i8] c"/etc/init/vz_init_done.conf\00"
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@O_CREAT = global i32 0
@.str.4 = [50 x i8] c"Unable to create /etc/init/vz_init_done.conf: %s\0A\00"
@.str.5 = [216 x i8] c"# tell vzctl that start was successfull\0A#\0A# This task is to tell vzctl that start was successfull\0A\0Adescription\09\22tell vzctl that start was successfull\22\0A\0Astart on stopped rc RUNLEVEL=[2345]\0A\0Atask\0A\0Aexec touch /.vzfifo\0A\00"
@.str.6 = [47 x i8] c"Error writing /etc/init/vz_init_done.conf: %s\0A\00"
@.str.7 = [14 x i8] c"/etc/event.d/\00"
@.str.8 = [26 x i8] c"/etc/event.d/vz_init_done\00"
@.str.9 = [48 x i8] c"Unable to create /etc/event.d/vz_init_done: %s\0A\00"
@.str.10 = [177 x i8] c"# This task runs if default runlevel is reached\0A# Added by OpenVZ vzctl\0Astart on stopped rc2\0Astart on stopped rc3\0Astart on stopped rc4\0Astart on stopped rc5\0Aexec touch /.vzfifo\0A\00"
@.str.11 = [45 x i8] c"Error writing /etc/event.d/vz_init_done: %s\0A\00"
@.str.12 = [13 x i8] c"/etc/inittab\00"
@O_RDWR = global i32 0
@O_APPEND = global i32 0
@.str.13 = [32 x i8] c"Unable to open /etc/inittab %s\0A\00"
@.str.15 = [5 x i8] c"\0Avz:\00"
@.str.16 = [29 x i8] c"vz:2345:once:touch /.vzfifo\0A\00"
@.str.17 = [36 x i8] c"Unable to write to /etc/inittab %s\0A\00"
define i32 @add_reach_runlevel_mark() {
%1 = alloca [4096 x i8]
%2 = alloca %struct.stat
%3 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%4 = bitcast %struct.stat* %2 to i8*
%5 = tail call i32 @unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%6 = tail call i64 @mkfifo(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 420)
%7 = icmp eq i64 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = tail call i8* @strerror(i32 %10)
%12 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %11)
br label %92
13: ; preds = %0
%14 = call i32 @stat(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), %struct.stat* %2)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %38
16: ; preds = %13
%17 = load i32, i32* @O_WRONLY
%18 = load i32, i32* @O_TRUNC
%19 = or i32 %18, %17
%20 = load i32, i32* @O_CREAT
%21 = or i32 %19, %20
%22 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %21, i32 420)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %29
24: ; preds = %16
%25 = load i32, i32* @stderr
%26 = load i32, i32* @errno
%27 = tail call i8* @strerror(i32 %26)
%28 = tail call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0), i8* %27)
br label %92
29: ; preds = %16
%30 = tail call i32 @write(i32 %22, i8* getelementptr inbounds ([216 x i8], [216 x i8]* @.str.5, i64 0, i64 0), i32 215)
%31 = tail call i32 @close(i32 %22)
%32 = icmp eq i32 %30, 215
br i1 %32, label %92, label %33
33: ; preds = %29
%34 = load i32, i32* @stderr
%35 = load i32, i32* @errno
%36 = tail call i8* @strerror(i32 %35)
%37 = tail call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.6, i64 0, i64 0), i8* %36)
br label %92
38: ; preds = %13
%39 = call i32 @stat(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), %struct.stat* %2)
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %63
41: ; preds = %38
%42 = load i32, i32* @O_WRONLY
%43 = load i32, i32* @O_TRUNC
%44 = or i32 %43, %42
%45 = load i32, i32* @O_CREAT
%46 = or i32 %44, %45
%47 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i32 %46, i32 420)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %54
49: ; preds = %41
%50 = load i32, i32* @stderr
%51 = load i32, i32* @errno
%52 = tail call i8* @strerror(i32 %51)
%53 = tail call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.9, i64 0, i64 0), i8* %52)
br label %92
54: ; preds = %41
%55 = tail call i32 @write(i32 %47, i8* getelementptr inbounds ([177 x i8], [177 x i8]* @.str.10, i64 0, i64 0), i32 176)
%56 = tail call i32 @close(i32 %47)
%57 = icmp eq i32 %55, 176
br i1 %57, label %92, label %58
58: ; preds = %54
%59 = load i32, i32* @stderr
%60 = load i32, i32* @errno
%61 = tail call i8* @strerror(i32 %60)
%62 = tail call i32 @fprintf(i32 %59, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.11, i64 0, i64 0), i8* %61)
br label %92
63: ; preds = %38
%64 = load i32, i32* @O_RDWR
%65 = load i32, i32* @O_APPEND
%66 = or i32 %65, %64
%67 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.12, i64 0, i64 0), i32 %66)
%68 = icmp eq i32 %67, -1
br i1 %68, label %69, label %74
69: ; preds = %63
%70 = load i32, i32* @stderr
%71 = load i32, i32* @errno
%72 = tail call i8* @strerror(i32 %71)
%73 = tail call i32 @fprintf(i32 %70, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.13, i64 0, i64 0), i8* %72)
br label %92
74: ; preds = %63, %77
%75 = call i64 @read(i32 %67, i8* %3, i32 4096)
%76 = icmp eq i64 %75, 0
br i1 %76, label %81, label %77
77: ; preds = %74
%78 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %75
store i8 0, i8* %78
%79 = call i32* @strstr(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.15, i64 0, i64 0))
%80 = icmp eq i32* %79, null
br i1 %80, label %74, label %89
81: ; preds = %74
%82 = call i32 @write(i32 %67, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.16, i64 0, i64 0), i32 28)
%83 = icmp eq i32 %82, -1
br i1 %83, label %84, label %89
84: ; preds = %81
%85 = load i32, i32* @stderr
%86 = load i32, i32* @errno
%87 = call i8* @strerror(i32 %86)
%88 = call i32 @fprintf(i32 %85, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.17, i64 0, i64 0), i8* %87)
br label %89
89: ; preds = %77, %81, %84
%90 = phi i32 [ -1, %84 ], [ 0, %81 ], [ 0, %77 ]
%91 = call i32 @close(i32 %67)
br label %92
92: ; preds = %54, %29, %89, %69, %58, %49, %33, %24, %8
%93 = phi i32 [ -1, %8 ], [ -1, %69 ], [ %90, %89 ], [ -1, %49 ], [ -1, %58 ], [ -1, %24 ], [ -1, %33 ], [ 0, %29 ], [ 0, %54 ]
ret i32 %93
}