#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 *);
scalar_t__ names_ok(int, char *, char *, char *, char *);
int sscanf(char *, char *, char *, char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void unmangle(char *name, char *nam, char *ext, char *prj, char *prg) {
  int n;
  if (strlen(name) > 18) {
    fprintf(stderr, "\nInput file name too long: %s", name);
    exit(1);
  }
  strcpy(prj, "   ");
  strcpy(prg, "   ");
  prj += 3;
  prg += 3;
  *ext = 0;
  n = sscanf(name, "%[^/]/%[^/]/%[^.].%s", prg, prj, nam, ext);
  if (n > 2 && names_ok(n, prg, prj, nam, ext))
    return;
  n = sscanf(name, "%[^.].%[^/]/%[^.].%s", prg, prj, nam, ext);
  if (names_ok(n, prg, prj, nam, ext))
    return;
  fprintf(stderr, "\nBad input file name: %s", name);
  exit(1);
}


x86 assembly (clang, -O0):
<unmangle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x12,%eax
jle    11b1 <unmangle+0x51>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe5e(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x20(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    -0x18(%rbp),%r9
lea    0xe17(%rip),%rsi
call   1070 <sscanf@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x2,-0x2c(%rbp)
jle    1244 <unmangle+0xe4>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
call   1040 <names_ok@plt>
cmp    $0x0,%rax
je     1244 <unmangle+0xe4>
jmp    12b1 <unmangle+0x151>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    -0x18(%rbp),%r9
lea    0xdd8(%rip),%rsi
call   1070 <sscanf@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
call   1040 <names_ok@plt>
cmp    $0x0,%rax
je     128e <unmangle+0x12e>
jmp    12b1 <unmangle+0x151>
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdaa(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unmangle>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r12
mov    %rcx,%rbx
mov    %rdx,%r15
mov    %rsi,%r13
mov    %rdi,%r14
call   1050 <strlen@plt>
cmp    $0x13,%eax
jge    122b <unmangle+0xcb>
lea    0xe8f(%rip),%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
add    $0x3,%rbx
add    $0x3,%r12
movb   $0x0,(%r15)
lea    0xe6a(%rip),%rsi
mov    %r14,%rdi
mov    %r12,%rdx
mov    %rbx,%rcx
mov    %r13,%r8
mov    %r15,%r9
call   1070 <sscanf@plt>
cmp    $0x3,%eax
jl     11e9 <unmangle+0x89>
mov    %eax,%edi
mov    %r12,%rsi
mov    %rbx,%rdx
mov    %r13,%rcx
mov    %r15,%r8
call   1040 <names_ok@plt>
test   %rax,%rax
jne    121c <unmangle+0xbc>
lea    0xe47(%rip),%rsi
mov    %r14,%rdi
mov    %r12,%rdx
mov    %rbx,%rcx
mov    %r13,%r8
mov    %r15,%r9
call   1070 <sscanf@plt>
mov    %eax,%edi
mov    %r12,%rsi
mov    %rbx,%rdx
mov    %r13,%rcx
mov    %r15,%r8
call   1040 <names_ok@plt>
test   %rax,%rax
je     123d <unmangle+0xdd>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
lea    0xdc5(%rip),%rsi
jmp    124d <unmangle+0xed>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
lea    0xdff(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"\0AInput file name too long: %s\00"
@.str.1 = [4 x i8] c" \00"
@.str.2 = [21 x i8] c"%[^/]/%[^/]/%[^.].%s\00"
@.str.3 = [21 x i8] c"%[^.].%[^/]/%[^.].%s\00"
@.str.4 = [25 x i8] c"\0ABad input file name: %s\00"
define void @unmangle(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i8* %4, i8** %10
%12 = load i8*, i8** %6
%13 = call i32 @strlen(i8* %12)
%14 = icmp sgt i32 %13, 18
br i1 %14, label %15, label %20
15: ; preds = %5
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %6
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %5
%21 = load i8*, i8** %9
%22 = call i32 @strcpy(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%23 = load i8*, i8** %10
%24 = call i32 @strcpy(i8* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%25 = load i8*, i8** %9
%26 = getelementptr inbounds i8, i8* %25, i64 3
store i8* %26, i8** %9
%27 = load i8*, i8** %10
%28 = getelementptr inbounds i8, i8* %27, i64 3
store i8* %28, i8** %10
%29 = load i8*, i8** %8
store i8 0, i8* %29
%30 = load i8*, i8** %6
%31 = load i8*, i8** %10
%32 = load i8*, i8** %9
%33 = load i8*, i8** %7
%34 = load i8*, i8** %8
%35 = call i32 @sscanf(i8* %30, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %31, i8* %32, i8* %33, i8* %34)
store i32 %35, i32* %11
%36 = load i32, i32* %11
%37 = icmp sgt i32 %36, 2
br i1 %37, label %38, label %47
38: ; preds = %20
%39 = load i32, i32* %11
%40 = load i8*, i8** %10
%41 = load i8*, i8** %9
%42 = load i8*, i8** %7
%43 = load i8*, i8** %8
%44 = call i64 @names_ok(i32 %39, i8* %40, i8* %41, i8* %42, i8* %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %38
br label %67
47: ; preds = %38, %20
%48 = load i8*, i8** %6
%49 = load i8*, i8** %10
%50 = load i8*, i8** %9
%51 = load i8*, i8** %7
%52 = load i8*, i8** %8
%53 = call i32 @sscanf(i8* %48, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %49, i8* %50, i8* %51, i8* %52)
store i32 %53, i32* %11
%54 = load i32, i32* %11
%55 = load i8*, i8** %10
%56 = load i8*, i8** %9
%57 = load i8*, i8** %7
%58 = load i8*, i8** %8
%59 = call i64 @names_ok(i32 %54, i8* %55, i8* %56, i8* %57, i8* %58)
%60 = icmp ne i64 %59, 0
br i1 %60, label %61, label %62
61: ; preds = %47
br label %67
62: ; preds = %47
%63 = load i32, i32* @stderr
%64 = load i8*, i8** %6
%65 = call i32 @fprintf(i32 %63, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %64)
%66 = call i32 @exit(i32 1)
unreachable
67: ; preds = %61, %46
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"\0AInput file name too long: %s\00"
@.str.1 = [4 x i8] c" \00"
@.str.2 = [21 x i8] c"%[^/]/%[^/]/%[^.].%s\00"
@.str.3 = [21 x i8] c"%[^.].%[^/]/%[^.].%s\00"
@.str.4 = [25 x i8] c"\0ABad input file name: %s\00"
define void @unmangle(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4) {
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp sgt i32 %6, 18
br i1 %7, label %8, label %12
8: ; preds = %5
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %0)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %5
%13 = tail call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%15 = getelementptr inbounds i8, i8* %3, i64 3
%16 = getelementptr inbounds i8, i8* %4, i64 3
store i8 0, i8* %2
%17 = tail call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %16, i8* %15, i8* %1, i8* %2)
%18 = icmp sgt i32 %17, 2
br i1 %18, label %19, label %22
19: ; preds = %12
%20 = tail call i64 @names_ok(i32 %17, i8* %16, i8* %15, i8* %1, i8* %2)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %19, %12
%23 = tail call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %16, i8* %15, i8* %1, i8* %2)
%24 = tail call i64 @names_ok(i32 %23, i8* %16, i8* %15, i8* %1, i8* %2)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %0)
%29 = tail call i32 @exit(i32 1)
unreachable
30: ; preds = %22, %19
ret void
}