#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 /*<<< orphan*/ EXIT_SUCCESS;
void *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDWR;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(void *, int *, int);
void *mmap(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
scalar_t__ munmap(void *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int shm_open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
void send_it(void) {
  int shm_fd, iflag = 1;
  void *shm_area;
  if ((shm_fd = shm_open("/my_shm", O_RDWR, 0)) == -1) {
    perror("shm_open");
    exit(errno);
  };
  shm_area = mmap(NULL, 8196, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0);
  if (shm_area == MAP_FAILED) {
    perror("mmap");
    exit(errno);
  };
  printf("SEND: Memory attached at %lX\n", (unsigned long)shm_area);
  memcpy(shm_area, &iflag, 4);
  if (munmap(shm_area, 8196)) {
    perror("munmap");
    exit(errno);
  };
  printf("SEND has successfully completed\n");
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<send_it>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x1,-0x8(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
lea    0xe71(%rip),%rdi
xor    %edx,%edx
call   1090 <shm_open@plt>
mov    %eax,-0x4(%rbp)
cmp    $0xffffffff,%eax
jne    11bc <send_it+0x4c>
lea    0xe5f(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%edx
mov    0x2df4(%rip),%rax
or     (%rax),%edx
mov    0x2e13(%rip),%rax
mov    (%rax),%ecx
mov    -0x4(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x2004,%esi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2db5(%rip),%rcx
cmp    (%rcx),%rax
jne    121e <send_it+0xae>
lea    0xe06(%rip),%rdi
call   1070 <perror@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rsi
lea    0xded(%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    -0x10(%rbp),%rdi
mov    $0x2004,%esi
call   1060 <munmap@plt>
cmp    $0x0,%rax
je     1274 <send_it+0x104>
lea    0xdd3(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<send_it>:
push   %rbx
sub    $0x10,%rsp
movl   $0x1,0xc(%rsp)
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
lea    0xe63(%rip),%rdi
xor    %edx,%edx
call   10a0 <shm_open@plt>
cmp    $0xffffffff,%eax
jne    11b5 <send_it+0x35>
lea    0xe58(%rip),%rdi
jmp    1250 <send_it+0xd0>
mov    0x2e3c(%rip),%rcx
mov    0x2dfd(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2e1a(%rip),%rcx
mov    (%rcx),%ecx
xor    %edi,%edi
mov    $0x2004,%esi
mov    %eax,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,%rbx
mov    0x2dc4(%rip),%rax
cmp    (%rax),%rbx
jne    11fa <send_it+0x7a>
lea    0xe19(%rip),%rdi
jmp    1250 <send_it+0xd0>
lea    0xe15(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1060 <memcpy@plt>
mov    %rbx,%rdi
mov    $0x2004,%esi
call   1070 <munmap@plt>
test   %rax,%rax
jne    1249 <send_it+0xc9>
lea    0xe05(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    0xde4(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"/my_shm\00"
@O_RDWR = global i32 0
@.str.1 = [9 x i8] c"shm_open\00"
@errno = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [5 x i8] c"mmap\00"
@.str.3 = [30 x i8] c"SEND: Memory attached at %lX\0A\00"
@.str.4 = [7 x i8] c"munmap\00"
@.str.5 = [33 x i8] c"SEND has successfully completed\0A\00"
@EXIT_SUCCESS = global i32 0
define void @send_it() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
store i32 1, i32* %2
%4 = load i32, i32* @O_RDWR
%5 = call i32 @shm_open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %4, i32 0)
store i32 %5, i32* %1
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* @errno
%10 = call i32 @exit(i32 %9)
unreachable
11: ; preds = %0
%12 = load i32, i32* @PROT_READ
%13 = load i32, i32* @PROT_WRITE
%14 = or i32 %12, %13
%15 = load i32, i32* @MAP_SHARED
%16 = load i32, i32* %1
%17 = call i8* @mmap(i32* null, i32 8196, i32 %14, i32 %15, i32 %16, i32 0)
store i8* %17, i8** %3
%18 = load i8*, i8** %3
%19 = load i8*, i8** @MAP_FAILED
%20 = icmp eq i8* %18, %19
br i1 %20, label %21, label %25
21: ; preds = %11
%22 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%23 = load i32, i32* @errno
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %11
%26 = load i8*, i8** %3
%27 = ptrtoint i8* %26 to i64
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i64 %27)
%29 = load i8*, i8** %3
%30 = call i32 @memcpy(i8* %29, i32* %2, i32 4)
%31 = load i8*, i8** %3
%32 = call i64 @munmap(i8* %31, i32 8196)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %25
%35 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%36 = load i32, i32* @errno
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %25
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0))
%40 = load i32, i32* @EXIT_SUCCESS
%41 = call i32 @exit(i32 %40)
unreachable
}

LLVM IR (-O2):
@.str = [8 x i8] c"/my_shm\00"
@O_RDWR = global i32 0
@.str.1 = [9 x i8] c"shm_open\00"
@errno = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [5 x i8] c"mmap\00"
@.str.3 = [30 x i8] c"SEND: Memory attached at %lX\0A\00"
@.str.4 = [7 x i8] c"munmap\00"
@EXIT_SUCCESS = global i32 0
@str = [32 x i8] c"SEND has successfully completed\00"
define void @send_it() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 1, i32* %1
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @shm_open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %3, i32 0)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%8 = load i32, i32* @errno
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %0
%11 = load i32, i32* @PROT_READ
%12 = load i32, i32* @PROT_WRITE
%13 = or i32 %12, %11
%14 = load i32, i32* @MAP_SHARED
%15 = tail call i8* @mmap(i32* null, i32 8196, i32 %13, i32 %14, i32 %4, i32 0)
%16 = load i8*, i8** @MAP_FAILED
%17 = icmp eq i8* %15, %16
br i1 %17, label %18, label %22
18: ; preds = %10
%19 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32, i32* @errno
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %10
%23 = ptrtoint i8* %15 to i64
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i64 %23)
%25 = call i32 @memcpy(i8* %15, i32* %1, i32 4)
%26 = call i64 @munmap(i8* %15, i32 8196)
%27 = icmp eq i64 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %22
%29 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%30 = load i32, i32* @errno
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %22
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%34 = load i32, i32* @EXIT_SUCCESS
%35 = call i32 @exit(i32 %34)
unreachable
}