#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 EXIT_SUCCESS;
int IPC_CREAT;
int /*<<< orphan*/ IPC_RMID;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
char *shmat(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ shmctl(int, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ shmdt(char *);
int shmget(int, int, int);
int /*<<< orphan*/ sleep(int);
int main() {
  char c;
  int shmid;
  key_t key;
  char *shm, *s;
  key = 5679;
  if ((shmid = shmget(key, 27, IPC_CREAT | 0700)) < 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);
  if (shmdt(shm) < 0) {
    perror("shmdt");
    exit(1);
  }
  if (shmctl(shmid, IPC_RMID, 0) < 0) {
    perror("shmctl");
    exit(1);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x162f,-0x10(%rbp)
mov    -0x10(%rbp),%edi
mov    0x2e40(%rip),%rax
mov    (%rax),%edx
or     $0x1c0,%edx
mov    $0x1b,%esi
call   1070 <shmget@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    11c4 <main+0x54>
lea    0xe4b(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%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)
mov    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jne    11fc <main+0x8c>
lea    0xe1a(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
movb   $0x61,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0x7a,%eax
jg     1236 <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    1208 <main+0x98>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2a,%eax
je     125c <main+0xec>
mov    $0x1,%edi
call   1090 <sleep@plt>
jmp    123d <main+0xcd>
mov    -0x18(%rbp),%rdi
call   1030 <shmdt@plt>
cmp    $0x0,%rax
jge    1285 <main+0x115>
lea    0xd97(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0xc(%rbp),%edi
mov    0x2d51(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <shmctl@plt>
cmp    $0x0,%rax
jge    12b8 <main+0x148>
lea    0xd6a(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2d19(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e56(%rip),%rax
mov    $0x1c0,%edx
or     (%rax),%edx
mov    $0x162f,%edi
mov    $0x1b,%esi
call   1070 <shmget@plt>
test   %eax,%eax
js     1223 <main+0xb3>
mov    %eax,%ebp
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <shmat@plt>
cmp    $0xffffffffffffffff,%rax
je     122c <main+0xbc>
mov    %rax,%rbx
movaps 0xe47(%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     11ef <main+0x7f>
nopl   0x0(%rax)
mov    $0x1,%edi
call   1090 <sleep@plt>
cmpb   $0x2a,(%rbx)
jne    11e0 <main+0x70>
mov    %rbx,%rdi
call   1030 <shmdt@plt>
test   %rax,%rax
js     1235 <main+0xc5>
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1040 <shmctl@plt>
test   %rax,%rax
js     123e <main+0xce>
mov    0x2dbe(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xde6(%rip),%rdi
jmp    1245 <main+0xd5>
lea    0xde4(%rip),%rdi
jmp    1245 <main+0xd5>
lea    0xde1(%rip),%rdi
jmp    1245 <main+0xd5>
lea    0xdde(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1080 <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"
@.str.2 = [6 x i8] c"shmdt\00"
@IPC_RMID = global i32 0
@.str.3 = [7 x i8] c"shmctl\00"
@EXIT_SUCCESS = global i32 0
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 5679, i32* %4
%7 = load i32, i32* %4
%8 = load i32, i32* @IPC_CREAT
%9 = or i32 %8, 448
%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 = load i8*, i8** %5
%46 = call i64 @shmdt(i8* %45)
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %44
%49 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %44
%52 = load i32, i32* %3
%53 = load i32, i32* @IPC_RMID
%54 = call i64 @shmctl(i32 %52, i32 %53, i32 0)
%55 = icmp slt i64 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %51
%57 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %51
%60 = load i32, i32* @EXIT_SUCCESS
ret i32 %60
}

LLVM IR (-O2):
@IPC_CREAT = global i32 0
@.str = [7 x i8] c"shmget\00"
@.str.1 = [6 x i8] c"shmat\00"
@.str.2 = [6 x i8] c"shmdt\00"
@IPC_RMID = global i32 0
@.str.3 = [7 x i8] c"shmctl\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = load i32, i32* @IPC_CREAT
%2 = or i32 %1, 448
%3 = tail call i32 @shmget(i32 5679, 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 i64 @shmdt(i8* %9)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%38 = tail call i32 @exit(i32 1)
unreachable
39: ; preds = %33
%40 = load i32, i32* @IPC_RMID
%41 = tail call i64 @shmctl(i32 %3, i32 %40, i32 0)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %39
%44 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%45 = tail call i32 @exit(i32 1)
unreachable
46: ; preds = %39
%47 = load i32, i32* @EXIT_SUCCESS
ret i32 %47
}