#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 CopySharedMemData(char *, int);
int /*<<< orphan*/ InitializeVariables();
int WriteDataToSharedMemory(char *);
char *giveTheDataPointer();
int /*<<< orphan*/ printf(char *, ...);
main() {
  char *testString =
      "123456789012345678901234567890012345678901234567890123456789012345678901"
      "234567890123456789012345678901234567890123456789012345678901234567890123"
      "456789012345678901234567890123456789012345678901234567890123456789012345"
      "678901234567890123456789012345678901234567890123456789012345678901234567"
      "890123456789012345678901234567890123456789012345678901234567890123456789"
      "012345678901234567890123456789012345678901234567890123456789012345678901"
      "234567890123456789012345678901234567890123456789012345678901234567890123"
      "456789012345678901234567890123456789012345678901234567890123456789012345"
      "678901234567890123456789012345678901234567890123456789012345678901234567"
      "890123456789012345678901234567890123456789012345678901234567890123456789"
      "012345678901234567890123456789012345678901234567890123456789012345678901"
      "234567890123456789012345678901234567890123456789012345678901234567890123"
      "456789012345678901234567890123456789012345678901234567890123456789012345"
      "678901234567890123456789012345678901234567890123456789012345678901234567"
      "890123456789012345678901234567890123456789012345678901234567890123456789"
      "012345678901234567890123456789012345678901234567890123456789012345678901"
      "234567890123456789012345678901234567890123456789012345678901234567890123"
      "456789012345678901234567890123456789012345678901234567890123456789012345"
      "678901234567890123456789012345678901234567890123456789012345678901234567"
      "890123456789012345678901234567890123456789012345678901234567890123456789"
      "012345678901234567890123456789012345678901234567890123456789012345678901"
      "234567890123456789012345678901234567890123456789012345678901234567890123"
      "456789012345678901234567890123456789012345678901234567890123456789012345"
      "678901234567890123456789012345678901234567890123456789012345678901234567"
      "890123456789012345678901234567890123456789012345678901234567890123456789"
      "012345678901234567890123456789012345678901234567890123456789012345678901"
      "234567890123456789012345678901234567890123456789012345678901234567890123"
      "456789012345678901234567890123456789012345678901234567890123456789012345"
      "678901234567890123456789012345678901234567890123456789012345678901234567"
      "890123456789012345678901234567890123456789012345678901234567890123456789"
      "012345678901234567890123456789012345678901234567890123456789012345678901"
      "234567890123456789012345678901234567890123456789012345678901234567890123"
      "456789012345678901234567890123456789012345678901234567890123456789012345"
      "678901234567890123456789012345678901234567890123456789012345678901234567"
      "890123456789012345678901234567890123456789012345678901234567890123456789"
      "0123456789";
  InitializeVariables();
  int result = WriteDataToSharedMemory(testString);
  switch (result) {
  case 0:
    printf("Data written in.\n");
    break;
  case 1:
    printf("ERROR Shared memory not initialized.\n");
    break;
  case 2:
    printf("Data too long.  Not all were written in.\n");
    break;
  default:
    printf("result = '%d'\n", result);
    break;
  }
  char hold[2500];
  result = CopySharedMemData(hold, 2500);
  switch (result) {
  case 0:
    printf("Data read correctly.\n");
    break;
  case 1:
    printf("ERROR Shared memory not initialized.\n");
    break;
  case 2:
    printf("Data too long.  Not all were read in.\n");
    break;
  default:
    printf("result = '%d'\n", result);
    break;
  }
  printf("hold='%s'\n", hold);
  printf("The pointer content='%s'\n", giveTheDataPointer());
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x9f0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rax
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
call   1070 <InitializeVariables@plt>
mov    -0x10(%rbp),%rdi
call   1050 <WriteDataToSharedMemory@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x9e4(%rbp)
test   %eax,%eax
je     11be <main+0x6e>
jmp    1196 <main+0x46>
mov    -0x9e4(%rbp),%eax
sub    $0x1,%eax
je     11d1 <main+0x81>
jmp    11aa <main+0x5a>
mov    -0x9e4(%rbp),%eax
sub    $0x2,%eax
je     11e4 <main+0x94>
jmp    11f7 <main+0xa7>
lea    0x181e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1208 <main+0xb8>
lea    0x181d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1208 <main+0xb8>
lea    0x1830(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1208 <main+0xb8>
mov    -0x14(%rbp),%esi
lea    0x1844(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x9e0(%rbp),%rdi
mov    $0x9c4,%esi
call   1030 <CopySharedMemData@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x9e8(%rbp)
test   %eax,%eax
je     125a <main+0x10a>
jmp    1232 <main+0xe2>
mov    -0x9e8(%rbp),%eax
sub    $0x1,%eax
je     126d <main+0x11d>
jmp    1246 <main+0xf6>
mov    -0x9e8(%rbp),%eax
sub    $0x2,%eax
je     1280 <main+0x130>
jmp    1293 <main+0x143>
lea    0x17f3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12a4 <main+0x154>
lea    0x1781(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12a4 <main+0x154>
lea    0x17e3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12a4 <main+0x154>
mov    -0x14(%rbp),%esi
lea    0x17a8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x9e0(%rbp),%rsi
lea    0x17df(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <giveTheDataPointer@plt>
mov    %rax,%rsi
lea    0x17d2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x9f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x9c8,%rsp
xor    %eax,%eax
call   1080 <InitializeVariables@plt>
lea    0xe8b(%rip),%rdi
call   1060 <WriteDataToSharedMemory@plt>
cmp    $0x2,%eax
je     1196 <main+0x36>
cmp    $0x1,%eax
je     11a4 <main+0x44>
test   %eax,%eax
jne    11b2 <main+0x52>
lea    0x1911(%rip),%rdi
call   1030 <puts@plt>
jmp    11c2 <main+0x62>
lea    0x187a(%rip),%rdi
call   1030 <puts@plt>
jmp    11c2 <main+0x62>
lea    0x18d0(%rip),%rdi
call   1030 <puts@plt>
jmp    11c2 <main+0x62>
lea    0x182a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%rdi
mov    $0x9c4,%esi
call   1040 <CopySharedMemData@plt>
cmp    $0x2,%eax
je     11eb <main+0x8b>
cmp    $0x1,%eax
je     11f9 <main+0x99>
test   %eax,%eax
jne    1207 <main+0xa7>
lea    0x1882(%rip),%rdi
call   1030 <puts@plt>
jmp    1217 <main+0xb7>
lea    0x184e(%rip),%rdi
call   1030 <puts@plt>
jmp    1217 <main+0xb7>
lea    0x187b(%rip),%rdi
call   1030 <puts@plt>
jmp    1217 <main+0xb7>
lea    0x17d5(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x17d4(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <giveTheDataPointer@plt>
lea    0x17c7(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x9c8,%rsp
ret

LLVM IR (-O0):
@.str = [2531 x i8] c"1234567890123456789012345678900123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789\00"
@.str.1 = [18 x i8] c"Data written in.\0A\00"
@.str.2 = [38 x i8] c"ERROR Shared memory not initialized.\0A\00"
@.str.3 = [42 x i8] c"Data too long. Not all were written in.\0A\00"
@.str.4 = [15 x i8] c"result = '%d'\0A\00"
@.str.5 = [22 x i8] c"Data read correctly.\0A\00"
@.str.6 = [39 x i8] c"Data too long. Not all were read in.\0A\00"
@.str.7 = [11 x i8] c"hold='%s'\0A\00"
@.str.8 = [26 x i8] c"The pointer content='%s'\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [2500 x i8]
store i32 0, i32* %1
store i8* getelementptr inbounds ([2531 x i8], [2531 x i8]* @.str, i64 0, i64 0), i8** %2
%5 = call i32 (...) @InitializeVariables()
%6 = load i8*, i8** %2
%7 = call i32 @WriteDataToSharedMemory(i8* %6)
store i32 %7, i32* %3
%8 = load i32, i32* %3
switch i32 %8, label %15 [
i32 0, label %9
i32 1, label %11
i32 2, label %13
]
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %18
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
br label %18
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
br label %18
15: ; preds = %0
%16 = load i32, i32* %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %15, %13, %11, %9
%19 = getelementptr inbounds [2500 x i8], [2500 x i8]* %4, i64 0, i64 0
%20 = call i32 @CopySharedMemData(i8* %19, i32 2500)
store i32 %20, i32* %3
%21 = load i32, i32* %3
switch i32 %21, label %28 [
i32 0, label %22
i32 1, label %24
i32 2, label %26
]
22: ; preds = %18
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
br label %31
24: ; preds = %18
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
br label %31
26: ; preds = %18
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0))
br label %31
28: ; preds = %18
%29 = load i32, i32* %3
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %28, %26, %24, %22
%32 = getelementptr inbounds [2500 x i8], [2500 x i8]* %4, i64 0, i64 0
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* %32)
%34 = call i8* (...) @giveTheDataPointer()
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i8* %34)
%36 = load i32, i32* %1
ret i32 %36
}

LLVM IR (-O2):
@.str = [2531 x i8] c"1234567890123456789012345678900123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789\00"
@.str.4 = [15 x i8] c"result = '%d'\0A\00"
@.str.7 = [11 x i8] c"hold='%s'\0A\00"
@.str.8 = [26 x i8] c"The pointer content='%s'\0A\00"
@str = [41 x i8] c"Data too long. Not all were written in.\00"
@str.9 = [38 x i8] c"Data too long. Not all were read in.\00"
@str.11 = [21 x i8] c"Data read correctly.\00"
@str.12 = [37 x i8] c"ERROR Shared memory not initialized.\00"
@str.13 = [17 x i8] c"Data written in.\00"
define i32 @main() {
%1 = alloca [2500 x i8]
%2 = tail call i32 (...) @InitializeVariables()
%3 = tail call i32 @WriteDataToSharedMemory(i8* getelementptr inbounds ([2531 x i8], [2531 x i8]* @.str, i64 0, i64 0))
switch i32 %3, label %10 [
i32 0, label %4
i32 1, label %6
i32 2, label %8
]
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.13, i64 0, i64 0))
br label %12
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.12, i64 0, i64 0))
br label %12
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
br label %12
10: ; preds = %0
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %3)
br label %12
12: ; preds = %10, %8, %6, %4
%13 = getelementptr inbounds [2500 x i8], [2500 x i8]* %1, i64 0, i64 0
%14 = call i32 @CopySharedMemData(i8* %13, i32 2500)
switch i32 %14, label %21 [
i32 0, label %15
i32 1, label %17
i32 2, label %19
]
15: ; preds = %12
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.11, i64 0, i64 0))
br label %23
17: ; preds = %12
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.12, i64 0, i64 0))
br label %23
19: ; preds = %12
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.9, i64 0, i64 0))
br label %23
21: ; preds = %12
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %14)
br label %23
23: ; preds = %21, %19, %17, %15
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* %13)
%25 = call i8* (...) @giveTheDataPointer()
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i8* %25)
ret i32 0
}