void mainmemc() {
  int shmid2;
  int shmid;
  int semid = semget(0XA, 0, 0);
  shmid = shmget(0XA, 0, 0);
  char *c;
  int *contador;
  char *aux;
  int *aux2;
  c = (char *)shmat(shmid, 0, 0);
  contador = (int *)shmat(shmid2, 0, 0);
  aux = c;
  aux2 = 5;
  P(semid, 1);
  V(semid, 0);
  int sale = 0;
  while (*contador == 0) {
    P(semid, 1);
    printf("%c", c[sale]);
    *contador = *contador - 1;
    V(semid, 0);
  }
  shmdt(aux);
  shmdt(aux2);
}


x86 assembly (clang, -O0):
<mainmemc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    $0xa,%edi
xor    %edx,%edx
mov    %edx,%esi
mov    $0x0,%al
call   1030 <semget@plt>
mov    %eax,-0xc(%rbp)
mov    $0xa,%edi
xor    %edx,%edx
mov    %edx,%esi
mov    $0x0,%al
call   1090 <shmget@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
mov    $0x0,%al
call   1080 <shmat@plt>
cltq
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
mov    $0x0,%al
call   1080 <shmat@plt>
cltq
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    $0x5,%eax
mov    %rax,-0x30(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x1,%esi
mov    $0x0,%al
call   1040 <P@plt>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
mov    $0x0,%al
call   1050 <V@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
jne    124f <mainmemc+0xdf>
mov    -0xc(%rbp),%edi
mov    $0x1,%esi
mov    $0x0,%al
call   1040 <P@plt>
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
sub    $0x1,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0xc(%rbp),%edi
xor    %esi,%esi
mov    $0x0,%al
call   1050 <V@plt>
jmp    11f9 <mainmemc+0x89>
mov    -0x28(%rbp),%rdi
mov    $0x0,%al
call   1060 <shmdt@plt>
mov    -0x30(%rbp),%rdi
mov    $0x0,%al
call   1060 <shmdt@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mainmemc>:
push   %rbp
push   %r14
push   %rbx
mov    $0xa,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1030 <semget@plt>
mov    %eax,%ebp
mov    $0xa,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1090 <shmget@plt>
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1080 <shmat@plt>
movslq %eax,%r14
xor    %esi,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1080 <shmat@plt>
movslq %eax,%rbx
mov    %ebp,%edi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <P@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1060 <V@plt>
cmpl   $0x0,(%rbx)
jne    11fc <mainmemc+0x8c>
mov    %ebp,%edi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <P@plt>
movsbl (%r14),%edi
call   1040 <putchar@plt>
addl   $0xffffffff,(%rbx)
jmp    11d0 <mainmemc+0x60>
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <shmdt@plt>
mov    $0x5,%edi
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1070 <shmdt@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
define void @mainmemc() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = call i32 (i32, i32, i32, ...) bitcast (i32 (...)* @semget to i32 (i32, i32, i32, ...)*)(i32 10, i32 0, i32 0)
store i32 %9, i32* %3
%10 = call i32 (i32, i32, i32, ...) bitcast (i32 (...)* @shmget to i32 (i32, i32, i32, ...)*)(i32 10, i32 0, i32 0)
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = call i32 (i32, i32, i32, ...) bitcast (i32 (...)* @shmat to i32 (i32, i32, i32, ...)*)(i32 %11, i32 0, i32 0)
%13 = sext i32 %12 to i64
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %4
%15 = load i32, i32* %1
%16 = call i32 (i32, i32, i32, ...) bitcast (i32 (...)* @shmat to i32 (i32, i32, i32, ...)*)(i32 %15, i32 0, i32 0)
%17 = sext i32 %16 to i64
%18 = inttoptr i64 %17 to i32*
store i32* %18, i32** %5
%19 = load i8*, i8** %4
store i8* %19, i8** %6
store i32* inttoptr (i64 5 to i32*), i32** %7
%20 = load i32, i32* %3
%21 = call i32 (i32, i32, ...) bitcast (i32 (...)* @P to i32 (i32, i32, ...)*)(i32 %20, i32 1)
%22 = load i32, i32* %3
%23 = call i32 (i32, i32, ...) bitcast (i32 (...)* @V to i32 (i32, i32, ...)*)(i32 %22, i32 0)
store i32 0, i32* %8
br label %24
24: ; preds = %28, %0
%25 = load i32*, i32** %5
%26 = load i32, i32* %25
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %44
28: ; preds = %24
%29 = load i32, i32* %3
%30 = call i32 (i32, i32, ...) bitcast (i32 (...)* @P to i32 (i32, i32, ...)*)(i32 %29, i32 1)
%31 = load i8*, i8** %4
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %36)
%38 = load i32*, i32** %5
%39 = load i32, i32* %38
%40 = sub nsw i32 %39, 1
%41 = load i32*, i32** %5
store i32 %40, i32* %41
%42 = load i32, i32* %3
%43 = call i32 (i32, i32, ...) bitcast (i32 (...)* @V to i32 (i32, i32, ...)*)(i32 %42, i32 0)
br label %24
44: ; preds = %24
%45 = load i8*, i8** %6
%46 = call i32 (i8*, ...) bitcast (i32 (...)* @shmdt to i32 (i8*, ...)*)(i8* %45)
%47 = load i32*, i32** %7
%48 = call i32 (i32*, ...) bitcast (i32 (...)* @shmdt to i32 (i32*, ...)*)(i32* %47)
ret void
}

LLVM IR (-O2):
define void @mainmemc() {
%1 = tail call i32 (i32, i32, i32, ...) bitcast (i32 (...)* @semget to i32 (i32, i32, i32, ...)*)(i32 10, i32 0, i32 0)
%2 = tail call i32 (i32, i32, i32, ...) bitcast (i32 (...)* @shmget to i32 (i32, i32, i32, ...)*)(i32 10, i32 0, i32 0)
%3 = tail call i32 (i32, i32, i32, ...) bitcast (i32 (...)* @shmat to i32 (i32, i32, i32, ...)*)(i32 %2, i32 0, i32 0)
%4 = sext i32 %3 to i64
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 (i32, i32, i32, ...) bitcast (i32 (...)* @shmat to i32 (i32, i32, i32, ...)*)(i32 undef, i32 0, i32 0)
%7 = sext i32 %6 to i64
%8 = inttoptr i64 %7 to i32*
%9 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @P to i32 (i32, i32, ...)*)(i32 %1, i32 1)
%10 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @V to i32 (i32, i32, ...)*)(i32 %1, i32 0)
%11 = load i32, i32* %8
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %23
13: ; preds = %0, %13
%14 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @P to i32 (i32, i32, ...)*)(i32 %1, i32 1)
%15 = load i8, i8* %5
%16 = sext i8 %15 to i32
%17 = tail call i32 @putchar(i32 %16)
%18 = load i32, i32* %8
%19 = add nsw i32 %18, -1
store i32 %19, i32* %8
%20 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @V to i32 (i32, i32, ...)*)(i32 %1, i32 0)
%21 = load i32, i32* %8
%22 = icmp eq i32 %21, 0
br i1 %22, label %13, label %23
23: ; preds = %13, %0
%24 = tail call i32 (i8*, ...) bitcast (i32 (...)* @shmdt to i32 (i8*, ...)*)(i8* %5)
%25 = tail call i32 (i32*, ...) bitcast (i32 (...)* @shmdt to i32 (i32*, ...)*)(i32* inttoptr (i64 5 to i32*))
ret void
}