#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 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(void) {
  srand(time(NULL));
  int size = 40;
  int shmid, i;
  long *buf;
  shmid = shmget(45281, size * sizeof(char), IPC_CREAT | 0600);
  if (shmid == -1) {
    perror("Creating shared memory");
  }
  buf = (long *)shmat(shmid, NULL, 0);
  if (buf == NULL) {
    perror("Attaching shared memory segment");
    exit(1);
  }
  long p = 2;
  int q = 2;
  char a;
  for (i = 0; i < size; i++) {
    p *= q;
    buf[i] = p;
  }
  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   $0x28,-0x8(%rbp)
movslq -0x8(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%esi
mov    0x2e41(%rip),%rax
mov    (%rax),%edx
or     $0x180,%edx
mov    $0xb0e1,%edi
call   1070 <shmget@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11c2 <main+0x62>
lea    0xe43(%rip),%rdi
call   1050 <perror@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    11f5 <main+0x95>
lea    0xe31(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movq   $0x2,-0x20(%rbp)
movl   $0x2,-0x24(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1242 <main+0xe2>
movslq -0x24(%rbp),%rax
imul   -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    120b <main+0xab>
mov    0x2d97(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
mov    0x2e62(%rip),%rax
mov    $0x180,%edx
or     (%rax),%edx
mov    $0xb0e1,%edi
mov    $0x28,%esi
call   1070 <shmget@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     11fc <main+0x9c>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <shmat@plt>
test   %rax,%rax
je     120a <main+0xaa>
mov    $0x2,%ecx
mov    $0x4,%edx
nopl   (%rax)
lea    (%rcx,%rcx,1),%rsi
mov    %rsi,-0x20(%rax,%rdx,8)
lea    0x0(,%rcx,4),%rsi
mov    %rsi,-0x18(%rax,%rdx,8)
lea    0x0(,%rcx,8),%rsi
mov    %rsi,-0x10(%rax,%rdx,8)
mov    %rcx,%rsi
shl    $0x4,%rsi
mov    %rsi,-0x8(%rax,%rdx,8)
shl    $0x5,%rcx
mov    %rcx,(%rax,%rdx,8)
add    $0x5,%rdx
cmp    $0x2c,%rdx
jne    11b0 <main+0x50>
mov    0x2de8(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret
lea    0xdfd(%rip),%rdi
call   1050 <perror@plt>
jmp    1193 <main+0x33>
lea    0xe06(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

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

LLVM IR (-O2):
@IPC_CREAT = global i32 0
@.str = [23 x i8] c"Creating shared memory\00"
@.str.1 = [32 x i8] c"Attaching shared memory segment\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, 384
%5 = tail call i32 @shmget(i32 45281, i32 40, i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = tail call i64 @shmat(i32 %5, i32* null, i32 0)
%11 = inttoptr i64 %10 to i64*
%12 = icmp eq i64 %10, 0
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = tail call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %9, %16
%17 = phi i64 [ %33, %16 ], [ 0, %9 ]
%18 = phi i64 [ %31, %16 ], [ 2, %9 ]
%19 = shl nsw i64 %18, 1
%20 = getelementptr inbounds i64, i64* %11, i64 %17
store i64 %19, i64* %20
%21 = add nuw nsw i64 %17, 1
%22 = shl nsw i64 %18, 2
%23 = getelementptr inbounds i64, i64* %11, i64 %21
store i64 %22, i64* %23
%24 = add nuw nsw i64 %17, 2
%25 = shl nsw i64 %18, 3
%26 = getelementptr inbounds i64, i64* %11, i64 %24
store i64 %25, i64* %26
%27 = add nuw nsw i64 %17, 3
%28 = shl nsw i64 %18, 4
%29 = getelementptr inbounds i64, i64* %11, i64 %27
store i64 %28, i64* %29
%30 = add nuw nsw i64 %17, 4
%31 = shl nsw i64 %18, 5
%32 = getelementptr inbounds i64, i64* %11, i64 %30
store i64 %31, i64* %32
%33 = add nuw nsw i64 %17, 5
%34 = icmp eq i64 %33, 40
br i1 %34, label %35, label %16
35: ; preds = %16
%36 = load i32, i32* @EXIT_SUCCESS
ret i32 %36
}