#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*/ getch();
short index(char *, char);
int /*<<< orphan*/ printf(char *, short);
int /*<<< orphan*/ report(int, char *);
int /*<<< orphan*/ strcat(char *, char *);
void checkpath(char *name) {
  char *p, c;
  short i;
  static char badchar[] = ",;:_[]=<>/";
  for (p = name; *p; p++) {
    if (!(((c = *p) > '!') && (c < 0x7f) && !index(badchar, c))) {
      *p = '\0';
      strcat(name, p + 1);
    }
  }
  if (i = index(name, '.')) {
    printf("i=%d\n", i);
    getch();
    if (i > 8) {
      p = name + i;
      name[8] = '.';
      name[9] = '\0';
      p[3] = '\0';
      strcat(name, p);
    }
  }
  name[12] = '\0';
  report(4, name);
}


x86 assembly (clang, -O0):
<checkpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11db <checkpath+0x8b>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x11(%rbp)
movsbl %al,%eax
cmp    $0x21,%eax
jle    11ad <checkpath+0x5d>
movsbl -0x11(%rbp),%eax
cmp    $0x7f,%eax
jge    11ad <checkpath+0x5d>
lea    0x2eae(%rip),%rdi
movsbl -0x11(%rbp),%esi
call   1040 <index@plt>
cmp    $0x0,%ax
je     11c5 <checkpath+0x75>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x1,%rsi
call   1060 <strcat@plt>
jmp    11ca <checkpath+0x7a>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1164 <checkpath+0x14>
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <index@plt>
mov    %ax,-0x14(%rbp)
cmp    $0x0,%ax
je     1257 <checkpath+0x107>
lea    0xe02(%rip),%rdi
movswl -0x14(%rbp),%esi
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <getch@plt>
movswl -0x14(%rbp),%eax
cmp    $0x8,%eax
jle    1252 <checkpath+0x102>
mov    -0x8(%rbp),%rax
movswl -0x14(%rbp),%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x2e,0x8(%rax)
mov    -0x8(%rbp),%rax
movb   $0x0,0x9(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x3(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcat@plt>
jmp    1257 <checkpath+0x107>
mov    -0x8(%rbp),%rax
movb   $0x0,0xc(%rax)
mov    -0x8(%rbp),%rsi
mov    $0x4,%edi
call   1070 <report@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkpath>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    (%rdi),%al
test   %al,%al
je     11a4 <checkpath+0x54>
lea    0x1(%r14),%rbx
lea    0x2edf(%rip),%r15
jmp    118a <checkpath+0x3a>
nopl   0x0(%rax,%rax,1)
movb   $0x0,-0x1(%rbx)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <strcat@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     11a4 <checkpath+0x54>
lea    -0x22(%rax),%ecx
cmp    $0x5c,%cl
ja     1170 <checkpath+0x20>
movsbl %al,%esi
mov    %r15,%rdi
call   1040 <index@plt>
test   %ax,%ax
jne    1170 <checkpath+0x20>
jmp    117f <checkpath+0x2f>
mov    %r14,%rdi
mov    $0x2e,%esi
call   1040 <index@plt>
test   %ax,%ax
je     11f0 <checkpath+0xa0>
mov    %eax,%ebx
movswl %ax,%esi
lea    0xe3e(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <getch@plt>
cmp    $0x9,%bx
jl     11f0 <checkpath+0xa0>
movzwl %bx,%eax
lea    (%r14,%rax,1),%rsi
movw   $0x2e,0x8(%r14)
movb   $0x0,0x3(%r14,%rax,1)
mov    %r14,%rdi
call   1060 <strcat@plt>
movb   $0x0,0xc(%r14)
mov    $0x4,%edi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1070 <report@plt>

LLVM IR (-O0):
@checkpath.badchar = internal global [11 x i8] c",;:_[]=<>/\00"
@.str = [6 x i8] c"i=%d\0A\00"
define void @checkpath(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i16
store i8* %0, i8** %2
%6 = load i8*, i8** %2
store i8* %6, i8** %3
br label %7
7: ; preds = %31, %1
%8 = load i8*, i8** %3
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
br i1 %10, label %11, label %34
11: ; preds = %7
%12 = load i8*, i8** %3
%13 = load i8, i8* %12
store i8 %13, i8* %4
%14 = sext i8 %13 to i32
%15 = icmp sgt i32 %14, 33
br i1 %15, label %16, label %24
16: ; preds = %11
%17 = load i8, i8* %4
%18 = sext i8 %17 to i32
%19 = icmp slt i32 %18, 127
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i8, i8* %4
%22 = call signext i16 @index(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @checkpath.badchar, i64 0, i64 0), i8 signext %21)
%23 = icmp ne i16 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %20, %16, %11
%25 = load i8*, i8** %3
store i8 0, i8* %25
%26 = load i8*, i8** %2
%27 = load i8*, i8** %3
%28 = getelementptr inbounds i8, i8* %27, i64 1
%29 = call i32 @strcat(i8* %26, i8* %28)
br label %30
30: ; preds = %24, %20
br label %31
31: ; preds = %30
%32 = load i8*, i8** %3
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %3
br label %7
34: ; preds = %7
%35 = load i8*, i8** %2
%36 = call signext i16 @index(i8* %35, i8 signext 46)
store i16 %36, i16* %5
%37 = icmp ne i16 %36, 0
br i1 %37, label %38, label %61
38: ; preds = %34
%39 = load i16, i16* %5
%40 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i16 signext %39)
%41 = call i32 (...) @getch()
%42 = load i16, i16* %5
%43 = sext i16 %42 to i32
%44 = icmp sgt i32 %43, 8
br i1 %44, label %45, label %60
45: ; preds = %38
%46 = load i8*, i8** %2
%47 = load i16, i16* %5
%48 = sext i16 %47 to i32
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %46, i64 %49
store i8* %50, i8** %3
%51 = load i8*, i8** %2
%52 = getelementptr inbounds i8, i8* %51, i64 8
store i8 46, i8* %52
%53 = load i8*, i8** %2
%54 = getelementptr inbounds i8, i8* %53, i64 9
store i8 0, i8* %54
%55 = load i8*, i8** %3
%56 = getelementptr inbounds i8, i8* %55, i64 3
store i8 0, i8* %56
%57 = load i8*, i8** %2
%58 = load i8*, i8** %3
%59 = call i32 @strcat(i8* %57, i8* %58)
br label %60
60: ; preds = %45, %38
br label %61
61: ; preds = %60, %34
%62 = load i8*, i8** %2
%63 = getelementptr inbounds i8, i8* %62, i64 12
store i8 0, i8* %63
%64 = load i8*, i8** %2
%65 = call i32 @report(i32 4, i8* %64)
ret void
}

LLVM IR (-O2):
@checkpath.badchar = internal global [11 x i8] c",;:_[]=<>/\00"
@.str = [6 x i8] c"i=%d\0A\00"
define void @checkpath(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %19, label %4
4: ; preds = %1, %15
%5 = phi i8 [ %17, %15 ], [ %2, %1 ]
%6 = phi i8* [ %16, %15 ], [ %0, %1 ]
%7 = add i8 %5, -34
%8 = icmp ult i8 %7, 93
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = tail call signext i16 @index(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @checkpath.badchar, i64 0, i64 0), i8 signext %5)
%11 = icmp eq i16 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %9, %4
store i8 0, i8* %6
%13 = getelementptr inbounds i8, i8* %6, i64 1
%14 = tail call i32 @strcat(i8* %0, i8* %13)
br label %15
15: ; preds = %9, %12
%16 = getelementptr inbounds i8, i8* %6, i64 1
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %4
19: ; preds = %15, %1
%20 = tail call signext i16 @index(i8* %0, i8 signext 46)
%21 = icmp eq i16 %20, 0
br i1 %21, label %33, label %22
22: ; preds = %19
%23 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i16 signext %20)
%24 = tail call i32 (...) @getch()
%25 = icmp sgt i16 %20, 8
br i1 %25, label %26, label %33
26: ; preds = %22
%27 = zext i16 %20 to i64
%28 = getelementptr inbounds i8, i8* %0, i64 %27
%29 = getelementptr inbounds i8, i8* %0, i64 8
store i8 46, i8* %29
%30 = getelementptr inbounds i8, i8* %0, i64 9
store i8 0, i8* %30
%31 = getelementptr inbounds i8, i8* %28, i64 3
store i8 0, i8* %31
%32 = tail call i32 @strcat(i8* %0, i8* %28)
br label %33
33: ; preds = %22, %26, %19
%34 = getelementptr inbounds i8, i8* %0, i64 12
store i8 0, i8* %34
%35 = tail call i32 @report(i32 4, i8* %0)
ret void
}