#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 IPC_CREAT;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ read(int /*<<< orphan*/, char *, int);
scalar_t__ shmat(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ shmdt(char *);
int shmget(int, int, int);
scalar_t__ write(int, char *, int);
int main() {
  char *ptr;
  int shm_fd;
  shm_fd = shmget(1, 1, IPC_CREAT | 0666);
  ptr = (char *)shmat(shm_fd, 0, 0);
  read(0, ptr, 10);
  write(1, ptr, 10);
  shmdt(ptr);
  if (write(1, ptr, 10) < 0)
    perror(" error:");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%edx
or     $0x1b6,%edx
mov    $0x1,%esi
mov    %esi,%edi
call   1080 <shmget@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   1070 <shmat@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
xor    %edi,%edi
mov    $0xa,%edx
call   1050 <read@plt>
mov    -0x10(%rbp),%rsi
mov    $0x1,%edi
mov    $0xa,%edx
call   1040 <write@plt>
mov    -0x10(%rbp),%rdi
call   1030 <shmdt@plt>
mov    -0x10(%rbp),%rsi
mov    $0x1,%edi
mov    $0xa,%edx
call   1040 <write@plt>
cmp    $0x0,%rax
jge    1202 <main+0x92>
lea    0xe03(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e68(%rip),%rax
mov    $0x1b6,%edx
or     (%rax),%edx
mov    $0x1,%edi
mov    $0x1,%esi
call   1080 <shmget@plt>
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <shmat@plt>
mov    %rax,%rbx
xor    %edi,%edi
mov    %rax,%rsi
mov    $0xa,%edx
call   1050 <read@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0xa,%edx
call   1040 <write@plt>
mov    %rbx,%rdi
call   1030 <shmdt@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0xa,%edx
call   1040 <write@plt>
test   %rax,%rax
jns    11e8 <main+0x78>
lea    0xe1d(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@IPC_CREAT = global i32 0
@.str = [8 x i8] c" error:\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @IPC_CREAT
%5 = or i32 %4, 438
%6 = call i32 @shmget(i32 1, i32 1, i32 %5)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = call i64 @shmat(i32 %7, i32 0, i32 0)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %2
%10 = load i8*, i8** %2
%11 = call i32 @read(i32 0, i8* %10, i32 10)
%12 = load i8*, i8** %2
%13 = call i64 @write(i32 1, i8* %12, i32 10)
%14 = load i8*, i8** %2
%15 = call i32 @shmdt(i8* %14)
%16 = load i8*, i8** %2
%17 = call i64 @write(i32 1, i8* %16, i32 10)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %0
%20 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %19, %0
%22 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@IPC_CREAT = global i32 0
@.str = [8 x i8] c" error:\00"
define i32 @main() {
%1 = load i32, i32* @IPC_CREAT
%2 = or i32 %1, 438
%3 = tail call i32 @shmget(i32 1, i32 1, i32 %2)
%4 = tail call i64 @shmat(i32 %3, i32 0, i32 0)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 @read(i32 0, i8* %5, i32 10)
%7 = tail call i64 @write(i32 1, i8* %5, i32 10)
%8 = tail call i32 @shmdt(i8* %5)
%9 = tail call i64 @write(i32 1, i8* %5, i32 10)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %0
%14 = tail call i32 @exit(i32 0)
unreachable
}