#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 */
scalar_t__ ENAMETOOLONG;
int /*<<< orphan*/ _PC_NAME_MAX;
int /*<<< orphan*/ _SC_VERSION;
scalar_t__ errno;
char *malloc(long);
long pathconf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int shm_unlink(char *);
long sysconf(int /*<<< orphan*/);
int main(void) {
  int result, i;
  long name_max;
  char *shm_name;
  name_max = pathconf("/", _PC_NAME_MAX);
  shm_name = malloc(name_max + 3);
  shm_name[0] = '/';
  for (i = 1; i < name_max + 2; i++)
    shm_name[i] = 'a';
  shm_name[name_max + 2] = 0;
  result = shm_unlink(shm_name);
  if (result == -1 && errno == ENAMETOOLONG) {
    printf("Test PASSED\n");
    return 0;
  } else if (result != -1) {
    printf("FAILED: shm_unlink() succeeded\n");
    return 1;
  }
  if (sysconf(_SC_VERSION) >= 200800L) {
    printf("UNTESTED: shm_open() did not fail with ENAMETOLONG\n");
    return 5;
  }
  perror("FAILED: shm_unlink");
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
lea    0xe81(%rip),%rdi
call   1030 <pathconf@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x3,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x2f,(%rax)
movl   $0x1,-0xc(%rbp)
movslq -0xc(%rbp),%rax
mov    -0x18(%rbp),%rcx
add    $0x2,%rcx
cmp    %rcx,%rax
jge    11d6 <main+0x76>
mov    -0x20(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x61,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11a7 <main+0x47>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,0x2(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
call   1080 <shm_unlink@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    122b <main+0xcb>
mov    0x2dd8(%rip),%rax
mov    (%rax),%rax
mov    0x2dc6(%rip),%rcx
cmp    (%rcx),%rax
jne    122b <main+0xcb>
lea    0xde8(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1297 <main+0x137>
cmpl   $0xffffffff,-0x8(%rbp)
je     124d <main+0xed>
lea    0xdd3(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1297 <main+0x137>
jmp    1252 <main+0xf2>
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
cmp    $0x31060,%rax
jl     1284 <main+0x124>
lea    0xdbc(%rip),%rdi
call   1040 <printf@plt>
movl   $0x5,-0x4(%rbp)
jmp    1297 <main+0x137>
lea    0xdd8(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
lea    0xe7b(%rip),%rdi
call   1040 <pathconf@plt>
mov    %rax,%rbx
lea    0x3(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,%r14
movb   $0x2f,(%rax)
lea    0x2(%rbx),%r15
test   %rbx,%rbx
js     11c7 <main+0x57>
mov    %r14,%rdi
add    $0x1,%rdi
cmp    $0x3,%r15
mov    $0x2,%edx
cmovge %r15,%rdx
add    $0xffffffffffffffff,%rdx
mov    $0x61,%esi
call   1050 <memset@plt>
movb   $0x0,(%r14,%r15,1)
mov    %r14,%rdi
call   1090 <shm_unlink@plt>
cmp    $0xffffffff,%eax
je     11ec <main+0x7c>
lea    0xe68(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
jmp    1239 <main+0xc9>
mov    0x2de5(%rip),%rax
mov    (%rax),%rax
mov    0x2dd3(%rip),%rcx
cmp    (%rcx),%rax
jne    1212 <main+0xa2>
lea    0xe5e(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    1239 <main+0xc9>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
call   1080 <sysconf@plt>
cmp    $0x31060,%rax
jl     123f <main+0xcf>
lea    0xde6(%rip),%rdi
call   1030 <puts@plt>
mov    $0x5,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdbc(%rip),%rdi
call   1070 <perror@plt>
jmp    11e5 <main+0x75>

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@_PC_NAME_MAX = global i32 0
@errno = global i64 0
@ENAMETOOLONG = global i64 0
@.str.1 = [13 x i8] c"Test PASSED\0A\00"
@.str.2 = [32 x i8] c"FAILED: shm_unlink() succeeded\0A\00"
@_SC_VERSION = global i32 0
@.str.3 = [52 x i8] c"UNTESTED: shm_open() did not fail with ENAMETOLONG\0A\00"
@.str.4 = [19 x i8] c"FAILED: shm_unlink\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
%5 = alloca i8*
store i32 0, i32* %1
%6 = load i32, i32* @_PC_NAME_MAX
%7 = call i64 @pathconf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %6)
store i64 %7, i64* %4
%8 = load i64, i64* %4
%9 = add nsw i64 %8, 3
%10 = call i8* @malloc(i64 %9)
store i8* %10, i8** %5
%11 = load i8*, i8** %5
%12 = getelementptr inbounds i8, i8* %11, i64 0
store i8 47, i8* %12
store i32 1, i32* %3
br label %13
13: ; preds = %24, %0
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = load i64, i64* %4
%17 = add nsw i64 %16, 2
%18 = icmp slt i64 %15, %17
br i1 %18, label %19, label %27
19: ; preds = %13
%20 = load i8*, i8** %5
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
store i8 97, i8* %23
br label %24
24: ; preds = %19
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
br label %13
27: ; preds = %13
%28 = load i8*, i8** %5
%29 = load i64, i64* %4
%30 = add nsw i64 %29, 2
%31 = getelementptr inbounds i8, i8* %28, i64 %30
store i8 0, i8* %31
%32 = load i8*, i8** %5
%33 = call i32 @shm_unlink(i8* %32)
store i32 %33, i32* %2
%34 = load i32, i32* %2
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %42
36: ; preds = %27
%37 = load i64, i64* @errno
%38 = load i64, i64* @ENAMETOOLONG
%39 = icmp eq i64 %37, %38
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %56
42: ; preds = %36, %27
%43 = load i32, i32* %2
%44 = icmp ne i32 %43, -1
br i1 %44, label %45, label %47
45: ; preds = %42
%46 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %56
47: ; preds = %42
br label %48
48: ; preds = %47
%49 = load i32, i32* @_SC_VERSION
%50 = call i64 @sysconf(i32 %49)
%51 = icmp sge i64 %50, 200800
br i1 %51, label %52, label %54
52: ; preds = %48
%53 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0))
store i32 5, i32* %1
br label %56
54: ; preds = %48
%55 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %1
br label %56
56: ; preds = %54, %52, %45, %40
%57 = load i32, i32* %1
ret i32 %57
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@_PC_NAME_MAX = global i32 0
@errno = global i64 0
@ENAMETOOLONG = global i64 0
@_SC_VERSION = global i32 0
@.str.4 = [19 x i8] c"FAILED: shm_unlink\00"
@str = [51 x i8] c"UNTESTED: shm_open() did not fail with ENAMETOLONG\00"
@str.5 = [31 x i8] c"FAILED: shm_unlink() succeeded\00"
@str.6 = [12 x i8] c"Test PASSED\00"
define i32 @main() {
%1 = load i32, i32* @_PC_NAME_MAX
%2 = tail call i64 @pathconf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = add nsw i64 %2, 3
%4 = tail call i8* @malloc(i64 %3)
store i8 47, i8* %4
%5 = add i64 %2, 2
%6 = icmp sgt i64 %2, -1
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = getelementptr i8, i8* %4, i64 1
%9 = call i64 @llvm.smax.i64(i64 %5, i64 2)
%10 = add nsw i64 %9, -1
br label %11
11: ; preds = %7, %0
%12 = getelementptr inbounds i8, i8* %4, i64 %5
store i8 0, i8* %12
%13 = tail call i32 @shm_unlink(i8* %4)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %21
15: ; preds = %11
%16 = load i64, i64* @errno
%17 = load i64, i64* @ENAMETOOLONG
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.6, i64 0, i64 0))
br label %31
21: ; preds = %11
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.5, i64 0, i64 0))
br label %31
23: ; preds = %15
%24 = load i32, i32* @_SC_VERSION
%25 = tail call i64 @sysconf(i32 %24)
%26 = icmp sgt i64 %25, 200799
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str, i64 0, i64 0))
br label %31
29: ; preds = %23
%30 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %31
31: ; preds = %29, %27, %21, %19
%32 = phi i32 [ 0, %19 ], [ 1, %21 ], [ 5, %27 ], [ 1, %29 ]
ret i32 %32
}