#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(void *, int *, 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*/);
void send_it(void) {
  int shmid, iflag = 1;
  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("SEND: Memory attached at %lX\n", (unsigned long)shm_area);
  memcpy(shm_area, &iflag, 4);
  if (shmdt(shm_area) == -1) {
    perror("shmdt");
    exit(errno);
  };
  printf("SENDND 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    $0x1a,%edi
mov    $0x2004,%esi
xor    %edx,%edx
call   1080 <shmget@plt>
mov    %eax,-0x4(%rbp)
cmp    $0xffffffff,%eax
jne    11b6 <send_it+0x46>
lea    0xe5d(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e31(%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    11f2 <send_it+0x82>
lea    0xe28(%rip),%rdi
call   1060 <perror@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rsi
lea    0xe10(%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
call   1030 <shmdt@plt>
cmp    $0xffffffff,%eax
jne    1242 <send_it+0xd2>
lea    0xdfc(%rip),%rdi
call   1060 <perror@plt>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<send_it>:
push   %rbx
sub    $0x10,%rsp
movl   $0x1,0xc(%rsp)
mov    $0x1a,%edi
mov    $0x2004,%esi
xor    %edx,%edx
call   1090 <shmget@plt>
cmp    $0xffffffff,%eax
jne    11ac <send_it+0x2c>
lea    0xe56(%rip),%rdi
jmp    1200 <send_it+0x80>
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <shmat@plt>
cmp    $0xffffffffffffffff,%rax
jne    11c6 <send_it+0x46>
lea    0xe43(%rip),%rdi
jmp    1200 <send_it+0x80>
mov    %rax,%rbx
lea    0xe3d(%rip),%rdi
mov    %rax,%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
call   1040 <shmdt@plt>
cmp    $0xffffffff,%eax
jne    1213 <send_it+0x93>
lea    0xe2b(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    0xe17(%rip),%rdi
call   1030 <puts@plt>
mov    0x2db2(%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 = [30 x i8] c"SEND: Memory attached at %lX\0A\00"
@.str.3 = [6 x i8] c"shmdt\00"
@.str.4 = [35 x i8] c"SENDND 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 = 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 ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i64 %20)
%22 = load i8*, i8** %3
%23 = call i32 @memcpy(i8* %22, i32* %2, i32 4)
%24 = load i8*, i8** %3
%25 = call i32 @shmdt(i8* %24)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %31
27: ; preds = %18
%28 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%29 = load i32, i32* @errno
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %18
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
%33 = load i32, i32* @EXIT_SUCCESS
%34 = call i32 @exit(i32 %33)
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 = [30 x i8] c"SEND: Memory attached at %lX\0A\00"
@.str.3 = [6 x i8] c"shmdt\00"
@EXIT_SUCCESS = global i32 0
@str = [34 x i8] c"SENDND has successfully completed\00"
define void @send_it() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 1, 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 ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i64 %17)
%19 = call i32 @memcpy(i8* %10, i32* %1, i32 4)
%20 = call i32 @shmdt(i8* %10)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %26
22: ; preds = %16
%23 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%24 = load i32, i32* @errno
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %16
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%28 = load i32, i32* @EXIT_SUCCESS
%29 = call i32 @exit(i32 %28)
unreachable
}