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

/* Variables and functions */
scalar_t__ fork();
int mkstemp(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ reader(int);
int /*<<< orphan*/ unlink(char *);
int write(int, int *, int);
int /*<<< orphan*/ writer(int);
int main() {
  char filename[] = "dmtcp-shared-memory.XXXXXX";
  int fd;
  fd = mkstemp(filename);
  printf("creating temporary file in local directory: %s\n", filename);
  unlink(filename);
  int initValue = -1;
  while (write(fd, &initValue, sizeof(initValue)) != sizeof(initValue)) {
    continue;
  }
  if (fork()) {
    writer(fd);
  } else {
    reader(fd);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe7a(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe77(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xe74(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xe71(%rip),%ax
mov    %ax,-0x8(%rbp)
mov    0xe69(%rip),%al
mov    %al,-0x6(%rbp)
lea    -0x20(%rbp),%rdi
call   1070 <mkstemp@plt>
mov    %eax,-0x24(%rbp)
lea    -0x20(%rbp),%rsi
lea    0xe50(%rip),%rdi
call   1060 <printf@plt>
lea    -0x20(%rbp),%rdi
call   1030 <unlink@plt>
movl   $0xffffffff,-0x28(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
cltq
cmp    $0x4,%rax
je     1202 <main+0x92>
jmp    11e0 <main+0x70>
mov    $0x0,%al
call   1090 <fork@plt>
cmp    $0x0,%rax
je     1220 <main+0xb0>
mov    -0x24(%rbp),%edi
call   1080 <writer@plt>
jmp    1228 <main+0xb8>
mov    -0x24(%rbp),%edi
call   1050 <reader@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x38,%rsp
movups 0xe8d(%rip),%xmm0
movups %xmm0,0x1b(%rsp)
movaps 0xe76(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1070 <mkstemp@plt>
mov    %eax,%ebx
lea    0xe76(%rip),%rdi
mov    %r14,%rsi
call   1060 <printf@plt>
mov    %r14,%rdi
call   1030 <unlink@plt>
movl   $0xffffffff,0xc(%rsp)
ff
lea    0xc(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1040 <write@plt>
cmp    $0x4,%eax
jne    11d0 <main+0x60>
xor    %eax,%eax
call   1090 <fork@plt>
mov    %ebx,%edi
test   %rax,%rax
je     11f9 <main+0x89>
call   1080 <writer@plt>
jmp    11fe <main+0x8e>
call   1050 <reader@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.filename = [27 x i8] c"dmtcp-shared-memory.XXXXXX\00"
@.str = [48 x i8] c"creating temporary file in local directory: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [27 x i8]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [27 x i8]* %2 to i8*
%6 = getelementptr inbounds [27 x i8], [27 x i8]* %2, i64 0, i64 0
%7 = call i32 @mkstemp(i8* %6)
store i32 %7, i32* %3
%8 = getelementptr inbounds [27 x i8], [27 x i8]* %2, i64 0, i64 0
%9 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds [27 x i8], [27 x i8]* %2, i64 0, i64 0
%11 = call i32 @unlink(i8* %10)
store i32 -1, i32* %4
br label %12
12: ; preds = %17, %0
%13 = load i32, i32* %3
%14 = call i32 @write(i32 %13, i32* %4, i32 4)
%15 = sext i32 %14 to i64
%16 = icmp ne i64 %15, 4
br i1 %16, label %17, label %18
17: ; preds = %12
br label %12
18: ; preds = %12
%19 = call i64 (...) @fork()
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i32, i32* %3
%23 = call i32 @writer(i32 %22)
br label %27
24: ; preds = %18
%25 = load i32, i32* %3
%26 = call i32 @reader(i32 %25)
br label %27
27: ; preds = %24, %21
ret i32 0
}

LLVM IR (-O2):
@__const.main.filename = [27 x i8] c"dmtcp-shared-memory.XXXXXX\00"
@.str = [48 x i8] c"creating temporary file in local directory: %s\0A\00"
define i32 @main() {
%1 = alloca [27 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [27 x i8], [27 x i8]* %1, i64 0, i64 0
%4 = call i32 @mkstemp(i8* %3)
%5 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* %3)
%6 = call i32 @unlink(i8* %3)
%7 = bitcast i32* %2 to i8*
store i32 -1, i32* %2
br label %8
8: ; preds = %8, %0
%9 = call i32 @write(i32 %4, i32* %2, i32 4)
%10 = icmp eq i32 %9, 4
br i1 %10, label %11, label %8
11: ; preds = %8
%12 = call i64 (...) @fork()
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = call i32 @writer(i32 %4)
br label %18
16: ; preds = %11
%17 = call i32 @reader(i32 %4)
br label %18
18: ; preds = %16, %14
ret i32 0
}