#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__ EFAULT;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ err(char *);
scalar_t__ errno;
int /*<<< orphan*/ printf(char *);
int rename(char *, char *);
int main(int argc, char *argv[]) {
  if (argc != 1 ||
      (argv[0][0] != '.' && argv[0][0] != '/' && argv[0][0] != 'r'))
    abort();
  if (rename(argv[0], NULL) != -1 || errno != EFAULT)
    err("rename 1 ");
  errno = 0;
  if (rename(NULL, argv[0]) != -1 || errno != EFAULT)
    err("rename 2");
  printf("pass\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1199 <main+0x59>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     11a0 <main+0x60>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     11a0 <main+0x60>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x72,%eax
je     11a0 <main+0x60>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <rename@plt>
cmp    $0xffffffff,%eax
jne    11d3 <main+0x93>
mov    0x2e18(%rip),%rax
mov    (%rax),%rax
mov    0x2e2e(%rip),%rcx
cmp    (%rcx),%rax
je     11df <main+0x9f>
lea    0xe26(%rip),%rdi
call   1050 <err@plt>
mov    0x2df2(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1060 <rename@plt>
cmp    $0xffffffff,%eax
jne    1220 <main+0xe0>
mov    0x2dcb(%rip),%rax
mov    (%rax),%rax
mov    0x2de1(%rip),%rcx
cmp    (%rcx),%rax
je     122c <main+0xec>
lea    0xde3(%rip),%rdi
call   1050 <err@plt>
lea    0xde0(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%edi
jne    11dd <main+0x9d>
mov    %rsi,%rbx
mov    (%rsi),%rdi
mov    (%rdi),%al
lea    -0x2e(%rax),%ecx
cmp    $0x2,%cl
jb     1161 <main+0x21>
cmp    $0x72,%al
jne    11dd <main+0x9d>
xor    %esi,%esi
call   1060 <rename@plt>
cmp    $0xffffffff,%eax
jne    1183 <main+0x43>
mov    0x2e64(%rip),%rax
mov    (%rax),%rax
mov    0x2e7a(%rip),%rcx
cmp    (%rcx),%rax
je     118f <main+0x4f>
lea    0xe76(%rip),%rdi
call   1050 <err@plt>
mov    0x2e42(%rip),%r14
movq   $0x0,(%r14)
mov    (%rbx),%rsi
xor    %edi,%edi
call   1060 <rename@plt>
cmp    $0xffffffff,%eax
jne    11bb <main+0x7b>
mov    (%r14),%rax
mov    0x2e42(%rip),%rcx
cmp    (%rcx),%rax
je     11c7 <main+0x87>
lea    0xe48(%rip),%rdi
call   1050 <err@plt>
lea    0xe45(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@errno = global i64 0
@EFAULT = global i64 0
@.str = [10 x i8] c"rename 1 \00"
@.str.1 = [9 x i8] c"rename 2\00"
@.str.2 = [6 x i8] c"pass\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* %4
%7 = icmp ne i32 %6, 1
br i1 %7, label %32, label %8
8: ; preds = %2
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 0
%11 = load i8*, i8** %10
%12 = getelementptr inbounds i8, i8* %11, i64 0
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 46
br i1 %15, label %16, label %34
16: ; preds = %8
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = getelementptr inbounds i8, i8* %19, i64 0
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 47
br i1 %23, label %24, label %34
24: ; preds = %16
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = getelementptr inbounds i8, i8* %27, i64 0
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 114
br i1 %31, label %32, label %34
32: ; preds = %24, %2
%33 = call i32 (...) @abort()
unreachable
34: ; preds = %24, %16, %8
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 0
%37 = load i8*, i8** %36
%38 = call i32 @rename(i8* %37, i8* null)
%39 = icmp ne i32 %38, -1
br i1 %39, label %44, label %40
40: ; preds = %34
%41 = load i64, i64* @errno
%42 = load i64, i64* @EFAULT
%43 = icmp ne i64 %41, %42
br i1 %43, label %44, label %46
44: ; preds = %40, %34
%45 = call i32 @err(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %46
46: ; preds = %44, %40
store i64 0, i64* @errno
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 0
%49 = load i8*, i8** %48
%50 = call i32 @rename(i8* null, i8* %49)
%51 = icmp ne i32 %50, -1
br i1 %51, label %56, label %52
52: ; preds = %46
%53 = load i64, i64* @errno
%54 = load i64, i64* @EFAULT
%55 = icmp ne i64 %53, %54
br i1 %55, label %56, label %58
56: ; preds = %52, %46
%57 = call i32 @err(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %58
58: ; preds = %56, %52
%59 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@errno = global i64 0
@EFAULT = global i64 0
@.str = [10 x i8] c"rename 1 \00"
@.str.1 = [9 x i8] c"rename 2\00"
@str = [5 x i8] c"pass\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = load i8, i8* %5
switch i8 %6, label %7 [
i8 46, label %9
i8 47, label %9
i8 114, label %9
]
7: ; preds = %4, %2
%8 = tail call i32 (...) @abort()
unreachable
9: ; preds = %4, %4, %4
%10 = tail call i32 @rename(i8* %5, i8* null)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load i64, i64* @errno
%14 = load i64, i64* @EFAULT
%15 = icmp eq i64 %13, %14
br i1 %15, label %18, label %16
16: ; preds = %12, %9
%17 = tail call i32 @err(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %12
store i64 0, i64* @errno
%19 = load i8*, i8** %1
%20 = tail call i32 @rename(i8* null, i8* %19)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = load i64, i64* @errno
%24 = load i64, i64* @EFAULT
%25 = icmp eq i64 %23, %24
br i1 %25, label %28, label %26
26: ; preds = %22, %18
%27 = tail call i32 @err(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %26, %22
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
ret i32 0
}