#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 *, int /*<<< orphan*/);
int shmget(int, int, int);
void main() {
  int data[] = {1, 2, 3, 4, 5, 6};
  int id;
  void *base;
  if ((id = shmget(10, 24, 0666 | IPC_CREAT)) == -1) {
    printf("Error get.\n\n");
  } else {
    if ((base = shmat(id, data, 0)) == -1) {
      printf("Error map.\n\n");
    } else {
      while (1)
        ;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0xec1(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xebe(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xebb(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e80(%rip),%rax
mov    (%rax),%edx
or     $0x1b6,%edx
mov    $0xa,%edi
mov    $0x18,%esi
call   1050 <shmget@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
jne    1194 <main+0x64>
lea    0xe8e(%rip),%rdi
call   1030 <printf@plt>
jmp    11d6 <main+0xa6>
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1040 <shmat@plt>
mov    %rax,-0x30(%rbp)
mov    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jne    11c7 <main+0x97>
lea    0xe68(%rip),%rdi
call   1030 <printf@plt>
jmp    11d1 <main+0xa1>
jmp    11cc <main+0x9c>
jmp    11cc <main+0x9c>
jmp    11d6 <main+0xa6>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
mov    0xed5(%rip),%rax
mov    %rax,0x10(%rsp)
movaps 0xeb9(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    0x2e8e(%rip),%rax
mov    $0x1b6,%edx
or     (%rax),%edx
mov    $0xa,%edi
mov    $0x18,%esi
call   1050 <shmget@plt>
cmp    $0xffffffff,%eax
je     1182 <main+0x52>
mov    %rsp,%rsi
mov    %eax,%edi
xor    %edx,%edx
call   1040 <shmat@plt>
cmp    $0xffffffffffffffff,%rax
je     1192 <main+0x62>
nop
jmp    1180 <main+0x50>
lea    0xe9b(%rip),%rdi
add    $0x18,%rsp
jmp    1030 <puts@plt>
lea    0xe7f(%rip),%rdi
call   1030 <puts@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
@__const.main.data = [6 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6]
@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"
define void @main() {
%1 = alloca [6 x i32]
%2 = alloca i32
%3 = alloca i8*
%4 = bitcast [6 x i32]* %1 to i8*
%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* %2
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %21
11: ; preds = %0
%12 = load i32, i32* %2
%13 = getelementptr inbounds [6 x i32], [6 x i32]* %1, i64 0, i64 0
%14 = call i8* @shmat(i32 %12, i32* %13, i32 0)
store i8* %14, i8** %3
%15 = icmp eq i8* %14, inttoptr (i64 -1 to i8*)
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %20
18: ; preds = %11
br label %19
19: ; preds = %18, %19
br label %19
20: ; preds = %16
br label %21
21: ; preds = %20, %9
ret void
}

LLVM IR (-O2):
@__const.main.data = [6 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6]
@IPC_CREAT = global i32 0
@str = [12 x i8] c"Error map.\0A\00"
@str.2 = [12 x i8] c"Error get.\0A\00"
define void @main() {
%1 = alloca [6 x i32]
%2 = bitcast [6 x i32]* %1 to i8*
%3 = load i32, i32* @IPC_CREAT
%4 = or i32 %3, 438
%5 = tail call i32 @shmget(i32 10, i32 24, i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.2, i64 0, i64 0))
br label %16
9: ; preds = %0
%10 = getelementptr inbounds [6 x i32], [6 x i32]* %1, i64 0, i64 0
%11 = call i8* @shmat(i32 %5, i32* %10, i32 0)
%12 = icmp eq i8* %11, inttoptr (i64 -1 to i8*)
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %16
15: ; preds = %9, %15
br label %15
16: ; preds = %13, %7
ret void
}