#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 */
typedef int /*<<< orphan*/ buf2;

/* Variables and functions */
int ENAMETOOLONG;
int /*<<< orphan*/ _PC_PATH_MAX;
int /*<<< orphan*/ bye(char *, int);
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char *malloc(int);
int pathconf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int readlink(char *, char *, int);
char *rindex(char *, char);
int /*<<< orphan*/ strcat(char *, char *);
int main(int argc, char *argv[]) {
  char *buf;
  char buf2[1024];
  int max, i;
  max = pathconf(argv[0], _PC_PATH_MAX);
  max *= 10;
  if (max <= 0)
    bye("path_max", max);
  if ((buf = malloc(max + 1)) == NULL)
    bye("malloc", 0);
  strcat(buf, argv[0]);
  if (rindex(buf, '/') == NULL)
    strcat(buf, "./");
  for (i = rindex(buf, '/') - buf + 1; i < max; i++)
    buf[i] = 'a';
  buf[i] = 0;
  i = readlink(buf, buf2, sizeof(buf2) - 1);
  if (i != -1)
    bye("i", i);
  if (errno != ENAMETOOLONG) {
    perror(buf);
    bye("errno", errno);
  }
  printf("pass\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
call   1040 <pathconf@plt>
mov    %eax,-0x424(%rbp)
imul   $0xa,-0x424(%rbp),%eax
mov    %eax,-0x424(%rbp)
cmpl   $0x0,-0x424(%rbp)
jg     11f0 <main+0x60>
mov    -0x424(%rbp),%esi
lea    0xe15(%rip),%rdi
call   1070 <bye@plt>
mov    -0x424(%rbp),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    121a <main+0x8a>
lea    0xdf6(%rip),%rdi
xor    %esi,%esi
call   1070 <bye@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   10a0 <strcat@plt>
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1080 <rindex@plt>
cmp    $0x0,%rax
jne    1252 <main+0xc2>
mov    -0x18(%rbp),%rdi
lea    0xdc3(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1080 <rindex@plt>
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,-0x428(%rbp)
mov    -0x428(%rbp),%eax
cmp    -0x424(%rbp),%eax
jge    12a6 <main+0x116>
mov    -0x18(%rbp),%rax
movslq -0x428(%rbp),%rcx
movb   $0x61,(%rax,%rcx,1)
mov    -0x428(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x428(%rbp)
jmp    1271 <main+0xe1>
mov    -0x18(%rbp),%rax
movslq -0x428(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
lea    -0x420(%rbp),%rsi
mov    $0x3ff,%edx
call   1030 <readlink@plt>
mov    %eax,-0x428(%rbp)
cmpl   $0xffffffff,-0x428(%rbp)
je     12ef <main+0x15f>
mov    -0x428(%rbp),%esi
lea    0xd29(%rip),%rdi
call   1070 <bye@plt>
mov    0x2ce2(%rip),%rax
mov    (%rax),%eax
mov    0x2cd1(%rip),%rcx
cmp    (%rcx),%eax
je     1325 <main+0x195>
mov    -0x18(%rbp),%rdi
call   1090 <perror@plt>
mov    0x2cc1(%rip),%rax
mov    (%rax),%esi
lea    0xcf5(%rip),%rdi
call   1070 <bye@plt>
lea    0xcef(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%r15
mov    (%rsi),%rdi
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
call   1050 <pathconf@plt>
lea    (%rax,%rax,1),%ecx
lea    (%rcx,%rcx,4),%r14d
test   %eax,%eax
jg     11da <main+0x3a>
lea    0xe2e(%rip),%rdi
mov    %r14d,%esi
call   1080 <bye@plt>
mov    %r14d,%edi
or     $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11fb <main+0x5b>
lea    0xe15(%rip),%rdi
xor    %esi,%esi
call   1080 <bye@plt>
mov    (%r15),%rsi
mov    %rbx,%rdi
call   10b0 <strcat@plt>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1090 <rindex@plt>
test   %rax,%rax
jne    1227 <main+0x87>
lea    0xdf1(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <strcat@plt>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1090 <rindex@plt>
mov    %eax,%ecx
sub    %ebx,%ecx
add    $0x1,%ecx
cmp    %r14d,%ecx
jge    1262 <main+0xc2>
movslq %ecx,%rcx
mov    %rbx,%rdi
add    %rcx,%rdi
lea    (%r14,%rbx,1),%edx
sub    %eax,%edx
add    $0xfffffffe,%edx
add    $0x1,%rdx
mov    $0x61,%esi
call   1060 <memset@plt>
jmp    1265 <main+0xc5>
mov    %ecx,%r14d
movslq %r14d,%rax
movb   $0x0,(%rbx,%rax,1)
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0x3ff,%edx
call   1040 <readlink@plt>
cmp    $0xffffffff,%eax
je     128f <main+0xef>
lea    0xd8b(%rip),%rdi
mov    %eax,%esi
call   1080 <bye@plt>
mov    0x2d42(%rip),%r14
mov    (%r14),%eax
mov    0x2d30(%rip),%rcx
cmp    (%rcx),%eax
je     12bb <main+0x11b>
mov    %rbx,%rdi
call   10a0 <perror@plt>
mov    (%r14),%esi
lea    0xd5f(%rip),%rdi
call   1080 <bye@plt>
lea    0xd59(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@_PC_PATH_MAX = global i32 0
@.str = [9 x i8] c"path_max\00"
@.str.1 = [7 x i8] c"malloc\00"
@.str.2 = [3 x i8] c"./\00"
@.str.3 = [2 x i8] c"i\00"
@errno = global i32 0
@ENAMETOOLONG = global i32 0
@.str.4 = [6 x i8] c"errno\00"
@.str.5 = [6 x i8] c"pass\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [1024 x i8]
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = load i32, i32* @_PC_PATH_MAX
%14 = call i32 @pathconf(i8* %12, i32 %13)
store i32 %14, i32* %8
%15 = load i32, i32* %8
%16 = mul nsw i32 %15, 10
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = icmp sle i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = load i32, i32* %8
%21 = call i32 @bye(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %19, %2
%23 = load i32, i32* %8
%24 = add nsw i32 %23, 1
%25 = call i8* @malloc(i32 %24)
store i8* %25, i8** %6
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = call i32 @bye(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 0)
br label %29
29: ; preds = %27, %22
%30 = load i8*, i8** %6
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 0
%33 = load i8*, i8** %32
%34 = call i32 @strcat(i8* %30, i8* %33)
%35 = load i8*, i8** %6
%36 = call i8* @rindex(i8* %35, i8 signext 47)
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %41
38: ; preds = %29
%39 = load i8*, i8** %6
%40 = call i32 @strcat(i8* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %41
41: ; preds = %38, %29
%42 = load i8*, i8** %6
%43 = call i8* @rindex(i8* %42, i8 signext 47)
%44 = load i8*, i8** %6
%45 = ptrtoint i8* %43 to i64
%46 = ptrtoint i8* %44 to i64
%47 = sub i64 %45, %46
%48 = add nsw i64 %47, 1
%49 = trunc i64 %48 to i32
store i32 %49, i32* %9
br label %50
50: ; preds = %59, %41
%51 = load i32, i32* %9
%52 = load i32, i32* %8
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %62
54: ; preds = %50
%55 = load i8*, i8** %6
%56 = load i32, i32* %9
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
store i8 97, i8* %58
br label %59
59: ; preds = %54
%60 = load i32, i32* %9
%61 = add nsw i32 %60, 1
store i32 %61, i32* %9
br label %50
62: ; preds = %50
%63 = load i8*, i8** %6
%64 = load i32, i32* %9
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %63, i64 %65
store i8 0, i8* %66
%67 = load i8*, i8** %6
%68 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%69 = call i32 @readlink(i8* %67, i8* %68, i32 1023)
store i32 %69, i32* %9
%70 = load i32, i32* %9
%71 = icmp ne i32 %70, -1
br i1 %71, label %72, label %75
72: ; preds = %62
%73 = load i32, i32* %9
%74 = call i32 @bye(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 %73)
br label %75
75: ; preds = %72, %62
%76 = load i32, i32* @errno
%77 = load i32, i32* @ENAMETOOLONG
%78 = icmp ne i32 %76, %77
br i1 %78, label %79, label %84
79: ; preds = %75
%80 = load i8*, i8** %6
%81 = call i32 @perror(i8* %80)
%82 = load i32, i32* @errno
%83 = call i32 @bye(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %82)
br label %84
84: ; preds = %79, %75
%85 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%86 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@_PC_PATH_MAX = global i32 0
@.str = [9 x i8] c"path_max\00"
@.str.1 = [7 x i8] c"malloc\00"
@.str.2 = [3 x i8] c"./\00"
@.str.3 = [2 x i8] c"i\00"
@errno = global i32 0
@ENAMETOOLONG = global i32 0
@.str.4 = [6 x i8] c"errno\00"
@str = [5 x i8] c"pass\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = load i8*, i8** %1
%6 = load i32, i32* @_PC_PATH_MAX
%7 = tail call i32 @pathconf(i8* %5, i32 %6)
%8 = mul i32 %7, 10
%9 = icmp slt i32 %7, 1
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 @bye(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %12
12: ; preds = %10, %2
%13 = or i32 %8, 1
%14 = tail call i8* @malloc(i32 %13)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = tail call i32 @bye(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 0)
br label %18
18: ; preds = %16, %12
%19 = load i8*, i8** %1
%20 = tail call i32 @strcat(i8* %14, i8* %19)
%21 = tail call i8* @rindex(i8* %14, i8 signext 47)
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = tail call i32 @strcat(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %18
%26 = tail call i8* @rindex(i8* %14, i8 signext 47)
%27 = ptrtoint i8* %26 to i64
%28 = ptrtoint i8* %14 to i64
%29 = sub i64 %27, %28
%30 = trunc i64 %29 to i32
%31 = add i32 %30, 1
%32 = icmp slt i32 %31, %8
br i1 %32, label %33, label %43
33: ; preds = %25
%34 = sext i32 %31 to i64
%35 = getelementptr i8, i8* %14, i64 %34
%36 = trunc i64 %28 to i32
%37 = add i32 %8, %36
%38 = add i32 %37, -2
%39 = trunc i64 %27 to i32
%40 = sub i32 %38, %39
%41 = zext i32 %40 to i64
%42 = add nuw nsw i64 %41, 1
br label %43
43: ; preds = %33, %25
%44 = phi i32 [ %31, %25 ], [ %8, %33 ]
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %14, i64 %45
store i8 0, i8* %46
%47 = call i32 @readlink(i8* %14, i8* %4, i32 1023)
%48 = icmp eq i32 %47, -1
br i1 %48, label %51, label %49
49: ; preds = %43
%50 = tail call i32 @bye(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 %47)
br label %51
51: ; preds = %49, %43
%52 = load i32, i32* @errno
%53 = load i32, i32* @ENAMETOOLONG
%54 = icmp eq i32 %52, %53
br i1 %54, label %59, label %55
55: ; preds = %51
%56 = tail call i32 @perror(i8* %14)
%57 = load i32, i32* @errno
%58 = tail call i32 @bye(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %57)
br label %59
59: ; preds = %55, %51
%60 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%61 = tail call i32 @exit(i32 0)
unreachable
}