#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*/ die(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char *shmat(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int shmget(int, int, int);
int /*<<< orphan*/ sleep(int);
int main() {
  char c;
  int shmid;
  key_t key;
  char *shm, *s;
  key = 5678;
  if ((shmid = shmget(key, 27, IPC_CREAT | 0666)) < 0)
    die("shmget");
  if ((shm = shmat(shmid, NULL, 0)) == (char *)-1)
    die("shmat");
  s = shm;
  for (c = 'a'; c <= 'z'; c++)
    *s++ = c;
  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    119a <main+0x4a>
lea    0xe6b(%rip),%rdi
call   1030 <die@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    11c8 <main+0x78>
lea    0xe44(%rip),%rdi
call   1030 <die@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
movb   $0x61,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0x7a,%eax
jg     1202 <main+0xb2>
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    11d4 <main+0x84>
jmp    1207 <main+0xb7>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2a,%eax
je     1226 <main+0xd6>
mov    $0x1,%edi
call   1070 <sleep@plt>
jmp    1207 <main+0xb7>
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>
mov    %eax,%ebx
test   %eax,%eax
jns    1180 <main+0x30>
lea    0xe95(%rip),%rdi
call   1030 <die@plt>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <shmat@plt>
mov    %rax,%rbx
cmp    $0xffffffffffffffff,%rax
jne    11a0 <main+0x50>
lea    0xe7c(%rip),%rdi
call   1030 <die@plt>
movaps 0xe59(%rip),%xmm0
movups %xmm0,(%rbx)
movabs $0x7877767574737271,%rax
76 77 78
mov    %rax,0x10(%rbx)
movw   $0x7a79,0x18(%rbx)
cmpb   $0x2a,(%rbx)
je     11df <main+0x8f>
cs nopw 0x0(%rax,%rax,1)
nopl   (%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 %14
12: ; preds = %0
%13 = call i32 @die(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %0
%15 = load i32, i32* %3
%16 = call i8* @shmat(i32 %15, i32* null, i32 0)
store i8* %16, i8** %5
%17 = icmp eq i8* %16, inttoptr (i64 -1 to i8*)
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @die(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %14
%21 = load i8*, i8** %5
store i8* %21, i8** %6
store i8 97, i8* %2
br label %22
22: ; preds = %30, %20
%23 = load i8, i8* %2
%24 = sext i8 %23 to i32
%25 = icmp sle i32 %24, 122
br i1 %25, label %26, label %33
26: ; preds = %22
%27 = load i8, i8* %2
%28 = load i8*, i8** %6
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %6
store i8 %27, i8* %28
br label %30
30: ; preds = %26
%31 = load i8, i8* %2
%32 = add i8 %31, 1
store i8 %32, i8* %2
br label %22
33: ; preds = %22
br label %34
34: ; preds = %39, %33
%35 = load i8*, i8** %5
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp ne i32 %37, 42
br i1 %38, label %39, label %41
39: ; preds = %34
%40 = call i32 @sleep(i32 1)
br label %34
41: ; preds = %34
%42 = 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 %7
5: ; preds = %0
%6 = tail call i32 @die(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = tail call i8* @shmat(i32 %3, i32* null, i32 0)
%9 = icmp eq i8* %8, inttoptr (i64 -1 to i8*)
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @die(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
%13 = getelementptr inbounds i8, i8* %8, i64 16
%14 = bitcast i8* %8 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>* %14
%15 = getelementptr inbounds i8, i8* %8, i64 17
store i8 113, i8* %13
%16 = getelementptr inbounds i8, i8* %8, i64 18
store i8 114, i8* %15
%17 = getelementptr inbounds i8, i8* %8, i64 19
store i8 115, i8* %16
%18 = getelementptr inbounds i8, i8* %8, i64 20
store i8 116, i8* %17
%19 = getelementptr inbounds i8, i8* %8, i64 21
store i8 117, i8* %18
%20 = getelementptr inbounds i8, i8* %8, i64 22
store i8 118, i8* %19
%21 = getelementptr inbounds i8, i8* %8, i64 23
store i8 119, i8* %20
%22 = getelementptr inbounds i8, i8* %8, i64 24
store i8 120, i8* %21
%23 = getelementptr inbounds i8, i8* %8, i64 25
store i8 121, i8* %22
store i8 122, i8* %23
%24 = load i8, i8* %8
%25 = icmp eq i8 %24, 42
br i1 %25, label %30, label %26
26: ; preds = %12, %26
%27 = tail call i32 @sleep(i32 1)
%28 = load i8, i8* %8
%29 = icmp eq i8 %28, 42
br i1 %29, label %30, label %26
30: ; preds = %26, %12
%31 = tail call i32 @exit(i32 0)
unreachable
}