#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 /*<<< orphan*/ time_t;
typedef int key_t;

/* Variables and functions */
int IPC_CREAT;
double difftime(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ execlp(char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
char *shmat(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int shmget(int, int const, int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  const int bufflen = 255;
  int shmid;
  char *buffer;
  key_t key = 0xdeadc0de;
  time_t start, stop;
  shmid = shmget(key, bufflen, IPC_CREAT | 0600);
  if (shmid == -1) {
    printf("Error shmget\n");
    exit(0);
  }
  buffer = shmat(shmid, NULL, 0);
  if (buffer == NULL) {
    printf("Error shmat\n");
    exit(0);
  }
  start = time(NULL);
  int i, counter = 0;
  while (1) {
    if (i > 0 && buffer[i % bufflen] == buffer[(i % bufflen) - 1])
      counter++;
    else
      counter = 1;
    if (counter == 5) {
      stop = time(NULL);
      printf("Czas szukania: %f\n", difftime(stop, start));
      execlp("killall", "killall", "procek.sh", NULL);
      return 0;
    }
    i++;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xff,-0x8(%rbp)
movl   $0xdeadc0de,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2e49(%rip),%rax
mov    (%rax),%edx
or     $0x180,%edx
mov    $0xff,%esi
call   1070 <shmget@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11cb <main+0x5b>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%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    11fd <main+0x8d>
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x0,-0x28(%rbp)
jle    126d <main+0xfd>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%eax
mov    $0xff,%ecx
cltd
idiv   %ecx
mov    -0x38(%rbp),%rax
movslq %edx,%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x28(%rbp),%eax
mov    $0xff,%esi
cltd
idiv   %esi
mov    -0x30(%rbp),%eax
sub    $0x1,%edx
movslq %edx,%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    126d <main+0xfd>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1274 <main+0x104>
movl   $0x1,-0x2c(%rbp)
cmpl   $0x5,-0x2c(%rbp)
jne    12c5 <main+0x155>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1040 <difftime@plt>
lea    0xd7f(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
lea    0xd84(%rip),%rsi
lea    0xd85(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
call   1090 <execlp@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1210 <main+0xa0>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    0x2e55(%rip),%rax
mov    $0x180,%edx
or     (%rax),%edx
mov    $0xdeadc0de,%edi
mov    $0xff,%esi
call   1080 <shmget@plt>
cmp    $0xffffffff,%eax
je     125a <main+0xda>
xor    %ebp,%ebp
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <shmat@plt>
test   %rax,%rax
je     1263 <main+0xe3>
mov    %rax,%rbx
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%r14d
mov    $0x80808081,%r8d
jmp    11e5 <main+0x65>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%ecx
mov    %edx,%ebp
mov    %ecx,%esi
imul   %r8,%rsi
shr    $0x27,%rsi
mov    %esi,%edx
shl    $0x8,%edx
sub    %edx,%esi
add    %ecx,%esi
mov    $0x1,%edx
test   %ecx,%ecx
jle    11e0 <main+0x60>
mov    %esi,%edi
movzbl (%rbx,%rdi,1),%eax
add    $0xffffffff,%esi
movslq %esi,%rsi
add    $0x1,%ebp
cmp    (%rbx,%rsi,1),%al
jne    11e0 <main+0x60>
mov    %ebp,%edx
cmp    $0x5,%ebp
jne    11e0 <main+0x60>
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
mov    %r14d,%esi
call   1050 <difftime@plt>
lea    0xdcc(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xdd1(%rip),%rdi
lea    0xdd2(%rip),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
call   10a0 <execlp@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdd0(%rip),%rdi
jmp    126a <main+0xea>
lea    0xdbb(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@IPC_CREAT = global i32 0
@.str = [14 x i8] c"Error shmget\0A\00"
@.str.1 = [13 x i8] c"Error shmat\0A\00"
@.str.2 = [19 x i8] c"Czas szukania: %f\0A\00"
@.str.3 = [8 x i8] c"killall\00"
@.str.4 = [10 x i8] c"procek.sh\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
store i32 255, i32* %2
store i32 -559038242, i32* %5
%10 = load i32, i32* %5
%11 = load i32, i32* @IPC_CREAT
%12 = or i32 %11, 384
%13 = call i32 @shmget(i32 %10, i32 255, i32 %12)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %0
%20 = load i32, i32* %3
%21 = call i8* @shmat(i32 %20, i32* null, i32 0)
store i8* %21, i8** %4
%22 = load i8*, i8** %4
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%26 = call i32 @exit(i32 0)
unreachable
27: ; preds = %19
%28 = call i32 @time(i32* null)
store i32 %28, i32* %6
store i32 0, i32* %9
br label %29
29: ; preds = %27, %63
%30 = load i32, i32* %8
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %52
32: ; preds = %29
%33 = load i8*, i8** %4
%34 = load i32, i32* %8
%35 = srem i32 %34, 255
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %33, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = load i8*, i8** %4
%41 = load i32, i32* %8
%42 = srem i32 %41, 255
%43 = sub nsw i32 %42, 1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %40, i64 %44
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %39, %47
br i1 %48, label %49, label %52
49: ; preds = %32
%50 = load i32, i32* %9
%51 = add nsw i32 %50, 1
store i32 %51, i32* %9
br label %53
52: ; preds = %32, %29
store i32 1, i32* %9
br label %53
53: ; preds = %52, %49
%54 = load i32, i32* %9
%55 = icmp eq i32 %54, 5
br i1 %55, label %56, label %63
56: ; preds = %53
%57 = call i32 @time(i32* null)
store i32 %57, i32* %7
%58 = load i32, i32* %7
%59 = load i32, i32* %6
%60 = call double @difftime(i32 %58, i32 %59)
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), double %60)
%62 = call i32 @execlp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32* null)
ret i32 0
63: ; preds = %53
%64 = load i32, i32* %8
%65 = add nsw i32 %64, 1
store i32 %65, i32* %8
br label %29
}

LLVM IR (-O2):
@IPC_CREAT = global i32 0
@.str.2 = [19 x i8] c"Czas szukania: %f\0A\00"
@.str.3 = [8 x i8] c"killall\00"
@.str.4 = [10 x i8] c"procek.sh\00"
@str = [12 x i8] c"Error shmat\00"
@str.5 = [13 x i8] c"Error shmget\00"
define i32 @main() {
%1 = load i32, i32* @IPC_CREAT
%2 = or i32 %1, 384
%3 = tail call i32 @shmget(i32 -559038242, i32 255, i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.5, i64 0, i64 0))
%7 = tail call i32 @exit(i32 0)
unreachable
8: ; preds = %0
%9 = tail call i8* @shmat(i32 %3, i32* null, i32 0)
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 0)
unreachable
14: ; preds = %8
%15 = tail call i32 @time(i32* null)
br label %16
16: ; preds = %38, %14
%17 = phi i32 [ undef, %14 ], [ %40, %38 ]
%18 = phi i32 [ 0, %14 ], [ %39, %38 ]
%19 = icmp sgt i32 %17, 0
br i1 %19, label %20, label %38
20: ; preds = %16
%21 = urem i32 %17, 255
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %9, i64 %22
%24 = load i8, i8* %23
%25 = add nsw i32 %21, -1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %9, i64 %26
%28 = load i8, i8* %27
%29 = icmp eq i8 %24, %28
%30 = add nsw i32 %18, 1
br i1 %29, label %31, label %38
31: ; preds = %20
%32 = icmp eq i32 %30, 5
br i1 %32, label %33, label %38
33: ; preds = %31
%34 = tail call i32 @time(i32* null)
%35 = tail call double @difftime(i32 %34, i32 %15)
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), double %35)
%37 = tail call i32 @execlp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32* null)
ret i32 0
38: ; preds = %20, %16, %31
%39 = phi i32 [ %30, %31 ], [ 1, %16 ], [ 1, %20 ]
%40 = add nsw i32 %17, 1
br label %16
}