#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 /*<<< orphan*/ mode_t;

/* Variables and functions */
char *alloca(int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int open_cloexec(char const *, int, int /*<<< orphan*/);
int strlen(char const *);
int shm_open(const char *path, int oflag, mode_t mode) {
  int len = strlen(path);
  char *pathbuf = alloca(len + 10);
  memcpy(pathbuf, "/dev/shm/", 9);
  memcpy(pathbuf + 9, path, len + 1);
  return open_cloexec(path, oflag, mode);
}


x86 assembly (clang, -O0):
<shm_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
add    $0xa,%edi
call   1040 <alloca@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe88(%rip),%rsi
mov    $0x9,%edx
call   1050 <memcpy@plt>
mov    -0x20(%rbp),%rdi
add    $0x9,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
add    $0x1,%edx
call   1050 <memcpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1060 <open_cloexec@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shm_open>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%r12
call   1030 <strlen@plt>
mov    %eax,%ebp
lea    0xa(%rbp),%edi
call   1040 <alloca@plt>
mov    %rax,%rbx
lea    0xe96(%rip),%rsi
mov    %rax,%rdi
mov    $0x9,%edx
call   1050 <memcpy@plt>
add    $0x9,%rbx
add    $0x1,%ebp
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
call   1050 <memcpy@plt>
mov    %r12,%rdi
mov    %r15d,%esi
mov    %r14d,%edx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <open_cloexec@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/shm/\00"
define i32 @shm_open(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = add nsw i32 %11, 10
%13 = call i8* @alloca(i32 %12)
store i8* %13, i8** %8
%14 = load i8*, i8** %8
%15 = call i32 @memcpy(i8* %14, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 9)
%16 = load i8*, i8** %8
%17 = getelementptr inbounds i8, i8* %16, i64 9
%18 = load i8*, i8** %4
%19 = load i32, i32* %7
%20 = add nsw i32 %19, 1
%21 = call i32 @memcpy(i8* %17, i8* %18, i32 %20)
%22 = load i8*, i8** %4
%23 = load i32, i32* %5
%24 = load i32, i32* %6
%25 = call i32 @open_cloexec(i8* %22, i32 %23, i32 %24)
ret i32 %25
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/shm/\00"
define i32 @shm_open(i8* %0, i32 %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = add nsw i32 %4, 10
%6 = tail call i8* @alloca(i32 %5)
%7 = tail call i32 @memcpy(i8* %6, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 9)
%8 = getelementptr inbounds i8, i8* %6, i64 9
%9 = add nsw i32 %4, 1
%10 = tail call i32 @memcpy(i8* %8, i8* %0, i32 %9)
%11 = tail call i32 @open_cloexec(i8* %0, i32 %1, i32 %2)
ret i32 %11
}