#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_EXCL;
int O_RDWR;
int S_IREAD;
int S_IWRITE;
int /*<<< orphan*/ printf(char *, char *);
int shm_open(char *, int, int);
int appmod_shm_open(char *appmod_shm_path) {
  int appmod_shm_fd = 0;
  if ((appmod_shm_fd = shm_open(appmod_shm_path, (O_CREAT | O_EXCL | O_RDWR),
                                (S_IREAD | S_IWRITE))) > 0) {
    printf("\n [*] Opened - %s first \n", appmod_shm_path);
  } else if ((appmod_shm_fd = shm_open(appmod_shm_path, (O_CREAT | O_RDWR),
                                       (S_IREAD | S_IWRITE))) < 0) {
    printf("\n [!] Unexpected SHM Error - %s\n", appmod_shm_path);
    return 0;
  }
  return appmod_shm_fd;
}


x86 assembly (clang, -O0):
<appmod_shm_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2eba(%rip),%rax
mov    (%rax),%esi
mov    0x2e81(%rip),%rax
or     (%rax),%esi
mov    0x2e90(%rip),%rax
or     (%rax),%esi
mov    0x2e67(%rip),%rax
mov    (%rax),%edx
mov    0x2e76(%rip),%rax
or     (%rax),%edx
call   1040 <shm_open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    118a <appmod_shm_open+0x6a>
mov    -0x10(%rbp),%rsi
lea    0xe80(%rip),%rdi
call   1030 <printf@plt>
jmp    11e4 <appmod_shm_open+0xc4>
mov    -0x10(%rbp),%rdi
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
mov    0x2e42(%rip),%rax
or     (%rax),%esi
mov    0x2e19(%rip),%rax
mov    (%rax),%edx
mov    0x2e28(%rip),%rax
or     (%rax),%edx
call   1040 <shm_open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11df <appmod_shm_open+0xbf>
mov    -0x10(%rbp),%rsi
lea    0xe4c(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ea <appmod_shm_open+0xca>
jmp    11e4 <appmod_shm_open+0xc4>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<appmod_shm_open>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2ec3(%rip),%r14
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
or     (%r14),%esi
mov    0x2e98(%rip),%r12
or     (%r12),%esi
mov    0x2e6d(%rip),%r15
mov    0x2e7e(%rip),%r13
mov    0x0(%r13),%edx
or     (%r15),%edx
call   1040 <shm_open@plt>
test   %eax,%eax
jle    117d <appmod_shm_open+0x5d>
mov    %eax,%ebp
lea    0xe8d(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
jmp    1199 <appmod_shm_open+0x79>
mov    (%r12),%esi
or     (%r14),%esi
mov    0x0(%r13),%edx
or     (%r15),%edx
mov    %rbx,%rdi
call   1040 <shm_open@plt>
mov    %eax,%ebp
test   %eax,%eax
js     11aa <appmod_shm_open+0x8a>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
lea    0xe67(%rip),%rdi
jmp    1173 <appmod_shm_open+0x53>

LLVM IR (-O0):
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@O_RDWR = global i32 0
@S_IREAD = global i32 0
@S_IWRITE = global i32 0
@.str = [26 x i8] c"\0A [*] Opened - %s first \0A\00"
@.str.1 = [33 x i8] c"\0A [!] Unexpected SHM Error - %s\0A\00"
define i32 @appmod_shm_open(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
%5 = load i8*, i8** %3
%6 = load i32, i32* @O_CREAT
%7 = load i32, i32* @O_EXCL
%8 = or i32 %6, %7
%9 = load i32, i32* @O_RDWR
%10 = or i32 %8, %9
%11 = load i32, i32* @S_IREAD
%12 = load i32, i32* @S_IWRITE
%13 = or i32 %11, %12
%14 = call i32 @shm_open(i8* %5, i32 %10, i32 %13)
store i32 %14, i32* %4
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %1
%17 = load i8*, i8** %3
%18 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %33
19: ; preds = %1
%20 = load i8*, i8** %3
%21 = load i32, i32* @O_CREAT
%22 = load i32, i32* @O_RDWR
%23 = or i32 %21, %22
%24 = load i32, i32* @S_IREAD
%25 = load i32, i32* @S_IWRITE
%26 = or i32 %24, %25
%27 = call i32 @shm_open(i8* %20, i32 %23, i32 %26)
store i32 %27, i32* %4
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %19
%30 = load i8*, i8** %3
%31 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %30)
store i32 0, i32* %2
br label %35
32: ; preds = %19
br label %33
33: ; preds = %32, %16
%34 = load i32, i32* %4
store i32 %34, i32* %2
br label %35
35: ; preds = %33, %29
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@O_RDWR = global i32 0
@S_IREAD = global i32 0
@S_IWRITE = global i32 0
@.str = [26 x i8] c"\0A [*] Opened - %s first \0A\00"
@.str.1 = [33 x i8] c"\0A [!] Unexpected SHM Error - %s\0A\00"
define i32 @appmod_shm_open(i8* %0) {
%2 = load i32, i32* @O_CREAT
%3 = load i32, i32* @O_EXCL
%4 = or i32 %3, %2
%5 = load i32, i32* @O_RDWR
%6 = or i32 %4, %5
%7 = load i32, i32* @S_IREAD
%8 = load i32, i32* @S_IWRITE
%9 = or i32 %8, %7
%10 = tail call i32 @shm_open(i8* %0, i32 %6, i32 %9)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %21, label %12
12: ; preds = %1
%13 = load i32, i32* @O_CREAT
%14 = load i32, i32* @O_RDWR
%15 = or i32 %14, %13
%16 = load i32, i32* @S_IREAD
%17 = load i32, i32* @S_IWRITE
%18 = or i32 %17, %16
%19 = tail call i32 @shm_open(i8* %0, i32 %15, i32 %18)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %12, %1
%22 = phi i8* [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), %12 ]
%23 = phi i32 [ %10, %1 ], [ 0, %12 ]
%24 = tail call i32 @printf(i8* %22, i8* %0)
br label %25
25: ; preds = %21, %12
%26 = phi i32 [ %19, %12 ], [ %23, %21 ]
ret i32 %26
}