#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;
char *shmat(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int shmget(int, int, int);
int shm_wr() {
  char c;
  int shmid;
  key_t key;
  char *shm, *s;
  key = 0x01122;
  if ((shmid = shmget(key, 27, IPC_CREAT | 0666)) < 0) {
    return -1;
  }
  if ((shm = shmat(shmid, NULL, 0)) == (char *)-1) {
    return -2;
  }
  s = shm;
  for (c = 'a'; c <= 'z'; c++)
    *s++ = c;
  s = NULL;
  return 0;
}


x86 assembly (clang, -O0):
<shm_wr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x1122,-0x10(%rbp)
mov    -0x10(%rbp),%edi
mov    0x2ea7(%rip),%rax
mov    (%rax),%edx
or     $0x1b6,%edx
mov    $0x1b,%esi
call   1040 <shmget@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    1163 <shm_wr+0x43>
movl   $0xffffffff,-0x4(%rbp)
jmp    11da <shm_wr+0xba>
mov    -0xc(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1030 <shmat@plt>
mov    %rax,-0x18(%rbp)
mov    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jne    1191 <shm_wr+0x71>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11da <shm_wr+0xba>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
movb   $0x61,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0x7a,%eax
jg     11cb <shm_wr+0xab>
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    119d <shm_wr+0x7d>
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shm_wr>:
push   %rbx
mov    0x2eb8(%rip),%rax
mov    $0x1b6,%edx
or     (%rax),%edx
mov    $0x1122,%edi
mov    $0x1b,%esi
call   1040 <shmget@plt>
test   %eax,%eax
js     1175 <shm_wr+0x55>
xor    %ebx,%ebx
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1030 <shmat@plt>
cmp    $0xffffffffffffffff,%rax
je     117c <shm_wr+0x5c>
movaps 0xea4(%rip),%xmm0
movups %xmm0,(%rax)
movabs $0x7877767574737271,%rcx
76 77 78
mov    %rcx,0x10(%rax)
movw   $0x7a79,0x18(%rax)
jmp    1181 <shm_wr+0x61>
mov    $0xffffffff,%ebx
jmp    1181 <shm_wr+0x61>
mov    $0xfffffffe,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@IPC_CREAT = global i32 0
define i32 @shm_wr() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
store i32 4386, 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 %13
12: ; preds = %0
store i32 -1, i32* %1
br label %32
13: ; preds = %0
%14 = load i32, i32* %3
%15 = call i8* @shmat(i32 %14, i32* null, i32 0)
store i8* %15, i8** %5
%16 = icmp eq i8* %15, inttoptr (i64 -1 to i8*)
br i1 %16, label %17, label %18
17: ; preds = %13
store i32 -2, i32* %1
br label %32
18: ; preds = %13
%19 = load i8*, i8** %5
store i8* %19, i8** %6
store i8 97, i8* %2
br label %20
20: ; preds = %28, %18
%21 = load i8, i8* %2
%22 = sext i8 %21 to i32
%23 = icmp sle i32 %22, 122
br i1 %23, label %24, label %31
24: ; preds = %20
%25 = load i8, i8* %2
%26 = load i8*, i8** %6
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %6
store i8 %25, i8* %26
br label %28
28: ; preds = %24
%29 = load i8, i8* %2
%30 = add i8 %29, 1
store i8 %30, i8* %2
br label %20
31: ; preds = %20
store i8* null, i8** %6
store i32 0, i32* %1
br label %32
32: ; preds = %31, %17, %12
%33 = load i32, i32* %1
ret i32 %33
}

LLVM IR (-O2):
@IPC_CREAT = global i32 0
define i32 @shm_wr() {
%1 = load i32, i32* @IPC_CREAT
%2 = or i32 %1, 438
%3 = tail call i32 @shmget(i32 4386, i32 27, i32 %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %20, label %5
5: ; preds = %0
%6 = tail call i8* @shmat(i32 %3, i32* null, i32 0)
%7 = icmp eq i8* %6, inttoptr (i64 -1 to i8*)
br i1 %7, label %20, label %8
8: ; preds = %5
%9 = getelementptr inbounds i8, i8* %6, i64 16
%10 = bitcast i8* %6 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>* %10
%11 = getelementptr inbounds i8, i8* %6, i64 17
store i8 113, i8* %9
%12 = getelementptr inbounds i8, i8* %6, i64 18
store i8 114, i8* %11
%13 = getelementptr inbounds i8, i8* %6, i64 19
store i8 115, i8* %12
%14 = getelementptr inbounds i8, i8* %6, i64 20
store i8 116, i8* %13
%15 = getelementptr inbounds i8, i8* %6, i64 21
store i8 117, i8* %14
%16 = getelementptr inbounds i8, i8* %6, i64 22
store i8 118, i8* %15
%17 = getelementptr inbounds i8, i8* %6, i64 23
store i8 119, i8* %16
%18 = getelementptr inbounds i8, i8* %6, i64 24
store i8 120, i8* %17
%19 = getelementptr inbounds i8, i8* %6, i64 25
store i8 121, i8* %18
store i8 122, i8* %19
br label %20
20: ; preds = %8, %5, %0
%21 = phi i32 [ -1, %0 ], [ -2, %5 ], [ 0, %8 ]
ret i32 %21
}