#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*/ assert(int);
scalar_t__ close(int);
int shm_open(char *, int, int);
scalar_t__ shm_unlink(char *);
int /*<<< orphan*/ sleep(int);
int main() {
  int fd;
  assert((fd = shm_open(("/linuxquestions.org"), O_RDWR | O_CREAT,
                        S_IRUSR | S_IWUSR)) >= 0);
  sleep(30);
  assert(close(fd) == 0);
  assert(shm_unlink(("/linuxquestions.org")) == 0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
mov    0x2e89(%rip),%rax
or     (%rax),%esi
mov    0x2e50(%rip),%rax
mov    (%rax),%edx
mov    0x2e57(%rip),%rax
or     (%rax),%edx
lea    0xe76(%rip),%rdi
call   1050 <shm_open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    $0x1e,%edi
call   1070 <sleep@plt>
mov    -0x8(%rbp),%edi
call   1030 <close@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xe34(%rip),%rdi
call   1060 <shm_unlink@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e86(%rip),%rax
mov    0x2e97(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e5c(%rip),%rax
mov    0x2e65(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xe82(%rip),%rbx
mov    %rbx,%rdi
call   1050 <shm_open@plt>
mov    %eax,%ebp
mov    %eax,%edi
not    %edi
shr    $0x1f,%edi
call   1040 <assert@plt>
mov    $0x1e,%edi
call   1070 <sleep@plt>
mov    %ebp,%edi
call   1030 <close@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1040 <assert@plt>
mov    %rbx,%rdi
call   1060 <shm_unlink@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1040 <assert@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"/linuxquestions.org\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = load i32, i32* @O_RDWR
%4 = load i32, i32* @O_CREAT
%5 = or i32 %3, %4
%6 = load i32, i32* @S_IRUSR
%7 = load i32, i32* @S_IWUSR
%8 = or i32 %6, %7
%9 = call i32 @shm_open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %8)
store i32 %9, i32* %2
%10 = icmp sge i32 %9, 0
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = call i32 @sleep(i32 30)
%14 = load i32, i32* %2
%15 = call i64 @close(i32 %14)
%16 = icmp eq i64 %15, 0
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = call i64 @shm_unlink(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"/linuxquestions.org\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
define i32 @main() {
%1 = load i32, i32* @O_RDWR
%2 = load i32, i32* @O_CREAT
%3 = or i32 %2, %1
%4 = load i32, i32* @S_IRUSR
%5 = load i32, i32* @S_IWUSR
%6 = or i32 %5, %4
%7 = tail call i32 @shm_open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %6)
%8 = xor i32 %7, -1
%9 = lshr i32 %8, 31
%10 = tail call i32 @assert(i32 %9)
%11 = tail call i32 @sleep(i32 30)
%12 = tail call i64 @close(i32 %7)
%13 = icmp eq i64 %12, 0
%14 = zext i1 %13 to i32
%15 = tail call i32 @assert(i32 %14)
%16 = tail call i64 @shm_unlink(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
%18 = zext i1 %17 to i32
%19 = tail call i32 @assert(i32 %18)
ret i32 0
}