#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_PATH_MAX;
int _POSIX_NAME_MAX;
int /*<<< orphan*/ _SC_VERSION;
scalar_t__ errno;
char *malloc(int);
int 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, path_max;
  char *shm_name;
  path_max = pathconf("/", _PC_PATH_MAX);
  if (path_max == -1) {
    perror("pathconf() failed");
    return 2;
  }
  shm_name = malloc(path_max + 1);
  if (!shm_name) {
    perror("malloc() failed");
    return 2;
  }
  for (i = 0; i < path_max; i++)
    shm_name[i] = (i + 1) % _POSIX_NAME_MAX ? 'a' : '/';
  shm_name[path_max] = 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    0x2e5a(%rip),%rax
mov    (%rax),%esi
lea    0xe81(%rip),%rdi
call   1030 <pathconf@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    11a9 <main+0x49>
lea    0xe6a(%rip),%rdi
call   1060 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    12e9 <main+0x189>
mov    -0x10(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11db <main+0x7b>
lea    0xe4a(%rip),%rdi
call   1060 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    12e9 <main+0x189>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1229 <main+0xc9>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    0x2df5(%rip),%rcx
cltd
idivl  (%rcx)
mov    $0x2f,%eax
mov    $0x61,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11e2 <main+0x82>
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
call   1080 <shm_unlink@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    127d <main+0x11d>
mov    0x2d76(%rip),%rax
mov    (%rax),%rax
mov    0x2d64(%rip),%rcx
cmp    (%rcx),%rax
jne    127d <main+0x11d>
lea    0xdb8(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e9 <main+0x189>
cmpl   $0xffffffff,-0x8(%rbp)
je     129f <main+0x13f>
lea    0xda3(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12e9 <main+0x189>
jmp    12a4 <main+0x144>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
cmp    $0x31060,%rax
jl     12d6 <main+0x176>
lea    0xd8d(%rip),%rdi
call   1040 <printf@plt>
movl   $0x5,-0x4(%rbp)
jmp    12e9 <main+0x189>
lea    0xda9(%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   %r14
push   %rbx
push   %rax
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
lea    0xe8c(%rip),%rdi
call   1040 <pathconf@plt>
cmp    $0xffffffff,%eax
je     1295 <main+0x135>
mov    %eax,%r14d
lea    0x1(%r14),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     129e <main+0x13e>
mov    %rax,%rdi
test   %r14d,%r14d
jle    1222 <main+0xc2>
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%r8d
cmp    $0x1,%r14d
jne    11b9 <main+0x59>
xor    %ebx,%ebx
jmp    1204 <main+0xa4>
mov    %r8d,%r10d
and    $0xfffffffe,%r10d
xor    %ecx,%ecx
mov    $0x2f,%r9d
nopl   0x0(%rax,%rax,1)
lea    0x1(%rcx),%eax
cltd
idiv   %esi
test   %edx,%edx
mov    $0x61,%eax
cmove  %r9d,%eax
mov    %al,(%rdi,%rcx,1)
lea    0x2(%rcx),%rbx
mov    %ebx,%eax
cltd
idiv   %esi
test   %edx,%edx
mov    $0x61,%eax
cmove  %r9d,%eax
mov    %al,0x1(%rdi,%rcx,1)
mov    %rbx,%rcx
cmp    %rbx,%r10
jne    11d0 <main+0x70>
test   $0x1,%r8b
je     1222 <main+0xc2>
lea    0x1(%rbx),%eax
cltd
idiv   %esi
test   %edx,%edx
mov    $0x2f,%eax
mov    $0x61,%ecx
cmove  %eax,%ecx
mov    %cl,(%rdi,%rbx,1)
movslq %r14d,%rax
movb   $0x0,(%rdi,%rax,1)
call   1080 <shm_unlink@plt>
cmp    $0xffffffff,%eax
je     1246 <main+0xe6>
lea    0xe30(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
jmp    12af <main+0x14f>
mov    0x2d7b(%rip),%rax
mov    (%rax),%rax
mov    0x2d69(%rip),%rcx
cmp    (%rcx),%rax
jne    126c <main+0x10c>
lea    0xe27(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    12af <main+0x14f>
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
cmp    $0x31060,%rax
jl     12b7 <main+0x157>
lea    0xdae(%rip),%rdi
call   1030 <puts@plt>
mov    $0x5,%eax
jmp    12af <main+0x14f>
lea    0xd66(%rip),%rdi
jmp    12a5 <main+0x145>
lea    0xd6f(%rip),%rdi
call   1060 <perror@plt>
mov    $0x2,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xd66(%rip),%rdi
call   1060 <perror@plt>
jmp    123f <main+0xdf>

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

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@_PC_PATH_MAX = global i32 0
@.str.1 = [18 x i8] c"pathconf() failed\00"
@.str.2 = [16 x i8] c"malloc() failed\00"
@_POSIX_NAME_MAX = global i32 0
@errno = global i64 0
@ENAMETOOLONG = global i64 0
@_SC_VERSION = global i32 0
@.str.6 = [19 x i8] c"FAILED: shm_unlink\00"
@str = [51 x i8] c"UNTESTED: shm_open() did not fail with ENAMETOLONG\00"
@str.7 = [32 x i8] c"FAILED: shm_unlink() succeeded.\00"
@str.8 = [12 x i8] c"Test PASSED\00"
define i32 @main() {
%1 = load i32, i32* @_PC_PATH_MAX
%2 = tail call i32 @pathconf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %69
6: ; preds = %0
%7 = add nuw nsw i32 %2, 1
%8 = tail call i8* @malloc(i32 %7)
%9 = icmp eq i8* %8, null
br i1 %9, label %19, label %10
10: ; preds = %6
%11 = icmp sgt i32 %2, 0
br i1 %11, label %12, label %48
12: ; preds = %10
%13 = load i32, i32* @_POSIX_NAME_MAX
%14 = zext i32 %2 to i64
%15 = and i64 %14, 1
%16 = icmp eq i32 %2, 1
br i1 %16, label %38, label %17
17: ; preds = %12
%18 = and i64 %14, 4294967294
br label %21
19: ; preds = %6
%20 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %69
21: ; preds = %21, %17
%22 = phi i64 [ 0, %17 ], [ %30, %21 ]
%23 = phi i64 [ 0, %17 ], [ %36, %21 ]
%24 = or i64 %22, 1
%25 = trunc i64 %24 to i32
%26 = srem i32 %25, %13
%27 = icmp eq i32 %26, 0
%28 = select i1 %27, i8 47, i8 97
%29 = getelementptr inbounds i8, i8* %8, i64 %22
store i8 %28, i8* %29
%30 = add nuw nsw i64 %22, 2
%31 = trunc i64 %30 to i32
%32 = srem i32 %31, %13
%33 = icmp eq i32 %32, 0
%34 = select i1 %33, i8 47, i8 97
%35 = getelementptr inbounds i8, i8* %8, i64 %24
store i8 %34, i8* %35
%36 = add i64 %23, 2
%37 = icmp eq i64 %36, %18
br i1 %37, label %38, label %21
38: ; preds = %21, %12
%39 = phi i64 [ 0, %12 ], [ %30, %21 ]
%40 = icmp eq i64 %15, 0
br i1 %40, label %48, label %41
41: ; preds = %38
%42 = trunc i64 %39 to i32
%43 = add i32 %42, 1
%44 = srem i32 %43, %13
%45 = icmp eq i32 %44, 0
%46 = select i1 %45, i8 47, i8 97
%47 = getelementptr inbounds i8, i8* %8, i64 %39
store i8 %46, i8* %47
br label %48
48: ; preds = %41, %38, %10
%49 = sext i32 %2 to i64
%50 = getelementptr inbounds i8, i8* %8, i64 %49
store i8 0, i8* %50
%51 = tail call i32 @shm_unlink(i8* %8)
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %59
53: ; preds = %48
%54 = load i64, i64* @errno
%55 = load i64, i64* @ENAMETOOLONG
%56 = icmp eq i64 %54, %55
br i1 %56, label %57, label %61
57: ; preds = %53
%58 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.8, i64 0, i64 0))
br label %69
59: ; preds = %48
%60 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.7, i64 0, i64 0))
br label %69
61: ; preds = %53
%62 = load i32, i32* @_SC_VERSION
%63 = tail call i64 @sysconf(i32 %62)
%64 = icmp sgt i64 %63, 200799
br i1 %64, label %65, label %67
65: ; preds = %61
%66 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str, i64 0, i64 0))
br label %69
67: ; preds = %61
%68 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
br label %69
69: ; preds = %67, %65, %59, %57, %19, %4
%70 = phi i32 [ 2, %4 ], [ 0, %57 ], [ 1, %59 ], [ 5, %65 ], [ 1, %67 ], [ 2, %19 ]
ret i32 %70
}