#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*/ printf(char *, ...);
void *shmat(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ shmdt(void *);
int shmget(int, int, int);
void main() {
  int id;
  void *base;
  if ((id = shmget(10, 24, 0666 | IPC_CREAT)) == -1) {
    printf("Error get.\n\n");
  } else {
    if ((base = shmat(id, NULL, 0)) == -1) {
      printf("Error map.\n\n");
    } else {
      int *x = (int *)base;
      for (size_t i = 0; i < 6; i++) {
        printf("%d\n", x[i]);
      }
      shmdt(base);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e91(%rip),%rax
mov    (%rax),%edx
or     $0x1b6,%edx
mov    $0xa,%edi
mov    $0x18,%esi
call   1060 <shmget@plt>
mov    %eax,-0x4(%rbp)
cmp    $0xffffffff,%eax
jne    1185 <main+0x45>
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    120d <main+0xcd>
mov    -0x4(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1050 <shmat@plt>
mov    %rax,-0x10(%rbp)
mov    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jne    11ba <main+0x7a>
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1208 <main+0xc8>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x6,-0x20(%rbp)
jae    11ff <main+0xbf>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11ca <main+0x8a>
mov    -0x10(%rbp),%rdi
call   1030 <shmdt@plt>
jmp    120d <main+0xcd>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2e85(%rip),%rax
mov    $0x1b6,%edx
or     (%rax),%edx
mov    $0xa,%edi
mov    $0x18,%esi
call   1070 <shmget@plt>
cmp    $0xffffffff,%eax
je     11ed <main+0x9d>
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <shmat@plt>
cmp    $0xffffffffffffffff,%rax
je     11f6 <main+0xa6>
mov    %rax,%rbx
mov    (%rax),%esi
lea    0xe6d(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x14(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <shmdt@plt>
lea    0xe1c(%rip),%rdi
jmp    11fd <main+0xad>
lea    0xe07(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <puts@plt>

LLVM IR (-O0):
@IPC_CREAT = global i32 0
@.str = [13 x i8] c"Error get.\0A\0A\00"
@.str.1 = [13 x i8] c"Error map.\0A\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i64
%5 = load i32, i32* @IPC_CREAT
%6 = or i32 438, %5
%7 = call i32 @shmget(i32 10, i32 24, i32 %6)
store i32 %7, i32* %1
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %36
11: ; preds = %0
%12 = load i32, i32* %1
%13 = call i8* @shmat(i32 %12, i32* null, i32 0)
store i8* %13, i8** %2
%14 = icmp eq i8* %13, inttoptr (i64 -1 to i8*)
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %35
17: ; preds = %11
%18 = load i8*, i8** %2
%19 = bitcast i8* %18 to i32*
store i32* %19, i32** %3
store i64 0, i64* %4
br label %20
20: ; preds = %29, %17
%21 = load i64, i64* %4
%22 = icmp ult i64 %21, 6
br i1 %22, label %23, label %32
23: ; preds = %20
%24 = load i32*, i32** %3
%25 = load i64, i64* %4
%26 = getelementptr inbounds i32, i32* %24, i64 %25
%27 = load i32, i32* %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %23
%30 = load i64, i64* %4
%31 = add i64 %30, 1
store i64 %31, i64* %4
br label %20
32: ; preds = %20
%33 = load i8*, i8** %2
%34 = call i32 @shmdt(i8* %33)
br label %35
35: ; preds = %32, %15
br label %36
36: ; preds = %35, %9
ret void
}

LLVM IR (-O2):
@IPC_CREAT = global i32 0
@.str.2 = [4 x i8] c"%d\0A\00"
@str = [12 x i8] c"Error map.\0A\00"
@str.3 = [12 x i8] c"Error get.\0A\00"
define void @main() {
%1 = load i32, i32* @IPC_CREAT
%2 = or i32 %1, 438
%3 = tail call i32 @shmget(i32 10, i32 24, i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.3, i64 0, i64 0))
br label %37
7: ; preds = %0
%8 = tail call i8* @shmat(i32 %3, i32* null, i32 0)
%9 = icmp eq i8* %8, inttoptr (i64 -1 to i8*)
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %37
12: ; preds = %7
%13 = bitcast i8* %8 to i32*
%14 = load i32, i32* %13
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = getelementptr inbounds i8, i8* %8, i64 4
%17 = bitcast i8* %16 to i32*
%18 = load i32, i32* %17
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = getelementptr inbounds i8, i8* %8, i64 8
%21 = bitcast i8* %20 to i32*
%22 = load i32, i32* %21
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %22)
%24 = getelementptr inbounds i8, i8* %8, i64 12
%25 = bitcast i8* %24 to i32*
%26 = load i32, i32* %25
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = getelementptr inbounds i8, i8* %8, i64 16
%29 = bitcast i8* %28 to i32*
%30 = load i32, i32* %29
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = getelementptr inbounds i8, i8* %8, i64 20
%33 = bitcast i8* %32 to i32*
%34 = load i32, i32* %33
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%36 = tail call i32 @shmdt(i8* %8)
br label %37
37: ; preds = %10, %12, %5
ret void
}