#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 tolower(char);
void ldir_name_to_filename(char *filename, char *src) {
  int new_fn_idx, old_fn_idx;
  for (new_fn_idx = old_fn_idx = 0; old_fn_idx < 11; old_fn_idx++) {
    char c = src[old_fn_idx];
    if (c != ' ')
      filename[new_fn_idx++] = tolower(c);
    if (old_fn_idx == 7)
      filename[new_fn_idx++] = '.';
  }
  filename[new_fn_idx++] = '\0';
}


x86 assembly (clang, -O0):
<ldir_name_to_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xb,-0x18(%rbp)
jge    11a6 <ldir_name_to_filename+0x96>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0x20,%eax
je     1173 <ldir_name_to_filename+0x63>
movsbl -0x19(%rbp),%edi
call   1030 <tolower@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x14(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
cmpl   $0x7,-0x18(%rbp)
jne    1193 <ldir_name_to_filename+0x83>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
movslq %ecx,%rcx
movb   $0x2e,(%rax,%rcx,1)
jmp    1198 <ldir_name_to_filename+0x88>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    112e <ldir_name_to_filename+0x1e>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ldir_name_to_filename>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    113a <ldir_name_to_filename+0x2a>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rbx
cmp    $0xb,%rbx
je     1168 <ldir_name_to_filename+0x58>
movzbl (%r14,%rbx,1),%eax
cmp    $0x20,%al
je     1155 <ldir_name_to_filename+0x45>
movsbl %al,%edi
call   1030 <tolower@plt>
movslq %ebp,%rcx
add    $0x1,%ebp
mov    %al,(%r15,%rcx,1)
cmp    $0x7,%rbx
jne    1130 <ldir_name_to_filename+0x20>
movslq %ebp,%rax
add    $0x1,%ebp
movb   $0x2e,(%r15,%rax,1)
jmp    1130 <ldir_name_to_filename+0x20>
movslq %ebp,%rax
movb   $0x0,(%r15,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @ldir_name_to_filename(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %6
store i32 0, i32* %5
br label %8
8: ; preds = %38, %2
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 11
br i1 %10, label %11, label %41
11: ; preds = %8
%12 = load i8*, i8** %4
%13 = load i32, i32* %6
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
store i8 %16, i8* %7
%17 = load i8, i8* %7
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 32
br i1 %19, label %20, label %28
20: ; preds = %11
%21 = load i8, i8* %7
%22 = call signext i8 @tolower(i8 signext %21)
%23 = load i8*, i8** %3
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
store i32 %25, i32* %5
%26 = sext i32 %24 to i64
%27 = getelementptr inbounds i8, i8* %23, i64 %26
store i8 %22, i8* %27
br label %28
28: ; preds = %20, %11
%29 = load i32, i32* %6
%30 = icmp eq i32 %29, 7
br i1 %30, label %31, label %37
31: ; preds = %28
%32 = load i8*, i8** %3
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
store i32 %34, i32* %5
%35 = sext i32 %33 to i64
%36 = getelementptr inbounds i8, i8* %32, i64 %35
store i8 46, i8* %36
br label %37
37: ; preds = %31, %28
br label %38
38: ; preds = %37
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
store i32 %40, i32* %6
br label %8
41: ; preds = %8
%42 = load i8*, i8** %3
%43 = load i32, i32* %5
%44 = add nsw i32 %43, 1
store i32 %44, i32* %5
%45 = sext i32 %43 to i64
%46 = getelementptr inbounds i8, i8* %42, i64 %45
store i8 0, i8* %46
ret void
}

LLVM IR (-O2):
define void @ldir_name_to_filename(i8* nocapture writeonly %0, i8* nocapture %1) {
br label %3
3: ; preds = %2, %21
%4 = phi i64 [ 0, %2 ], [ %23, %21 ]
%5 = phi i32 [ 0, %2 ], [ %22, %21 ]
%6 = getelementptr inbounds i8, i8* %1, i64 %4
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 32
br i1 %8, label %14, label %9
9: ; preds = %3
%10 = tail call signext i8 @tolower(i8 signext %7)
%11 = add nsw i32 %5, 1
%12 = sext i32 %5 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
store i8 %10, i8* %13
br label %14
14: ; preds = %9, %3
%15 = phi i32 [ %11, %9 ], [ %5, %3 ]
%16 = icmp eq i64 %4, 7
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = add nsw i32 %15, 1
%19 = sext i32 %15 to i64
%20 = getelementptr inbounds i8, i8* %0, i64 %19
store i8 46, i8* %20
br label %21
21: ; preds = %17, %14
%22 = phi i32 [ %18, %17 ], [ %15, %14 ]
%23 = add nuw nsw i64 %4, 1
%24 = icmp eq i64 %23, 11
br i1 %24, label %25, label %3
25: ; preds = %21
%26 = sext i32 %22 to i64
%27 = getelementptr inbounds i8, i8* %0, i64 %26
store i8 0, i8* %27
ret void
}