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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%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    11c6 <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    1197 <main+0x47>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,0x2(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
call   1070 <shm_unlink@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    121b <main+0xcb>
mov    0x2df0(%rip),%rax
mov    (%rax),%rax
mov    0x2dde(%rip),%rcx
cmp    (%rcx),%rax
jne    121b <main+0xcb>
lea    0xdf8(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1255 <main+0x105>
cmpl   $0xffffffff,-0x8(%rbp)
je     123d <main+0xed>
lea    0xde3(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1255 <main+0x105>
jmp    1242 <main+0xf2>
lea    0xddd(%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    0x2e64(%rip),%rax
mov    (%rax),%esi
lea    0xe8b(%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     11b7 <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   1080 <shm_unlink@plt>
cmp    $0xffffffff,%eax
je     11dc <main+0x7c>
lea    0xe5a(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
jmp    1200 <main+0xa0>
mov    0x2dfd(%rip),%rax
mov    (%rax),%rax
mov    0x2deb(%rip),%rcx
cmp    (%rcx),%rax
jne    1206 <main+0xa6>
lea    0xe47(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdf5(%rip),%rdi
call   1070 <perror@plt>
jmp    11d5 <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 = [23 x i8] c"shm_unlink() success.\0A\00"
@.str.3 = [40 x i8] c"shm_unlink does not set the right errno\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 %50
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 ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %50
47: ; preds = %42
br label %48
48: ; preds = %47
%49 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
br label %50
50: ; preds = %48, %45, %40
%51 = load i32, i32* %1
ret i32 %51
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@_PC_NAME_MAX = global i32 0
@errno = global i64 0
@ENAMETOOLONG = global i64 0
@.str.3 = [40 x i8] c"shm_unlink does not set the right errno\00"
@str = [22 x i8] c"shm_unlink() success.\00"
@str.4 = [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.4, i64 0, i64 0))
br label %25
21: ; preds = %11
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %25
23: ; preds = %15
%24 = tail call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
br label %25
25: ; preds = %23, %21, %19
%26 = phi i32 [ 0, %19 ], [ 1, %21 ], [ 1, %23 ]
ret i32 %26
}