#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("An error occurs when calling pathconf()");
    return 2;
  }
  shm_name = malloc(path_max + 1);
  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    12c6 <main+0x166>
mov    -0x10(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1206 <main+0xa6>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    0x2e18(%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    11bf <main+0x5f>
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    125a <main+0xfa>
mov    0x2d99(%rip),%rax
mov    (%rax),%rax
mov    0x2d87(%rip),%rcx
cmp    (%rcx),%rax
jne    125a <main+0xfa>
lea    0xde1(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12c6 <main+0x166>
cmpl   $0xffffffff,-0x8(%rbp)
je     127c <main+0x11c>
lea    0xdcc(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c6 <main+0x166>
jmp    1281 <main+0x121>
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
cmp    $0x31060,%rax
jl     12b3 <main+0x153>
lea    0xdb6(%rip),%rdi
call   1040 <printf@plt>
movl   $0x5,-0x4(%rbp)
jmp    12c6 <main+0x166>
lea    0xdd2(%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     1285 <main+0x125>
mov    %eax,%r14d
lea    0x1(%r14),%edi
call   1050 <malloc@plt>
mov    %rax,%rdi
test   %r14d,%r14d
jle    1212 <main+0xb2>
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%r8d
cmp    $0x1,%r14d
jne    11b0 <main+0x50>
xor    %ebx,%ebx
jmp    11f4 <main+0x94>
mov    %r8d,%r10d
and    $0xfffffffe,%r10d
xor    %ecx,%ecx
mov    $0x2f,%r9d
nop
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    11c0 <main+0x60>
test   $0x1,%r8b
je     1212 <main+0xb2>
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     1236 <main+0xd6>
lea    0xe46(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
jmp    1296 <main+0x136>
mov    0x2d8b(%rip),%rax
mov    (%rax),%rax
mov    0x2d79(%rip),%rcx
cmp    (%rcx),%rax
jne    125c <main+0xfc>
lea    0xe3d(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    1296 <main+0x136>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
cmp    $0x31060,%rax
jl     129e <main+0x13e>
lea    0xdc4(%rip),%rdi
call   1030 <puts@plt>
mov    $0x5,%eax
jmp    1296 <main+0x136>
lea    0xd76(%rip),%rdi
call   1060 <perror@plt>
mov    $0x2,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xd85(%rip),%rdi
call   1060 <perror@plt>
jmp    122f <main+0xcf>

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

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