#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 *calloc(int, int);
char *strchr(char *, char);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strrchr(char const *, char);
char *fat_make_shortname(const char *longname) {
  if (!longname)
    return 0;
  char *shortname = calloc(11, 1);
  strncpy(shortname, longname, 8);
  int i = 0;
  char *dot = strchr(shortname, '.');
  if (dot) {
    dot[0] = '\0';
  }
  i = strlen(shortname);
  while (i < 8)
    shortname[i++] = ' ';
  dot = strrchr(longname, '.');
  if (dot)
    strncpy(&shortname[8], &dot[1], 3);
  i = strlen(shortname);
  while (i < 11)
    shortname[i++] = ' ';
  return shortname;
}


x86 assembly (clang, -O0):
<fat_make_shortname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1174 <fat_make_shortname+0x24>
movq   $0x0,-0x8(%rbp)
jmp    1265 <fat_make_shortname+0x115>
mov    $0xb,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11c4 <fat_make_shortname+0x74>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x8,-0x1c(%rbp)
jge    11f5 <fat_make_shortname+0xa5>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x1c(%rbp)
movslq %ecx,%rcx
movb   $0x20,(%rax,%rcx,1)
jmp    11d0 <fat_make_shortname+0x80>
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     122c <fat_make_shortname+0xdc>
mov    -0x18(%rbp),%rdi
add    $0x8,%rdi
mov    -0x28(%rbp),%rsi
add    $0x1,%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xb,-0x1c(%rbp)
jge    125d <fat_make_shortname+0x10d>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x1c(%rbp)
movslq %ecx,%rcx
movb   $0x20,(%rax,%rcx,1)
jmp    1238 <fat_make_shortname+0xe8>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fat_make_shortname>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1223 <fat_make_shortname+0xc3>
mov    %rdi,%r14
mov    $0xb,%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11a7 <fat_make_shortname+0x47>
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x7,%eax
jg     11cf <fat_make_shortname+0x6f>
movslq %eax,%rdi
add    %rbx,%rdi
mov    $0x7,%edx
sub    %eax,%edx
add    $0x1,%rdx
mov    $0x20,%esi
call   1070 <memset@plt>
mov    %r14,%rdi
mov    $0x2e,%esi
call   1060 <strrchr@plt>
test   %rax,%rax
je     11f6 <fat_make_shortname+0x96>
lea    0x8(%rbx),%rdi
add    $0x1,%rax
mov    %rax,%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0xa,%eax
jg     1225 <fat_make_shortname+0xc5>
movslq %eax,%rcx
mov    %rbx,%rdi
add    %rcx,%rdi
mov    $0xa,%edx
sub    %eax,%edx
add    $0x1,%rdx
mov    $0x20,%esi
call   1070 <memset@plt>
jmp    1225 <fat_make_shortname+0xc5>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @fat_make_shortname(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %1
store i8* null, i8** %2
br label %59
10: ; preds = %1
%11 = call i8* @calloc(i32 11, i32 1)
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = load i8*, i8** %3
%14 = call i32 @strncpy(i8* %12, i8* %13, i32 8)
store i32 0, i32* %5
%15 = load i8*, i8** %4
%16 = call i8* @strchr(i8* %15, i8 signext 46)
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %22
19: ; preds = %10
%20 = load i8*, i8** %6
%21 = getelementptr inbounds i8, i8* %20, i64 0
store i8 0, i8* %21
br label %22
22: ; preds = %19, %10
%23 = load i8*, i8** %4
%24 = call i32 @strlen(i8* %23)
store i32 %24, i32* %5
br label %25
25: ; preds = %28, %22
%26 = load i32, i32* %5
%27 = icmp slt i32 %26, 8
br i1 %27, label %28, label %34
28: ; preds = %25
%29 = load i8*, i8** %4
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
%32 = sext i32 %30 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
store i8 32, i8* %33
br label %25
34: ; preds = %25
%35 = load i8*, i8** %3
%36 = call i8* @strrchr(i8* %35, i8 signext 46)
store i8* %36, i8** %6
%37 = load i8*, i8** %6
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %45
39: ; preds = %34
%40 = load i8*, i8** %4
%41 = getelementptr inbounds i8, i8* %40, i64 8
%42 = load i8*, i8** %6
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = call i32 @strncpy(i8* %41, i8* %43, i32 3)
br label %45
45: ; preds = %39, %34
%46 = load i8*, i8** %4
%47 = call i32 @strlen(i8* %46)
store i32 %47, i32* %5
br label %48
48: ; preds = %51, %45
%49 = load i32, i32* %5
%50 = icmp slt i32 %49, 11
br i1 %50, label %51, label %57
51: ; preds = %48
%52 = load i8*, i8** %4
%53 = load i32, i32* %5
%54 = add nsw i32 %53, 1
store i32 %54, i32* %5
%55 = sext i32 %53 to i64
%56 = getelementptr inbounds i8, i8* %52, i64 %55
store i8 32, i8* %56
br label %48
57: ; preds = %48
%58 = load i8*, i8** %4
store i8* %58, i8** %2
br label %59
59: ; preds = %57, %9
%60 = load i8*, i8** %2
ret i8* %60
}

LLVM IR (-O2):
define i8* @fat_make_shortname(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %34, label %3
3: ; preds = %1
%4 = tail call dereferenceable_or_null(11) i8* @calloc(i32 11, i32 1)
%5 = tail call i32 @strncpy(i8* %4, i8* %0, i32 8)
%6 = tail call i8* @strchr(i8* dereferenceable(1) %4, i8 signext 46)
%7 = icmp eq i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %3
store i8 0, i8* %6
br label %9
9: ; preds = %8, %3
%10 = tail call i32 @strlen(i8* %4)
%11 = icmp slt i32 %10, 8
br i1 %11, label %12, label %18
12: ; preds = %9
%13 = sext i32 %10 to i64
%14 = getelementptr i8, i8* %4, i64 %13
%15 = sub i32 7, %10
%16 = zext i32 %15 to i64
%17 = add nuw nsw i64 %16, 1
br label %18
18: ; preds = %12, %9
%19 = tail call i8* @strrchr(i8* %0, i8 signext 46)
%20 = icmp eq i8* %19, null
br i1 %20, label %25, label %21
21: ; preds = %18
%22 = getelementptr inbounds i8, i8* %4, i64 8
%23 = getelementptr inbounds i8, i8* %19, i64 1
%24 = tail call i32 @strncpy(i8* %22, i8* %23, i32 3)
br label %25
25: ; preds = %21, %18
%26 = tail call i32 @strlen(i8* %4)
%27 = icmp slt i32 %26, 11
br i1 %27, label %28, label %34
28: ; preds = %25
%29 = sext i32 %26 to i64
%30 = getelementptr i8, i8* %4, i64 %29
%31 = sub i32 10, %26
%32 = zext i32 %31 to i64
%33 = add nuw nsw i64 %32, 1
br label %34
34: ; preds = %28, %25, %1
%35 = phi i8* [ null, %1 ], [ %4, %25 ], [ %4, %28 ]
ret i8* %35
}