#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*/ FILE;

/* Variables and functions */
scalar_t__ ENOENT;
int /*<<< orphan*/ abort();
scalar_t__ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int main(int argc, char *argv[]) {
  char *fnam = argv[0];
  FILE *f;
  if (argv[0][0] != '/') {
    fnam = malloc(strlen(argv[0]) + 2);
    if (fnam == NULL)
      abort();
    strcpy(fnam, "/");
    strcat(fnam, argv[0]);
  }
  f = fopen(fnam, "rb");
  if (f == NULL)
    abort();
  fclose(f);
  if (fopen("/nonexistent", "rb") != NULL || errno != ENOENT)
    abort();
  printf("pass\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     1202 <main+0x82>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <strlen@plt>
mov    %rax,%rdi
add    $0x2,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e2 <main+0x62>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x18(%rbp),%rdi
lea    0xe13(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   10a0 <strcat@plt>
mov    -0x18(%rbp),%rdi
lea    0xdf5(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1228 <main+0xa8>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xdcd(%rip),%rdi
lea    0xdc3(%rip),%rsi
call   1090 <fopen@plt>
cmp    $0x0,%rax
jne    1268 <main+0xe8>
mov    0x2d8b(%rip),%rax
mov    (%rax),%rax
mov    0x2d71(%rip),%rcx
cmp    (%rcx),%rax
je     126f <main+0xef>
mov    $0x0,%al
call   1030 <abort@plt>
lea    0xd9c(%rip),%rdi
call   1070 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    (%rsi),%rbx
cmpb   $0x2f,(%rbx)
je     11c2 <main+0x42>
mov    %rsi,%r14
mov    %rbx,%rdi
call   1070 <strlen@plt>
lea    0x2(%rax),%rdi
call   1080 <malloc@plt>
test   %rax,%rax
je     1222 <main+0xa2>
mov    %rax,%rbx
lea    0xe51(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
mov    (%r14),%rsi
mov    %rbx,%rdi
call   10a0 <strcat@plt>
lea    0xe39(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1222 <main+0xa2>
mov    %rax,%rdi
call   1060 <fclose@plt>
lea    0xe20(%rip),%rdi
lea    0xe16(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
jne    1222 <main+0xa2>
mov    0x2de3(%rip),%rax
mov    (%rax),%rax
mov    0x2dc9(%rip),%rcx
cmp    (%rcx),%rax
jne    1222 <main+0xa2>
lea    0xdff(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [13 x i8] c"/nonexistent\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.3 = [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 i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 0
%10 = load i8*, i8** %9
store i8* %10, i8** %6
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = getelementptr inbounds i8, i8* %13, i64 0
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 47
br i1 %17, label %18, label %37
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i64 @strlen(i8* %21)
%23 = add nsw i64 %22, 2
%24 = call i8* @malloc(i64 %23)
store i8* %24, i8** %6
%25 = load i8*, i8** %6
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %29
27: ; preds = %18
%28 = call i32 (...) @abort()
unreachable
29: ; preds = %18
%30 = load i8*, i8** %6
%31 = call i32 @strcpy(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%32 = load i8*, i8** %6
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 0
%35 = load i8*, i8** %34
%36 = call i32 @strcat(i8* %32, i8* %35)
br label %37
37: ; preds = %29, %2
%38 = load i8*, i8** %6
%39 = call i32* @fopen(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %39, i32** %7
%40 = load i32*, i32** %7
%41 = icmp eq i32* %40, null
br i1 %41, label %42, label %44
42: ; preds = %37
%43 = call i32 (...) @abort()
unreachable
44: ; preds = %37
%45 = load i32*, i32** %7
%46 = call i32 @fclose(i32* %45)
%47 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%48 = icmp ne i32* %47, null
br i1 %48, label %53, label %49
49: ; preds = %44
%50 = load i64, i64* @errno
%51 = load i64, i64* @ENOENT
%52 = icmp ne i64 %50, %51
br i1 %52, label %53, label %55
53: ; preds = %49, %44
%54 = call i32 (...) @abort()
unreachable
55: ; preds = %49
%56 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [13 x i8] c"/nonexistent\00"
@errno = global i64 0
@ENOENT = global i64 0
@str = [5 x i8] c"pass\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = load i8, i8* %3
%5 = icmp eq i8 %4, 47
br i1 %5, label %17, label %6
6: ; preds = %2
%7 = tail call i64 @strlen(i8* %3)
%8 = add nsw i64 %7, 2
%9 = tail call i8* @malloc(i64 %8)
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 (...) @abort()
unreachable
13: ; preds = %6
%14 = tail call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = load i8*, i8** %1
%16 = tail call i32 @strcat(i8* %9, i8* %15)
br label %17
17: ; preds = %13, %2
%18 = phi i8* [ %9, %13 ], [ %3, %2 ]
%19 = tail call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = tail call i32 (...) @abort()
unreachable
23: ; preds = %17
%24 = tail call i32 @fclose(i32* %19)
%25 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load i64, i64* @errno
%29 = load i64, i64* @ENOENT
%30 = icmp eq i64 %28, %29
br i1 %30, label %33, label %31
31: ; preds = %27, %23
%32 = tail call i32 (...) @abort()
unreachable
33: ; preds = %27
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
ret i32 0
}