#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);
  if (name_max == -1) {
    perror("pathconf() failed");
    return 2;
  }
  shm_name = malloc(name_max + 3);
  if (!shm_name) {
    perror("malloc() failed");
    return 2;
  }
  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)
cmpq   $0xffffffffffffffff,-0x18(%rbp)
jne    11ab <main+0x4b>
lea    0xe68(%rip),%rdi
call   1060 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    12dd <main+0x17d>
mov    -0x18(%rbp),%rdi
add    $0x3,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11df <main+0x7f>
lea    0xe46(%rip),%rdi
call   1060 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    12dd <main+0x17d>
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    121c <main+0xbc>
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    11ed <main+0x8d>
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    1271 <main+0x111>
mov    0x2d92(%rip),%rax
mov    (%rax),%rax
mov    0x2d80(%rip),%rcx
cmp    (%rcx),%rax
jne    1271 <main+0x111>
lea    0xdc4(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12dd <main+0x17d>
cmpl   $0xffffffff,-0x8(%rbp)
je     1293 <main+0x133>
lea    0xdaf(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12dd <main+0x17d>
jmp    1298 <main+0x138>
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
cmp    $0x31060,%rax
jl     12ca <main+0x16a>
lea    0xd98(%rip),%rdi
call   1040 <printf@plt>
movl   $0x5,-0x4(%rbp)
jmp    12dd <main+0x17d>
lea    0xdb4(%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>
cmp    $0xffffffffffffffff,%rax
je     124e <main+0xde>
mov    %rax,%rbx
lea    0x3(%rax),%rdi
call   1060 <malloc@plt>
test   %rax,%rax
je     1257 <main+0xe7>
mov    %rax,%r14
movb   $0x2f,(%rax)
lea    0x2(%rbx),%r15
test   %rbx,%rbx
js     11da <main+0x6a>
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     11ff <main+0x8f>
lea    0xe77(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
jmp    1268 <main+0xf8>
mov    0x2dd2(%rip),%rax
mov    (%rax),%rax
mov    0x2dc0(%rip),%rcx
cmp    (%rcx),%rax
jne    1225 <main+0xb5>
lea    0xe6d(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    1268 <main+0xf8>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
call   1080 <sysconf@plt>
cmp    $0x31060,%rax
jl     126e <main+0xfe>
lea    0xdf5(%rip),%rdi
call   1030 <puts@plt>
mov    $0x5,%eax
jmp    1268 <main+0xf8>
lea    0xdad(%rip),%rdi
jmp    125e <main+0xee>
lea    0xdb6(%rip),%rdi
call   1070 <perror@plt>
mov    $0x2,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdaf(%rip),%rdi
call   1070 <perror@plt>
jmp    11f8 <main+0x88>

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

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@_PC_NAME_MAX = global i32 0
@.str.1 = [18 x i8] c"pathconf() failed\00"
@.str.2 = [16 x i8] c"malloc() failed\00"
@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 = [31 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_NAME_MAX
%2 = tail call i64 @pathconf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp eq i64 %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 %39
6: ; preds = %0
%7 = add nsw i64 %2, 3
%8 = tail call i8* @malloc(i64 %7)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %39
12: ; preds = %6
store i8 47, i8* %8
%13 = add i64 %2, 2
%14 = icmp sgt i64 %2, -1
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = getelementptr i8, i8* %8, i64 1
%17 = call i64 @llvm.smax.i64(i64 %13, i64 2)
%18 = add nsw i64 %17, -1
br label %19
19: ; preds = %15, %12
%20 = getelementptr inbounds i8, i8* %8, i64 %13
store i8 0, i8* %20
%21 = tail call i32 @shm_unlink(i8* %8)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %29
23: ; preds = %19
%24 = load i64, i64* @errno
%25 = load i64, i64* @ENAMETOOLONG
%26 = icmp eq i64 %24, %25
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.8, i64 0, i64 0))
br label %39
29: ; preds = %19
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.7, i64 0, i64 0))
br label %39
31: ; preds = %23
%32 = load i32, i32* @_SC_VERSION
%33 = tail call i64 @sysconf(i32 %32)
%34 = icmp sgt i64 %33, 200799
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str, i64 0, i64 0))
br label %39
37: ; preds = %31
%38 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
br label %39
39: ; preds = %37, %35, %29, %27, %10, %4
%40 = phi i32 [ 2, %4 ], [ 0, %27 ], [ 1, %29 ], [ 5, %35 ], [ 1, %37 ], [ 2, %10 ]
ret i32 %40
}