#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 */
char *GetShm(int, int, int);
int IPC_CREAT;
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int GetShm2(void **pstShm, int iShmID, int iSize, int iFlag) {
  char *sShm;
  if (!(sShm = GetShm(iShmID, iSize, iFlag & (~IPC_CREAT)))) {
    if (!(iFlag & IPC_CREAT))
      return -1;
    if (!(sShm = GetShm(iShmID, iSize, iFlag)))
      return -1;
    memset(sShm, 0, iSize);
  }
  *pstShm = sShm;
  return 0;
}


x86 assembly (clang, -O0):
<GetShm2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    0x2e9b(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    %eax,%edx
call   1040 <GetShm@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11b6 <GetShm2+0x96>
mov    -0x1c(%rbp),%eax
mov    0x2e77(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    1180 <GetShm2+0x60>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c8 <GetShm2+0xa8>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1040 <GetShm@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11a8 <GetShm2+0x88>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c8 <GetShm2+0xa8>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetShm2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %esi,%r12d
mov    %rdi,%rbx
mov    0x2ea2(%rip),%r13
mov    0x0(%r13),%edx
not    %edx
and    %ecx,%edx
mov    %esi,%edi
mov    %r15d,%esi
call   1040 <GetShm@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1189 <GetShm2+0x69>
mov    %r13,%rax
mov    $0xffffffff,%r13d
test   %r14d,(%rax)
je     118f <GetShm2+0x6f>
mov    %r12d,%edi
mov    %r15d,%esi
mov    %r14d,%edx
call   1040 <GetShm@plt>
test   %rax,%rax
je     118f <GetShm2+0x6f>
mov    %rax,%rbp
mov    %rax,%rdi
xor    %esi,%esi
mov    %r15d,%edx
call   1030 <memset@plt>
mov    %rbp,(%rbx)
xor    %r13d,%r13d
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@IPC_CREAT = global i32 0
define i32 @GetShm2(i8** %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i8** %0, i8*** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%11 = load i32, i32* %7
%12 = load i32, i32* %8
%13 = load i32, i32* %9
%14 = load i32, i32* @IPC_CREAT
%15 = xor i32 %14, -1
%16 = and i32 %13, %15
%17 = call i8* @GetShm(i32 %11, i32 %12, i32 %16)
store i8* %17, i8** %10
%18 = icmp ne i8* %17, null
br i1 %18, label %36, label %19
19: ; preds = %4
%20 = load i32, i32* %9
%21 = load i32, i32* @IPC_CREAT
%22 = and i32 %20, %21
%23 = icmp ne i32 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %19
store i32 -1, i32* %5
br label %39
25: ; preds = %19
%26 = load i32, i32* %7
%27 = load i32, i32* %8
%28 = load i32, i32* %9
%29 = call i8* @GetShm(i32 %26, i32 %27, i32 %28)
store i8* %29, i8** %10
%30 = icmp ne i8* %29, null
br i1 %30, label %32, label %31
31: ; preds = %25
store i32 -1, i32* %5
br label %39
32: ; preds = %25
%33 = load i8*, i8** %10
%34 = load i32, i32* %8
%35 = call i32 @memset(i8* %33, i32 0, i32 %34)
br label %36
36: ; preds = %32, %4
%37 = load i8*, i8** %10
%38 = load i8**, i8*** %6
store i8* %37, i8** %38
store i32 0, i32* %5
br label %39
39: ; preds = %36, %31, %24
%40 = load i32, i32* %5
ret i32 %40
}

LLVM IR (-O2):
@IPC_CREAT = global i32 0
define i32 @GetShm2(i8** nocapture writeonly %0, i32 %1, i32 %2, i32 %3) {
%5 = load i32, i32* @IPC_CREAT
%6 = xor i32 %5, -1
%7 = and i32 %6, %3
%8 = tail call i8* @GetShm(i32 %1, i32 %2, i32 %7)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %19
10: ; preds = %4
%11 = load i32, i32* @IPC_CREAT
%12 = and i32 %11, %3
%13 = icmp eq i32 %12, 0
br i1 %13, label %21, label %14
14: ; preds = %10
%15 = tail call i8* @GetShm(i32 %1, i32 %2, i32 %3)
%16 = icmp eq i8* %15, null
br i1 %16, label %21, label %17
17: ; preds = %14
%18 = tail call i32 @memset(i8* %15, i32 0, i32 %2)
br label %19
19: ; preds = %17, %4
%20 = phi i8* [ %8, %4 ], [ %15, %17 ]
store i8* %20, i8** %0
br label %21
21: ; preds = %14, %10, %19
%22 = phi i32 [ 0, %19 ], [ -1, %10 ], [ -1, %14 ]
ret i32 %22
}