#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 */

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ printf(char *);
int shm_open(char *, int, int);
int /*<<< orphan*/ shm_unlink(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ syserr(char *);
scalar_t__ system(char *);
int main() {
  int fd_memory = -1;
  printf("Obecnie w /dev/shm znajdują się:\n");
  if (system("ls /dev/shm"))
    syserr("ls");
  printf("\n\n");
  fd_memory =
      shm_open("/pw_practice_memory", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
  if (fd_memory == -1)
    syserr("shm_open");
  printf("Stworzyłem fragment pamięci, jeśli nie istniał\n");
  printf("Obecnie w /dev/shm znajdują się:\n");
  if (system("ls /dev/shm"))
    syserr("ls");
  printf("\n\n");
  sleep(2);
  close(fd_memory);
  printf("Zamknąłem deskryptor pamięci\n");
  printf("Obecnie w /dev/shm znajdują się:\n");
  if (system("ls /dev/shm"))
    syserr("ls");
  printf("\n\n");
  sleep(2);
  shm_unlink("/pw_practice_memory");
  printf("Usunąłem plik pamięci\n");
  printf("Obecnie w /dev/shm znajdują się:\n");
  if (system("ls /dev/shm"))
    syserr("ls");
  printf("\n\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x8(%rbp)
lea    0xe73(%rip),%rdi
call   1040 <printf@plt>
lea    0xe8b(%rip),%rdi
call   1030 <system@plt>
cmp    $0x0,%rax
je     11b4 <main+0x44>
lea    0xe81(%rip),%rdi
call   1050 <syserr@plt>
lea    0xe78(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
mov    0x2e10(%rip),%rax
or     (%rax),%esi
mov    0x2def(%rip),%rax
mov    (%rax),%edx
mov    0x2df6(%rip),%rax
or     (%rax),%edx
lea    0xe4b(%rip),%rdi
call   1070 <shm_open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1209 <main+0x99>
lea    0xe46(%rip),%rdi
call   1050 <syserr@plt>
lea    0xe43(%rip),%rdi
call   1040 <printf@plt>
lea    0xde4(%rip),%rdi
call   1040 <printf@plt>
lea    0xdfc(%rip),%rdi
call   1030 <system@plt>
cmp    $0x0,%rax
je     1243 <main+0xd3>
lea    0xdf2(%rip),%rdi
call   1050 <syserr@plt>
lea    0xde9(%rip),%rdi
call   1040 <printf@plt>
mov    $0x2,%edi
call   1090 <sleep@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
lea    0xe1f(%rip),%rdi
call   1040 <printf@plt>
lea    0xd8c(%rip),%rdi
call   1040 <printf@plt>
lea    0xda4(%rip),%rdi
call   1030 <system@plt>
cmp    $0x0,%rax
je     129b <main+0x12b>
lea    0xd9a(%rip),%rdi
call   1050 <syserr@plt>
lea    0xd91(%rip),%rdi
call   1040 <printf@plt>
mov    $0x2,%edi
call   1090 <sleep@plt>
lea    0xd7e(%rip),%rdi
call   1080 <shm_unlink@plt>
lea    0xde4(%rip),%rdi
call   1040 <printf@plt>
lea    0xd30(%rip),%rdi
call   1040 <printf@plt>
lea    0xd48(%rip),%rdi
call   1030 <system@plt>
cmp    $0x0,%rax
je     12f7 <main+0x187>
lea    0xd3e(%rip),%rdi
call   1050 <syserr@plt>
lea    0xd35(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xf20(%rip),%rdi
call   1030 <puts@plt>
lea    0xe7c(%rip),%rdi
call   1040 <system@plt>
test   %rax,%rax
je     119a <main+0x2a>
lea    0xe77(%rip),%rdi
call   1050 <syserr@plt>
lea    0xf1a(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e4b(%rip),%rax
mov    0x2e2c(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e09(%rip),%rax
mov    0x2e12(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xe3e(%rip),%rdi
call   1070 <shm_open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    11e9 <main+0x79>
lea    0xe3f(%rip),%rdi
call   1050 <syserr@plt>
lea    0xe3c(%rip),%rdi
call   1030 <puts@plt>
lea    0xe9c(%rip),%rdi
call   1030 <puts@plt>
lea    0xdf8(%rip),%rdi
call   1040 <system@plt>
test   %rax,%rax
je     121e <main+0xae>
lea    0xdf3(%rip),%rdi
call   1050 <syserr@plt>
lea    0xe96(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%edi
call   1090 <sleep@plt>
mov    %ebx,%edi
call   1060 <close@plt>
lea    0xe1d(%rip),%rdi
call   1030 <puts@plt>
lea    0xe4a(%rip),%rdi
call   1030 <puts@plt>
lea    0xda6(%rip),%rdi
call   1040 <system@plt>
test   %rax,%rax
je     1270 <main+0x100>
lea    0xda1(%rip),%rdi
call   1050 <syserr@plt>
lea    0xe44(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%edi
call   1090 <sleep@plt>
lea    0xd82(%rip),%rdi
call   1080 <shm_unlink@plt>
lea    0xde6(%rip),%rdi
call   1030 <puts@plt>
lea    0xdf3(%rip),%rdi
call   1030 <puts@plt>
lea    0xd4f(%rip),%rdi
call   1040 <system@plt>
test   %rax,%rax
je     12c7 <main+0x157>
lea    0xd4a(%rip),%rdi
call   1050 <syserr@plt>
lea    0xded(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [36 x i8] c"Obecnie w /dev/shm znajduj\C4\85 si\C4\99:\0A\00"
@.str.1 = [12 x i8] c"ls /dev/shm\00"
@.str.2 = [3 x i8] c"ls\00"
@.str.3 = [3 x i8] c"\0A\0A\00"
@.str.4 = [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.5 = [9 x i8] c"shm_open\00"
@.str.6 = [52 x i8] c"Stworzy\C5\82em fragment pami\C4\99ci, je\C5\9Bli nie istnia\C5\82\0A\00"
@.str.7 = [33 x i8] c"Zamkn\C4\85\C5\82em deskryptor pami\C4\99ci\0A\00"
@.str.8 = [26 x i8] c"Usun\C4\85\C5\82em plik pami\C4\99ci\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
store i32 -1, i32* %2
%3 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%4 = call i64 @system(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @syserr(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%10 = load i32, i32* @O_CREAT
%11 = load i32, i32* @O_RDWR
%12 = or i32 %10, %11
%13 = load i32, i32* @S_IRUSR
%14 = load i32, i32* @S_IWUSR
%15 = or i32 %13, %14
%16 = call i32 @shm_open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %12, i32 %15)
store i32 %16, i32* %2
%17 = load i32, i32* %2
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %8
%20 = call i32 @syserr(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %21
21: ; preds = %19, %8
%22 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.6, i64 0, i64 0))
%23 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%24 = call i64 @system(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = call i32 @syserr(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %26, %21
%29 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%30 = call i32 @sleep(i32 2)
%31 = load i32, i32* %2
%32 = call i32 @close(i32 %31)
%33 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0))
%34 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%35 = call i64 @system(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %28
%38 = call i32 @syserr(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %39
39: ; preds = %37, %28
%40 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%41 = call i32 @sleep(i32 2)
%42 = call i32 @shm_unlink(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%43 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0))
%44 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%45 = call i64 @system(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %39
%48 = call i32 @syserr(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %49
49: ; preds = %47, %39
%50 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [12 x i8] c"ls /dev/shm\00"
@.str.2 = [3 x i8] c"ls\00"
@.str.4 = [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.5 = [9 x i8] c"shm_open\00"
@str.10 = [51 x i8] c"Stworzy\C5\82em fragment pami\C4\99ci, je\C5\9Bli nie istnia\C5\82\00"
@str.13 = [32 x i8] c"Zamkn\C4\85\C5\82em deskryptor pami\C4\99ci\00"
@str.16 = [25 x i8] c"Usun\C4\85\C5\82em plik pami\C4\99ci\00"
@str.17 = [35 x i8] c"Obecnie w /dev/shm znajduj\C4\85 si\C4\99:\00"
@str.18 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.17, i64 0, i64 0))
%2 = tail call i64 @system(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i64 %2, 0
br i1 %3, label %6, label %4
4: ; preds = %0
%5 = tail call i32 @syserr(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %6
6: ; preds = %4, %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.18, i64 0, i64 0))
%8 = load i32, i32* @O_CREAT
%9 = load i32, i32* @O_RDWR
%10 = or i32 %9, %8
%11 = load i32, i32* @S_IRUSR
%12 = load i32, i32* @S_IWUSR
%13 = or i32 %12, %11
%14 = tail call i32 @shm_open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %10, i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %6
%17 = tail call i32 @syserr(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %18
18: ; preds = %16, %6
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str.10, i64 0, i64 0))
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.17, i64 0, i64 0))
%21 = tail call i64 @system(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %18
%24 = tail call i32 @syserr(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %18
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.18, i64 0, i64 0))
%27 = tail call i32 @sleep(i32 2)
%28 = tail call i32 @close(i32 %14)
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.13, i64 0, i64 0))
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.17, i64 0, i64 0))
%31 = tail call i64 @system(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %25
%34 = tail call i32 @syserr(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %35
35: ; preds = %33, %25
%36 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.18, i64 0, i64 0))
%37 = tail call i32 @sleep(i32 2)
%38 = tail call i32 @shm_unlink(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%39 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.16, i64 0, i64 0))
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.17, i64 0, i64 0))
%41 = tail call i64 @system(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%42 = icmp eq i64 %41, 0
br i1 %42, label %45, label %43
43: ; preds = %35
%44 = tail call i32 @syserr(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %45
45: ; preds = %43, %35
%46 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.18, i64 0, i64 0))
ret i32 0
}