#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*/ sem_t;
typedef int pid_t;

/* Variables and functions */
char *MAP_FAILED;
int MAP_SHARED;
int O_CREAT;
int O_RDWR;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ *SEM_FAILED;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ _SC_PAGE_SIZE;
int /*<<< orphan*/ close(int);
int fork();
int ftruncate(int, int);
int getpid();
scalar_t__ mmap(int /*<<< orphan*/ *, int, int, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(char *, int);
int /*<<< orphan*/ print_table(char *, int);
int /*<<< orphan*/ printf(char *, int, ...);
scalar_t__ sem_close(int /*<<< orphan*/ *);
int /*<<< orphan*/ *sem_open(char *, int, ...);
scalar_t__ sem_post(int /*<<< orphan*/ *);
int /*<<< orphan*/ sem_unlink(char *);
int /*<<< orphan*/ sem_wait(int /*<<< orphan*/ *);
int shm_open(char *, int, int);
int /*<<< orphan*/ shm_unlink(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int sysconf(int /*<<< orphan*/);
int /*<<< orphan*/ syserr(char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/);
int main() {
  char buff[12] = "Ala ma kota";
  char *mapped_mem;
  int fd_memory = -1;
  int flags, prot;
  pid_t pid;
  sem_t *sem;
  printf("Wielkość strony to %lu\n", sysconf(_SC_PAGE_SIZE));
  fd_memory =
      shm_open("/pw_practice_memory", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
  if (fd_memory == -1)
    syserr("shm_open");
  if (ftruncate(fd_memory, 12) == -1)
    syserr("truncate");
  prot = PROT_READ | PROT_WRITE;
  flags = MAP_SHARED;
  mapped_mem = (char *)mmap(NULL, 12, prot, flags, fd_memory, 0);
  close(fd_memory);
  shm_unlink("/pw_practice_memory");
  if (mapped_mem == MAP_FAILED)
    syserr("mmap");
  print_table(mapped_mem, 12);
  sem = sem_open("/pw_practice_sem", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, 0);
  if (sem == SEM_FAILED)
    syserr("parent sem_open");
  if (sem_close(sem))
    syserr("parent sem_close");
  switch (pid = fork()) {
  case -1:
    syserr("fork");
  case 0:
    sem = sem_open("/pw_practice_sem", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, 0);
    if (sem == SEM_FAILED)
      syserr("child sem_open");
    if (sem_wait(sem))
      syserr("child sem_wait");
    print_table(mapped_mem, 12);
    munmap(mapped_mem, 12);
    return 0;
  default:
    printf("Pid rodzica %d, pid dziecka: %d\n", getpid(), pid);
    break;
  }
  sleep(2);
  strncpy(mapped_mem, buff, 12);
  printf("Proces %d, Zmieniłem zawartosć pamięci\n", getpid());
  print_table(mapped_mem, 12);
  sem = sem_open("/pw_practice_sem", O_RDWR);
  if (sem == SEM_FAILED)
    syserr("parent sem_open 2");
  if (sem_post(sem))
    syserr("parent sem_post");
  wait(0);
  sem_close(sem);
  sem_unlink("/pw_practice_sem");
  munmap(mapped_mem, 12);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xdaa(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xda8(%rip),%eax
mov    %eax,-0x8(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
call   1100 <sysconf@plt>
mov    %eax,%esi
lea    0xd8b(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    0x2d69(%rip),%rax
mov    (%rax),%esi
mov    0x2d38(%rip),%rax
or     (%rax),%esi
mov    0x2d07(%rip),%rax
mov    (%rax),%edx
mov    0x2d16(%rip),%rax
or     (%rax),%edx
lea    0xd73(%rip),%rdi
call   1110 <shm_open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    12d1 <main+0x91>
lea    0xd6e(%rip),%rdi
call   1090 <syserr@plt>
mov    -0x1c(%rbp),%edi
mov    $0xc,%esi
call   10a0 <ftruncate@plt>
cmp    $0xffffffff,%eax
jne    12f3 <main+0xb3>
lea    0xd55(%rip),%rdi
call   1090 <syserr@plt>
mov    0x2cf6(%rip),%rax
mov    (%rax),%eax
mov    0x2cad(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x24(%rbp)
mov    0x2cd1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0xc,%esi
xor    %r9d,%r9d
call   1070 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
call   10b0 <close@plt>
lea    0xce4(%rip),%rdi
call   1120 <shm_unlink@plt>
mov    -0x18(%rbp),%rax
mov    0x2c46(%rip),%rcx
cmp    (%rcx),%rax
jne    1367 <main+0x127>
lea    0xcea(%rip),%rdi
call   1090 <syserr@plt>
mov    -0x18(%rbp),%rdi
mov    $0xc,%esi
call   1040 <print_table@plt>
mov    0x2c7c(%rip),%rax
mov    (%rax),%esi
mov    0x2c4b(%rip),%rax
or     (%rax),%esi
mov    0x2c1a(%rip),%rax
mov    (%rax),%edx
mov    0x2c29(%rip),%rax
or     (%rax),%edx
lea    0xcb1(%rip),%rdi
xor    %ecx,%ecx
mov    $0x0,%al
call   10d0 <sem_open@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    0x2c10(%rip),%rcx
cmp    (%rcx),%rax
jne    13cd <main+0x18d>
lea    0xc9a(%rip),%rdi
call   1090 <syserr@plt>
mov    -0x30(%rbp),%rdi
call   10f0 <sem_close@plt>
cmp    $0x0,%rax
je     13ec <main+0x1ac>
lea    0xc8b(%rip),%rdi
call   1090 <syserr@plt>
xor    %eax,%eax
call   1160 <fork@plt>
mov    %eax,-0x28(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x34(%rbp)
sub    $0xffffffff,%eax
je     1419 <main+0x1d9>
jmp    1409 <main+0x1c9>
mov    -0x34(%rbp),%eax
test   %eax,%eax
je     1425 <main+0x1e5>
jmp    14c3 <main+0x283>
lea    0xc63(%rip),%rdi
call   1090 <syserr@plt>
mov    0x2bcc(%rip),%rax
mov    (%rax),%esi
mov    0x2b9b(%rip),%rax
or     (%rax),%esi
mov    0x2b6a(%rip),%rax
mov    (%rax),%edx
mov    0x2b79(%rip),%rax
or     (%rax),%edx
lea    0xc01(%rip),%rdi
xor    %ecx,%ecx
mov    $0x0,%al
call   10d0 <sem_open@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    0x2b60(%rip),%rcx
cmp    (%rcx),%rax
jne    147d <main+0x23d>
lea    0xc10(%rip),%rdi
call   1090 <syserr@plt>
mov    -0x30(%rbp),%rdi
call   1050 <sem_wait@plt>
cmp    $0x0,%eax
je     149b <main+0x25b>
lea    0xc01(%rip),%rdi
call   1090 <syserr@plt>
mov    -0x18(%rbp),%rdi
mov    $0xc,%esi
call   1040 <print_table@plt>
mov    -0x18(%rbp),%rdi
mov    $0xc,%esi
call   10e0 <munmap@plt>
movl   $0x0,-0x4(%rbp)
jmp    15a9 <main+0x369>
mov    $0x0,%al
call   1060 <getpid@plt>
mov    %eax,%esi
mov    -0x28(%rbp),%edx
lea    0xbd0(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x2,%edi
call   1130 <sleep@plt>
mov    -0x18(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0xc,%edx
call   1030 <strncpy@plt>
mov    $0x0,%al
call   1060 <getpid@plt>
mov    %eax,%esi
lea    0xbbe(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    $0xc,%esi
call   1040 <print_table@plt>
mov    0x2aab(%rip),%rax
mov    (%rax),%esi
lea    0xb23(%rip),%rdi
mov    $0x0,%al
call   10d0 <sem_open@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    0x2a84(%rip),%rcx
cmp    (%rcx),%rax
jne    1559 <main+0x319>
lea    0xb9e(%rip),%rdi
call   1090 <syserr@plt>
mov    -0x30(%rbp),%rdi
call   10c0 <sem_post@plt>
cmp    $0x0,%rax
je     1578 <main+0x338>
lea    0xb91(%rip),%rdi
call   1090 <syserr@plt>
xor    %edi,%edi
call   1140 <wait@plt>
mov    -0x30(%rbp),%rdi
call   10f0 <sem_close@plt>
lea    0xac2(%rip),%rdi
call   1150 <sem_unlink@plt>
mov    -0x18(%rbp),%rdi
mov    $0xc,%esi
call   10e0 <munmap@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movabs $0x6b20616d20616c41,%rax
61 20 6b
mov    %rax,0x8(%rsp)
movl   $0x61746f,0x10(%rsp)
mov    0x2d34(%rip),%rax
mov    (%rax),%edi
call   1100 <sysconf@plt>
lea    0xd92(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x2d6e(%rip),%r15
mov    0x2d3f(%rip),%r14
mov    (%r14),%esi
or     (%r15),%esi
mov    0x2d0a(%rip),%r12
mov    0x2d1b(%rip),%r13
mov    0x0(%r13),%edx
or     (%r12),%edx
lea    0xd72(%rip),%rdi
call   1110 <shm_open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    12cc <main+0x8c>
lea    0xd73(%rip),%rdi
call   1090 <syserr@plt>
mov    %ebp,%edi
mov    $0xc,%esi
call   10a0 <ftruncate@plt>
cmp    $0xffffffff,%eax
jne    12e9 <main+0xa9>
lea    0xd5f(%rip),%rdi
call   1090 <syserr@plt>
mov    0x2d00(%rip),%rax
mov    0x2cb9(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2cde(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0xc,%esi
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1070 <mmap@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   10b0 <close@plt>
lea    0xcff(%rip),%rdi
call   1120 <shm_unlink@plt>
mov    0x2c65(%rip),%rax
cmp    %rbx,(%rax)
jne    1344 <main+0x104>
lea    0xd0d(%rip),%rdi
call   1090 <syserr@plt>
mov    %rbx,%rdi
mov    $0xc,%esi
call   1040 <print_table@plt>
mov    (%r14),%esi
or     (%r15),%esi
mov    0x0(%r13),%edx
or     (%r12),%edx
lea    0xceb(%rip),%rdi
xor    %ecx,%ecx
xor    %eax,%eax
call   10d0 <sem_open@plt>
mov    %rax,%rbp
mov    0x2c4f(%rip),%r14
cmp    (%r14),%rax
jne    138a <main+0x14a>
lea    0xcdd(%rip),%rdi
call   1090 <syserr@plt>
mov    %rbp,%rdi
call   10f0 <sem_close@plt>
test   %rax,%rax
je     13a3 <main+0x163>
lea    0xcd4(%rip),%rdi
call   1090 <syserr@plt>
xor    %eax,%eax
call   1160 <fork@plt>
test   %eax,%eax
je     13c1 <main+0x181>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1423 <main+0x1e3>
lea    0xcc7(%rip),%rdi
call   1090 <syserr@plt>
mov    0x2c08(%rip),%rax
mov    (%rax),%esi
or     (%r15),%esi
mov    0x0(%r13),%edx
or     (%r12),%edx
lea    0xc75(%rip),%rdi
xor    %ecx,%ecx
xor    %eax,%eax
call   10d0 <sem_open@plt>
mov    %rax,%rbp
cmp    (%r14),%rax
jne    13f9 <main+0x1b9>
lea    0xc94(%rip),%rdi
call   1090 <syserr@plt>
mov    %rbp,%rdi
call   1050 <sem_wait@plt>
test   %eax,%eax
je     1411 <main+0x1d1>
lea    0xc8b(%rip),%rdi
call   1090 <syserr@plt>
mov    %rbx,%rdi
mov    $0xc,%esi
call   1040 <print_table@plt>
jmp    14db <main+0x29b>
xor    %eax,%eax
call   1060 <getpid@plt>
lea    0xc75(%rip),%rdi
mov    %eax,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x2,%edi
call   1130 <sleep@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xc,%edx
call   1030 <strncpy@plt>
xor    %eax,%eax
call   1060 <getpid@plt>
lea    0xc61(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbx,%rdi
mov    $0xc,%esi
call   1040 <print_table@plt>
mov    0x2b4d(%rip),%rax
mov    (%rax),%esi
lea    0xbc5(%rip),%rdi
xor    %eax,%eax
call   10d0 <sem_open@plt>
mov    %rax,%rbp
cmp    (%r14),%rax
jne    14a7 <main+0x267>
lea    0xc50(%rip),%rdi
call   1090 <syserr@plt>
mov    %rbp,%rdi
call   10c0 <sem_post@plt>
test   %rax,%rax
je     14c0 <main+0x280>
lea    0xc49(%rip),%rdi
call   1090 <syserr@plt>
xor    %edi,%edi
call   1140 <wait@plt>
mov    %rbp,%rdi
call   10f0 <sem_close@plt>
lea    0xb7b(%rip),%rdi
call   1150 <sem_unlink@plt>
mov    %rbx,%rdi
mov    $0xc,%esi
call   10e0 <munmap@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.buff = [12 x i8] c"Ala ma kota\00"
@.str = [26 x i8] c"Wielko\C5\9B\C4\87 strony to %lu\0A\00"
@_SC_PAGE_SIZE = global i32 0
@.str.1 = [20 x i8] c"/pw_practice_memory\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.2 = [9 x i8] c"shm_open\00"
@.str.3 = [9 x i8] c"truncate\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.4 = [5 x i8] c"mmap\00"
@.str.5 = [17 x i8] c"/pw_practice_sem\00"
@SEM_FAILED = global i32* null
@.str.6 = [16 x i8] c"parent sem_open\00"
@.str.7 = [17 x i8] c"parent sem_close\00"
@.str.8 = [5 x i8] c"fork\00"
@.str.9 = [15 x i8] c"child sem_open\00"
@.str.10 = [15 x i8] c"child sem_wait\00"
@.str.11 = [33 x i8] c"Pid rodzica %d, pid dziecka: %d\0A\00"
@.str.12 = [43 x i8] c"Proces %d, Zmieni\C5\82em zawartos\C4\87 pami\C4\99ci\0A\00"
@.str.13 = [18 x i8] c"parent sem_open 2\00"
@.str.14 = [16 x i8] c"parent sem_post\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [12 x i8]
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
store i32 0, i32* %1
%9 = bitcast [12 x i8]* %2 to i8*
store i32 -1, i32* %4
%10 = load i32, i32* @_SC_PAGE_SIZE
%11 = call i32 @sysconf(i32 %10)
%12 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i32, i32* @O_CREAT
%14 = load i32, i32* @O_RDWR
%15 = or i32 %13, %14
%16 = load i32, i32* @S_IRUSR
%17 = load i32, i32* @S_IWUSR
%18 = or i32 %16, %17
%19 = call i32 @shm_open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 %18)
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %0
%23 = call i32 @syserr(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %22, %0
%25 = load i32, i32* %4
%26 = call i32 @ftruncate(i32 %25, i32 12)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 @syserr(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %30
30: ; preds = %28, %24
%31 = load i32, i32* @PROT_READ
%32 = load i32, i32* @PROT_WRITE
%33 = or i32 %31, %32
store i32 %33, i32* %6
%34 = load i32, i32* @MAP_SHARED
store i32 %34, i32* %5
%35 = load i32, i32* %6
%36 = load i32, i32* %5
%37 = load i32, i32* %4
%38 = call i64 @mmap(i32* null, i32 12, i32 %35, i32 %36, i32 %37, i32 0)
%39 = inttoptr i64 %38 to i8*
store i8* %39, i8** %3
%40 = load i32, i32* %4
%41 = call i32 @close(i32 %40)
%42 = call i32 @shm_unlink(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%43 = load i8*, i8** %3
%44 = load i8*, i8** @MAP_FAILED
%45 = icmp eq i8* %43, %44
br i1 %45, label %46, label %48
46: ; preds = %30
%47 = call i32 @syserr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %48
48: ; preds = %46, %30
%49 = load i8*, i8** %3
%50 = call i32 @print_table(i8* %49, i32 12)
%51 = load i32, i32* @O_CREAT
%52 = load i32, i32* @O_RDWR
%53 = or i32 %51, %52
%54 = load i32, i32* @S_IRUSR
%55 = load i32, i32* @S_IWUSR
%56 = or i32 %54, %55
%57 = call i32* (i8*, i32, ...) @sem_open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 %53, i32 %56, i32 0)
store i32* %57, i32** %8
%58 = load i32*, i32** %8
%59 = load i32*, i32** @SEM_FAILED
%60 = icmp eq i32* %58, %59
br i1 %60, label %61, label %63
61: ; preds = %48
%62 = call i32 @syserr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
br label %63
63: ; preds = %61, %48
%64 = load i32*, i32** %8
%65 = call i64 @sem_close(i32* %64)
%66 = icmp ne i64 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %63
%68 = call i32 @syserr(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
br label %69
69: ; preds = %67, %63
%70 = call i32 (...) @fork()
store i32 %70, i32* %7
switch i32 %70, label %97 [
i32 -1, label %71
i32 0, label %73
]
71: ; preds = %69
%72 = call i32 @syserr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
br label %73
73: ; preds = %69, %71
%74 = load i32, i32* @O_CREAT
%75 = load i32, i32* @O_RDWR
%76 = or i32 %74, %75
%77 = load i32, i32* @S_IRUSR
%78 = load i32, i32* @S_IWUSR
%79 = or i32 %77, %78
%80 = call i32* (i8*, i32, ...) @sem_open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 %76, i32 %79, i32 0)
store i32* %80, i32** %8
%81 = load i32*, i32** %8
%82 = load i32*, i32** @SEM_FAILED
%83 = icmp eq i32* %81, %82
br i1 %83, label %84, label %86
84: ; preds = %73
%85 = call i32 @syserr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
br label %86
86: ; preds = %84, %73
%87 = load i32*, i32** %8
%88 = call i32 @sem_wait(i32* %87)
%89 = icmp ne i32 %88, 0
br i1 %89, label %90, label %92
90: ; preds = %86
%91 = call i32 @syserr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0))
br label %92
92: ; preds = %90, %86
%93 = load i8*, i8** %3
%94 = call i32 @print_table(i8* %93, i32 12)
%95 = load i8*, i8** %3
%96 = call i32 @munmap(i8* %95, i32 12)
store i32 0, i32* %1
br label %130
97: ; preds = %69
%98 = call i32 (...) @getpid()
%99 = load i32, i32* %7
%100 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.11, i64 0, i64 0), i32 %98, i32 %99)
br label %101
101: ; preds = %97
%102 = call i32 @sleep(i32 2)
%103 = load i8*, i8** %3
%104 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%105 = call i32 @strncpy(i8* %103, i8* %104, i32 12)
%106 = call i32 (...) @getpid()
%107 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.12, i64 0, i64 0), i32 %106)
%108 = load i8*, i8** %3
%109 = call i32 @print_table(i8* %108, i32 12)
%110 = load i32, i32* @O_RDWR
%111 = call i32* (i8*, i32, ...) @sem_open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 %110)
store i32* %111, i32** %8
%112 = load i32*, i32** %8
%113 = load i32*, i32** @SEM_FAILED
%114 = icmp eq i32* %112, %113
br i1 %114, label %115, label %117
115: ; preds = %101
%116 = call i32 @syserr(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.13, i64 0, i64 0))
br label %117
117: ; preds = %115, %101
%118 = load i32*, i32** %8
%119 = call i64 @sem_post(i32* %118)
%120 = icmp ne i64 %119, 0
br i1 %120, label %121, label %123
121: ; preds = %117
%122 = call i32 @syserr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.14, i64 0, i64 0))
br label %123
123: ; preds = %121, %117
%124 = call i32 @wait(i32 0)
%125 = load i32*, i32** %8
%126 = call i64 @sem_close(i32* %125)
%127 = call i32 @sem_unlink(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%128 = load i8*, i8** %3
%129 = call i32 @munmap(i8* %128, i32 12)
store i32 0, i32* %1
br label %130
130: ; preds = %123, %92
%131 = load i32, i32* %1
ret i32 %131
}

LLVM IR (-O2):
@__const.main.buff = [12 x i8] c"Ala ma kota\00"
@.str = [26 x i8] c"Wielko\C5\9B\C4\87 strony to %lu\0A\00"
@_SC_PAGE_SIZE = global i32 0
@.str.1 = [20 x i8] c"/pw_practice_memory\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.2 = [9 x i8] c"shm_open\00"
@.str.3 = [9 x i8] c"truncate\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.4 = [5 x i8] c"mmap\00"
@.str.5 = [17 x i8] c"/pw_practice_sem\00"
@SEM_FAILED = global i32* null
@.str.6 = [16 x i8] c"parent sem_open\00"
@.str.7 = [17 x i8] c"parent sem_close\00"
@.str.8 = [5 x i8] c"fork\00"
@.str.9 = [15 x i8] c"child sem_open\00"
@.str.10 = [15 x i8] c"child sem_wait\00"
@.str.11 = [33 x i8] c"Pid rodzica %d, pid dziecka: %d\0A\00"
@.str.12 = [43 x i8] c"Proces %d, Zmieni\C5\82em zawartos\C4\87 pami\C4\99ci\0A\00"
@.str.13 = [18 x i8] c"parent sem_open 2\00"
@.str.14 = [16 x i8] c"parent sem_post\00"
define i32 @main() {
%1 = alloca [12 x i8]
%2 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @_SC_PAGE_SIZE
%4 = tail call i32 @sysconf(i32 %3)
%5 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = load i32, i32* @O_CREAT
%7 = load i32, i32* @O_RDWR
%8 = or i32 %7, %6
%9 = load i32, i32* @S_IRUSR
%10 = load i32, i32* @S_IWUSR
%11 = or i32 %10, %9
%12 = tail call i32 @shm_open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %8, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = tail call i32 @syserr(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %14, %0
%17 = tail call i32 @ftruncate(i32 %12, i32 12)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = tail call i32 @syserr(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %21
21: ; preds = %19, %16
%22 = load i32, i32* @PROT_READ
%23 = load i32, i32* @PROT_WRITE
%24 = or i32 %23, %22
%25 = load i32, i32* @MAP_SHARED
%26 = tail call i64 @mmap(i32* null, i32 12, i32 %24, i32 %25, i32 %12, i32 0)
%27 = inttoptr i64 %26 to i8*
%28 = tail call i32 @close(i32 %12)
%29 = tail call i32 @shm_unlink(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%30 = load i8*, i8** @MAP_FAILED
%31 = icmp eq i8* %30, %27
br i1 %31, label %32, label %34
32: ; preds = %21
%33 = tail call i32 @syserr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %34
34: ; preds = %32, %21
%35 = tail call i32 @print_table(i8* %27, i32 12)
%36 = load i32, i32* @O_CREAT
%37 = load i32, i32* @O_RDWR
%38 = or i32 %37, %36
%39 = load i32, i32* @S_IRUSR
%40 = load i32, i32* @S_IWUSR
%41 = or i32 %40, %39
%42 = tail call i32* (i8*, i32, ...) @sem_open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 %38, i32 %41, i32 0)
%43 = load i32*, i32** @SEM_FAILED
%44 = icmp eq i32* %42, %43
br i1 %44, label %45, label %47
45: ; preds = %34
%46 = tail call i32 @syserr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
br label %47
47: ; preds = %45, %34
%48 = tail call i64 @sem_close(i32* %42)
%49 = icmp eq i64 %48, 0
br i1 %49, label %52, label %50
50: ; preds = %47
%51 = tail call i32 @syserr(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
br label %52
52: ; preds = %50, %47
%53 = tail call i32 (...) @fork()
switch i32 %53, label %76 [
i32 -1, label %54
i32 0, label %56
]
54: ; preds = %52
%55 = tail call i32 @syserr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
br label %56
56: ; preds = %52, %54
%57 = load i32, i32* @O_CREAT
%58 = load i32, i32* @O_RDWR
%59 = or i32 %58, %57
%60 = load i32, i32* @S_IRUSR
%61 = load i32, i32* @S_IWUSR
%62 = or i32 %61, %60
%63 = tail call i32* (i8*, i32, ...) @sem_open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 %59, i32 %62, i32 0)
%64 = load i32*, i32** @SEM_FAILED
%65 = icmp eq i32* %63, %64
br i1 %65, label %66, label %68
66: ; preds = %56
%67 = tail call i32 @syserr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
br label %68
68: ; preds = %66, %56
%69 = tail call i32 @sem_wait(i32* %63)
%70 = icmp eq i32 %69, 0
br i1 %70, label %73, label %71
71: ; preds = %68
%72 = tail call i32 @syserr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0))
br label %73
73: ; preds = %71, %68
%74 = tail call i32 @print_table(i8* %27, i32 12)
%75 = tail call i32 @munmap(i8* %27, i32 12)
br label %100
76: ; preds = %52
%77 = tail call i32 (...) @getpid()
%78 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.11, i64 0, i64 0), i32 %77, i32 %53)
%79 = tail call i32 @sleep(i32 2)
%80 = call i32 @strncpy(i8* %27, i8* %2, i32 12)
%81 = call i32 (...) @getpid()
%82 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.12, i64 0, i64 0), i32 %81)
%83 = call i32 @print_table(i8* %27, i32 12)
%84 = load i32, i32* @O_RDWR
%85 = call i32* (i8*, i32, ...) @sem_open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 %84)
%86 = load i32*, i32** @SEM_FAILED
%87 = icmp eq i32* %85, %86
br i1 %87, label %88, label %90
88: ; preds = %76
%89 = call i32 @syserr(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.13, i64 0, i64 0))
br label %90
90: ; preds = %88, %76
%91 = call i64 @sem_post(i32* %85)
%92 = icmp eq i64 %91, 0
br i1 %92, label %95, label %93
93: ; preds = %90
%94 = call i32 @syserr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.14, i64 0, i64 0))
br label %95
95: ; preds = %93, %90
%96 = call i32 @wait(i32 0)
%97 = call i64 @sem_close(i32* %85)
%98 = call i32 @sem_unlink(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%99 = call i32 @munmap(i8* %27, i32 12)
br label %100
100: ; preds = %95, %73
ret i32 0
}