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

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ SIGQUIT;
int /*<<< orphan*/ _SC_OPEN_MAX;
int chdir(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ kill(int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int pipe(int *);
int /*<<< orphan*/ read(int, int *, int);
int /*<<< orphan*/ setpgid(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ setsid();
int sysconf(int /*<<< orphan*/);
void do_daemonise(const char *pidfilename, bool close_all_fd) {
  int fd;
  int pid;
  FILE *pidfile;
  int pipefds[2];
  int fdlimit;
  int cfd;
  if (pipe(pipefds) == -1) {
    perror("pipe");
    exit(1);
  }
  switch ((pid = fork())) {
  case 0:
    break;
  case -1:
    perror("fork");
    exit(1);
    break;
  default:
    close(pipefds[1]);
    if (read(pipefds[0], &pid, 1) < 0)
      perror("read");
    exit(0);
  }
  fd = open("/dev/null", O_RDWR);
  if (fd == -1) {
    perror("/dev/null open");
    exit(1);
  }
  dup2(fd, 0);
  dup2(fd, 1);
  dup2(fd, 2);
  close(fd);
  if (chdir("/") == -1) {
    perror("chdir");
    exit(1);
  }
  if (close_all_fd) {
    fdlimit = sysconf(_SC_OPEN_MAX);
    for (cfd = 3; cfd < fdlimit; cfd++) {
      if ((cfd != pipefds[0]) && (cfd != pipefds[1])) {
        close(cfd);
      }
    }
  }
  setsid();
  setpgid(0, 0);
  switch ((pid = fork())) {
  case -1:
    exit(1);
  case 0:
    close(pipefds[0]);
    close(pipefds[1]);
    break;
  default:
    if (pidfilename != NULL) {
      pidfile = fopen(pidfilename, "w");
      if (pidfile == NULL) {
        perror("open");
        kill(pid, SIGQUIT);
        exit(2);
      }
      fprintf(pidfile, "%d\n", pid);
      fclose(pidfile);
    }
    exit(0);
  }
}


x86 assembly (clang, -O0):
<do_daemonise>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x28(%rbp),%rdi
call   1070 <pipe@plt>
cmp    $0xffffffff,%eax
jne    1237 <do_daemonise+0x37>
lea    0xdd8(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
xor    %eax,%eax
call   1120 <fork@plt>
mov    %eax,-0x14(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x34(%rbp)
sub    $0xffffffff,%eax
je     1269 <do_daemonise+0x69>
jmp    1254 <do_daemonise+0x54>
mov    -0x34(%rbp),%eax
test   %eax,%eax
jne    127f <do_daemonise+0x7f>
jmp    1264 <do_daemonise+0x64>
jmp    12b4 <do_daemonise+0xb4>
lea    0xd95(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x24(%rbp),%edi
call   1060 <close@plt>
mov    -0x28(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x1,%edx
call   1090 <read@plt>
cmp    $0x0,%eax
jge    12ad <do_daemonise+0xad>
lea    0xd62(%rip),%rdi
call   10e0 <perror@plt>
xor    %edi,%edi
call   1110 <exit@plt>
mov    0x2d2d(%rip),%rax
mov    (%rax),%esi
lea    0xd4b(%rip),%rdi
call   10c0 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    12ec <do_daemonise+0xec>
lea    0xd3c(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x10(%rbp),%edi
xor    %esi,%esi
call   1050 <dup2@plt>
mov    -0x10(%rbp),%edi
mov    $0x1,%esi
call   1050 <dup2@plt>
mov    -0x10(%rbp),%edi
mov    $0x2,%esi
call   1050 <dup2@plt>
mov    -0x10(%rbp),%edi
call   1060 <close@plt>
lea    0xd09(%rip),%rdi
call   1040 <chdir@plt>
cmp    $0xffffffff,%eax
jne    1343 <do_daemonise+0x143>
lea    0xcf6(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
cmpl   $0x0,-0xc(%rbp)
je     13a9 <do_daemonise+0x1a9>
mov    0x2c7c(%rip),%rax
mov    (%rax),%edi
call   10f0 <sysconf@plt>
mov    %eax,-0x2c(%rbp)
movl   $0x3,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    13a4 <do_daemonise+0x1a4>
mov    -0x30(%rbp),%eax
cmp    -0x28(%rbp),%eax
je     1391 <do_daemonise+0x191>
mov    -0x30(%rbp),%eax
cmp    -0x24(%rbp),%eax
je     1391 <do_daemonise+0x191>
mov    -0x30(%rbp),%edi
call   1060 <close@plt>
jmp    1396 <do_daemonise+0x196>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1365 <do_daemonise+0x165>
jmp    13a9 <do_daemonise+0x1a9>
xor    %eax,%eax
mov    %eax,-0x40(%rbp)
mov    %al,-0x39(%rbp)
call   1080 <setsid@plt>
mov    -0x40(%rbp),%esi
mov    %esi,%edi
call   1100 <setpgid@plt>
mov    -0x39(%rbp),%al
call   1120 <fork@plt>
mov    %eax,-0x14(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x38(%rbp)
sub    $0xffffffff,%eax
je     13ee <do_daemonise+0x1ee>
jmp    13de <do_daemonise+0x1de>
mov    -0x38(%rbp),%eax
test   %eax,%eax
je     13f8 <do_daemonise+0x1f8>
jmp    140d <do_daemonise+0x20d>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x28(%rbp),%edi
call   1060 <close@plt>
mov    -0x24(%rbp),%edi
call   1060 <close@plt>
jmp    1481 <do_daemonise+0x281>
cmpq   $0x0,-0x8(%rbp)
je     147a <do_daemonise+0x27a>
mov    -0x8(%rbp),%rdi
lea    0xc0d(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    145e <do_daemonise+0x25e>
lea    0xbe5(%rip),%rdi
call   10e0 <perror@plt>
mov    -0x14(%rbp),%edi
mov    0x2b93(%rip),%rax
mov    (%rax),%esi
call   10b0 <kill@plt>
mov    $0x2,%edi
call   1110 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xbc6(%rip),%rsi
call   10a0 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
call   1110 <exit@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_daemonise>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
lea    0x4(%rsp),%rdi
call   1070 <pipe@plt>
cmp    $0xffffffff,%eax
je     1321 <do_daemonise+0x121>
xor    %eax,%eax
call   1120 <fork@plt>
mov    %eax,0xc(%rsp)
test   %eax,%eax
jne    1302 <do_daemonise+0x102>
mov    0x2dae(%rip),%rax
mov    (%rax),%esi
lea    0xdcc(%rip),%rdi
call   10c0 <open@plt>
cmp    $0xffffffff,%eax
je     132a <do_daemonise+0x12a>
mov    %eax,%ebx
mov    %eax,%edi
xor    %esi,%esi
call   1050 <dup2@plt>
mov    %ebx,%edi
mov    $0x1,%esi
call   1050 <dup2@plt>
mov    %ebx,%edi
mov    $0x2,%esi
call   1050 <dup2@plt>
mov    %ebx,%edi
call   1060 <close@plt>
lea    0xda6(%rip),%rdi
call   1040 <chdir@plt>
cmp    $0xffffffff,%eax
je     1333 <do_daemonise+0x133>
test   %ebp,%ebp
je     12cc <do_daemonise+0xcc>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
call   10f0 <sysconf@plt>
cmp    $0x4,%eax
jl     12cc <do_daemonise+0xcc>
mov    %eax,%ebp
mov    $0x3,%ebx
jmp    12b7 <do_daemonise+0xb7>
add    $0x1,%ebx
cmp    %ebx,%ebp
je     12cc <do_daemonise+0xcc>
cmp    0x4(%rsp),%ebx
je     12b0 <do_daemonise+0xb0>
cmp    0x8(%rsp),%ebx
je     12b0 <do_daemonise+0xb0>
mov    %ebx,%edi
call   1060 <close@plt>
jmp    12b0 <do_daemonise+0xb0>
xor    %eax,%eax
call   1080 <setsid@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1100 <setpgid@plt>
xor    %eax,%eax
call   1120 <fork@plt>
test   %eax,%eax
jne    1310 <do_daemonise+0x110>
mov    0x4(%rsp),%edi
call   1060 <close@plt>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
cmp    $0xffffffff,%eax
jne    1349 <do_daemonise+0x149>
lea    0xcf7(%rip),%rdi
jmp    133a <do_daemonise+0x13a>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1377 <do_daemonise+0x177>
mov    $0x1,%edi
call   1110 <exit@plt>
lea    0xcd8(%rip),%rdi
jmp    133a <do_daemonise+0x13a>
lea    0xce8(%rip),%rdi
jmp    133a <do_daemonise+0x13a>
lea    0xcf0(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
mov    0x4(%rsp),%edi
lea    0xc(%rsp),%rsi
mov    $0x1,%edx
call   1090 <read@plt>
test   %eax,%eax
jns    137c <do_daemonise+0x17c>
lea    0xc9a(%rip),%rdi
call   10e0 <perror@plt>
jmp    137c <do_daemonise+0x17c>
test   %r14,%r14
jne    1383 <do_daemonise+0x183>
xor    %edi,%edi
call   1110 <exit@plt>
lea    0xca6(%rip),%rsi
mov    %r14,%rdi
call   10d0 <fopen@plt>
test   %rax,%rax
jne    13bd <do_daemonise+0x1bd>
lea    0xc85(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2c36(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   10b0 <kill@plt>
mov    $0x2,%edi
call   1110 <exit@plt>
mov    %rax,%rbx
lea    0xc6b(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   10a0 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
call   1110 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"pipe\00"
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [5 x i8] c"read\00"
@.str.3 = [10 x i8] c"/dev/null\00"
@O_RDWR = global i32 0
@.str.4 = [15 x i8] c"/dev/null open\00"
@.str.5 = [2 x i8] c"/\00"
@.str.6 = [6 x i8] c"chdir\00"
@_SC_OPEN_MAX = global i32 0
@.str.7 = [2 x i8] c"w\00"
@.str.8 = [5 x i8] c"open\00"
@SIGQUIT = global i32 0
@.str.9 = [4 x i8] c"%d\0A\00"
define void @do_daemonise(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca [2 x i32]
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%12 = call i32 @pipe(i32* %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = call i32 (...) @fork()
store i32 %18, i32* %6
switch i32 %18, label %23 [
i32 0, label %19
i32 -1, label %20
]
19: ; preds = %17
br label %35
20: ; preds = %17
%21 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %17
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%25 = load i32, i32* %24
%26 = call i32 @close(i32 %25)
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%28 = load i32, i32* %27
%29 = call i32 @read(i32 %28, i32* %6, i32 1)
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %23
%32 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %31, %23
%34 = call i32 @exit(i32 0)
unreachable
35: ; preds = %19
%36 = load i32, i32* @O_RDWR
%37 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %36)
store i32 %37, i32* %5
%38 = load i32, i32* %5
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %43
40: ; preds = %35
%41 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %35
%44 = load i32, i32* %5
%45 = call i32 @dup2(i32 %44, i32 0)
%46 = load i32, i32* %5
%47 = call i32 @dup2(i32 %46, i32 1)
%48 = load i32, i32* %5
%49 = call i32 @dup2(i32 %48, i32 2)
%50 = load i32, i32* %5
%51 = call i32 @close(i32 %50)
%52 = call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %57
54: ; preds = %43
%55 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %43
%58 = load i32, i32* %4
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %85
60: ; preds = %57
%61 = load i32, i32* @_SC_OPEN_MAX
%62 = call i32 @sysconf(i32 %61)
store i32 %62, i32* %9
store i32 3, i32* %10
br label %63
63: ; preds = %81, %60
%64 = load i32, i32* %10
%65 = load i32, i32* %9
%66 = icmp slt i32 %64, %65
br i1 %66, label %67, label %84
67: ; preds = %63
%68 = load i32, i32* %10
%69 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%70 = load i32, i32* %69
%71 = icmp ne i32 %68, %70
br i1 %71, label %72, label %80
72: ; preds = %67
%73 = load i32, i32* %10
%74 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%75 = load i32, i32* %74
%76 = icmp ne i32 %73, %75
br i1 %76, label %77, label %80
77: ; preds = %72
%78 = load i32, i32* %10
%79 = call i32 @close(i32 %78)
br label %80
80: ; preds = %77, %72, %67
br label %81
81: ; preds = %80
%82 = load i32, i32* %10
%83 = add nsw i32 %82, 1
store i32 %83, i32* %10
br label %63
84: ; preds = %63
br label %85
85: ; preds = %84, %57
%86 = call i32 (...) @setsid()
%87 = call i32 @setpgid(i32 0, i32 0)
%88 = call i32 (...) @fork()
store i32 %88, i32* %6
switch i32 %88, label %98 [
i32 -1, label %89
i32 0, label %91
]
89: ; preds = %85
%90 = call i32 @exit(i32 1)
unreachable
91: ; preds = %85
%92 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%93 = load i32, i32* %92
%94 = call i32 @close(i32 %93)
%95 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%96 = load i32, i32* %95
%97 = call i32 @close(i32 %96)
br label %120
98: ; preds = %85
%99 = load i8*, i8** %3
%100 = icmp ne i8* %99, null
br i1 %100, label %101, label %118
101: ; preds = %98
%102 = load i8*, i8** %3
%103 = call i32* @fopen(i8* %102, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %103, i32** %7
%104 = load i32*, i32** %7
%105 = icmp eq i32* %104, null
br i1 %105, label %106, label %112
106: ; preds = %101
%107 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%108 = load i32, i32* %6
%109 = load i32, i32* @SIGQUIT
%110 = call i32 @kill(i32 %108, i32 %109)
%111 = call i32 @exit(i32 2)
unreachable
112: ; preds = %101
%113 = load i32*, i32** %7
%114 = load i32, i32* %6
%115 = call i32 @fprintf(i32* %113, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %114)
%116 = load i32*, i32** %7
%117 = call i32 @fclose(i32* %116)
br label %118
118: ; preds = %112, %98
%119 = call i32 @exit(i32 0)
unreachable
120: ; preds = %91
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"pipe\00"
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [5 x i8] c"read\00"
@.str.3 = [10 x i8] c"/dev/null\00"
@O_RDWR = global i32 0
@.str.4 = [15 x i8] c"/dev/null open\00"
@.str.5 = [2 x i8] c"/\00"
@.str.6 = [6 x i8] c"chdir\00"
@_SC_OPEN_MAX = global i32 0
@.str.7 = [2 x i8] c"w\00"
@.str.8 = [5 x i8] c"open\00"
@SIGQUIT = global i32 0
@.str.9 = [4 x i8] c"%d\0A\00"
define void @do_daemonise(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca [2 x i32]
%5 = bitcast i32* %3 to i8*
%6 = bitcast [2 x i32]* %4 to i8*
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%8 = call i32 @pipe(i32* %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = call i32 (...) @fork()
store i32 %14, i32* %3
switch i32 %14, label %18 [
i32 0, label %29
i32 -1, label %15
]
15: ; preds = %13
%16 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %13
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%20 = load i32, i32* %19
%21 = call i32 @close(i32 %20)
%22 = load i32, i32* %7
%23 = call i32 @read(i32 %22, i32* %3, i32 1)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %18
%26 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %25, %18
%28 = call i32 @exit(i32 0)
unreachable
29: ; preds = %13
%30 = load i32, i32* @O_RDWR
%31 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %30)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %29
%37 = call i32 @dup2(i32 %31, i32 0)
%38 = call i32 @dup2(i32 %31, i32 1)
%39 = call i32 @dup2(i32 %31, i32 2)
%40 = call i32 @close(i32 %31)
%41 = call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %46
43: ; preds = %36
%44 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %36
%47 = icmp eq i32 %1, 0
br i1 %47, label %66, label %48
48: ; preds = %46
%49 = load i32, i32* @_SC_OPEN_MAX
%50 = call i32 @sysconf(i32 %49)
%51 = icmp sgt i32 %50, 3
br i1 %51, label %52, label %66
52: ; preds = %48
%53 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
br label %54
54: ; preds = %52, %63
%55 = phi i32 [ 3, %52 ], [ %64, %63 ]
%56 = load i32, i32* %7
%57 = icmp eq i32 %55, %56
%58 = load i32, i32* %53
%59 = icmp eq i32 %55, %58
%60 = select i1 %57, i1 true, i1 %59
br i1 %60, label %63, label %61
61: ; preds = %54
%62 = call i32 @close(i32 %55)
br label %63
63: ; preds = %54, %61
%64 = add nuw nsw i32 %55, 1
%65 = icmp eq i32 %64, %50
br i1 %65, label %66, label %54
66: ; preds = %63, %48, %46
%67 = call i32 (...) @setsid()
%68 = call i32 @setpgid(i32 0, i32 0)
%69 = call i32 (...) @fork()
switch i32 %69, label %78 [
i32 -1, label %70
i32 0, label %72
]
70: ; preds = %66
%71 = call i32 @exit(i32 1)
unreachable
72: ; preds = %66
%73 = load i32, i32* %7
%74 = call i32 @close(i32 %73)
%75 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%76 = load i32, i32* %75
%77 = call i32 @close(i32 %76)
ret void
78: ; preds = %66
%79 = icmp eq i8* %0, null
br i1 %79, label %91, label %80
80: ; preds = %78
%81 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%82 = icmp eq i32* %81, null
br i1 %82, label %83, label %88
83: ; preds = %80
%84 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%85 = load i32, i32* @SIGQUIT
%86 = call i32 @kill(i32 %69, i32 %85)
%87 = call i32 @exit(i32 2)
unreachable
88: ; preds = %80
%89 = call i32 @fprintf(i32* %81, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %69)
%90 = call i32 @fclose(i32* %81)
br label %91
91: ; preds = %88, %78
%92 = call i32 @exit(i32 0)
unreachable
}