#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 */

/* Variables and functions */
int /*<<< orphan*/ ePrintf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int mmGetId(char *, char);
char *shmat(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
char *mmGetPtr(char *path, char key) {
  char *shmptr;
  int shmid = mmGetId(path, key);
  shmptr = shmat(shmid, 0, 0);
  if (shmptr == (char *)-1) {
    ePrintf("ftok: %s\n", strerror(errno));
    return (char *)-1;
  }
  return shmptr;
}


x86 assembly (clang, -O0):
<mmGetPtr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rdi
movsbl -0x11(%rbp),%esi
call   1040 <mmGetId@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   1050 <shmat@plt>
mov    %rax,-0x20(%rbp)
mov    $0xffffffffffffffff,%rax
cmp    %rax,-0x20(%rbp)
jne    11af <mmGetPtr+0x6f>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %eax,%esi
lea    0xe66(%rip),%rdi
call   1030 <ePrintf@plt>
mov    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
jmp    11b7 <mmGetPtr+0x77>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mmGetPtr>:
push   %rbx
call   1040 <mmGetId@plt>
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <shmat@plt>
mov    %rax,%rbx
cmp    $0xffffffffffffffff,%rax
jne    1176 <mmGetPtr+0x36>
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe91(%rip),%rdi
mov    %eax,%esi
call   1030 <ePrintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"ftok: %s\0A\00"
@errno = global i32 0
define i8* @mmGetPtr(i8* %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i8 %1, i8* %5
%8 = load i8*, i8** %4
%9 = load i8, i8* %5
%10 = call i32 @mmGetId(i8* %8, i8 signext %9)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = call i8* @shmat(i32 %11, i32 0, i32 0)
store i8* %12, i8** %6
%13 = load i8*, i8** %6
%14 = icmp eq i8* %13, inttoptr (i64 -1 to i8*)
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i32, i32* @errno
%17 = call i32 @strerror(i32 %16)
%18 = call i32 @ePrintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %17)
store i8* inttoptr (i64 -1 to i8*), i8** %3
br label %21
19: ; preds = %2
%20 = load i8*, i8** %6
store i8* %20, i8** %3
br label %21
21: ; preds = %19, %15
%22 = load i8*, i8** %3
ret i8* %22
}

LLVM IR (-O2):
@.str = [10 x i8] c"ftok: %s\0A\00"
@errno = global i32 0
define i8* @mmGetPtr(i8* %0, i8 signext %1) {
%3 = tail call i32 @mmGetId(i8* %0, i8 signext %1)
%4 = tail call i8* @shmat(i32 %3, i32 0, i32 0)
%5 = icmp eq i8* %4, inttoptr (i64 -1 to i8*)
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @errno
%8 = tail call i32 @strerror(i32 %7)
%9 = tail call i32 @ePrintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %10
10: ; preds = %2, %6
ret i8* %4
}