#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*/ string;
typedef scalar_t__ pid_t;

/* Variables and functions */
int IPC_CREAT;
int /*<<< orphan*/ IPC_PRIVATE;
int /*<<< orphan*/ IPC_RMID;
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char);
scalar_t__ shmat(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ shmctl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ shmdt(char *);
int shmget(int /*<<< orphan*/, int, int);
int wait(int /*<<< orphan*/ *);
int main(int argc, char const *argv[]) {
  char string[4];
  char *p;
  int shmid;
  shmid = shmget(IPC_PRIVATE, sizeof(string[4]), 0666 | IPC_CREAT);
  p = (char *)shmat(shmid, NULL, 0);
  pid_t child = fork();
  if (child < 0) {
    perror("Fork fallita");
    exit(-1);
  } else if ((int)child == 0) {
    p[0] = 'p';
    p[1] = 'a';
    p[2] = 'p';
    p[3] = 'i';
    shmdt(p);
  } else {
    if (wait(NULL) == -1) {
      perror("Wait fallita");
      exit(-1);
    }
    for (int i = 0; i < 4; i++) {
      printf("%c", p[i]);
    }
    shmdt(p);
    shmctl(shmid, IPC_RMID, 0);
    exit(0);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
mov    0x2e21(%rip),%rax
mov    (%rax),%edx
or     $0x1b6,%edx
mov    $0x1,%esi
call   1080 <shmget@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <shmat@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jge    1202 <main+0x72>
lea    0xe0d(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x30(%rbp),%rax
cmp    $0x0,%eax
jne    123c <main+0xac>
mov    -0x20(%rbp),%rax
movb   $0x70,(%rax)
mov    -0x20(%rbp),%rax
movb   $0x61,0x1(%rax)
mov    -0x20(%rbp),%rax
movb   $0x70,0x2(%rax)
mov    -0x20(%rbp),%rax
movb   $0x69,0x3(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <shmdt@plt>
jmp    12be <main+0x12e>
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <wait@plt>
cmp    $0xffffffff,%eax
jne    1264 <main+0xd4>
lea    0xdb8(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0x4,-0x34(%rbp)
jge    129b <main+0x10b>
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
lea    0xd96(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1040 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    126b <main+0xdb>
mov    -0x20(%rbp),%rdi
call   1030 <shmdt@plt>
mov    -0x24(%rbp),%edi
mov    0x2d2a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <shmctl@plt>
xor    %edi,%edi
call   1090 <exit@plt>
jmp    12c3 <main+0x133>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
mov    0x2e2c(%rip),%rax
mov    $0x1b6,%edx
or     (%rax),%edx
mov    $0x1,%esi
call   1080 <shmget@plt>
mov    %eax,%ebp
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <shmat@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
js     11ea <main+0x5a>
test   %eax,%eax
jne    11f3 <main+0x63>
movl   $0x69706170,(%rbx)
mov    %rbx,%rdi
call   1030 <shmdt@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe0f(%rip),%rdi
jmp    1206 <main+0x76>
xor    %edi,%edi
call   10a0 <wait@plt>
cmp    $0xffffffff,%eax
jne    1215 <main+0x85>
lea    0xe07(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
movsbl (%rbx),%esi
lea    0xdfb(%rip),%r14
mov    %r14,%rdi
call   1040 <printf@plt>
movsbl 0x1(%rbx),%esi
mov    %r14,%rdi
call   1040 <printf@plt>
movsbl 0x2(%rbx),%esi
mov    %r14,%rdi
call   1040 <printf@plt>
movsbl 0x3(%rbx),%esi
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <shmdt@plt>
mov    0x2d7e(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1050 <shmctl@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@IPC_PRIVATE = global i32 0
@IPC_CREAT = global i32 0
@.str = [13 x i8] c"Fork fallita\00"
@.str.1 = [13 x i8] c"Wait fallita\00"
@.str.2 = [3 x i8] c"%c\00"
@IPC_RMID = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca [4 x i8]
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%10 = load i32, i32* @IPC_PRIVATE
%11 = load i32, i32* @IPC_CREAT
%12 = or i32 438, %11
%13 = call i32 @shmget(i32 %10, i32 1, i32 %12)
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = call i64 @shmat(i32 %14, i32* null, i32 0)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %6
%17 = call i64 (...) @fork()
store i64 %17, i64* %8
%18 = load i64, i64* %8
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %2
%21 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @exit(i32 -1)
unreachable
23: ; preds = %2
%24 = load i64, i64* %8
%25 = trunc i64 %24 to i32
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %38
27: ; preds = %23
%28 = load i8*, i8** %6
%29 = getelementptr inbounds i8, i8* %28, i64 0
store i8 112, i8* %29
%30 = load i8*, i8** %6
%31 = getelementptr inbounds i8, i8* %30, i64 1
store i8 97, i8* %31
%32 = load i8*, i8** %6
%33 = getelementptr inbounds i8, i8* %32, i64 2
store i8 112, i8* %33
%34 = load i8*, i8** %6
%35 = getelementptr inbounds i8, i8* %34, i64 3
store i8 105, i8* %35
%36 = load i8*, i8** %6
%37 = call i32 @shmdt(i8* %36)
br label %65
38: ; preds = %23
%39 = call i32 @wait(i32* null)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%43 = call i32 @exit(i32 -1)
unreachable
44: ; preds = %38
store i32 0, i32* %9
br label %45
45: ; preds = %55, %44
%46 = load i32, i32* %9
%47 = icmp slt i32 %46, 4
br i1 %47, label %48, label %58
48: ; preds = %45
%49 = load i8*, i8** %6
%50 = load i32, i32* %9
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
%53 = load i8, i8* %52
%54 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8 signext %53)
br label %55
55: ; preds = %48
%56 = load i32, i32* %9
%57 = add nsw i32 %56, 1
store i32 %57, i32* %9
br label %45
58: ; preds = %45
%59 = load i8*, i8** %6
%60 = call i32 @shmdt(i8* %59)
%61 = load i32, i32* %7
%62 = load i32, i32* @IPC_RMID
%63 = call i32 @shmctl(i32 %61, i32 %62, i32 0)
%64 = call i32 @exit(i32 0)
unreachable
65: ; preds = %27
br label %66
66: ; preds = %65
ret i32 0
}

LLVM IR (-O2):
@IPC_PRIVATE = global i32 0
@IPC_CREAT = global i32 0
@.str = [13 x i8] c"Fork fallita\00"
@.str.1 = [13 x i8] c"Wait fallita\00"
@.str.2 = [3 x i8] c"%c\00"
@IPC_RMID = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @IPC_PRIVATE
%4 = load i32, i32* @IPC_CREAT
%5 = or i32 %4, 438
%6 = tail call i32 @shmget(i32 %3, i32 1, i32 %5)
%7 = tail call i64 @shmat(i32 %6, i32* null, i32 0)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i64 (...) @fork()
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %2
%15 = trunc i64 %9 to i32
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %14
store i8 112, i8* %8
%18 = getelementptr inbounds i8, i8* %8, i64 1
store i8 97, i8* %18
%19 = getelementptr inbounds i8, i8* %8, i64 2
store i8 112, i8* %19
%20 = getelementptr inbounds i8, i8* %8, i64 3
store i8 105, i8* %20
%21 = tail call i32 @shmdt(i8* %8)
ret i32 0
22: ; preds = %14
%23 = tail call i32 @wait(i32* null)
%24 = icmp eq i32 %23, -1
br i1 %24, label %41, label %25
25: ; preds = %22
%26 = load i8, i8* %8
%27 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8 signext %26)
%28 = getelementptr inbounds i8, i8* %8, i64 1
%29 = load i8, i8* %28
%30 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8 signext %29)
%31 = getelementptr inbounds i8, i8* %8, i64 2
%32 = load i8, i8* %31
%33 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8 signext %32)
%34 = getelementptr inbounds i8, i8* %8, i64 3
%35 = load i8, i8* %34
%36 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8 signext %35)
%37 = tail call i32 @shmdt(i8* %8)
%38 = load i32, i32* @IPC_RMID
%39 = tail call i32 @shmctl(i32 %6, i32 %38, i32 0)
%40 = tail call i32 @exit(i32 0)
unreachable
41: ; preds = %22
%42 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%43 = tail call i32 @exit(i32 -1)
unreachable
}