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

/* Variables and functions */
scalar_t__ ENOSYS;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
char *getcwd(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int readlink(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int main(int argc, char *argv[]) {
  char buf[1024];
  char buf2[1024];
  int err;
  err = readlink("/proc/42/exe", buf, sizeof(buf));
  if (err < 0) {
    if (err == -1 && errno == ENOSYS)
      printf("ENOSYS\n");
    printf("xyzzy\n");
    exit(0);
  }
  if (getcwd(buf2, sizeof(buf2)) != buf2) {
    perror("getcwd");
    exit(1);
  }
  if (argv[0][0] == '/') {
    if (strcmp(argv[0], buf) != 0) {
      printf("%s != %s\n", buf, argv[0]);
      exit(1);
    }
  } else if (argv[0][0] != '.') {
    if (buf2[strlen(buf2) - 1] != '/')
      strcat(buf2, "/");
    strcat(buf2, argv[0]);
    if (strcmp(buf2, buf) != 0) {
      printf("%s != %s\n", buf, buf2);
      exit(1);
    }
  } else {
    strcat(buf2, argv[0] + 1);
    if (strcmp(buf, buf2) != 0) {
      printf("%s != %s\n", buf, buf2);
      exit(1);
    }
  }
  printf("pass\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x410(%rbp),%rsi
lea    0xe59(%rip),%rdi
mov    $0x400,%edx
call   1030 <readlink@plt>
mov    %eax,-0x814(%rbp)
cmpl   $0x0,-0x814(%rbp)
jge    120e <main+0x8e>
cmpl   $0xffffffff,-0x814(%rbp)
jne    11f9 <main+0x79>
mov    0x2e00(%rip),%rax
mov    (%rax),%rax
mov    0x2e06(%rip),%rcx
cmp    (%rcx),%rax
jne    11f9 <main+0x79>
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    -0x810(%rbp),%rdi
mov    $0x400,%esi
call   1060 <getcwd@plt>
lea    -0x810(%rbp),%rcx
cmp    %rcx,%rax
je     1245 <main+0xc5>
lea    0xde6(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    12a0 <main+0x120>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    -0x410(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     129b <main+0x11b>
lea    -0x410(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd99(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    13a7 <main+0x227>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     1343 <main+0x1c3>
lea    -0x810(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x810(%rbp,%rax,1),%eax
ff
cmp    $0x2f,%eax
je     12e8 <main+0x168>
lea    -0x810(%rbp),%rdi
lea    0xd4a(%rip),%rsi
call   1090 <strcat@plt>
lea    -0x810(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   1090 <strcat@plt>
lea    -0x810(%rbp),%rdi
lea    -0x410(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     133e <main+0x1be>
lea    -0x410(%rbp),%rsi
lea    -0x810(%rbp),%rdx
lea    0xcf6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    13a2 <main+0x222>
lea    -0x810(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
add    $0x1,%rsi
call   1090 <strcat@plt>
lea    -0x410(%rbp),%rdi
lea    -0x810(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     139d <main+0x21d>
lea    -0x410(%rbp),%rsi
lea    -0x810(%rbp),%rdx
lea    0xc97(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    13a2 <main+0x222>
jmp    13a7 <main+0x227>
lea    0xc81(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x808,%rsp
mov    %rsi,%r14
lea    0xe5c(%rip),%rdi
mov    %rsp,%rsi
mov    $0x400,%edx
call   1040 <readlink@plt>
test   %eax,%eax
jns    11e8 <main+0x58>
cmp    $0xffffffff,%eax
jne    11dc <main+0x4c>
mov    0x2e17(%rip),%rax
mov    (%rax),%rax
mov    0x2e1d(%rip),%rcx
cmp    (%rcx),%rax
jne    11dc <main+0x4c>
lea    0xe54(%rip),%rdi
call   1030 <puts@plt>
lea    0xe42(%rip),%rdi
jmp    12bb <main+0x12b>
lea    0x400(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1070 <getcwd@plt>
cmp    %rbx,%rax
jne    1237 <main+0xa7>
mov    (%r14),%rax
mov    (%rax),%cl
cmp    $0x2e,%cl
je     124d <main+0xbd>
cmp    $0x2f,%cl
jne    126c <main+0xdc>
mov    %rsp,%rsi
mov    %rax,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     12b4 <main+0x124>
mov    (%r14),%rdx
lea    0xde5(%rip),%rdi
mov    %rsp,%rsi
jmp    12d9 <main+0x149>
lea    0xdcf(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
add    $0x1,%rax
lea    0x400(%rsp),%rbx
mov    %rbx,%rdi
mov    %rax,%rsi
call   10a0 <strcat@plt>
mov    %rsp,%rdi
mov    %rbx,%rsi
jmp    12aa <main+0x11a>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%rbx,1)
je     1291 <main+0x101>
lea    0xd9a(%rip),%rsi
lea    0x400(%rsp),%rdi
call   10a0 <strcat@plt>
mov    (%r14),%rsi
lea    0x400(%rsp),%rbx
mov    %rbx,%rdi
call   10a0 <strcat@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    12c7 <main+0x137>
lea    0xd65(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    0xd46(%rip),%rdi
mov    %rsp,%rsi
lea    0x400(%rsp),%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"/proc/42/exe\00"
@errno = global i64 0
@ENOSYS = global i64 0
@.str.1 = [8 x i8] c"ENOSYS\0A\00"
@.str.2 = [7 x i8] c"xyzzy\0A\00"
@.str.3 = [7 x i8] c"getcwd\00"
@.str.4 = [10 x i8] c"%s != %s\0A\00"
@.str.5 = [2 x i8] c"/\00"
@.str.6 = [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 [1024 x i8]
%7 = alloca [1024 x i8]
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%10 = call i32 @readlink(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %9, i32 1024)
store i32 %10, i32* %8
%11 = load i32, i32* %8
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %25
13: ; preds = %2
%14 = load i32, i32* %8
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %22
16: ; preds = %13
%17 = load i64, i64* @errno
%18 = load i64, i64* @ENOSYS
%19 = icmp eq i64 %17, %18
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %16, %13
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 @exit(i32 0)
unreachable
25: ; preds = %2
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%27 = call i8* @getcwd(i8* %26, i32 1024)
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%29 = icmp ne i8* %27, %28
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %25
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 0
%36 = load i8*, i8** %35
%37 = getelementptr inbounds i8, i8* %36, i64 0
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 47
br i1 %40, label %41, label %56
41: ; preds = %33
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 0
%44 = load i8*, i8** %43
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%46 = call i64 @strcmp(i8* %44, i8* %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %55
48: ; preds = %41
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 0
%52 = load i8*, i8** %51
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %49, i8* %52)
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %41
br label %110
56: ; preds = %33
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 0
%59 = load i8*, i8** %58
%60 = getelementptr inbounds i8, i8* %59, i64 0
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = icmp ne i32 %62, 46
br i1 %63, label %64, label %92
64: ; preds = %56
%65 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%66 = call i32 @strlen(i8* %65)
%67 = sub nsw i32 %66, 1
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %68
%70 = load i8, i8* %69
%71 = sext i8 %70 to i32
%72 = icmp ne i32 %71, 47
br i1 %72, label %73, label %76
73: ; preds = %64
%74 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%75 = call i32 @strcat(i8* %74, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %76
76: ; preds = %73, %64
%77 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%78 = load i8**, i8*** %5
%79 = getelementptr inbounds i8*, i8** %78, i64 0
%80 = load i8*, i8** %79
%81 = call i32 @strcat(i8* %77, i8* %80)
%82 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%83 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%84 = call i64 @strcmp(i8* %82, i8* %83)
%85 = icmp ne i64 %84, 0
br i1 %85, label %86, label %91
86: ; preds = %76
%87 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%88 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %87, i8* %88)
%90 = call i32 @exit(i32 1)
unreachable
91: ; preds = %76
br label %109
92: ; preds = %56
%93 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%94 = load i8**, i8*** %5
%95 = getelementptr inbounds i8*, i8** %94, i64 0
%96 = load i8*, i8** %95
%97 = getelementptr inbounds i8, i8* %96, i64 1
%98 = call i32 @strcat(i8* %93, i8* %97)
%99 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%100 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%101 = call i64 @strcmp(i8* %99, i8* %100)
%102 = icmp ne i64 %101, 0
br i1 %102, label %103, label %108
103: ; preds = %92
%104 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%105 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%106 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %104, i8* %105)
%107 = call i32 @exit(i32 1)
unreachable
108: ; preds = %92
br label %109
109: ; preds = %108, %91
br label %110
110: ; preds = %109, %55
%111 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%112 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [13 x i8] c"/proc/42/exe\00"
@errno = global i64 0
@ENOSYS = global i64 0
@.str.3 = [7 x i8] c"getcwd\00"
@.str.4 = [10 x i8] c"%s != %s\0A\00"
@.str.5 = [2 x i8] c"/\00"
@str = [5 x i8] c"pass\00"
@str.7 = [6 x i8] c"xyzzy\00"
@str.8 = [7 x i8] c"ENOSYS\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = call i32 @readlink(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %5, i32 1024)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %20
9: ; preds = %2
%10 = icmp eq i32 %7, -1
br i1 %10, label %11, label %17
11: ; preds = %9
%12 = load i64, i64* @errno
%13 = load i64, i64* @ENOSYS
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.8, i64 0, i64 0))
br label %17
17: ; preds = %15, %11, %9
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.7, i64 0, i64 0))
%19 = tail call i32 @exit(i32 0)
unreachable
20: ; preds = %2
%21 = call i8* @getcwd(i8* %6, i32 1024)
%22 = icmp eq i8* %21, %6
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %20
%27 = load i8*, i8** %1
%28 = load i8, i8* %27
switch i8 %28, label %36 [
i8 47, label %29
i8 46, label %53
]
29: ; preds = %26
%30 = call i64 @strcmp(i8* %27, i8* %5)
%31 = icmp eq i64 %30, 0
br i1 %31, label %61, label %32
32: ; preds = %29
%33 = load i8*, i8** %1
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %5, i8* %33)
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %26
%37 = call i32 @strlen(i8* %6)
%38 = add nsw i32 %37, -1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = icmp eq i8 %41, 47
br i1 %42, label %45, label %43
43: ; preds = %36
%44 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %45
45: ; preds = %43, %36
%46 = load i8*, i8** %1
%47 = call i32 @strcat(i8* %6, i8* %46)
%48 = call i64 @strcmp(i8* %6, i8* %5)
%49 = icmp eq i64 %48, 0
br i1 %49, label %61, label %50
50: ; preds = %45
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %5, i8* %6)
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %26
%54 = getelementptr inbounds i8, i8* %27, i64 1
%55 = call i32 @strcat(i8* %6, i8* %54)
%56 = call i64 @strcmp(i8* %5, i8* %6)
%57 = icmp eq i64 %56, 0
br i1 %57, label %61, label %58
58: ; preds = %53
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %5, i8* %6)
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %45, %53, %29
%62 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%63 = call i32 @exit(i32 0)
unreachable
}