#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 IPC_CREAT;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
char *shmat(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int shmget(int, int, int);
int /*<<< orphan*/ sleep(int);
main() {
  char c;
  int shmid;
  key_t key;
  char *shm, *s;
  key = 5678;
  if ((shmid = shmget(key, 27, IPC_CREAT | 0666)) < 0) {
    perror("shmget");
    exit(1);
  }
  if ((shm = shmat(shmid, NULL, 0)) == (char *)-1) {
    perror("shmat");
    exit(1);
  }
  s = shm;
  for (c = 'a'; c <= 'z'; c++)
    *s++ = c;
  *s = '\0';
  while (*shm != '*')
    sleep(1);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x162e,-0x10(%rbp)
mov    -0x10(%rbp),%edi
mov    0x2e70(%rip),%rax
mov    (%rax),%edx
or     $0x1b6,%edx
mov    $0x1b,%esi
call   1050 <shmget@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    11a4 <main+0x54>
lea    0xe6b(%rip),%rdi
call   1030 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0xc(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <shmat@plt>
mov    %rax,-0x18(%rbp)
mov    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jne    11dc <main+0x8c>
lea    0xe3a(%rip),%rdi
call   1030 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
movb   $0x61,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0x7a,%eax
jg     1216 <main+0xc6>
mov    -0x5(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
mov    -0x5(%rbp),%al
add    $0x1,%al
mov    %al,-0x5(%rbp)
jmp    11e8 <main+0x98>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2a,%eax
je     123c <main+0xec>
mov    $0x1,%edi
call   1070 <sleep@plt>
jmp    121d <main+0xcd>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e88(%rip),%rax
mov    $0x1b6,%edx
or     (%rax),%edx
mov    $0x162e,%edi
mov    $0x1b,%esi
call   1050 <shmget@plt>
test   %eax,%eax
jns    117b <main+0x2b>
lea    0xe97(%rip),%rdi
jmp    1193 <main+0x43>
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <shmat@plt>
cmp    $0xffffffffffffffff,%rax
jne    11a2 <main+0x52>
lea    0xe84(%rip),%rdi
call   1030 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    %rax,%rbx
movaps 0xe54(%rip),%xmm0
movups %xmm0,(%rax)
movabs $0x7877767574737271,%rax
76 77 78
mov    %rax,0x10(%rbx)
movw   $0x7a79,0x18(%rbx)
movb   $0x0,0x1a(%rbx)
cmpb   $0x2a,(%rbx)
je     11df <main+0x8f>
nopl   0x0(%rax)
mov    $0x1,%edi
call   1070 <sleep@plt>
cmpb   $0x2a,(%rbx)
jne    11d0 <main+0x80>
xor    %edi,%edi
call   1060 <exit@plt>

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

LLVM IR (-O2):
@IPC_CREAT = global i32 0
@.str = [7 x i8] c"shmget\00"
@.str.1 = [6 x i8] c"shmat\00"
define i32 @main() {
%1 = load i32, i32* @IPC_CREAT
%2 = or i32 %1, 438
%3 = tail call i32 @shmget(i32 5678, i32 27, i32 %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = tail call i8* @shmat(i32 %3, i32* null, i32 0)
%10 = icmp eq i8* %9, inttoptr (i64 -1 to i8*)
br i1 %10, label %26, label %11
11: ; preds = %8
%12 = getelementptr inbounds i8, i8* %9, i64 16
%13 = bitcast i8* %9 to <16 x i8>*
store <16 x i8> <i8 97, i8 98, i8 99, i8 100, i8 101, i8 102, i8 103, i8 104, i8 105, i8 106, i8 107, i8 108, i8 109, i8 110, i8 111, i8 112>, <16 x i8>* %13
%14 = getelementptr inbounds i8, i8* %9, i64 17
store i8 113, i8* %12
%15 = getelementptr inbounds i8, i8* %9, i64 18
store i8 114, i8* %14
%16 = getelementptr inbounds i8, i8* %9, i64 19
store i8 115, i8* %15
%17 = getelementptr inbounds i8, i8* %9, i64 20
store i8 116, i8* %16
%18 = getelementptr inbounds i8, i8* %9, i64 21
store i8 117, i8* %17
%19 = getelementptr inbounds i8, i8* %9, i64 22
store i8 118, i8* %18
%20 = getelementptr inbounds i8, i8* %9, i64 23
store i8 119, i8* %19
%21 = getelementptr inbounds i8, i8* %9, i64 24
store i8 120, i8* %20
%22 = getelementptr inbounds i8, i8* %9, i64 25
store i8 121, i8* %21
%23 = getelementptr inbounds i8, i8* %9, i64 26
store i8 122, i8* %22
store i8 0, i8* %23
%24 = load i8, i8* %9
%25 = icmp eq i8 %24, 42
br i1 %25, label %33, label %29
26: ; preds = %8
%27 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%28 = tail call i32 @exit(i32 1)
unreachable
29: ; preds = %11, %29
%30 = tail call i32 @sleep(i32 1)
%31 = load i8, i8* %9
%32 = icmp eq i8 %31, 42
br i1 %32, label %33, label %29
33: ; preds = %29, %11
%34 = tail call i32 @exit(i32 0)
unreachable
}