#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__ strchr(char const *, char);
scalar_t__ strcmp(char const *, char *);
int validrename(const char *oldname, const char *newname) {
  if (strchr(oldname, '/') || strchr(newname, '/') || newname[0] != '.' ||
      strcmp(newname, ".") == 0)
    return (-1);
  while (*newname) {
    if (*newname == '.') {
      if (newname[1] == '.' || newname[1] == 0)
        return -1;
    }
    ++newname;
  }
  return 0;
}


x86 assembly (clang, -O0):
<validrename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
jne    118a <validrename+0x6a>
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
jne    118a <validrename+0x6a>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    118a <validrename+0x6a>
mov    -0x18(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1196 <validrename+0x76>
movl   $0xffffffff,-0x4(%rbp)
jmp    1203 <validrename+0xe3>
jmp    119b <validrename+0x7b>
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     11fc <validrename+0xdc>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11eb <validrename+0xcb>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2e,%eax
je     11da <validrename+0xba>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    11e6 <validrename+0xc6>
movl   $0xffffffff,-0x4(%rbp)
jmp    1203 <validrename+0xe3>
jmp    11eb <validrename+0xcb>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    119b <validrename+0x7b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validrename>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    $0x2f,%esi
call   1030 <strchr@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jne    118f <validrename+0x6f>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
test   %rax,%rax
jne    118f <validrename+0x6f>
cmpb   $0x2e,(%rbx)
jne    118f <validrename+0x6f>
lea    0xea8(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    1174 <validrename+0x54>
jmp    118f <validrename+0x6f>
nopw   0x0(%rax,%rax,1)
test   %al,%al
je     118d <validrename+0x6d>
add    $0x1,%rbx
movzbl -0x1(%rbx),%eax
cmp    $0x2e,%al
jne    1170 <validrename+0x50>
movzbl (%rbx),%eax
test   %al,%al
je     118f <validrename+0x6f>
cmp    $0x2e,%al
jne    1174 <validrename+0x54>
jmp    118f <validrename+0x6f>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define i32 @validrename(i8* %0, i8* %1) {
%3 = tail call i64 @strchr(i8* %0, i8 signext 47)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %22
5: ; preds = %2
%6 = tail call i64 @strchr(i8* %1, i8 signext 47)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %22
8: ; preds = %5
%9 = load i8, i8* %1
%10 = icmp eq i8 %9, 46
br i1 %10, label %11, label %22
11: ; preds = %8
%12 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %22, label %14
14: ; preds = %11, %20
%15 = phi i8* [ %21, %20 ], [ %1, %11 ]
%16 = load i8, i8* %15
switch i8 %16, label %20 [
i8 0, label %22
i8 46, label %17
]
17: ; preds = %14
%18 = getelementptr inbounds i8, i8* %15, i64 1
%19 = load i8, i8* %18
switch i8 %19, label %20 [
i8 46, label %22
i8 0, label %22
]
20: ; preds = %17, %14
%21 = getelementptr inbounds i8, i8* %15, i64 1
br label %14
22: ; preds = %14, %17, %17, %2, %5, %8, %11
%23 = phi i32 [ -1, %11 ], [ -1, %8 ], [ -1, %5 ], [ -1, %2 ], [ 0, %14 ], [ -1, %17 ], [ -1, %17 ]
ret i32 %23
}