#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 */
unsigned char computeNameChecksum(unsigned char *);
int getDirentrySize(unsigned char *);
int /*<<< orphan*/ setLfnEntry(unsigned char *, int, unsigned char,
                               unsigned char *, int, int);
int /*<<< orphan*/ setSfnEntry(unsigned char *, char, unsigned char *,
                               unsigned int);
int strlen(char const *);
int createDirentry(unsigned char *lname, unsigned char *sname, char directory,
                   unsigned int cluster, unsigned char *buffer) {
  int i;
  int lsize;
  int nameSize;
  unsigned char chsum;
  lsize = getDirentrySize(lname) - 1;
  chsum = computeNameChecksum(sname);
  nameSize = strlen((const char *)lname);
  for (i = 0; i <= lsize; i++) {
    setLfnEntry(lname, nameSize, chsum, buffer, lsize - i, lsize);
  }
  lsize++;
  setSfnEntry(sname, directory, buffer + (lsize * 32), cluster);
  return lsize + 1;
}


x86 assembly (clang, -O0):
<createDirentry>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <getDirentrySize@plt>
sub    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <computeNameChecksum@plt>
mov    %al,-0x2d(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jg     11d6 <createDirentry+0x86>
mov    -0x8(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x2d(%rbp),%al
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8d
sub    -0x24(%rbp),%r8d
mov    -0x28(%rbp),%r9d
movzbl %al,%edx
call   1070 <setLfnEntry@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    119a <createDirentry+0x4a>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x11(%rbp),%al
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%ecx
shl    $0x5,%ecx
movslq %ecx,%rcx
add    %rcx,%rdx
mov    -0x18(%rbp),%ecx
movsbl %al,%esi
call   1050 <setSfnEntry@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createDirentry>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%rbx
mov    %ecx,0x4(%rsp)
mov    %edx,(%rsp)
mov    %rsi,%r14
mov    %rdi,%rbp
call   1060 <getDirentrySize@plt>
mov    %eax,%r12d
mov    %r14,0x10(%rsp)
mov    %r14,%rdi
call   1030 <computeNameChecksum@plt>
mov    %eax,%r15d
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %r12,0x8(%rsp)
test   %r12d,%r12d
jle    11cd <createDirentry+0x7d>
mov    %eax,%r14d
mov    0x8(%rsp),%rax
lea    -0x1(%rax),%r13d
movzbl %r15b,%r15d
mov    %r13d,%r12d
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %r14d,%esi
mov    %r15d,%edx
mov    %rbx,%rcx
mov    %r12d,%r8d
mov    %r13d,%r9d
call   1070 <setLfnEntry@plt>
add    $0xffffffff,%r12d
jb     11b0 <createDirentry+0x60>
mov    0x8(%rsp),%rbp
mov    %ebp,%eax
shl    $0x5,%eax
cltq
add    %rax,%rbx
movsbl (%rsp),%esi
mov    0x10(%rsp),%rdi
mov    %rbx,%rdx
mov    0x4(%rsp),%ecx
call   1050 <setSfnEntry@plt>
add    $0x1,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @createDirentry(i8* %0, i8* %1, i8 signext %2, i32 %3, i8* %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8 %2, i8* %8
store i32 %3, i32* %9
store i8* %4, i8** %10
%15 = load i8*, i8** %6
%16 = call i32 @getDirentrySize(i8* %15)
%17 = sub nsw i32 %16, 1
store i32 %17, i32* %12
%18 = load i8*, i8** %7
%19 = call zeroext i8 @computeNameChecksum(i8* %18)
store i8 %19, i8* %14
%20 = load i8*, i8** %6
%21 = call i32 @strlen(i8* %20)
store i32 %21, i32* %13
store i32 0, i32* %11
br label %22
22: ; preds = %36, %5
%23 = load i32, i32* %11
%24 = load i32, i32* %12
%25 = icmp sle i32 %23, %24
br i1 %25, label %26, label %39
26: ; preds = %22
%27 = load i8*, i8** %6
%28 = load i32, i32* %13
%29 = load i8, i8* %14
%30 = load i8*, i8** %10
%31 = load i32, i32* %12
%32 = load i32, i32* %11
%33 = sub nsw i32 %31, %32
%34 = load i32, i32* %12
%35 = call i32 @setLfnEntry(i8* %27, i32 %28, i8 zeroext %29, i8* %30, i32 %33, i32 %34)
br label %36
36: ; preds = %26
%37 = load i32, i32* %11
%38 = add nsw i32 %37, 1
store i32 %38, i32* %11
br label %22
39: ; preds = %22
%40 = load i32, i32* %12
%41 = add nsw i32 %40, 1
store i32 %41, i32* %12
%42 = load i8*, i8** %7
%43 = load i8, i8* %8
%44 = load i8*, i8** %10
%45 = load i32, i32* %12
%46 = mul nsw i32 %45, 32
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %44, i64 %47
%49 = load i32, i32* %9
%50 = call i32 @setSfnEntry(i8* %42, i8 signext %43, i8* %48, i32 %49)
%51 = load i32, i32* %12
%52 = add nsw i32 %51, 1
ret i32 %52
}

LLVM IR (-O2):
define i32 @createDirentry(i8* %0, i8* %1, i8 signext %2, i32 %3, i8* %4) {
%6 = tail call i32 @getDirentrySize(i8* %0)
%7 = add nsw i32 %6, -1
%8 = tail call zeroext i8 @computeNameChecksum(i8* %1)
%9 = tail call i32 @strlen(i8* %0)
%10 = icmp sgt i32 %6, 0
br i1 %10, label %11, label %17
11: ; preds = %5, %11
%12 = phi i32 [ %15, %11 ], [ 0, %5 ]
%13 = sub nsw i32 %7, %12
%14 = tail call i32 @setLfnEntry(i8* %0, i32 %9, i8 zeroext %8, i8* %4, i32 %13, i32 %7)
%15 = add nuw nsw i32 %12, 1
%16 = icmp eq i32 %15, %6
br i1 %16, label %17, label %11
17: ; preds = %11, %5
%18 = shl nsw i32 %6, 5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %4, i64 %19
%21 = tail call i32 @setSfnEntry(i8* %1, i8 signext %2, i8* %20, i32 %3)
%22 = add nsw i32 %6, 1
ret i32 %22
}