#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 */
char *strchr(char *, char);
scalar_t__ strncmp(char *, char *, int);
int is_valid_fname(char *fname) {
  char *it = fname;
  while (1) {
    if (strncmp(it, "..", 2) == 0) {
      return 0;
    }
    it = strchr(it, '/');
    if (it == NULL)
      break;
    it++;
  }
  return 1;
}


x86 assembly (clang, -O0):
<is_valid_fname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xec1(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    115f <is_valid_fname+0x3f>
movl   $0x0,-0x4(%rbp)
jmp    1199 <is_valid_fname+0x79>
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1181 <is_valid_fname+0x61>
jmp    1192 <is_valid_fname+0x72>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1134 <is_valid_fname+0x14>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_valid_fname>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
lea    0xed2(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     1186 <is_valid_fname+0x66>
lea    0xeb9(%rip),%rbp
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1180 <is_valid_fname+0x60>
mov    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1150 <is_valid_fname+0x30>
jmp    1186 <is_valid_fname+0x66>
mov    $0x1,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"..\00"
define i32 @is_valid_fname(i8* %0) {
%2 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%3 = icmp eq i64 %2, 0
br i1 %3, label %12, label %7
4: ; preds = %7
%5 = tail call i64 @strncmp(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%6 = icmp eq i64 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %1, %4
%8 = phi i8* [ %11, %4 ], [ %0, %1 ]
%9 = tail call i8* @strchr(i8* dereferenceable(1) %8, i8 signext 47)
%10 = icmp eq i8* %9, null
%11 = getelementptr inbounds i8, i8* %9, i64 1
br i1 %10, label %12, label %4
12: ; preds = %4, %7, %1
%13 = phi i32 [ 0, %1 ], [ 1, %7 ], [ 0, %4 ]
ret i32 %13
}