#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);
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*/ *);
main() {
  int shmid, i;
  int *buf;
  char znak;
  long int a = 2;
  int q = 2;
  srand(time(NULL));
  shmid = shmget(45281, 40 * sizeof(char), IPC_CREAT | 0600);
  if (shmid == -1) {
    perror("Utworzenie segmentu pamieci wspoldzielonej");
    exit(1);
  }
  buf = (int *)shmat(shmid, NULL, 0);
  if (buf == NULL) {
    perror("Przylaczenie segmentu pamieci wspoldzielonej");
    exit(1);
  }
  for (i = 0; i < 40 * sizeof(char); i++) {
    a *= q;
    buf[i] = a;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x2,-0x28(%rbp)
movl   $0x2,-0x2c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edx
or     $0x180,%edx
mov    $0xb0e1,%edi
mov    $0x28,%esi
call   1070 <shmget@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11cf <main+0x6f>
lea    0xe40(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <shmat@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1202 <main+0xa2>
lea    0xe38(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movl   $0x0,-0xc(%rbp)
movslq -0xc(%rbp),%rax
cmp    $0x28,%rax
jae    1243 <main+0xe3>
movslq -0x2c(%rbp),%rax
imul   -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %eax,%edx
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1209 <main+0xa9>
mov    -0x4(%rbp),%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    0x2e6a(%rip),%rax
mov    $0x180,%edx
or     (%rax),%edx
mov    $0xb0e1,%edi
mov    $0x28,%esi
call   1070 <shmget@plt>
cmp    $0xffffffff,%eax
je     11eb <main+0x8b>
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <shmat@plt>
test   %rax,%rax
je     11f4 <main+0x94>
mov    $0x2,%ecx
mov    $0x4,%edx
nopl   0x0(%rax,%rax,1)
lea    (%rcx,%rcx,1),%esi
mov    %esi,-0x10(%rax,%rdx,4)
lea    0x0(,%rcx,4),%esi
mov    %esi,-0xc(%rax,%rdx,4)
lea    0x0(,%rcx,8),%esi
mov    %esi,-0x8(%rax,%rdx,4)
mov    %ecx,%esi
shl    $0x4,%esi
mov    %esi,-0x4(%rax,%rdx,4)
shl    $0x5,%rcx
mov    %ecx,(%rax,%rdx,4)
add    $0x5,%rdx
cmp    $0x2c,%rdx
jne    11b0 <main+0x50>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe0e(%rip),%rdi
jmp    11fb <main+0x9b>
lea    0xe30(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

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

LLVM IR (-O2):
@IPC_CREAT = global i32 0
@.str = [43 x i8] c"Utworzenie segmentu pamieci wspoldzielonej\00"
@.str.1 = [45 x i8] c"Przylaczenie segmentu pamieci wspoldzielonej\00"
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 %10
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([43 x i8], [43 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 %14, label %17
14: ; preds = %10
%15 = tail call i32 @perror(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %10, %17
%18 = phi i64 [ %39, %17 ], [ 0, %10 ]
%19 = phi i64 [ %36, %17 ], [ 2, %10 ]
%20 = trunc i64 %19 to i32
%21 = shl i32 %20, 1
%22 = getelementptr inbounds i32, i32* %12, i64 %18
store i32 %21, i32* %22
%23 = add nuw nsw i64 %18, 1
%24 = trunc i64 %19 to i32
%25 = shl i32 %24, 2
%26 = getelementptr inbounds i32, i32* %12, i64 %23
store i32 %25, i32* %26
%27 = add nuw nsw i64 %18, 2
%28 = trunc i64 %19 to i32
%29 = shl i32 %28, 3
%30 = getelementptr inbounds i32, i32* %12, i64 %27
store i32 %29, i32* %30
%31 = add nuw nsw i64 %18, 3
%32 = trunc i64 %19 to i32
%33 = shl i32 %32, 4
%34 = getelementptr inbounds i32, i32* %12, i64 %31
store i32 %33, i32* %34
%35 = add nuw nsw i64 %18, 4
%36 = shl nsw i64 %19, 5
%37 = trunc i64 %36 to i32
%38 = getelementptr inbounds i32, i32* %12, i64 %35
store i32 %37, i32* %38
%39 = add nuw nsw i64 %18, 5
%40 = icmp eq i64 %39, 40
br i1 %40, label %41, label %17
41: ; preds = %17
ret i32 0
}