#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 */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ isalnum(char);
int /*<<< orphan*/ stderr;
void validate(char *path) {
  char *s;
  for (s = path; *s; s++) {
    if (!isalnum(*s) && *s != '/') {
      fprintf(stderr, "invalid path: %s\n", path);
      exit(1);
    }
  }
}


x86 assembly (clang, -O0):
<validate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11af <validate+0x7f>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isalnum@plt>
cmp    $0x0,%eax
jne    1199 <validate+0x69>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     1199 <validate+0x69>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe76(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    119e <validate+0x6e>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1144 <validate+0x14>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate>:
push   %r14
push   %rbx
push   %rax
mov    (%rdi),%al
test   %al,%al
je     118f <validate+0x5f>
mov    %rdi,%r14
lea    0x1(%rdi),%rbx
jmp    115b <validate+0x2b>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     118f <validate+0x5f>
movsbl %al,%edi
call   1030 <isalnum@plt>
test   %eax,%eax
jne    1150 <validate+0x20>
cmpb   $0x2f,-0x1(%rbx)
je     1150 <validate+0x20>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"invalid path: %s\0A\00"
define void @validate(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
store i8* %4, i8** %3
br label %5
5: ; preds = %25, %1
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
%8 = icmp ne i8 %7, 0
br i1 %8, label %9, label %28
9: ; preds = %5
%10 = load i8*, i8** %3
%11 = load i8, i8* %10
%12 = call i32 @isalnum(i8 signext %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %24, label %14
14: ; preds = %9
%15 = load i8*, i8** %3
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 47
br i1 %18, label %19, label %24
19: ; preds = %14
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %2
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %14, %9
br label %25
25: ; preds = %24
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %3
br label %5
28: ; preds = %5
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"invalid path: %s\0A\00"
define void @validate(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %20, label %4
4: ; preds = %1, %16
%5 = phi i8 [ %18, %16 ], [ %2, %1 ]
%6 = phi i8* [ %17, %16 ], [ %0, %1 ]
%7 = tail call i32 @isalnum(i8 signext %5)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %4
%10 = load i8, i8* %6
%11 = icmp eq i8 %10, 47
br i1 %11, label %16, label %12
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %0)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %4, %9
%17 = getelementptr inbounds i8, i8* %6, i64 1
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %20, label %4
20: ; preds = %16, %1
ret void
}