#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 *malloc(unsigned short);
int /*<<< orphan*/ strcpy(char *, char const *);
unsigned short strlen(char const *);
char *addLmdExtension(const char *fileName) {
  char *answer;
  unsigned short length = strlen(fileName);
  if (fileName[length - 4] == '.' && fileName[length - 3] == 'l' &&
      fileName[length - 2] == 'm' && fileName[length - 1] == 'd')
    return (char *)fileName;
  answer = malloc((length + 5) * sizeof(char));
  strcpy(answer, fileName);
  answer[length] = '.';
  answer[length + 1] = 'l';
  answer[length + 2] = 'm';
  answer[length + 3] = 'd';
  answer[length + 4] = '\0';
  return answer;
}


x86 assembly (clang, -O0):
<addLmdExtension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %ax,-0x1a(%rbp)
mov    -0x10(%rbp),%rax
movzwl -0x1a(%rbp),%ecx
sub    $0x4,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    11c2 <addLmdExtension+0x92>
mov    -0x10(%rbp),%rax
movzwl -0x1a(%rbp),%ecx
sub    $0x3,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x6c,%eax
jne    11c2 <addLmdExtension+0x92>
mov    -0x10(%rbp),%rax
movzwl -0x1a(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x6d,%eax
jne    11c2 <addLmdExtension+0x92>
mov    -0x10(%rbp),%rax
movzwl -0x1a(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x64,%eax
jne    11c2 <addLmdExtension+0x92>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1244 <addLmdExtension+0x114>
movzwl -0x1a(%rbp),%eax
add    $0x5,%eax
cltq
shl    $0x0,%rax
movzwl %ax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
movzwl -0x1a(%rbp),%ecx
movb   $0x2e,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
movzwl -0x1a(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x6c,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
movzwl -0x1a(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x6d,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
movzwl -0x1a(%rbp),%ecx
add    $0x3,%ecx
movslq %ecx,%rcx
movb   $0x64,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
movzwl -0x1a(%rbp),%ecx
add    $0x4,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addLmdExtension>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
movzwl %ax,%eax
cmpb   $0x2e,-0x4(%rax,%r14,1)
mov    %eax,%r15d
jne    1163 <addLmdExtension+0x33>
cmpb   $0x6c,-0x3(%r15,%r14,1)
jne    1163 <addLmdExtension+0x33>
cmpb   $0x6d,-0x2(%r15,%r14,1)
jne    1163 <addLmdExtension+0x33>
cmpb   $0x64,-0x1(%r15,%r14,1)
je     118d <addLmdExtension+0x5d>
add    $0x5,%eax
movzwl %ax,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
movl   $0x646d6c2e,(%rbx,%r15,1)
64
movb   $0x0,0x4(%rbx,%r15,1)
mov    %rbx,%r14
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @addLmdExtension(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i16
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call zeroext i16 @strlen(i8* %6)
store i16 %7, i16* %5
%8 = load i8*, i8** %3
%9 = load i16, i16* %5
%10 = zext i16 %9 to i32
%11 = sub nsw i32 %10, 4
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %8, i64 %12
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 46
br i1 %16, label %17, label %49
17: ; preds = %1
%18 = load i8*, i8** %3
%19 = load i16, i16* %5
%20 = zext i16 %19 to i32
%21 = sub nsw i32 %20, 3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %18, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 108
br i1 %26, label %27, label %49
27: ; preds = %17
%28 = load i8*, i8** %3
%29 = load i16, i16* %5
%30 = zext i16 %29 to i32
%31 = sub nsw i32 %30, 2
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %28, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 109
br i1 %36, label %37, label %49
37: ; preds = %27
%38 = load i8*, i8** %3
%39 = load i16, i16* %5
%40 = zext i16 %39 to i32
%41 = sub nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %38, i64 %42
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %45, 100
br i1 %46, label %47, label %49
47: ; preds = %37
%48 = load i8*, i8** %3
store i8* %48, i8** %2
br label %89
49: ; preds = %37, %27, %17, %1
%50 = load i16, i16* %5
%51 = zext i16 %50 to i32
%52 = add nsw i32 %51, 5
%53 = sext i32 %52 to i64
%54 = mul i64 %53, 1
%55 = trunc i64 %54 to i16
%56 = call i8* @malloc(i16 zeroext %55)
store i8* %56, i8** %4
%57 = load i8*, i8** %4
%58 = load i8*, i8** %3
%59 = call i32 @strcpy(i8* %57, i8* %58)
%60 = load i8*, i8** %4
%61 = load i16, i16* %5
%62 = zext i16 %61 to i64
%63 = getelementptr inbounds i8, i8* %60, i64 %62
store i8 46, i8* %63
%64 = load i8*, i8** %4
%65 = load i16, i16* %5
%66 = zext i16 %65 to i32
%67 = add nsw i32 %66, 1
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %64, i64 %68
store i8 108, i8* %69
%70 = load i8*, i8** %4
%71 = load i16, i16* %5
%72 = zext i16 %71 to i32
%73 = add nsw i32 %72, 2
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8, i8* %70, i64 %74
store i8 109, i8* %75
%76 = load i8*, i8** %4
%77 = load i16, i16* %5
%78 = zext i16 %77 to i32
%79 = add nsw i32 %78, 3
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i8, i8* %76, i64 %80
store i8 100, i8* %81
%82 = load i8*, i8** %4
%83 = load i16, i16* %5
%84 = zext i16 %83 to i32
%85 = add nsw i32 %84, 4
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds i8, i8* %82, i64 %86
store i8 0, i8* %87
%88 = load i8*, i8** %4
store i8* %88, i8** %2
br label %89
89: ; preds = %49, %47
%90 = load i8*, i8** %2
ret i8* %90
}

LLVM IR (-O2):
define i8* @addLmdExtension(i8* %0) {
%2 = tail call zeroext i16 @strlen(i8* %0)
%3 = zext i16 %2 to i32
%4 = add nsw i32 %3, -4
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 46
br i1 %8, label %9, label %27
9: ; preds = %1
%10 = add nsw i32 %3, -3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 108
br i1 %14, label %15, label %27
15: ; preds = %9
%16 = add nsw i32 %3, -2
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 109
br i1 %20, label %21, label %27
21: ; preds = %15
%22 = add nsw i32 %3, -1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %0, i64 %23
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 100
br i1 %26, label %45, label %27
27: ; preds = %21, %15, %9, %1
%28 = add i16 %2, 5
%29 = tail call i8* @malloc(i16 zeroext %28)
%30 = tail call i32 @strcpy(i8* %29, i8* %0)
%31 = zext i16 %2 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8 46, i8* %32
%33 = add nuw nsw i32 %3, 1
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %29, i64 %34
store i8 108, i8* %35
%36 = add nuw nsw i32 %3, 2
%37 = zext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %29, i64 %37
store i8 109, i8* %38
%39 = add nuw nsw i32 %3, 3
%40 = zext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %29, i64 %40
store i8 100, i8* %41
%42 = add nuw nsw i32 %3, 4
%43 = zext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %29, i64 %43
store i8 0, i8* %44
br label %45
45: ; preds = %21, %27
%46 = phi i8* [ %29, %27 ], [ %0, %21 ]
ret i8* %46
}