#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 key_t;

/* Variables and functions */
int EXIT_SUCCESS;
int IPC_CREAT;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
scalar_t__ shmat(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int shmget(int, int, int);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  srand(time(NULL));
  key_t key = 2137;
  int sharedMemoryID;
  int *sharedMemory;
  int i;
  int a = 1;
  int q = 2;
  sharedMemoryID = shmget(key, 30, IPC_CREAT | 0666);
  if (sharedMemoryID < 0) {
    perror("Sharing memory error");
    exit(1);
  }
  sharedMemory = (int *)shmat(sharedMemoryID, NULL, 0);
  if (sharedMemory == NULL) {
    perror("Sharing memory segment error");
    exit(1);
  }
  for (i = 0; i < 30; i++) {
    a *= q;
    sharedMemory[i] = a;
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
movl   $0x859,-0x8(%rbp)
movl   $0x1,-0x20(%rbp)
movl   $0x2,-0x24(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e3a(%rip),%rax
mov    (%rax),%edx
or     $0x1b6,%edx
mov    $0x1e,%esi
call   1070 <shmget@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11d3 <main+0x73>
lea    0xe3c(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0xc(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <shmat@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1206 <main+0xa6>
lea    0xe1e(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x1e,-0x1c(%rbp)
jge    123d <main+0xdd>
mov    -0x24(%rbp),%eax
imul   -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    120d <main+0xad>
mov    0x2d9c(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
mov    0x2e62(%rip),%rax
mov    $0x1b6,%edx
or     (%rax),%edx
mov    $0x859,%edi
mov    $0x1e,%esi
call   1070 <shmget@plt>
test   %eax,%eax
js     1205 <main+0xa5>
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <shmat@plt>
test   %rax,%rax
je     120e <main+0xae>
movaps 0xe59(%rip),%xmm0
movups %xmm0,(%rax)
movaps 0xe5f(%rip),%xmm0
movups %xmm0,0x10(%rax)
movaps 0xe64(%rip),%xmm0
movups %xmm0,0x20(%rax)
movaps 0xe69(%rip),%xmm0
movups %xmm0,0x30(%rax)
movaps 0xe6e(%rip),%xmm0
movups %xmm0,0x40(%rax)
movaps 0xe73(%rip),%xmm0
movups %xmm0,0x50(%rax)
movaps 0xe78(%rip),%xmm0
movups %xmm0,0x60(%rax)
movabs $0x4000000020000000,%rcx
mov    %rcx,0x70(%rax)
mov    0x2ddf(%rip),%rax
mov    (%rax),%eax
pop    %rcx
ret
lea    0xe64(%rip),%rdi
jmp    1215 <main+0xb5>
lea    0xe70(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@IPC_CREAT = global i32 0
@.str = [21 x i8] c"Sharing memory error\00"
@.str.1 = [29 x i8] c"Sharing memory segment error\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 @time(i32* null)
%9 = call i32 @srand(i32 %8)
store i32 2137, i32* %2
store i32 1, i32* %6
store i32 2, i32* %7
%10 = load i32, i32* %2
%11 = load i32, i32* @IPC_CREAT
%12 = or i32 %11, 438
%13 = call i32 @shmget(i32 %10, i32 30, i32 %12)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %0
%17 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %0
%20 = load i32, i32* %3
%21 = call i64 @shmat(i32 %20, i32* null, i32 0)
%22 = inttoptr i64 %21 to i32*
store i32* %22, i32** %4
%23 = load i32*, i32** %4
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %28
25: ; preds = %19
%26 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %19
store i32 0, i32* %5
br label %29
29: ; preds = %41, %28
%30 = load i32, i32* %5
%31 = icmp slt i32 %30, 30
br i1 %31, label %32, label %44
32: ; preds = %29
%33 = load i32, i32* %7
%34 = load i32, i32* %6
%35 = mul nsw i32 %34, %33
store i32 %35, i32* %6
%36 = load i32, i32* %6
%37 = load i32*, i32** %4
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
store i32 %36, i32* %40
br label %41
41: ; preds = %32
%42 = load i32, i32* %5
%43 = add nsw i32 %42, 1
store i32 %43, i32* %5
br label %29
44: ; preds = %29
%45 = load i32, i32* @EXIT_SUCCESS
ret i32 %45
}

LLVM IR (-O2):
@IPC_CREAT = global i32 0
@.str = [21 x i8] c"Sharing memory error\00"
@.str.1 = [29 x i8] c"Sharing memory segment error\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = tail call i32 @time(i32* null)
%2 = tail call i32 @srand(i32 %1)
%3 = load i32, i32* @IPC_CREAT
%4 = or i32 %3, 438
%5 = tail call i32 @shmget(i32 2137, i32 30, i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = tail call i64 @shmat(i32 %5, i32* null, i32 0)
%12 = inttoptr i64 %11 to i32*
%13 = icmp eq i64 %11, 0
br i1 %13, label %31, label %14
14: ; preds = %10
%15 = inttoptr i64 %11 to <4 x i32>*
store <4 x i32> <i32 2, i32 4, i32 8, i32 16>, <4 x i32>* %15
%16 = getelementptr inbounds i32, i32* %12, i64 4
%17 = bitcast i32* %16 to <4 x i32>*
store <4 x i32> <i32 32, i32 64, i32 128, i32 256>, <4 x i32>* %17
%18 = getelementptr inbounds i32, i32* %12, i64 8
%19 = bitcast i32* %18 to <4 x i32>*
store <4 x i32> <i32 512, i32 1024, i32 2048, i32 4096>, <4 x i32>* %19
%20 = getelementptr inbounds i32, i32* %12, i64 12
%21 = bitcast i32* %20 to <4 x i32>*
store <4 x i32> <i32 8192, i32 16384, i32 32768, i32 65536>, <4 x i32>* %21
%22 = getelementptr inbounds i32, i32* %12, i64 16
%23 = bitcast i32* %22 to <4 x i32>*
store <4 x i32> <i32 131072, i32 262144, i32 524288, i32 1048576>, <4 x i32>* %23
%24 = getelementptr inbounds i32, i32* %12, i64 20
%25 = bitcast i32* %24 to <4 x i32>*
store <4 x i32> <i32 2097152, i32 4194304, i32 8388608, i32 16777216>, <4 x i32>* %25
%26 = getelementptr inbounds i32, i32* %12, i64 24
%27 = bitcast i32* %26 to <4 x i32>*
store <4 x i32> <i32 33554432, i32 67108864, i32 134217728, i32 268435456>, <4 x i32>* %27
%28 = getelementptr inbounds i32, i32* %12, i64 28
store i32 536870912, i32* %28
%29 = getelementptr inbounds i32, i32* %12, i64 29
store i32 1073741824, i32* %29
%30 = load i32, i32* @EXIT_SUCCESS
ret i32 %30
31: ; preds = %10
%32 = tail call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%33 = tail call i32 @exit(i32 1)
unreachable
}