#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;
scalar_t__ errno;
char *malloc(int);
int pathconf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int shm_unlink(char *);
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("shm_unlink() success.\n");
    return 1;
  }
  perror("shm_unlink");
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1030 <pathconf@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    1199 <main+0x49>
lea    0xe7a(%rip),%rdi
call   1060 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1284 <main+0x134>
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    11f6 <main+0xa6>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    0x2e28(%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    11af <main+0x5f>
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
call   1070 <shm_unlink@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    124a <main+0xfa>
mov    0x2db1(%rip),%rax
mov    (%rax),%rax
mov    0x2d9f(%rip),%rcx
cmp    (%rcx),%rax
jne    124a <main+0xfa>
lea    0xdf1(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1284 <main+0x134>
cmpl   $0xffffffff,-0x8(%rbp)
je     126c <main+0x11c>
lea    0xddc(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1284 <main+0x134>
jmp    1271 <main+0x121>
lea    0xdd6(%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    0x2e7d(%rip),%rax
mov    (%rax),%esi
lea    0xe9c(%rip),%rdi
call   1040 <pathconf@plt>
cmp    $0xffffffff,%eax
je     1252 <main+0x102>
mov    %eax,%r14d
lea    0x1(%r14),%edi
call   1050 <malloc@plt>
mov    %rax,%rdi
test   %r14d,%r14d
jle    1202 <main+0xb2>
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%r8d
cmp    $0x1,%r14d
jne    11a0 <main+0x50>
xor    %ebx,%ebx
jmp    11e4 <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    11b0 <main+0x60>
test   $0x1,%r8b
je     1202 <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   1070 <shm_unlink@plt>
cmp    $0xffffffff,%eax
je     1226 <main+0xd6>
lea    0xe1b(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
jmp    124a <main+0xfa>
mov    0x2da3(%rip),%rax
mov    (%rax),%rax
mov    0x2d91(%rip),%rcx
cmp    (%rcx),%rax
jne    1265 <main+0x115>
lea    0xe08(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xda9(%rip),%rdi
call   1060 <perror@plt>
mov    $0x2,%eax
jmp    124a <main+0xfa>
lea    0xdbe(%rip),%rdi
call   1060 <perror@plt>
jmp    121f <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 = [23 x i8] c"shm_unlink() success.\0A\00"
@.str.4 = [11 x i8] c"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 %59
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 %59
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 ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
br label %59
56: ; preds = %51
br label %57
57: ; preds = %56
%58 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %1
br label %59
59: ; preds = %57, %54, %49, %10
%60 = load i32, i32* %1
ret i32 %60
}

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
@.str.4 = [11 x i8] c"shm_unlink\00"
@str = [22 x i8] c"shm_unlink() success.\00"
@str.5 = [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 %59
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.5, i64 0, i64 0))
br label %59
55: ; preds = %44
%56 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %59
57: ; preds = %49
%58 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
br label %59
59: ; preds = %57, %55, %53, %4
%60 = phi i32 [ 2, %4 ], [ 0, %53 ], [ 1, %55 ], [ 1, %57 ]
ret i32 %60
}