#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*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strrchr(char const *, char);
char *short_lfn(const char *lfn, char *dos_name) {
  char name[9] = "", ext[4] = "";
  char *dot = strrchr(lfn, '.');
  if (dot == NULL || dot == lfn) {
    strncpy(name, lfn, 8);
    name[8] = '\0';
    if (strlen(lfn) > 8) {
      strncpy(ext, lfn + 8, 3);
      ext[3] = '\0';
    } else
      ext[0] = '\0';
  } else {
    int name_len = dot - lfn;
    if (name_len > 8)
      name_len = 8;
    strncpy(name, lfn, name_len);
    name[name_len] = '\0';
    strncpy(ext, dot + 1, 3);
    ext[3] = '\0';
  }
  {
    char *ptr;
    for (ptr = name; *ptr; ptr++)
      if (*ptr == ' ' || *ptr == '.')
        *ptr = '_';
    for (ptr = ext; *ptr; ptr++)
      if (*ptr == ' ' || *ptr == '.')
        *ptr = '_';
  }
  strcpy(dos_name, name);
  if (*ext) {
    strcat(dos_name, ".");
    strcat(dos_name, ext);
  }
  return dos_name;
}


x86 assembly (clang, -O0):
<short_lfn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x19(%rbp),%rdi
xor    %esi,%esi
mov    $0x9,%edx
call   1070 <memset@plt>
lea    -0x1d(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1070 <memset@plt>
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11bb <short_lfn+0x5b>
mov    -0x28(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    120b <short_lfn+0xab>
lea    -0x19(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x11(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x8,%eax
jle    1202 <short_lfn+0xa2>
lea    -0x1d(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    $0x8,%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x1a(%rbp)
jmp    1206 <short_lfn+0xa6>
movb   $0x0,-0x1d(%rbp)
jmp    125d <short_lfn+0xfd>
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x2c(%rbp)
cmpl   $0x8,-0x2c(%rbp)
jle    122a <short_lfn+0xca>
movl   $0x8,-0x2c(%rbp)
lea    -0x19(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <strncpy@plt>
movslq -0x2c(%rbp),%rax
movb   $0x0,-0x19(%rbp,%rax,1)
lea    -0x1d(%rbp),%rdi
mov    -0x28(%rbp),%rsi
add    $0x1,%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x1a(%rbp)
lea    -0x19(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmpb   $0x0,(%rax)
je     12af <short_lfn+0x14f>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
je     1292 <short_lfn+0x132>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    1299 <short_lfn+0x139>
mov    -0x38(%rbp),%rax
movb   $0x5f,(%rax)
jmp    129e <short_lfn+0x13e>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1265 <short_lfn+0x105>
lea    -0x1d(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmpb   $0x0,(%rax)
je     1301 <short_lfn+0x1a1>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
je     12e4 <short_lfn+0x184>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    12eb <short_lfn+0x18b>
mov    -0x38(%rbp),%rax
movb   $0x5f,(%rax)
jmp    12f0 <short_lfn+0x190>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    12b7 <short_lfn+0x157>
mov    -0x10(%rbp),%rdi
lea    -0x19(%rbp),%rsi
call   1040 <strcpy@plt>
cmpb   $0x0,-0x1d(%rbp)
je     1335 <short_lfn+0x1d5>
mov    -0x10(%rbp),%rdi
lea    0xcdd(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x10(%rbp),%rdi
lea    -0x1d(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x10(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<short_lfn>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
movb   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
movl   $0x0,0x4(%rsp)
mov    $0x2e,%esi
call   1060 <strrchr@plt>
test   %rax,%rax
je     11c2 <short_lfn+0x72>
mov    %rax,%rbx
cmp    %r15,%rax
je     11c2 <short_lfn+0x72>
mov    %ebx,%eax
sub    %r15d,%eax
cmp    $0x8,%eax
mov    $0x8,%ebp
cmovl  %eax,%ebp
lea    0x8(%rsp),%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
movslq %ebp,%rax
movb   $0x0,0x8(%rsp,%rax,1)
add    $0x1,%rbx
lea    0x4(%rsp),%rdi
mov    %rbx,%rsi
jmp    11f2 <short_lfn+0xa2>
lea    0x8(%rsp),%rdi
mov    %r15,%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x10(%rsp)
mov    %r15,%rdi
call   1050 <strlen@plt>
cmp    $0x9,%eax
jl     1203 <short_lfn+0xb3>
add    $0x8,%r15
lea    0x4(%rsp),%rdi
mov    %r15,%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x7(%rsp)
jmp    1208 <short_lfn+0xb8>
movb   $0x0,0x4(%rsp)
lea    0x8(%rsp),%rax
jmp    1217 <short_lfn+0xc7>
nop
movb   $0x5f,(%rax)
add    $0x1,%rax
movzbl (%rax),%ecx
cmp    $0x20,%cl
je     1210 <short_lfn+0xc0>
cmp    $0x2e,%cl
je     1210 <short_lfn+0xc0>
test   %cl,%cl
jne    1213 <short_lfn+0xc3>
lea    0x4(%rsp),%rax
jmp    1237 <short_lfn+0xe7>
nop
movb   $0x5f,(%rax)
add    $0x1,%rax
movzbl (%rax),%ecx
cmp    $0x20,%cl
je     1230 <short_lfn+0xe0>
cmp    $0x2e,%cl
je     1230 <short_lfn+0xe0>
test   %cl,%cl
jne    1233 <short_lfn+0xe3>
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
cmpb   $0x0,0x4(%rsp)
je     1278 <short_lfn+0x128>
lea    0xd9d(%rip),%rsi
mov    %r14,%rdi
call   1070 <strcat@plt>
lea    0x4(%rsp),%rsi
mov    %r14,%rdi
call   1070 <strcat@plt>
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
define i8* @short_lfn(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [9 x i8]
%6 = alloca [4 x i8]
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%10 = bitcast [9 x i8]* %5 to i8*
%11 = bitcast [4 x i8]* %6 to i8*
%12 = load i8*, i8** %3
%13 = call i8* @strrchr(i8* %12, i8 signext 46)
store i8* %13, i8** %7
%14 = load i8*, i8** %7
%15 = icmp eq i8* %14, null
br i1 %15, label %20, label %16
16: ; preds = %2
%17 = load i8*, i8** %7
%18 = load i8*, i8** %3
%19 = icmp eq i8* %17, %18
br i1 %19, label %20, label %37
20: ; preds = %16, %2
%21 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%22 = load i8*, i8** %3
%23 = call i32 @strncpy(i8* %21, i8* %22, i32 8)
%24 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 8
store i8 0, i8* %24
%25 = load i8*, i8** %3
%26 = call i32 @strlen(i8* %25)
%27 = icmp sgt i32 %26, 8
br i1 %27, label %28, label %34
28: ; preds = %20
%29 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%30 = load i8*, i8** %3
%31 = getelementptr inbounds i8, i8* %30, i64 8
%32 = call i32 @strncpy(i8* %29, i8* %31, i32 3)
%33 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 3
store i8 0, i8* %33
br label %36
34: ; preds = %20
%35 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
store i8 0, i8* %35
br label %36
36: ; preds = %34, %28
br label %60
37: ; preds = %16
%38 = load i8*, i8** %7
%39 = load i8*, i8** %3
%40 = ptrtoint i8* %38 to i64
%41 = ptrtoint i8* %39 to i64
%42 = sub i64 %40, %41
%43 = trunc i64 %42 to i32
store i32 %43, i32* %8
%44 = load i32, i32* %8
%45 = icmp sgt i32 %44, 8
br i1 %45, label %46, label %47
46: ; preds = %37
store i32 8, i32* %8
br label %47
47: ; preds = %46, %37
%48 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%49 = load i8*, i8** %3
%50 = load i32, i32* %8
%51 = call i32 @strncpy(i8* %48, i8* %49, i32 %50)
%52 = load i32, i32* %8
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 %53
store i8 0, i8* %54
%55 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%56 = load i8*, i8** %7
%57 = getelementptr inbounds i8, i8* %56, i64 1
%58 = call i32 @strncpy(i8* %55, i8* %57, i32 3)
%59 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 3
store i8 0, i8* %59
br label %60
60: ; preds = %47, %36
%61 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
store i8* %61, i8** %9
br label %62
62: ; preds = %79, %60
%63 = load i8*, i8** %9
%64 = load i8, i8* %63
%65 = icmp ne i8 %64, 0
br i1 %65, label %66, label %82
66: ; preds = %62
%67 = load i8*, i8** %9
%68 = load i8, i8* %67
%69 = sext i8 %68 to i32
%70 = icmp eq i32 %69, 32
br i1 %70, label %76, label %71
71: ; preds = %66
%72 = load i8*, i8** %9
%73 = load i8, i8* %72
%74 = sext i8 %73 to i32
%75 = icmp eq i32 %74, 46
br i1 %75, label %76, label %78
76: ; preds = %71, %66
%77 = load i8*, i8** %9
store i8 95, i8* %77
br label %78
78: ; preds = %76, %71
br label %79
79: ; preds = %78
%80 = load i8*, i8** %9
%81 = getelementptr inbounds i8, i8* %80, i32 1
store i8* %81, i8** %9
br label %62
82: ; preds = %62
%83 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
store i8* %83, i8** %9
br label %84
84: ; preds = %101, %82
%85 = load i8*, i8** %9
%86 = load i8, i8* %85
%87 = icmp ne i8 %86, 0
br i1 %87, label %88, label %104
88: ; preds = %84
%89 = load i8*, i8** %9
%90 = load i8, i8* %89
%91 = sext i8 %90 to i32
%92 = icmp eq i32 %91, 32
br i1 %92, label %98, label %93
93: ; preds = %88
%94 = load i8*, i8** %9
%95 = load i8, i8* %94
%96 = sext i8 %95 to i32
%97 = icmp eq i32 %96, 46
br i1 %97, label %98, label %100
98: ; preds = %93, %88
%99 = load i8*, i8** %9
store i8 95, i8* %99
br label %100
100: ; preds = %98, %93
br label %101
101: ; preds = %100
%102 = load i8*, i8** %9
%103 = getelementptr inbounds i8, i8* %102, i32 1
store i8* %103, i8** %9
br label %84
104: ; preds = %84
%105 = load i8*, i8** %4
%106 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%107 = call i32 @strcpy(i8* %105, i8* %106)
%108 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%109 = load i8, i8* %108
%110 = icmp ne i8 %109, 0
br i1 %110, label %111, label %117
111: ; preds = %104
%112 = load i8*, i8** %4
%113 = call i32 @strcat(i8* %112, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%114 = load i8*, i8** %4
%115 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%116 = call i32 @strcat(i8* %114, i8* %115)
br label %117
117: ; preds = %111, %104
%118 = load i8*, i8** %4
ret i8* %118
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define i8* @short_lfn(i8* %0, i8* returned %1) {
%3 = alloca [9 x i8]
%4 = alloca i32
%5 = bitcast i32* %4 to [4 x i8]*
%6 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 0
%7 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%8 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%9 = icmp eq i8* %8, null
%10 = icmp eq i8* %8, %0
%11 = or i1 %9, %10
br i1 %11, label %12, label %22
12: ; preds = %2
%13 = call i32 @strncpy(i8* %6, i8* %0, i32 8)
%14 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 8
store i8 0, i8* %14
%15 = call i32 @strlen(i8* %0)
%16 = icmp sgt i32 %15, 8
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = getelementptr inbounds i8, i8* %0, i64 8
%19 = call i32 @strncpy(i8* %7, i8* %18, i32 3)
%20 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 3
store i8 0, i8* %20
br label %35
21: ; preds = %12
store i8 0, i8* %7
br label %35
22: ; preds = %2
%23 = ptrtoint i8* %8 to i64
%24 = ptrtoint i8* %0 to i64
%25 = sub i64 %23, %24
%26 = trunc i64 %25 to i32
%27 = icmp slt i32 %26, 8
%28 = select i1 %27, i32 %26, i32 8
%29 = call i32 @strncpy(i8* %6, i8* %0, i32 %28)
%30 = sext i32 %28 to i64
%31 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 %30
store i8 0, i8* %31
%32 = getelementptr inbounds i8, i8* %8, i64 1
%33 = call i32 @strncpy(i8* %7, i8* %32, i32 3)
%34 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 3
store i8 0, i8* %34
br label %35
35: ; preds = %17, %21, %22
br label %36
36: ; preds = %35, %40
%37 = phi i8* [ %41, %40 ], [ %6, %35 ]
%38 = load i8, i8* %37
switch i8 %38, label %40 [
i8 0, label %42
i8 32, label %39
i8 46, label %39
]
39: ; preds = %36, %36
store i8 95, i8* %37
br label %40
40: ; preds = %36, %39
%41 = getelementptr inbounds i8, i8* %37, i64 1
br label %36
42: ; preds = %36, %46
%43 = phi i8* [ %47, %46 ], [ %7, %36 ]
%44 = load i8, i8* %43
switch i8 %44, label %46 [
i8 0, label %48
i8 32, label %45
i8 46, label %45
]
45: ; preds = %42, %42
store i8 95, i8* %43
br label %46
46: ; preds = %42, %45
%47 = getelementptr inbounds i8, i8* %43, i64 1
br label %42
48: ; preds = %42
%49 = call i32 @strcpy(i8* %1, i8* %6)
%50 = load i8, i8* %7
%51 = icmp eq i8 %50, 0
br i1 %51, label %55, label %52
52: ; preds = %48
%53 = call i32 @strcat(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%54 = call i32 @strcat(i8* %1, i8* %7)
br label %55
55: ; preds = %52, %48
ret i8* %1
}