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

/* Variables and functions */
int EOF;
int EXIT_FAILURE;
int IPC_CREAT;
int /*<<< orphan*/ IPC_RMID;
int errno;
int /*<<< orphan*/ execl(char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int remove(char *);
char *shmat(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ shmctl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ shmdt(char *);
int shmget(int, int, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ waitpid(int, int *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  pid_t pid1, pid2, pid3;
  int status1;
  int status2;
  int status3;
  int pidstatus1;
  int pidstatus2;
  int count = 1;
  int linecount_id;
  char *linecount;
  key_t key;
  key = 5554;
  linecount_id = shmget(key, 500, IPC_CREAT | 0666);
  if (linecount_id < 0) {
    perror("in start shmget");
    exit(1);
  }
  linecount = shmat(linecount_id, NULL, 0);
  if (linecount == (char *)-1) {
    perror("shmat");
    exit(1);
  }
  FILE *fp;
  static int filestatus;
  filestatus = remove("output.txt");
  if (filestatus == 0)
    printf("Output filen er blevet slettet.\n");
  else {
    printf("Kunne ikke slette filen \n");
    perror("Error");
  }
  fp = fopen("input.txt", "r");
  if (fp == NULL) {
    perror("start : Can not open file !!");
    exit(EXIT_FAILURE);
  }
  static int c;
  unsigned long newline_count = 0;
  while ((c = fgetc(fp)) != EOF) {
    if (c == '\n')
      newline_count++;
  }
  fclose(fp);
  while (count <= newline_count) {
    *linecount = count;
    pid1 = fork();
    if (pid1 == -1) {
      fprintf(stderr, "can't fork, error %d\n", errno);
      exit(EXIT_FAILURE);
    } else if (pid1 == 0) {
      execl("prog1", "prog1", NULL);
    } else {
      waitpid(pid1, &status1, 0);
      pid2 = fork();
      if (pid2 == -1) {
        fprintf(stderr, "can't fork, error %d\n", errno);
        exit(EXIT_FAILURE);
      } else if (pid2 == 0) {
        execl("prog2", "prog2", NULL);
      } else {
        waitpid(pid2, &status2, 0);
        pid3 = fork();
        if (pid3 == -1) {
          fprintf(stderr, "can't fork, error %d\n", errno);
          exit(EXIT_FAILURE);
        } else if (pid3 == 0) {
          execl("prog3", "prog3", NULL);
        } else {
          waitpid(pid3, &status3, 0);
        }
      }
    }
    count++;
  }
  shmctl(linecount_id, IPC_RMID, 0);
  shmdt(linecount);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x34(%rbp)
movl   $0x15b2,-0x44(%rbp)
mov    -0x44(%rbp),%edi
mov    0x2d9a(%rip),%rax
mov    (%rax),%edx
or     $0x1b6,%edx
mov    $0x1f4,%esi
call   10e0 <shmget@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jge    1253 <main+0x63>
lea    0xdbc(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x38(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10d0 <shmat@plt>
mov    %rax,-0x40(%rbp)
mov    $0xffffffffffffffff,%rax
cmp    %rax,-0x40(%rbp)
jne    128c <main+0x9c>
lea    0xd93(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    0xd83(%rip),%rdi
call   1030 <remove@plt>
mov    %eax,0x2e02(%rip)
cmpl   $0x0,0x2dfb(%rip)
jne    12bc <main+0xcc>
lea    0xd6f(%rip),%rdi
call   1060 <printf@plt>
jmp    12d4 <main+0xe4>
lea    0xd7f(%rip),%rdi
call   1060 <printf@plt>
lea    0xd8d(%rip),%rdi
call   10c0 <perror@plt>
lea    0xd87(%rip),%rdi
lea    0xd7e(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    1310 <main+0x120>
lea    0xd6f(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2cbf(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
movq   $0x0,-0x58(%rbp)
mov    -0x50(%rbp),%rdi
call   1070 <fgetc@plt>
mov    %eax,0x2d81(%rip)
mov    0x2cba(%rip),%rcx
cmp    (%rcx),%eax
je     1354 <main+0x164>
cmpl   $0xa,0x2d6b(%rip)
jne    134f <main+0x15f>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    1318 <main+0x128>
mov    -0x50(%rbp),%rdi
call   1050 <fclose@plt>
movslq -0x34(%rbp),%rax
cmp    -0x58(%rbp),%rax
ja     14ed <main+0x2fd>
mov    -0x34(%rbp),%eax
mov    %al,%cl
mov    -0x40(%rbp),%rax
mov    %cl,(%rax)
mov    $0x0,%al
call   1110 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    13b6 <main+0x1c6>
mov    0x2c47(%rip),%rax
mov    (%rax),%edi
mov    0x2c36(%rip),%rax
mov    (%rax),%edx
lea    0xce6(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2c19(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
cmpl   $0x0,-0x14(%rbp)
jne    13d8 <main+0x1e8>
lea    0xcd8(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    %rsi,%rdi
call   1100 <execl@plt>
jmp    14da <main+0x2ea>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1090 <waitpid@plt>
mov    $0x0,%al
call   1110 <fork@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1426 <main+0x236>
mov    0x2bd7(%rip),%rax
mov    (%rax),%edi
mov    0x2bc6(%rip),%rax
mov    (%rax),%edx
lea    0xc76(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2ba9(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
cmpl   $0x0,-0x18(%rbp)
jne    1448 <main+0x258>
lea    0xc6e(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    %rsi,%rdi
call   1100 <execl@plt>
jmp    14d0 <main+0x2e0>
mov    -0x18(%rbp),%edi
lea    -0x24(%rbp),%rsi
xor    %edx,%edx
call   1090 <waitpid@plt>
mov    $0x0,%al
call   1110 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1496 <main+0x2a6>
mov    0x2b67(%rip),%rax
mov    (%rax),%edi
mov    0x2b56(%rip),%rax
mov    (%rax),%edx
lea    0xc06(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2b39(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    14b8 <main+0x2c8>
lea    0xc04(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    %rsi,%rdi
call   1100 <execl@plt>
jmp    14c6 <main+0x2d6>
mov    -0x1c(%rbp),%edi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1090 <waitpid@plt>
jmp    14cb <main+0x2db>
jmp    14d0 <main+0x2e0>
jmp    14d5 <main+0x2e5>
jmp    14da <main+0x2ea>
jmp    14df <main+0x2ef>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    135d <main+0x16d>
mov    -0x38(%rbp),%edi
mov    0x2ac9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <shmctl@plt>
mov    -0x40(%rbp),%rdi
call   1040 <shmdt@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2db3(%rip),%rax
mov    $0x1b6,%edx
or     (%rax),%edx
mov    $0x15b2,%edi
mov    $0x1f4,%esi
call   10e0 <shmget@plt>
test   %eax,%eax
js     1430 <main+0x240>
mov    %eax,%ebx
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10d0 <shmat@plt>
cmp    $0xffffffffffffffff,%rax
je     1439 <main+0x249>
mov    %rax,%r15
lea    0xdd2(%rip),%rdi
call   1030 <remove@plt>
test   %eax,%eax
jne    13e7 <main+0x1f7>
lea    0xe37(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,0x8(%rsp)
lea    0xdbf(%rip),%rdi
lea    0xdb6(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     144f <main+0x25f>
mov    %rax,%r12
mov    %rax,%rdi
call   1070 <fgetc@plt>
mov    0x2d59(%rip),%r14
cmp    (%r14),%eax
jne    12a1 <main+0xb1>
mov    %r12,%rdi
call   1060 <fclose@plt>
jmp    13ba <main+0x1ca>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,%r13
mov    %eax,%ebx
xor    %ebp,%ebp
cmp    $0xa,%eax
sete   %bpl
add    %r13,%rbp
mov    %r12,%rdi
call   1070 <fgetc@plt>
cmp    (%r14),%eax
jne    12b0 <main+0xc0>
mov    %r12,%rdi
call   1060 <fclose@plt>
test   %rbp,%rbp
je     13ba <main+0x1ca>
xor    %eax,%eax
cmp    $0xa,%ebx
sete   %al
add    %rax,%r13
lea    0xd73(%rip),%rbp
lea    0x14(%rsp),%rbx
lea    0xd6d(%rip),%r12
xor    %r14d,%r14d
jmp    132a <main+0x13a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    %rbp,%rsi
xor    %edx,%edx
call   1100 <execl@plt>
add    $0x1,%r14
cmp    %r14,%r13
je     13ba <main+0x1ca>
lea    0x1(%r14),%eax
mov    %al,(%r15)
xor    %eax,%eax
call   1110 <fork@plt>
test   %eax,%eax
je     1310 <main+0x120>
cmp    $0xffffffff,%eax
je     1404 <main+0x214>
mov    %eax,%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1090 <waitpid@plt>
xor    %eax,%eax
call   1110 <fork@plt>
test   %eax,%eax
je     13a0 <main+0x1b0>
cmp    $0xffffffff,%eax
je     1404 <main+0x214>
mov    %eax,%edi
lea    0x10(%rsp),%rsi
xor    %edx,%edx
call   1090 <waitpid@plt>
xor    %eax,%eax
call   1110 <fork@plt>
test   %eax,%eax
je     13ab <main+0x1bb>
cmp    $0xffffffff,%eax
je     1404 <main+0x214>
mov    %eax,%edi
lea    0xc(%rsp),%rsi
xor    %edx,%edx
call   1090 <waitpid@plt>
jmp    131d <main+0x12d>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r12,%rsi
jmp    1316 <main+0x126>
lea    0xcbe(%rip),%rdi
mov    %rdi,%rsi
jmp    1316 <main+0x126>
mov    0x2bff(%rip),%rax
mov    (%rax),%esi
mov    0x8(%rsp),%edi
xor    %edx,%edx
call   10a0 <shmctl@plt>
mov    %r15,%rdi
call   1050 <shmdt@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc88(%rip),%rdi
call   1040 <puts@plt>
lea    0xc27(%rip),%rdi
call   10c0 <perror@plt>
jmp    125d <main+0x6d>
mov    0x2bcd(%rip),%rax
mov    (%rax),%edi
mov    0x2bbc(%rip),%rax
mov    (%rax),%edx
lea    0xc31(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2b9f(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
lea    0xbc9(%rip),%rdi
jmp    1440 <main+0x250>
lea    0xbd0(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    0xbdb(%rip),%rdi
call   10c0 <perror@plt>
jmp    1422 <main+0x232>

LLVM IR (-O0):
@IPC_CREAT = global i32 0
@.str = [16 x i8] c"in start shmget\00"
@.str.1 = [6 x i8] c"shmat\00"
@main.filestatus = internal global i32 0
@.str.2 = [11 x i8] c"output.txt\00"
@.str.3 = [33 x i8] c"Output filen er blevet slettet.\0A\00"
@.str.4 = [26 x i8] c"Kunne ikke slette filen \0A\00"
@.str.5 = [6 x i8] c"Error\00"
@.str.6 = [10 x i8] c"input.txt\00"
@.str.7 = [2 x i8] c"r\00"
@.str.8 = [29 x i8] c"start : Can not open file !!\00"
@EXIT_FAILURE = global i32 0
@main.c = internal global i32 0
@EOF = global i32 0
@stderr = global i32 0
@.str.9 = [22 x i8] c"can't fork, error %d\0A\00"
@errno = global i32 0
@.str.10 = [6 x i8] c"prog1\00"
@.str.11 = [6 x i8] c"prog2\00"
@.str.12 = [6 x i8] c"prog3\00"
@IPC_RMID = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i32
%18 = alloca i32*
%19 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %14
store i32 5554, i32* %17
%20 = load i32, i32* %17
%21 = load i32, i32* @IPC_CREAT
%22 = or i32 %21, 438
%23 = call i32 @shmget(i32 %20, i32 500, i32 %22)
store i32 %23, i32* %15
%24 = load i32, i32* %15
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %2
%27 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %2
%30 = load i32, i32* %15
%31 = call i8* @shmat(i32 %30, i32* null, i32 0)
store i8* %31, i8** %16
%32 = load i8*, i8** %16
%33 = icmp eq i8* %32, inttoptr (i64 -1 to i8*)
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %29
%38 = call i32 @remove(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
store i32 %38, i32* @main.filestatus
%39 = load i32, i32* @main.filestatus
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
br label %46
43: ; preds = %37
%44 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%45 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %46
46: ; preds = %43, %41
%47 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %47, i32** %18
%48 = load i32*, i32** %18
%49 = icmp eq i32* %48, null
br i1 %49, label %50, label %54
50: ; preds = %46
%51 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0))
%52 = load i32, i32* @EXIT_FAILURE
%53 = call i32 @exit(i32 %52)
unreachable
54: ; preds = %46
store i64 0, i64* %19
br label %55
55: ; preds = %66, %54
%56 = load i32*, i32** %18
%57 = call i32 @fgetc(i32* %56)
store i32 %57, i32* @main.c
%58 = load i32, i32* @EOF
%59 = icmp ne i32 %57, %58
br i1 %59, label %60, label %67
60: ; preds = %55
%61 = load i32, i32* @main.c
%62 = icmp eq i32 %61, 10
br i1 %62, label %63, label %66
63: ; preds = %60
%64 = load i64, i64* %19
%65 = add i64 %64, 1
store i64 %65, i64* %19
br label %66
66: ; preds = %63, %60
br label %55
67: ; preds = %55
%68 = load i32*, i32** %18
%69 = call i32 @fclose(i32* %68)
br label %70
70: ; preds = %135, %67
%71 = load i32, i32* %14
%72 = sext i32 %71 to i64
%73 = load i64, i64* %19
%74 = icmp ule i64 %72, %73
br i1 %74, label %75, label %138
75: ; preds = %70
%76 = load i32, i32* %14
%77 = trunc i32 %76 to i8
%78 = load i8*, i8** %16
store i8 %77, i8* %78
%79 = call i32 (...) @fork()
store i32 %79, i32* %6
%80 = load i32, i32* %6
%81 = icmp eq i32 %80, -1
br i1 %81, label %82, label %88
82: ; preds = %75
%83 = load i32, i32* @stderr
%84 = load i32, i32* @errno
%85 = call i32 @fprintf(i32 %83, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i32 %84)
%86 = load i32, i32* @EXIT_FAILURE
%87 = call i32 @exit(i32 %86)
unreachable
88: ; preds = %75
%89 = load i32, i32* %6
%90 = icmp eq i32 %89, 0
br i1 %90, label %91, label %93
91: ; preds = %88
%92 = call i32 @execl(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), i32* null)
br label %134
93: ; preds = %88
%94 = load i32, i32* %6
%95 = call i32 @waitpid(i32 %94, i32* %9, i32 0)
%96 = call i32 (...) @fork()
store i32 %96, i32* %7
%97 = load i32, i32* %7
%98 = icmp eq i32 %97, -1
br i1 %98, label %99, label %105
99: ; preds = %93
%100 = load i32, i32* @stderr
%101 = load i32, i32* @errno
%102 = call i32 @fprintf(i32 %100, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i32 %101)
%103 = load i32, i32* @EXIT_FAILURE
%104 = call i32 @exit(i32 %103)
unreachable
105: ; preds = %93
%106 = load i32, i32* %7
%107 = icmp eq i32 %106, 0
br i1 %107, label %108, label %110
108: ; preds = %105
%109 = call i32 @execl(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), i32* null)
br label %132
110: ; preds = %105
%111 = load i32, i32* %7
%112 = call i32 @waitpid(i32 %111, i32* %10, i32 0)
%113 = call i32 (...) @fork()
store i32 %113, i32* %8
%114 = load i32, i32* %8
%115 = icmp eq i32 %114, -1
br i1 %115, label %116, label %122
116: ; preds = %110
%117 = load i32, i32* @stderr
%118 = load i32, i32* @errno
%119 = call i32 @fprintf(i32 %117, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i32 %118)
%120 = load i32, i32* @EXIT_FAILURE
%121 = call i32 @exit(i32 %120)
unreachable
122: ; preds = %110
%123 = load i32, i32* %8
%124 = icmp eq i32 %123, 0
br i1 %124, label %125, label %127
125: ; preds = %122
%126 = call i32 @execl(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0), i32* null)
br label %130
127: ; preds = %122
%128 = load i32, i32* %8
%129 = call i32 @waitpid(i32 %128, i32* %11, i32 0)
br label %130
130: ; preds = %127, %125
br label %131
131: ; preds = %130
br label %132
132: ; preds = %131, %108
br label %133
133: ; preds = %132
br label %134
134: ; preds = %133, %91
br label %135
135: ; preds = %134
%136 = load i32, i32* %14
%137 = add nsw i32 %136, 1
store i32 %137, i32* %14
br label %70
138: ; preds = %70
%139 = load i32, i32* %15
%140 = load i32, i32* @IPC_RMID
%141 = call i32 @shmctl(i32 %139, i32 %140, i32 0)
%142 = load i8*, i8** %16
%143 = call i32 @shmdt(i8* %142)
ret i32 0
}

LLVM IR (-O2):
@IPC_CREAT = global i32 0
@.str = [16 x i8] c"in start shmget\00"
@.str.1 = [6 x i8] c"shmat\00"
@.str.2 = [11 x i8] c"output.txt\00"
@.str.5 = [6 x i8] c"Error\00"
@.str.6 = [10 x i8] c"input.txt\00"
@.str.7 = [2 x i8] c"r\00"
@.str.8 = [29 x i8] c"start : Can not open file !!\00"
@EXIT_FAILURE = global i32 0
@EOF = global i32 0
@stderr = global i32 0
@.str.9 = [22 x i8] c"can't fork, error %d\0A\00"
@errno = global i32 0
@.str.10 = [6 x i8] c"prog1\00"
@.str.11 = [6 x i8] c"prog2\00"
@.str.12 = [6 x i8] c"prog3\00"
@IPC_RMID = global i32 0
@str = [25 x i8] c"Kunne ikke slette filen \00"
@str.13 = [32 x i8] c"Output filen er blevet slettet.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = load i32, i32* @IPC_CREAT
%10 = or i32 %9, 438
%11 = tail call i32 @shmget(i32 5554, i32 500, i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = tail call i8* @shmat(i32 %11, i32* null, i32 0)
%18 = icmp eq i8* %17, inttoptr (i64 -1 to i8*)
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %16
%23 = tail call i32 @remove(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.13, i64 0, i64 0))
br label %30
27: ; preds = %22
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%29 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %30
30: ; preds = %27, %25
%31 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%32 = icmp eq i32* %31, null
br i1 %32, label %39, label %33
33: ; preds = %30
%34 = tail call i32 @fgetc(i32* %31)
%35 = load i32, i32* @EOF
%36 = icmp eq i32 %34, %35
br i1 %36, label %37, label %43
37: ; preds = %33
%38 = tail call i32 @fclose(i32* %31)
br label %94
39: ; preds = %30
%40 = tail call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0))
%41 = load i32, i32* @EXIT_FAILURE
%42 = tail call i32 @exit(i32 %41)
unreachable
43: ; preds = %33, %43
%44 = phi i32 [ %49, %43 ], [ %34, %33 ]
%45 = phi i64 [ %48, %43 ], [ 0, %33 ]
%46 = icmp eq i32 %44, 10
%47 = zext i1 %46 to i64
%48 = add i64 %45, %47
%49 = tail call i32 @fgetc(i32* %31)
%50 = load i32, i32* @EOF
%51 = icmp eq i32 %49, %50
br i1 %51, label %52, label %43
52: ; preds = %43
%53 = tail call i32 @fclose(i32* %31)
%54 = icmp eq i64 %48, 0
br i1 %54, label %94, label %55
55: ; preds = %52, %91
%56 = phi i64 [ %92, %91 ], [ 1, %52 ]
%57 = trunc i64 %56 to i8
store i8 %57, i8* %17
%58 = call i32 (...) @fork()
switch i32 %58, label %67 [
i32 -1, label %59
i32 0, label %65
]
59: ; preds = %55
%60 = load i32, i32* @stderr
%61 = load i32, i32* @errno
%62 = call i32 @fprintf(i32 %60, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i32 %61)
%63 = load i32, i32* @EXIT_FAILURE
%64 = call i32 @exit(i32 %63)
unreachable
65: ; preds = %55
%66 = call i32 @execl(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), i32* null)
br label %91
67: ; preds = %55
%68 = call i32 @waitpid(i32 %58, i32* %3, i32 0)
%69 = call i32 (...) @fork()
switch i32 %69, label %78 [
i32 -1, label %70
i32 0, label %76
]
70: ; preds = %67
%71 = load i32, i32* @stderr
%72 = load i32, i32* @errno
%73 = call i32 @fprintf(i32 %71, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i32 %72)
%74 = load i32, i32* @EXIT_FAILURE
%75 = call i32 @exit(i32 %74)
unreachable
76: ; preds = %67
%77 = call i32 @execl(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), i32* null)
br label %91
78: ; preds = %67
%79 = call i32 @waitpid(i32 %69, i32* %4, i32 0)
%80 = call i32 (...) @fork()
switch i32 %80, label %89 [
i32 -1, label %81
i32 0, label %87
]
81: ; preds = %78
%82 = load i32, i32* @stderr
%83 = load i32, i32* @errno
%84 = call i32 @fprintf(i32 %82, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i32 %83)
%85 = load i32, i32* @EXIT_FAILURE
%86 = call i32 @exit(i32 %85)
unreachable
87: ; preds = %78
%88 = call i32 @execl(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0), i32* null)
br label %91
89: ; preds = %78
%90 = call i32 @waitpid(i32 %80, i32* %5, i32 0)
br label %91
91: ; preds = %65, %76, %87, %89
%92 = add nuw i64 %56, 1
%93 = icmp eq i64 %56, %48
br i1 %93, label %94, label %55
94: ; preds = %91, %37, %52
%95 = load i32, i32* @IPC_RMID
%96 = call i32 @shmctl(i32 %11, i32 %95, i32 0)
%97 = call i32 @shmdt(i8* %17)
ret i32 0
}