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

/* Variables and functions */
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(int *, void *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
void *shmat(int, void *, int /*<<< orphan*/);
int shmdt(void *);
int shmget(int /*<<< orphan*/, int, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
void receive_it(void) {
  int shmid, iflag = 8;
  void *shm_area;
  if ((shmid = shmget((key_t)26, 8196, 0)) == -1) {
    perror("shmget");
    exit(errno);
  };
  if ((shm_area = shmat(shmid, (void *)0, 0)) == (void *)-1) {
    perror("shmat");
    exit(errno);
  };
  printf("RCV: Memory attached at %lX\n", (unsigned long)shm_area);
  memcpy(shm_area, &iflag, 4);
  printf("iflag is now = %d\n", iflag);
  while (iflag == 8) {
    memcpy(&iflag, shm_area, 4);
    sleep(1);
  }
  printf("RCV has successfully completed\n");
  printf("iflag is now = %d\n", iflag);
  if (shmdt(shm_area) == -1) {
    perror("shmdt");
    exit(errno);
  };
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<receive_it>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x8,-0x8(%rbp)
mov    $0x1a,%edi
mov    $0x2004,%esi
xor    %edx,%edx
call   1080 <shmget@plt>
mov    %eax,-0x4(%rbp)
cmp    $0xffffffff,%eax
jne    11c6 <receive_it+0x46>
lea    0xe4d(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x4(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <shmat@plt>
mov    %rax,-0x10(%rbp)
mov    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jne    1202 <receive_it+0x82>
lea    0xe18(%rip),%rdi
call   1060 <perror@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rsi
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x4,%edx
call   1050 <memcpy@plt>
mov    -0x8(%rbp),%esi
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x8,-0x8(%rbp)
jne    1262 <receive_it+0xe2>
mov    -0x10(%rbp),%rsi
lea    -0x8(%rbp),%rdi
mov    $0x4,%edx
call   1050 <memcpy@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
jmp    1237 <receive_it+0xb7>
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%esi
lea    0xdb0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <shmdt@plt>
cmp    $0xffffffff,%eax
jne    12ad <receive_it+0x12d>
lea    0xdc3(%rip),%rdi
call   1060 <perror@plt>
mov    0x2d3a(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x2d24(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<receive_it>:
push   %r14
push   %rbx
push   %rax
movl   $0x8,0x4(%rsp)
mov    $0x1a,%edi
mov    $0x2004,%esi
xor    %edx,%edx
call   1090 <shmget@plt>
cmp    $0xffffffff,%eax
jne    11be <receive_it+0x2e>
lea    0xe47(%rip),%rdi
jmp    1273 <receive_it+0xe3>
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <shmat@plt>
cmp    $0xffffffffffffffff,%rax
jne    11db <receive_it+0x4b>
lea    0xe31(%rip),%rdi
jmp    1273 <receive_it+0xe3>
mov    %rax,%r14
lea    0xe28(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x4(%rsp),%rsi
mov    %r14,%rdi
mov    $0x4,%edx
call   1060 <memcpy@plt>
mov    0x4(%rsp),%esi
lea    0xe1e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x8,0x4(%rsp)
jne    1241 <receive_it+0xb1>
lea    0x4(%rsp),%rbx
nop
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1060 <memcpy@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
cmpl   $0x8,0x4(%rsp)
je     1220 <receive_it+0x90>
lea    0xdfb(%rip),%rdi
call   1030 <puts@plt>
mov    0x4(%rsp),%esi
lea    0xdd2(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1040 <shmdt@plt>
cmp    $0xffffffff,%eax
jne    1286 <receive_it+0xf6>
lea    0xdca(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"shmget\00"
@errno = global i32 0
@.str.1 = [6 x i8] c"shmat\00"
@.str.2 = [29 x i8] c"RCV: Memory attached at %lX\0A\00"
@.str.3 = [19 x i8] c"iflag is now = %d\0A\00"
@.str.4 = [32 x i8] c"RCV has successfully completed\0A\00"
@.str.5 = [6 x i8] c"shmdt\00"
@EXIT_SUCCESS = global i32 0
define void @receive_it() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
store i32 8, i32* %2
%4 = call i32 @shmget(i32 26, i32 8196, i32 0)
store i32 %4, i32* %1
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @errno
%9 = call i32 @exit(i32 %8)
unreachable
10: ; preds = %0
%11 = load i32, i32* %1
%12 = call i8* @shmat(i32 %11, i8* null, i32 0)
store i8* %12, i8** %3
%13 = icmp eq i8* %12, inttoptr (i64 -1 to i8*)
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32, i32* @errno
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %10
%19 = load i8*, i8** %3
%20 = ptrtoint i8* %19 to i64
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i64 %20)
%22 = load i8*, i8** %3
%23 = bitcast i8* %22 to i32*
%24 = bitcast i32* %2 to i8*
%25 = call i32 @memcpy(i32* %23, i8* %24, i32 4)
%26 = load i32, i32* %2
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %31, %18
%29 = load i32, i32* %2
%30 = icmp eq i32 %29, 8
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = load i8*, i8** %3
%33 = call i32 @memcpy(i32* %2, i8* %32, i32 4)
%34 = call i32 @sleep(i32 1)
br label %28
35: ; preds = %28
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%37 = load i32, i32* %2
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %37)
%39 = load i8*, i8** %3
%40 = call i32 @shmdt(i8* %39)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %46
42: ; preds = %35
%43 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%44 = load i32, i32* @errno
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %35
%47 = load i32, i32* @EXIT_SUCCESS
%48 = call i32 @exit(i32 %47)
unreachable
}

LLVM IR (-O2):
@.str = [7 x i8] c"shmget\00"
@errno = global i32 0
@.str.1 = [6 x i8] c"shmat\00"
@.str.2 = [29 x i8] c"RCV: Memory attached at %lX\0A\00"
@.str.3 = [19 x i8] c"iflag is now = %d\0A\00"
@.str.5 = [6 x i8] c"shmdt\00"
@EXIT_SUCCESS = global i32 0
@str = [31 x i8] c"RCV has successfully completed\00"
define void @receive_it() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 8, i32* %1
%3 = tail call i32 @shmget(i32 26, i32 8196, i32 0)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @errno
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %0
%10 = tail call i8* @shmat(i32 %3, i8* null, i32 0)
%11 = icmp eq i8* %10, inttoptr (i64 -1 to i8*)
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @errno
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %9
%17 = ptrtoint i8* %10 to i64
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i64 %17)
%19 = bitcast i8* %10 to i32*
%20 = call i32 @memcpy(i32* %19, i8* %2, i32 4)
%21 = load i32, i32* %1
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %1
%24 = icmp eq i32 %23, 8
br i1 %24, label %25, label %30
25: ; preds = %16, %25
%26 = call i32 @memcpy(i32* %1, i8* %10, i32 4)
%27 = call i32 @sleep(i32 1)
%28 = load i32, i32* %1
%29 = icmp eq i32 %28, 8
br i1 %29, label %25, label %30
30: ; preds = %25, %16
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%32 = load i32, i32* %1
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %32)
%34 = call i32 @shmdt(i8* %10)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %40
36: ; preds = %30
%37 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%38 = load i32, i32* @errno
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %30
%41 = load i32, i32* @EXIT_SUCCESS
%42 = call i32 @exit(i32 %41)
unreachable
}