#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 EXIT_SUCCESS;
int IPC_CREAT;
int IPC_EXCL;
int /*<<< orphan*/ IPC_PRIVATE;
int /*<<< orphan*/ IPC_RMID;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ shmat(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ shmctl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ shmdt(int *);
int shmget(int /*<<< orphan*/, int, int);
int wait(int *);
int main(int argc, char *argv[]) {
  int segmento, status, id, pid, *p;
  segmento = shmget(IPC_PRIVATE, sizeof(int),
                    IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR);
  p = (int *)shmat(segmento, 0, 0);
  *p = 700;
  id = fork();
  if (id < 0) {
    printf("Erro na criação do novo processo...\n");
    exit(-2);
  } else if (id == 0) {
    *p += 5;
    printf("Processo filho = %d\n", *p);
  } else {
    pid = wait(&status);
    *p += 10;
    printf("Processo pai = %d\n", *p);
  }
  shmdt(p);
  shmctl(segmento, IPC_RMID, 0);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
mov    0x2e0a(%rip),%rax
mov    (%rax),%edx
mov    0x2e41(%rip),%rax
or     (%rax),%edx
mov    0x2e08(%rip),%rax
or     (%rax),%edx
mov    0x2e17(%rip),%rax
or     (%rax),%edx
mov    $0x4,%esi
call   1070 <shmget@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   1060 <shmat@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movl   $0x2bc,(%rax)
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1216 <main+0x96>
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xfffffffe,%edi
call   1080 <exit@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    1244 <main+0xc4>
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
add    $0x5,%ecx
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%esi
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    126f <main+0xef>
lea    -0x18(%rbp),%rdi
call   1090 <wait@plt>
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
add    $0xa,%ecx
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%esi
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1274 <main+0xf4>
mov    -0x28(%rbp),%rdi
call   1030 <shmdt@plt>
mov    -0x14(%rbp),%edi
mov    0x2d41(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <shmctl@plt>
mov    0x2d21(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e16(%rip),%rax
mov    0x2e4f(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e34(%rip),%rax
mov    0x2e0d(%rip),%rcx
or     (%rcx),%edx
mov    (%rax),%edi
mov    0x2e1a(%rip),%rax
or     (%rax),%edx
mov    $0x4,%esi
call   1080 <shmget@plt>
mov    %eax,%ebp
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <shmat@plt>
mov    %rax,%rbx
movl   $0x2bc,(%rax)
xor    %eax,%eax
call   10b0 <fork@plt>
test   %eax,%eax
js     1246 <main+0xb6>
je     1207 <main+0x77>
lea    0x4(%rsp),%rdi
call   10a0 <wait@plt>
mov    (%rbx),%esi
add    $0xa,%esi
mov    %esi,(%rbx)
lea    0xe10(%rip),%rdi
jmp    1215 <main+0x85>
mov    (%rbx),%esi
add    $0x5,%esi
mov    %esi,(%rbx)
lea    0xdeb(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <shmdt@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1060 <shmctl@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xddb(%rip),%rdi
call   1030 <puts@plt>
mov    $0xfffffffe,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@IPC_PRIVATE = global i32 0
@IPC_CREAT = global i32 0
@IPC_EXCL = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str = [39 x i8] c"Erro na cria\C3\A7\C3\A3o do novo processo...\0A\00"
@.str.1 = [21 x i8] c"Processo filho = %d\0A\00"
@.str.2 = [19 x i8] c"Processo pai = %d\0A\00"
@IPC_RMID = global i32 0
@EXIT_SUCCESS = 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*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @IPC_PRIVATE
%12 = load i32, i32* @IPC_CREAT
%13 = load i32, i32* @IPC_EXCL
%14 = or i32 %12, %13
%15 = load i32, i32* @S_IRUSR
%16 = or i32 %14, %15
%17 = load i32, i32* @S_IWUSR
%18 = or i32 %16, %17
%19 = call i32 @shmget(i32 %11, i32 4, i32 %18)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = call i64 @shmat(i32 %20, i32 0, i32 0)
%22 = inttoptr i64 %21 to i32*
store i32* %22, i32** %10
%23 = load i32*, i32** %10
store i32 700, i32* %23
%24 = call i32 (...) @fork()
store i32 %24, i32* %8
%25 = load i32, i32* %8
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %2
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%29 = call i32 @exit(i32 -2)
unreachable
30: ; preds = %2
%31 = load i32, i32* %8
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %40
33: ; preds = %30
%34 = load i32*, i32** %10
%35 = load i32, i32* %34
%36 = add nsw i32 %35, 5
store i32 %36, i32* %34
%37 = load i32*, i32** %10
%38 = load i32, i32* %37
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %38)
br label %48
40: ; preds = %30
%41 = call i32 @wait(i32* %7)
store i32 %41, i32* %9
%42 = load i32*, i32** %10
%43 = load i32, i32* %42
%44 = add nsw i32 %43, 10
store i32 %44, i32* %42
%45 = load i32*, i32** %10
%46 = load i32, i32* %45
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %46)
br label %48
48: ; preds = %40, %33
br label %49
49: ; preds = %48
%50 = load i32*, i32** %10
%51 = call i32 @shmdt(i32* %50)
%52 = load i32, i32* %6
%53 = load i32, i32* @IPC_RMID
%54 = call i32 @shmctl(i32 %52, i32 %53, i32 0)
%55 = load i32, i32* @EXIT_SUCCESS
ret i32 %55
}

LLVM IR (-O2):
@IPC_PRIVATE = global i32 0
@IPC_CREAT = global i32 0
@IPC_EXCL = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [21 x i8] c"Processo filho = %d\0A\00"
@.str.2 = [19 x i8] c"Processo pai = %d\0A\00"
@IPC_RMID = global i32 0
@EXIT_SUCCESS = global i32 0
@str = [38 x i8] c"Erro na cria\C3\A7\C3\A3o do novo processo...\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = load i32, i32* @IPC_PRIVATE
%6 = load i32, i32* @IPC_CREAT
%7 = load i32, i32* @IPC_EXCL
%8 = or i32 %7, %6
%9 = load i32, i32* @S_IRUSR
%10 = or i32 %8, %9
%11 = load i32, i32* @S_IWUSR
%12 = or i32 %10, %11
%13 = tail call i32 @shmget(i32 %5, i32 4, i32 %12)
%14 = tail call i64 @shmat(i32 %13, i32 0, i32 0)
%15 = inttoptr i64 %14 to i32*
store i32 700, i32* %15
%16 = tail call i32 (...) @fork()
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%20 = tail call i32 @exit(i32 -2)
unreachable
21: ; preds = %2
%22 = icmp eq i32 %16, 0
br i1 %22, label %23, label %27
23: ; preds = %21
%24 = load i32, i32* %15
%25 = add nsw i32 %24, 5
store i32 %25, i32* %15
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %25)
br label %32
27: ; preds = %21
%28 = call i32 @wait(i32* %3)
%29 = load i32, i32* %15
%30 = add nsw i32 %29, 10
store i32 %30, i32* %15
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %23, %27
%33 = call i32 @shmdt(i32* %15)
%34 = load i32, i32* @IPC_RMID
%35 = call i32 @shmctl(i32 %13, i32 %34, i32 0)
%36 = load i32, i32* @EXIT_SUCCESS
ret i32 %36
}