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

/* Variables and functions */
int IPC_CREAT;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
char *shmat(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int shmget(int, int, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ *strstr(char *, char *);
int main() {
  key_t key;
  int shmid;
  char *shmem;
  char data[100];
  key = 4186;
  if ((shmid = shmget(key, 2046, IPC_CREAT | 0666)) < 0) {
    perror("There is an error with creating shared memory segment ");
    exit(1);
  }
  if ((shmem = shmat(shmid, NULL, 0)) == (char *)-1) {
    perror("There is an error in acessing the shared space");
    exit(1);
  }
  while (1) {
    printf("\n Enter your data ");
    gets(data);
    if (strstr(data, "C00L") != NULL) {
      strcpy(shmem, data);
      printf("\n FOUNDDDD");
    }
    while (*shmem != '\0') {
      sleep(1);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x105a,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e2d(%rip),%rax
mov    (%rax),%edx
or     $0x1b6,%edx
mov    $0x7fe,%esi
call   1080 <shmget@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    11e7 <main+0x57>
lea    0xe28(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0xc(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <shmat@plt>
mov    %rax,-0x18(%rbp)
mov    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jne    121f <main+0x8f>
lea    0xe27(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    1224 <main+0x94>
lea    0xe3b(%rip),%rdi
call   1040 <printf@plt>
lea    -0x80(%rbp),%rdi
call   1050 <gets@plt>
lea    -0x80(%rbp),%rdi
lea    0xe35(%rip),%rsi
call   10b0 <strstr@plt>
cmp    $0x0,%rax
je     126c <main+0xdc>
mov    -0x18(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   1030 <strcpy@plt>
lea    0xe17(%rip),%rdi
call   1040 <printf@plt>
jmp    1271 <main+0xe1>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1290 <main+0x100>
mov    $0x1,%edi
call   10a0 <sleep@plt>
jmp    1271 <main+0xe1>
jmp    1224 <main+0x94>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x70,%rsp
mov    0x2e3c(%rip),%rax
mov    $0x1b6,%edx
or     (%rax),%edx
mov    $0x105a,%edi
mov    $0x7fe,%esi
call   1080 <shmget@plt>
test   %eax,%eax
js     1241 <main+0xb1>
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <shmat@plt>
cmp    $0xffffffffffffffff,%rax
je     124a <main+0xba>
mov    %rax,%rbx
lea    0xe89(%rip),%r14
mov    %rsp,%r15
lea    0xe92(%rip),%r12
lea    0xe90(%rip),%r13
xchg   %ax,%ax
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %r15,%rdi
call   1050 <gets@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   10b0 <strstr@plt>
test   %rax,%rax
je     123a <main+0xaa>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %r13,%rdi
call   1040 <printf@plt>
jmp    123a <main+0xaa>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x1,%edi
call   10a0 <sleep@plt>
cmpb   $0x0,(%rbx)
jne    1230 <main+0xa0>
jmp    11f0 <main+0x60>
lea    0xdb8(%rip),%rdi
jmp    1251 <main+0xc1>
lea    0xde6(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@IPC_CREAT = global i32 0
@.str = [55 x i8] c"There is an error with creating shared memory segment \00"
@.str.1 = [47 x i8] c"There is an error in acessing the shared space\00"
@.str.2 = [19 x i8] c"\0A Enter your data \00"
@.str.3 = [5 x i8] c"C00L\00"
@.str.4 = [11 x i8] c"\0A FOUNDDDD\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [100 x i8]
store i32 0, i32* %1
store i32 4186, i32* %2
%6 = load i32, i32* %2
%7 = load i32, i32* @IPC_CREAT
%8 = or i32 %7, 438
%9 = call i32 @shmget(i32 %6, i32 2046, i32 %8)
store i32 %9, i32* %3
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %0
%15 = load i32, i32* %3
%16 = call i8* @shmat(i32 %15, i32* null, i32 0)
store i8* %16, i8** %4
%17 = icmp eq i8* %16, inttoptr (i64 -1 to i8*)
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = call i32 @perror(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %14
br label %22
22: ; preds = %21, %42
%23 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%25 = call i32 @gets(i8* %24)
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%27 = call i32* @strstr(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%28 = icmp ne i32* %27, null
br i1 %28, label %29, label %34
29: ; preds = %22
%30 = load i8*, i8** %4
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%32 = call i32 @strcpy(i8* %30, i8* %31)
%33 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
br label %34
34: ; preds = %29, %22
br label %35
35: ; preds = %40, %34
%36 = load i8*, i8** %4
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %35
%41 = call i32 @sleep(i32 1)
br label %35
42: ; preds = %35
br label %22
}

LLVM IR (-O2):
@IPC_CREAT = global i32 0
@.str = [55 x i8] c"There is an error with creating shared memory segment \00"
@.str.1 = [47 x i8] c"There is an error in acessing the shared space\00"
@.str.2 = [19 x i8] c"\0A Enter your data \00"
@.str.3 = [5 x i8] c"C00L\00"
@.str.4 = [11 x i8] c"\0A FOUNDDDD\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @IPC_CREAT
%4 = or i32 %3, 438
%5 = tail call i32 @shmget(i32 4186, i32 2046, i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = tail call i8* @shmat(i32 %5, i32* null, i32 0)
%12 = icmp eq i8* %11, inttoptr (i64 -1 to i8*)
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = tail call i32 @perror(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %10, %27
%17 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @gets(i8* %2)
%19 = call i32* @strstr(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %24, label %21
21: ; preds = %16
%22 = call i32 @strcpy(i8* %11, i8* %2)
%23 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
br label %24
24: ; preds = %21, %16
%25 = load i8, i8* %11
%26 = icmp eq i8 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %28, %24
br label %16
28: ; preds = %24, %28
%29 = call i32 @sleep(i32 1)
%30 = load i8, i8* %11
%31 = icmp eq i8 %30, 0
br i1 %31, label %27, label %28
}