#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 O_CREAT;
int O_RDWR;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ replace_char(char *, char, char);
int shm_open(char *, int, int);
int /*<<< orphan*/ strcpy(char *, char const *);
int create_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 | O_CREAT, S_IRUSR | S_IWUSR);
}


x86 assembly (clang, -O0):
<create_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    0x2e62(%rip),%rax
mov    (%rax),%esi
mov    0x2e71(%rip),%rax
or     (%rax),%esi
mov    0x2e38(%rip),%rax
mov    (%rax),%edx
mov    0x2e3f(%rip),%rax
or     (%rax),%edx
call   1050 <shm_open@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_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    0x2e7b(%rip),%rax
mov    0x2e8c(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e51(%rip),%rax
mov    0x2e5a(%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
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
define i32 @create_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* @O_CREAT
%14 = or i32 %12, %13
%15 = load i32, i32* @S_IRUSR
%16 = load i32, i32* @S_IWUSR
%17 = or i32 %15, %16
%18 = call i32 @shm_open(i8* %11, i32 %14, i32 %17)
ret i32 %18
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
define i32 @create_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* @O_CREAT
%9 = or i32 %8, %7
%10 = load i32, i32* @S_IRUSR
%11 = load i32, i32* @S_IWUSR
%12 = or i32 %11, %10
%13 = call i32 @shm_open(i8* %3, i32 %9, i32 %12)
ret i32 %13
}