#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
scalar_t__ shmat(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int shmget(int, int, int);
void client() {
  key_t key;
  int shmid = 0;
  char *addr = NULL;
  int i = 0;
  key = 75;
  if ((shmid = shmget(key, 1024, 0777)) == -1) {
    perror("client shmget error");
    exit(1);
  }
  if ((addr = (char *)shmat(shmid, NULL, 0)) == (char *)-1) {
    perror("client shmid error");
    exit(1);
  }
  *addr = 'b';
  for (i = 0; i < 5; i++) {
    while (*addr != 'b')
      ;
    *addr = 'a';
  }
}


x86 assembly (clang, -O0):
<client>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x4b,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x400,%esi
mov    $0x1ff,%edx
call   1050 <shmget@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    1199 <client+0x59>
lea    0xe76(%rip),%rdi
call   1030 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <shmat@plt>
mov    %rax,-0x10(%rbp)
mov    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jne    11d1 <client+0x91>
lea    0xe52(%rip),%rdi
call   1030 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
movb   $0x62,(%rax)
movl   $0x0,-0x14(%rbp)
cmpl   $0x5,-0x14(%rbp)
jge    1218 <client+0xd8>
jmp    11ee <client+0xae>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x62,%eax
je     1203 <client+0xc3>
jmp    11ee <client+0xae>
mov    -0x10(%rbp),%rax
movb   $0x61,(%rax)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11df <client+0x9f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<client>:
push   %rax
mov    $0x4b,%edi
mov    $0x400,%esi
mov    $0x1ff,%edx
call   1050 <shmget@plt>
cmp    $0xffffffff,%eax
je     1172 <client+0x32>
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <shmat@plt>
cmp    $0xffffffffffffffff,%rax
je     117b <client+0x3b>
movb   $0x61,(%rax)
xchg   %ax,%ax
jmp    1170 <client+0x30>
lea    0xe87(%rip),%rdi
jmp    1182 <client+0x42>
lea    0xe92(%rip),%rdi
call   1030 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"client shmget error\00"
@.str.1 = [19 x i8] c"client shmid error\00"
define void @client() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i32 0, i32* %2
store i8* null, i8** %3
store i32 0, i32* %4
store i32 75, i32* %1
%5 = load i32, i32* %1
%6 = call i32 @shmget(i32 %5, i32 1024, i32 511)
store i32 %6, i32* %2
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = load i32, i32* %2
%13 = call i64 @shmat(i32 %12, i32* null, i32 0)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %3
%15 = icmp eq i8* %14, inttoptr (i64 -1 to i8*)
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %11
%20 = load i8*, i8** %3
store i8 98, i8* %20
store i32 0, i32* %4
br label %21
21: ; preds = %33, %19
%22 = load i32, i32* %4
%23 = icmp slt i32 %22, 5
br i1 %23, label %24, label %36
24: ; preds = %21
br label %25
25: ; preds = %30, %24
%26 = load i8*, i8** %3
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 98
br i1 %29, label %30, label %31
30: ; preds = %25
br label %25
31: ; preds = %25
%32 = load i8*, i8** %3
store i8 97, i8* %32
br label %33
33: ; preds = %31
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 1
store i32 %35, i32* %4
br label %21
36: ; preds = %21
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"client shmget error\00"
@.str.1 = [19 x i8] c"client shmid error\00"
define void @client() {
%1 = tail call i32 @shmget(i32 75, i32 1024, i32 511)
%2 = icmp eq i32 %1, -1
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @exit(i32 1)
unreachable
6: ; preds = %0
%7 = tail call i64 @shmat(i32 %1, i32* null, i32 0)
%8 = inttoptr i64 %7 to i8*
%9 = icmp eq i8* %8, inttoptr (i64 -1 to i8*)
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %6
store i8 97, i8* %8
br label %14
14: ; preds = %13, %14
br label %14
}