#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*/ O_RDWR;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ replace_char(char *, char, char);
int shm_open(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strcpy(char *, char const *);
int open_shared_memory(const char *name) {
  char mem_name[255];
  mem_name[0] = '/';
  strcpy(mem_name + 1, name);
  replace_char(mem_name, '/', '_');
  return shm_open(mem_name, O_RDWR, S_IRUSR | S_IWUSR);
}


x86 assembly (clang, -O0):
<open_shared_memory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x2f,-0x110(%rbp)
lea    -0x110(%rbp),%rdi
add    $0x1,%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x110(%rbp),%rdi
mov    $0x2f,%esi
mov    $0x5f,%edx
call   1040 <replace_char@plt>
lea    -0x110(%rbp),%rdi
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
mov    0x2e49(%rip),%rax
mov    (%rax),%edx
mov    0x2e50(%rip),%rax
or     (%rax),%edx
call   1050 <shm_open@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_shared_memory>:
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%rsi
movb   $0x2f,(%rsp)
lea    0x1(%rsp),%rdi
call   1030 <strcpy@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x2f,%esi
mov    $0x5f,%edx
call   1040 <replace_char@plt>
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
mov    0x2e62(%rip),%rax
mov    0x2e6b(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    %rbx,%rdi
call   1050 <shm_open@plt>
add    $0x100,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
define i32 @open_shared_memory(i8* %0) {
%2 = alloca i8*
%3 = alloca [255 x i8]
store i8* %0, i8** %2
%4 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
store i8 47, i8* %4
%5 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds i8, i8* %5, i64 1
%7 = load i8*, i8** %2
%8 = call i32 @strcpy(i8* %6, i8* %7)
%9 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%10 = call i32 @replace_char(i8* %9, i8 signext 47, i8 signext 95)
%11 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%12 = load i32, i32* @O_RDWR
%13 = load i32, i32* @S_IRUSR
%14 = load i32, i32* @S_IWUSR
%15 = or i32 %13, %14
%16 = call i32 @shm_open(i8* %11, i32 %12, i32 %15)
ret i32 %16
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
define i32 @open_shared_memory(i8* %0) {
%2 = alloca [255 x i8]
%3 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
store i8 47, i8* %3
%4 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 1
%5 = call i32 @strcpy(i8* %4, i8* %0)
%6 = call i32 @replace_char(i8* %3, i8 signext 47, i8 signext 95)
%7 = load i32, i32* @O_RDWR
%8 = load i32, i32* @S_IRUSR
%9 = load i32, i32* @S_IWUSR
%10 = or i32 %9, %8
%11 = call i32 @shm_open(i8* %3, i32 %7, i32 %10)
ret i32 %11
}